@lynn123411/dsh-kimi-cu 0.1.3 → 0.2.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/DETAILS.md +58 -38
- package/README.md +16 -13
- package/cordis.patch.yml +25 -23
- package/lib/client.js +281 -0
- package/lib/client.js.map +7 -0
- package/lib/index.js +387 -0
- package/lib/index.js.map +7 -0
- package/locale/en.json +2 -2
- package/locale/zh.json +1 -1
- package/package.json +57 -13
- package/scripts/assert-lib-untracked.mjs +21 -0
- package/scripts/check-bundle.mjs +149 -120
- package/scripts/lib/client-bundle.mjs +40 -0
- package/scripts/smoke-client.mjs +124 -0
- package/scripts/smoke-host.mjs +102 -0
- package/scripts/test-card.mjs +249 -0
- package/scripts/test-status.mjs +296 -0
- package/skills/{kimi-cu → macos/kimi-cu}/SKILL.md +2 -0
- package/skills/windows/kimi-cu/SKILL.md +76 -0
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynn123411/dsh-kimi-cu",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "接上本机 KimiCU
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "接上本机 KimiCU(macOS / Windows):把它的 mcp 服务挂成 mcp__kimi-cu__* 工具,随包带操作技能,并在插件页给出安装检测与引导。",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
6
7
|
"exports": {
|
|
7
|
-
"
|
|
8
|
+
".": "./lib/index.js",
|
|
9
|
+
"./client": "./lib/client.js",
|
|
8
10
|
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
9
11
|
"./locale/en.json": "./locale/en.json",
|
|
10
|
-
"./locale/zh.json": "./locale/zh.json"
|
|
12
|
+
"./locale/zh.json": "./locale/zh.json",
|
|
13
|
+
"./package.json": "./package.json"
|
|
11
14
|
},
|
|
12
15
|
"files": [
|
|
16
|
+
"lib",
|
|
13
17
|
"cordis.patch.yml",
|
|
14
18
|
"skills",
|
|
15
19
|
"locale",
|
|
@@ -25,7 +29,8 @@
|
|
|
25
29
|
"dsh-plugin",
|
|
26
30
|
"cordis",
|
|
27
31
|
"mcp",
|
|
28
|
-
"kimi-cu"
|
|
32
|
+
"kimi-cu",
|
|
33
|
+
"computer-use"
|
|
29
34
|
],
|
|
30
35
|
"repository": {
|
|
31
36
|
"type": "git",
|
|
@@ -33,21 +38,60 @@
|
|
|
33
38
|
"directory": "plugins/dsh-kimi-cu"
|
|
34
39
|
},
|
|
35
40
|
"scripts": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
41
|
+
"build": "node build.mjs",
|
|
42
|
+
"prepack": "pnpm run build",
|
|
43
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
44
|
+
"test": "node build.mjs && node scripts/smoke-host.mjs && node scripts/smoke-client.mjs && node scripts/test-status.mjs && node scripts/test-card.mjs",
|
|
45
|
+
"assert:lib-untracked": "node scripts/assert-lib-untracked.mjs",
|
|
46
|
+
"check": "pnpm typecheck && pnpm test && pnpm assert:lib-untracked && node scripts/check-bundle.mjs && node ../../tools/probes/preset-skills.mjs --skills skills/macos && node ../../tools/probes/preset-skills.mjs --skills skills/windows"
|
|
47
|
+
},
|
|
48
|
+
"dsh": {
|
|
49
|
+
"bundle": {
|
|
50
|
+
"patch": "./cordis.patch.yml"
|
|
51
|
+
},
|
|
52
|
+
"client": {
|
|
53
|
+
"platform": "web",
|
|
54
|
+
"inject": [
|
|
55
|
+
"@deepseek-ai/dsh-client-locale",
|
|
56
|
+
"@deepseek-ai/dsh-client-ui-primitives",
|
|
57
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager",
|
|
58
|
+
"@deepseek-ai/dsh-client-ui-renderer"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
64
|
+
"@deepseek-ai/dsh-client-connection": ">=0.2.2-rc.2",
|
|
65
|
+
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.2-rc.2",
|
|
66
|
+
"@deepseek-ai/dsh-tools": ">=0.2.2-rc.2",
|
|
67
|
+
"react": "^18.2.0"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
71
|
+
"@deepseek-ai/dsh-client-connection": ">=0.2.2-rc.2",
|
|
72
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.2-rc.2",
|
|
73
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.2-rc.2",
|
|
74
|
+
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.2-rc.2",
|
|
75
|
+
"@deepseek-ai/dsh-client-ui-renderer": ">=0.2.2-rc.2",
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.2-rc.2",
|
|
77
|
+
"@deepseek-ai/dsh-system-prompt": ">=0.2.2-rc.2",
|
|
78
|
+
"@deepseek-ai/dsh-tools": ">=0.2.2-rc.2",
|
|
79
|
+
"@types/node": "^22.20.0",
|
|
80
|
+
"@types/react": "^19.2.18",
|
|
81
|
+
"@types/react-dom": "^19.3.0",
|
|
82
|
+
"esbuild": "^0.25.0",
|
|
83
|
+
"jsdom": "^26.1.0",
|
|
84
|
+
"react": "^18.3.1",
|
|
85
|
+
"react-dom": "^18.3.1",
|
|
86
|
+
"typescript": "^6.0.0"
|
|
38
87
|
},
|
|
39
88
|
"engines": {
|
|
40
|
-
"dsh": ">=0.2.2-rc.
|
|
89
|
+
"dsh": ">=0.2.2-rc.2",
|
|
41
90
|
"node": "^22.19 || >=24"
|
|
42
91
|
},
|
|
43
92
|
"packageManager": "pnpm@11.7.0",
|
|
44
93
|
"publishConfig": {
|
|
45
94
|
"access": "public"
|
|
46
95
|
},
|
|
47
|
-
"dsh": {
|
|
48
|
-
"bundle": {
|
|
49
|
-
"patch": "./cordis.patch.yml"
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
96
|
"icon": "./assets/icon.svg"
|
|
53
97
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 产物门禁:`lib/` 是 `src/` 的构建镜像,不许入 git(见 docs/rules/release.md「产物与清单」)。
|
|
3
|
+
* index 里还列着 lib/ 下任何文件就失败。
|
|
4
|
+
*
|
|
5
|
+
* 运行:node scripts/assert-lib-untracked.mjs [plugin-dir]
|
|
6
|
+
*/
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
8
|
+
import { dirname, join, resolve } from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const root = resolve(process.argv[2] ?? join(dirname(fileURLToPath(import.meta.url)), '..'));
|
|
12
|
+
const tracked = execFileSync('git', ['ls-files', 'lib'], { cwd: root, encoding: 'utf8' })
|
|
13
|
+
.split('\n')
|
|
14
|
+
.filter((line) => line.length > 0);
|
|
15
|
+
|
|
16
|
+
if (tracked.length > 0) {
|
|
17
|
+
console.error('assert-lib-untracked: lib/ 是构建镜像,不能入 git:');
|
|
18
|
+
for (const path of tracked) console.error(` ${path}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
console.log('assert-lib-untracked: ok(lib/ 下无跟踪文件)');
|
package/scripts/check-bundle.mjs
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* 包内自检:这个 bundle 装上之后,patch
|
|
3
|
+
* 包内自检:这个 bundle 装上之后,patch 里那五行真的各就各位,平台分流与技能目录都对。
|
|
4
4
|
*
|
|
5
5
|
* 三层断言,越往下越贴近真实装载:
|
|
6
|
-
* 1.
|
|
7
|
-
*
|
|
8
|
-
* 2. 文本面:patch
|
|
9
|
-
*
|
|
10
|
-
* 3. 契约面(本机装了内核才有):拿内核自带 include 的
|
|
11
|
-
* YAML 方言——读这份 patch
|
|
12
|
-
*
|
|
6
|
+
* 1. 清单面:files 点名的都在、bundle patch 指得到、exports 与 main 都在、dsh.client 声明了
|
|
7
|
+
* web 与四个契约包、两个语言的标题与说明齐备、两份技能的 frontmatter 合规。
|
|
8
|
+
* 2. 文本面:patch 只插五行、id 与内核包名对、四条平台行各带自己的守卫、macOS/Windows 两条
|
|
9
|
+
* MCP 行的命令与参数分开、两条技能行各扫自己的目录。这一层不需要内核,CI 上照跑。
|
|
10
|
+
* 3. 契约面(本机装了内核才有):拿内核自带 include 的 entryListSchema——就是装载时用的那份
|
|
11
|
+
* YAML 方言——读这份 patch,再把两条 MCP 行与两条技能行的 config 交给内核包的真 Config
|
|
12
|
+
* schema 校验;Windows 那条用假的 process 求值,并断言结果与 resolveInstall 一致。
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* 随包技能能不能被真发现与真装载不在这里:那是 `tools/probes/preset-skills.mjs` 的事,`check` 里紧接
|
|
18
|
-
* 着跑它。
|
|
14
|
+
* 随包技能能不能被真发现与真装载不在这里:那是 tools/probes/preset-skills.mjs 的事,check 里
|
|
15
|
+
* 对两个技能根各跑一次。
|
|
19
16
|
*
|
|
20
17
|
* 跑法:pnpm check / node scripts/check-bundle.mjs
|
|
21
18
|
* 退出码:0 通过(含明说跳过),1 不通过。
|
|
@@ -23,15 +20,18 @@
|
|
|
23
20
|
import assert from 'node:assert/strict';
|
|
24
21
|
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
25
22
|
import { createRequire } from 'node:module';
|
|
26
|
-
import { join, resolve } from 'node:path';
|
|
23
|
+
import { dirname, join, resolve } from 'node:path';
|
|
27
24
|
import { pathToFileURL } from 'node:url';
|
|
28
25
|
|
|
29
26
|
import { currentKernel } from '../../../tools/lib/repo.mjs';
|
|
27
|
+
import { resolveInstall } from '../src/server/resolve.ts';
|
|
30
28
|
|
|
31
29
|
const PACKAGE_NAME = '@lynn123411/dsh-kimi-cu';
|
|
32
|
-
const
|
|
30
|
+
const MACOS_BINARY = '/Applications/KimiCU.app/Contents/MacOS/kimi-cu';
|
|
33
31
|
const MACOS_GUARD = "process.platform !== 'darwin'";
|
|
34
|
-
const
|
|
32
|
+
const WINDOWS_GUARD = "process.platform !== 'win32'";
|
|
33
|
+
const ROW_IDS = ['dsh-kimi-cu', 'skill-kimi-cu-macos', 'skill-kimi-cu-windows'];
|
|
34
|
+
const SKILL_DIRS = { 'skill-kimi-cu-macos': 'macos', 'skill-kimi-cu-windows': 'windows' };
|
|
35
35
|
|
|
36
36
|
const packageDir = resolve(import.meta.dirname, '..');
|
|
37
37
|
const manifest = JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf8'));
|
|
@@ -41,9 +41,9 @@ let total = 0;
|
|
|
41
41
|
const skipped = [];
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
44
|
+
* 跑一条断言;同步与异步的断言共用一条路径(await 一个同步返回值是空操作)。
|
|
45
|
+
* @param label - 这条断言在说什么。
|
|
46
|
+
* @param fn - 断言本体,靠 node:assert 抛错。
|
|
47
47
|
* @returns {Promise<void>}
|
|
48
48
|
*/
|
|
49
49
|
async function test(label, fn) {
|
|
@@ -51,120 +51,158 @@ async function test(label, fn) {
|
|
|
51
51
|
try {
|
|
52
52
|
await fn();
|
|
53
53
|
} catch (error) {
|
|
54
|
-
console.error(
|
|
54
|
+
console.error(' FAIL ' + label);
|
|
55
55
|
throw error;
|
|
56
56
|
}
|
|
57
57
|
passed += 1;
|
|
58
|
-
console.log(
|
|
58
|
+
console.log(' ok ' + label);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* 明说跳过一条要内核才能跑的断言——「没跑」不能被读成「通过」。
|
|
63
|
-
* @param
|
|
64
|
-
* @param
|
|
63
|
+
* @param label - 跳过的是哪条。
|
|
64
|
+
* @param why - 为什么跑不了。
|
|
65
65
|
* @returns {void}
|
|
66
66
|
*/
|
|
67
67
|
function skip(label, why) {
|
|
68
68
|
skipped.push({ label, why });
|
|
69
|
-
console.log(
|
|
69
|
+
console.log(' skip ' + label + '(' + why + ')');
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
// ── 1. 清单面 ─────────────────────────────────────────────────────────────────
|
|
73
73
|
await test('bundle patch 指得到,files 点名的条目都在', () => {
|
|
74
74
|
const declared = manifest.dsh?.bundle?.patch;
|
|
75
75
|
assert.equal(typeof declared, 'string', 'package.json 缺 dsh.bundle.patch');
|
|
76
|
-
assert.ok(existsSync(join(packageDir, declared)),
|
|
77
|
-
for (const
|
|
78
|
-
|
|
79
|
-
assert.ok(existsSync(join(packageDir, probe)), `files 里的 ${pattern} 在目录里不存在`);
|
|
76
|
+
assert.ok(existsSync(join(packageDir, declared)), 'dsh.bundle.patch 指的 ' + declared + ' 不存在');
|
|
77
|
+
for (const entry of manifest.files) {
|
|
78
|
+
assert.ok(existsSync(join(packageDir, entry)), 'files 里的 ' + entry + ' 在目录里不存在');
|
|
80
79
|
}
|
|
81
80
|
});
|
|
82
81
|
|
|
83
82
|
const patchText = readFileSync(join(packageDir, manifest.dsh.bundle.patch), 'utf8');
|
|
84
83
|
|
|
85
|
-
await test('exports
|
|
84
|
+
await test('exports 的每个子路径都解析得到,main 与 client 都在', () => {
|
|
86
85
|
for (const [subpath, target] of Object.entries(manifest.exports)) {
|
|
87
|
-
assert.ok(existsSync(join(packageDir, target)),
|
|
86
|
+
assert.ok(existsSync(join(packageDir, target)), 'exports 的 ' + subpath + ' 指向 ' + target + ',文件不存在');
|
|
88
87
|
}
|
|
88
|
+
assert.equal(manifest.main, 'lib/index.js');
|
|
89
|
+
assert.ok(existsSync(join(packageDir, manifest.main)), 'main 指的产物不存在');
|
|
90
|
+
assert.ok(existsSync(join(packageDir, 'lib/client.js')), '浏览器半边的产物不存在');
|
|
89
91
|
assert.equal(manifest.icon, './assets/icon.svg');
|
|
90
92
|
assert.ok(existsSync(join(packageDir, 'assets/icon.svg')), 'package.json 的 icon 指的图标不存在');
|
|
91
93
|
});
|
|
92
94
|
|
|
95
|
+
await test('dsh.client 声明了 web 与四个契约包', () => {
|
|
96
|
+
assert.equal(manifest.dsh?.client?.platform, 'web');
|
|
97
|
+
const inject = manifest.dsh?.client?.inject ?? [];
|
|
98
|
+
for (const name of [
|
|
99
|
+
'@deepseek-ai/dsh-client-locale',
|
|
100
|
+
'@deepseek-ai/dsh-client-ui-primitives',
|
|
101
|
+
'@deepseek-ai/dsh-client-ui-plugin-manager',
|
|
102
|
+
'@deepseek-ai/dsh-client-ui-renderer',
|
|
103
|
+
]) {
|
|
104
|
+
assert.ok(inject.includes(name), 'dsh.client.inject 缺 ' + name);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
93
108
|
await test('两个语言都给了标题与说明——插件页的卡片靠它们', () => {
|
|
94
109
|
for (const lang of ['en', 'zh']) {
|
|
95
|
-
const locale = JSON.parse(readFileSync(join(packageDir, 'locale',
|
|
96
|
-
assert.ok(locale.meta?.title,
|
|
97
|
-
assert.ok(locale.meta?.description,
|
|
110
|
+
const locale = JSON.parse(readFileSync(join(packageDir, 'locale', lang + '.json'), 'utf8'));
|
|
111
|
+
assert.ok(locale.meta?.title, 'locale/' + lang + '.json 缺 meta.title,卡片会退回包名');
|
|
112
|
+
assert.ok(locale.meta?.description, 'locale/' + lang + '.json 缺 meta.description,卡片会退回 package.json 的描述');
|
|
98
113
|
}
|
|
99
114
|
});
|
|
100
115
|
|
|
101
|
-
await test('
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
116
|
+
await test('两份技能都在,frontmatter 的 name 与目录名一致且带描述', () => {
|
|
117
|
+
for (const dir of ['macos', 'windows']) {
|
|
118
|
+
const skillFile = join(packageDir, 'skills', dir, 'kimi-cu', 'SKILL.md');
|
|
119
|
+
assert.ok(existsSync(skillFile), 'skills/' + dir + '/kimi-cu/SKILL.md 不存在');
|
|
120
|
+
const block = /^---\r?\n([\s\S]*?)\r?\n---/.exec(readFileSync(skillFile, 'utf8'));
|
|
121
|
+
assert.ok(block, dir + ' 的 SKILL.md 必须以 YAML frontmatter 开头,否则技能发现会静默丢掉它');
|
|
122
|
+
assert.equal(/^name:\s*(.+)$/m.exec(block[1])?.[1].trim(), 'kimi-cu', dir + ' 的 frontmatter name 要与目录名一致');
|
|
123
|
+
assert.ok(/^description:\s*\S/m.test(block[1]), dir + ' 的 frontmatter 缺 description');
|
|
124
|
+
}
|
|
108
125
|
});
|
|
109
126
|
|
|
110
127
|
// ── 2. 文本面 ─────────────────────────────────────────────────────────────────
|
|
111
|
-
await test('patch
|
|
128
|
+
await test('patch 只插三行,id 就是约定的那三个', () => {
|
|
112
129
|
const ids = [...patchText.matchAll(/^\s*-\s*id:\s*(\S+)\s*$/gm)].map((match) => match[1]);
|
|
113
|
-
assert.deepEqual([...ids].sort(), [...ROW_IDS].sort(), 'patch
|
|
114
|
-
assert.
|
|
115
|
-
assert.match(patchText, /name: '@deepseek-ai\/dsh-skill-filesystem'/, '
|
|
130
|
+
assert.deepEqual([...ids].sort(), [...ROW_IDS].sort(), 'patch 里该有的行只有这三条,多一条就说明装配形状变了');
|
|
131
|
+
assert.equal(patchText.includes('dsh-mcp-client'), false, 'MCP 连接改由宿主半边注册,patch 里不该再有静态行');
|
|
132
|
+
assert.match(patchText, /name: '@deepseek-ai\/dsh-skill-filesystem'/, '技能行要挂内核的 skill-filesystem');
|
|
116
133
|
});
|
|
117
134
|
|
|
118
|
-
await test('
|
|
135
|
+
await test('两条平台行各带自己的守卫,根层行没有守卫', () => {
|
|
119
136
|
const guards = [...patchText.matchAll(/^\s*disabled:\s*(.+)$/gm)].map((match) => match[1].trim());
|
|
120
|
-
assert.equal(guards.length, 2, '
|
|
121
|
-
|
|
122
|
-
assert.equal(guard, `!!js ${MACOS_GUARD}`, `守卫要写成 !!js ${MACOS_GUARD},现为 ${guard}`);
|
|
123
|
-
}
|
|
137
|
+
assert.equal(guards.length, 2, '只有两条平台行需要 disabled 守卫');
|
|
138
|
+
assert.deepEqual([...guards].sort(), ['!!js ' + MACOS_GUARD, '!!js ' + WINDOWS_GUARD].sort());
|
|
124
139
|
});
|
|
125
140
|
|
|
126
|
-
|
|
141
|
+
await test('MCP 连接由宿主半边注册给 mcpManager,命令取自探测器', () => {
|
|
142
|
+
const source = readFileSync(join(packageDir, 'src', 'index.ts'), 'utf8');
|
|
143
|
+
assert.match(source, /ctx\.inject\(\['mcpManager'\]/, '管理器走可选注入,没有它插件照常加载');
|
|
144
|
+
assert.match(source, /mcpManager\.register\(MCP_SERVER_NAME/, '要注册到管理器,而不是自己起一条 mcp-client');
|
|
145
|
+
assert.match(source, /command: status\.mcp\.command/, '命令必须取自探测器,与状态卡、工具同源');
|
|
146
|
+
assert.match(source, /args: status\.mcp\.args/, '参数同样取自探测器');
|
|
147
|
+
const timeout = Number(/MCP_TOOL_TIMEOUT_MS = ([\d_]+)/.exec(source)?.[1].replaceAll('_', ''));
|
|
148
|
+
assert.ok(timeout >= 120000, '工具调用上限要覆盖长任务,现为 ' + timeout);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 取某一行在 patch 文本里的那一段(到下一行 id 或文件末尾)。
|
|
153
|
+
* @param id - 行 id。
|
|
154
|
+
* @returns 该行的文本。
|
|
155
|
+
*/
|
|
127
156
|
function rowBlock(id) {
|
|
128
|
-
const start = patchText.indexOf(
|
|
129
|
-
assert.ok(start !== -1,
|
|
130
|
-
const nextId = ROW_IDS.map((other) => patchText.indexOf(
|
|
157
|
+
const start = patchText.indexOf('id: ' + id);
|
|
158
|
+
assert.ok(start !== -1, 'patch 里找不到 ' + id + ' 行');
|
|
159
|
+
const nextId = ROW_IDS.map((other) => patchText.indexOf('id: ' + other, start + 1)).filter((at) => at > start);
|
|
131
160
|
return patchText.slice(start, nextId.length === 0 ? undefined : Math.min(...nextId));
|
|
132
161
|
}
|
|
133
162
|
|
|
134
|
-
await test('
|
|
135
|
-
const block = rowBlock('
|
|
136
|
-
assert.
|
|
137
|
-
assert.
|
|
138
|
-
assert.match(block, new RegExp(`command: ${KIMI_CU_BINARY.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`), 'KimiCU 的命令行在 app 包里,不是 PATH 上的命令');
|
|
139
|
-
assert.match(block, /failOnStartupError: true/, '缺装 KimiCU 时要当场报错,而不是静默少掉一排工具');
|
|
163
|
+
await test('根层行挂本包,不带平台守卫', () => {
|
|
164
|
+
const block = rowBlock('dsh-kimi-cu');
|
|
165
|
+
assert.ok(block.includes("name: '" + PACKAGE_NAME + "'"), '根层行要挂本包');
|
|
166
|
+
assert.doesNotMatch(block, /disabled:/, '根层行在别的平台上也要加载,卡片负责说明不支持');
|
|
140
167
|
});
|
|
141
168
|
|
|
142
|
-
await test('MCP
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
assert.
|
|
169
|
+
await test('探测器给出的 MCP 命令就是各平台的真实路径', () => {
|
|
170
|
+
const mac = resolveInstall({ platform: 'darwin', env: {}, exists: (path) => path === MACOS_BINARY });
|
|
171
|
+
assert.equal(mac.mcp.command, MACOS_BINARY, 'KimiCU 的命令行在 app 包里,不是 PATH 上的命令');
|
|
172
|
+
assert.deepEqual(mac.mcp.args, ['mcp', '-s', 'user'], 'macOS 的 MCP 需要 -s user');
|
|
173
|
+
const win = resolveInstall({
|
|
174
|
+
platform: 'win32',
|
|
175
|
+
env: { LOCALAPPDATA: 'C:\\Users\\t\\AppData\\Local' },
|
|
176
|
+
exists: () => false,
|
|
177
|
+
});
|
|
178
|
+
assert.equal(win.mcp.command, 'C:\\Users\\t\\AppData\\Local\\Kimi Computer Use\\kimi-cu.exe');
|
|
179
|
+
assert.deepEqual(win.mcp.args, ['mcp'], 'Windows 的 MCP 只传 mcp');
|
|
180
|
+
const other = resolveInstall({ platform: 'linux', env: {}, exists: () => false });
|
|
181
|
+
assert.equal(other.mcp, null, '不受支持的平台上探测器给 null,宿主半边就不注册');
|
|
146
182
|
});
|
|
147
183
|
|
|
148
|
-
await test('
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
184
|
+
await test('两条技能行另取 providerName、关掉默认目录,各扫自己的目录', () => {
|
|
185
|
+
for (const [id, dir] of Object.entries(SKILL_DIRS)) {
|
|
186
|
+
const block = rowBlock(id);
|
|
187
|
+
assert.ok(block.includes('providerName: kimi-cu'), id + ' 不另取名就会与内核那条默认技能行同名');
|
|
188
|
+
assert.ok(block.includes('includeDefaultRoots: false'), id + ' 不该重复扫项目与用户技能目录');
|
|
189
|
+
assert.ok(block.includes("'skills', '" + dir + "'"), id + ' 要扫 skills/' + dir);
|
|
190
|
+
assert.ok(block.includes("createRequire(baseUrl).resolve('" + PACKAGE_NAME + "/package.json')"), id + ' 的技能目录要按包名解析');
|
|
191
|
+
}
|
|
154
192
|
});
|
|
155
193
|
|
|
156
194
|
// ── 3. 契约面(要本机已装内核) ────────────────────────────────────────────────
|
|
157
195
|
/**
|
|
158
196
|
* 在内核安装树的包仓里找某个包的真实目录。
|
|
159
|
-
* @param
|
|
160
|
-
* @param
|
|
161
|
-
* @returns
|
|
197
|
+
* @param kernel - 内核安装树。
|
|
198
|
+
* @param name - 包名,例如 @deepseek-ai/dsh-mcp-client。
|
|
199
|
+
* @returns 包目录;没装就是 undefined。
|
|
162
200
|
*/
|
|
163
201
|
function kernelPackageDir(kernel, name) {
|
|
164
202
|
const store = join(kernel.dir, 'node_modules/.pnpm');
|
|
165
203
|
if (!existsSync(store)) return undefined;
|
|
166
204
|
for (const entry of readdirSync(store)) {
|
|
167
|
-
if (!entry.startsWith(
|
|
205
|
+
if (!entry.startsWith(name.replace('/', '+') + '@')) continue;
|
|
168
206
|
const candidate = join(store, entry, 'node_modules', name);
|
|
169
207
|
if (existsSync(join(candidate, 'package.json'))) return candidate;
|
|
170
208
|
}
|
|
@@ -172,33 +210,42 @@ function kernelPackageDir(kernel, name) {
|
|
|
172
210
|
}
|
|
173
211
|
|
|
174
212
|
/**
|
|
175
|
-
* 照 Loader 的方式求值一条
|
|
176
|
-
* @param
|
|
177
|
-
* @param
|
|
178
|
-
* @
|
|
213
|
+
* 照 Loader 的方式求值一条 !!js 表达式:作用域里有 baseUrl 与 process。
|
|
214
|
+
* @param expression - 表达式原文。
|
|
215
|
+
* @param baseUrl - 装载该行的目录(file URL)。
|
|
216
|
+
* @param processScope - process 替身;默认真 process。
|
|
217
|
+
* @returns 求值结果。
|
|
179
218
|
*/
|
|
180
|
-
function evaluateExpression(expression, baseUrl) {
|
|
219
|
+
function evaluateExpression(expression, baseUrl, processScope = process) {
|
|
181
220
|
const evaluate = new Function('scope', 'expression', 'with (scope) { return eval(expression) }');
|
|
182
|
-
return evaluate({ baseUrl, process }, expression);
|
|
221
|
+
return evaluate({ baseUrl, process: processScope }, expression);
|
|
183
222
|
}
|
|
184
223
|
|
|
185
224
|
const contractLabels = [
|
|
186
225
|
'patch 能被内核装载时用的那份 YAML 方言读懂',
|
|
187
|
-
'MCP
|
|
188
|
-
'
|
|
226
|
+
'macOS MCP 行的 config 通过内核 mcp-client 的真 Config schema',
|
|
227
|
+
'Windows MCP 行的 config 通过内核 mcp-client 的真 Config schema,且与 resolveInstall 一致',
|
|
228
|
+
'两条技能行的 config 通过内核 skill-filesystem 的真 Config schema,表达式落回对应目录',
|
|
189
229
|
];
|
|
190
230
|
|
|
191
|
-
/**
|
|
231
|
+
/**
|
|
232
|
+
* 本机内核,取不到就 undefined。
|
|
233
|
+
* @returns 内核安装树或 undefined。
|
|
234
|
+
*/
|
|
192
235
|
function localKernel() {
|
|
193
236
|
try {
|
|
194
237
|
return currentKernel();
|
|
195
238
|
} catch (error) {
|
|
196
|
-
for (const label of contractLabels) skip(label,
|
|
239
|
+
for (const label of contractLabels) skip(label, '本机没有可读的内核:' + error.message);
|
|
197
240
|
return undefined;
|
|
198
241
|
}
|
|
199
242
|
}
|
|
200
243
|
|
|
201
|
-
/**
|
|
244
|
+
/**
|
|
245
|
+
* 内核里这三样齐了才能验契约面;缺哪样就说哪样。
|
|
246
|
+
* @param kernel - 内核安装树。
|
|
247
|
+
* @returns 三个包目录或 undefined。
|
|
248
|
+
*/
|
|
202
249
|
function contractDirs(kernel) {
|
|
203
250
|
const dirs = {
|
|
204
251
|
include: kernelPackageDir(kernel, '@deepseek-ai/cordis-plugin-include'),
|
|
@@ -207,7 +254,7 @@ function contractDirs(kernel) {
|
|
|
207
254
|
};
|
|
208
255
|
const missing = Object.entries(dirs).filter(([, dir]) => dir === undefined).map(([name]) => name);
|
|
209
256
|
if (missing.length > 0) {
|
|
210
|
-
for (const label of contractLabels) skip(label,
|
|
257
|
+
for (const label of contractLabels) skip(label, '内核 ' + kernel.version + ' 的包仓里找不到 ' + missing.join('、'));
|
|
211
258
|
return undefined;
|
|
212
259
|
}
|
|
213
260
|
return dirs;
|
|
@@ -215,11 +262,8 @@ function contractDirs(kernel) {
|
|
|
215
262
|
|
|
216
263
|
/**
|
|
217
264
|
* 用内核装载时那份 YAML 方言读 patch,并按 id 摊平成一张表。
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* 两个 schema 实例不能混用,混了就是「unknown tag !!js」。
|
|
221
|
-
* @param {string} includeDir - 内核 `cordis-plugin-include` 的目录。
|
|
222
|
-
* @returns {Promise<Map<string, any>>} id → 行。
|
|
265
|
+
* @param includeDir - 内核 cordis-plugin-include 的目录。
|
|
266
|
+
* @returns id 到行的映射。
|
|
223
267
|
*/
|
|
224
268
|
async function parseRows(includeDir) {
|
|
225
269
|
const { entryListSchema } = await import(pathToFileURL(join(includeDir, 'lib/index.js')).href);
|
|
@@ -236,39 +280,24 @@ const dirs = kernel === undefined ? undefined : contractDirs(kernel);
|
|
|
236
280
|
if (kernel !== undefined && dirs !== undefined) {
|
|
237
281
|
const rows = await parseRows(dirs.include);
|
|
238
282
|
|
|
239
|
-
await test(
|
|
240
|
-
assert.deepEqual([...rows.keys()].sort(), [...ROW_IDS].sort(), '
|
|
241
|
-
for (const id of ROW_IDS) {
|
|
242
|
-
assert.deepEqual(rows.get(id).disabled, { __jsExpr: MACOS_GUARD }, `${id} 的守卫要原样交给 Loader 求值`);
|
|
243
|
-
}
|
|
283
|
+
await test('patch 能被内核 ' + kernel.version + ' 装载时用的 YAML 方言读懂,三行都在', () => {
|
|
284
|
+
assert.deepEqual([...rows.keys()].sort(), [...ROW_IDS].sort(), '解析出来该只有这三行');
|
|
244
285
|
});
|
|
245
286
|
|
|
246
|
-
await test('
|
|
247
|
-
const { Config } = await import(pathToFileURL(join(dirs.client, 'lib/index.js')).href);
|
|
248
|
-
const resolved = Config(rows.get('mcp-kimi-cu').config);
|
|
249
|
-
assert.equal(resolved.transport, 'stdio');
|
|
250
|
-
assert.equal(resolved.serverName, 'kimi-cu');
|
|
251
|
-
assert.equal(resolved.command, KIMI_CU_BINARY);
|
|
252
|
-
assert.deepEqual(resolved.args, ['mcp', '-s', 'user']);
|
|
253
|
-
assert.equal(resolved.failOnStartupError, true);
|
|
254
|
-
assert.ok(resolved.toolCallTimeoutMs >= 120_000, '真 schema 解析出来的工具调用上限要覆盖长任务');
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
await test('技能那行的 config 通过内核 skill-filesystem 的真 Config schema,表达式落回本包 skills/', async () => {
|
|
287
|
+
await test('两条技能行的 config 通过内核 skill-filesystem 的真 Config schema,表达式落回对应目录', async () => {
|
|
258
288
|
const { Config } = await import(pathToFileURL(join(dirs.skills, 'lib/index.js')).href);
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
assert.deepEqual(resolved.customSkillDirs.map((dir) => resolve(dir)), [resolve(join(packageDir, 'skills'))]);
|
|
289
|
+
for (const [id, dir] of Object.entries(SKILL_DIRS)) {
|
|
290
|
+
const row = rows.get(id);
|
|
291
|
+
const expression = row.config.customSkillDirs?.[0]?.__jsExpr;
|
|
292
|
+
assert.equal(typeof expression, 'string', id + ' 的 customSkillDirs 要由 !!js 算成绝对路径');
|
|
293
|
+
const fromPackage = evaluateExpression(expression, pathToFileURL(join(packageDir, 'index.js')).href);
|
|
294
|
+
assert.equal(resolve(fromPackage), resolve(join(packageDir, 'skills', dir)), id + ' 的表达式要落回 skills/' + dir);
|
|
295
|
+
const resolved = Config({ ...row.config, customSkillDirs: [fromPackage] });
|
|
296
|
+
assert.equal(resolved.providerName, 'kimi-cu');
|
|
297
|
+
assert.equal(resolved.includeDefaultRoots, false);
|
|
298
|
+
assert.deepEqual(resolved.customSkillDirs.map((entry) => resolve(entry)), [resolve(join(packageDir, 'skills', dir))]);
|
|
299
|
+
}
|
|
271
300
|
});
|
|
272
301
|
}
|
|
273
302
|
|
|
274
|
-
console.log(
|
|
303
|
+
console.log('\ncheck-bundle: ' + passed + '/' + total + ' 条断言通过' + (skipped.length === 0 ? '' : ',' + skipped.length + ' 条跳过'));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 按 Web shell 的方式装载 lib/client.js:window.__ModuleLoader__ 桩件 + 平台模块表。
|
|
3
|
+
* 两个客户端自检共用这一份,模块表只写一遍。
|
|
4
|
+
*/
|
|
5
|
+
import { createRequire } from 'node:module';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
|
|
10
|
+
/** ui-primitives 的薄桩:只顶掉 bundle 真的 require 的那几个名字。 */
|
|
11
|
+
const primitives = {
|
|
12
|
+
Button: () => null,
|
|
13
|
+
Tag: () => null,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 装载浏览器 bundle。
|
|
18
|
+
* @param root - 包根目录。
|
|
19
|
+
* @returns bundle 的导出与它 require 过的模块 id。
|
|
20
|
+
*/
|
|
21
|
+
export async function loadClientBundle(root) {
|
|
22
|
+
let exported;
|
|
23
|
+
const requires = [];
|
|
24
|
+
globalThis.window = {
|
|
25
|
+
__ModuleLoader__: {
|
|
26
|
+
load: ({ id, factory }) => {
|
|
27
|
+
requires.push(id);
|
|
28
|
+
exported = factory((spec) => {
|
|
29
|
+
if (spec === 'react') return require('react');
|
|
30
|
+
if (spec === 'react/jsx-runtime') return require('react/jsx-runtime');
|
|
31
|
+
if (spec === 'react-dom') return require('react-dom');
|
|
32
|
+
if (spec === '@deepseek-ai/dsh-client-ui-primitives') return primitives;
|
|
33
|
+
throw new Error('module table miss: ' + spec);
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
await import(join(root, 'lib/client.js') + '?bundle=' + Date.now());
|
|
39
|
+
return { exported, requires };
|
|
40
|
+
}
|