@lynn123411/dsh-kimi-cu 0.2.1 → 0.3.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.
@@ -0,0 +1,158 @@
1
+ /**
2
+ * 桌面操作独占槽位的自检:本插件要和官方 CUA、Cua Driver 一样经 `computerUse.register()`
3
+ * 占位,占不到就不把 `mcp__kimi-cu__*` 工具交出去。
4
+ *
5
+ * 用真 cordis Context 与真 `ctx.inject`,只把两个服务换成可观察的替身:
6
+ * `computerUse` 照抄宿主的独占语义(第二个注册直接抛错),`mcpManager` 记录每次注册。
7
+ *
8
+ * 跑法:pnpm test / node scripts/test-exclusivity.mjs
9
+ */
10
+ import assert from 'node:assert/strict';
11
+
12
+ import { Context, Service } from '@deepseek-ai/cordis';
13
+ import SystemPrompt from '@deepseek-ai/dsh-system-prompt';
14
+ import ToolRuntime from '@deepseek-ai/dsh-tools';
15
+
16
+ import * as plugin from '../lib/index.js';
17
+
18
+ let passed = 0;
19
+ let total = 0;
20
+ async function test(label, fn) {
21
+ total += 1;
22
+ try {
23
+ await fn();
24
+ passed += 1;
25
+ console.log(' ok ' + label);
26
+ } catch (error) {
27
+ console.error(' FAIL ' + label + ': ' + error.message);
28
+ throw error;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * 探测器替身:与平台无关,直接给出「已安装且 MCP 命令可用」的状态。
34
+ *
35
+ * 真探测器在 Linux 上必然给 `mcp: null`(不受支持的平台),注册那条链就跑不到,
36
+ * 而这里要验的是独占槽位与注册的先后关系,不是平台分流。
37
+ */
38
+ const fakeDetect = async () => ({
39
+ platform: 'darwin',
40
+ supported: true,
41
+ installed: true,
42
+ path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu',
43
+ version: '0.7.5',
44
+ doctor: { ran: true, ok: true, checks: [], raw: '' },
45
+ mcp: { command: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu', args: ['mcp', '-s', 'user'] },
46
+ install: null,
47
+ notes: [],
48
+ checkedAt: 0,
49
+ });
50
+
51
+ /** 等若干个微任务,让注入回调里那条同步链跑完。 */
52
+ async function settle() {
53
+ for (let i = 0; i < 8; i += 1) await Promise.resolve();
54
+ }
55
+
56
+ /**
57
+ * 等一个条件成立。探测要真的跑一次 `doctor`,是外部进程,不能只等微任务。
58
+ * @param {() => boolean} predicate - 条件。
59
+ * @param {string} what - 超时时的说明。
60
+ */
61
+ async function waitFor(predicate, what) {
62
+ const deadline = Date.now() + 20_000;
63
+ while (Date.now() < deadline) {
64
+ if (predicate()) return;
65
+ await new Promise((resolve) => setTimeout(resolve, 20));
66
+ }
67
+ throw new Error('等不到:' + what);
68
+ }
69
+
70
+ /** 宿主的桌面操作独占登记,语义照抄:占住之后第二个注册抛错并报出已占位的名字。 */
71
+ class FakeComputerUse extends Service {
72
+ constructor(ctx) {
73
+ super(ctx, 'computerUse');
74
+ this.registration = undefined;
75
+ }
76
+
77
+ get providerName() {
78
+ return this.registration;
79
+ }
80
+
81
+ register(name) {
82
+ if (this.registration !== undefined) {
83
+ throw new Error(`computer use provider "${this.registration}" is already registered`);
84
+ }
85
+ return this.ctx.effect(() => {
86
+ this.registration = name;
87
+ return () => {
88
+ this.registration = undefined;
89
+ };
90
+ }, 'computerUse.register()');
91
+ }
92
+ }
93
+
94
+ /** MCP 管理器替身:只记录注册过的服务器与撤销次数。 */
95
+ class FakeMcpManager extends Service {
96
+ constructor(ctx) {
97
+ super(ctx, 'mcpManager');
98
+ this.calls = [];
99
+ this.disposed = 0;
100
+ }
101
+
102
+ register(name, entry) {
103
+ this.calls.push({ name, entry });
104
+ return () => {
105
+ this.disposed += 1;
106
+ };
107
+ }
108
+ }
109
+
110
+ /** 起一个只带工具表的上下文:工具表要提示词服务来写 schema。 */
111
+ function host() {
112
+ const ctx = new Context();
113
+ new SystemPrompt(ctx, {});
114
+ new ToolRuntime(ctx);
115
+ return ctx;
116
+ }
117
+
118
+ await test('组合里没有 computerUse 时行为不变:照常注册 MCP 连接', async () => {
119
+ const ctx = host();
120
+ const mcp = new FakeMcpManager(ctx);
121
+ plugin.apply(ctx, { detect: fakeDetect });
122
+ await waitFor(() => mcp.calls.length === 1, '没有独占服务时应当照常交出工具');
123
+ assert.equal(mcp.calls[0].name, 'kimi-cu');
124
+ });
125
+
126
+ await test('槽位空着时先占位,占到了才注册 MCP 连接', async () => {
127
+ const ctx = host();
128
+ const cu = new FakeComputerUse(ctx);
129
+ const mcp = new FakeMcpManager(ctx);
130
+ plugin.apply(ctx, { detect: fakeDetect });
131
+ await waitFor(() => mcp.calls.length === 1, '占到位之后应当注册 MCP 连接');
132
+ assert.equal(cu.providerName, 'kimi-cu', '本插件应当占住桌面操作槽位');
133
+ });
134
+
135
+ await test('槽位被别的后端占着时不抢,也不交出工具', async () => {
136
+ const ctx = host();
137
+ const cu = new FakeComputerUse(ctx);
138
+ const release = cu.register('cua-driver-mcp');
139
+ const mcp = new FakeMcpManager(ctx);
140
+ plugin.apply(ctx, { detect: fakeDetect });
141
+ await settle();
142
+ await new Promise((resolve) => setTimeout(resolve, 300));
143
+ assert.equal(cu.providerName, 'cua-driver-mcp', '别的后端占着时不能顶掉它');
144
+ assert.equal(mcp.calls.length, 0, '占不到位就不该注册 mcp__kimi-cu__* 工具');
145
+ await release();
146
+ });
147
+
148
+ await test('占位后别的后端再注册会被拒:独占是双向的', async () => {
149
+ const ctx = host();
150
+ const cu = new FakeComputerUse(ctx);
151
+ const mcp = new FakeMcpManager(ctx);
152
+ plugin.apply(ctx, { detect: fakeDetect });
153
+ await waitFor(() => mcp.calls.length === 1, '应当注册 MCP 连接');
154
+ assert.equal(cu.providerName, 'kimi-cu');
155
+ assert.throws(() => cu.register('cua-driver-mcp'), /already registered/);
156
+ });
157
+
158
+ console.log('\ntest-exclusivity: ' + passed + '/' + total + ' 条断言通过');
@@ -0,0 +1,317 @@
1
+ /**
2
+ * 更新链路自检:清单解析、版本比较、阶段映射、失败分类,以及更新器的行为。
3
+ *
4
+ * 纯函数部分用固定输入验;更新器用替身验「已是最新不执行」「清单读不到时 macOS 照跑、
5
+ * Windows 报错」「单飞锁」「超时不 kill」「版本变了才重连」。
6
+ *
7
+ * 跑法:node scripts/test-update.mjs
8
+ */
9
+ import assert from 'node:assert/strict';
10
+ import { dirname, join, resolve } from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+
13
+ import {
14
+ classifyFailure,
15
+ compareVersions,
16
+ createUpdater,
17
+ manifestUrl,
18
+ parseManifest,
19
+ parseStage,
20
+ } from '../src/server/update.ts';
21
+
22
+ const root = resolve(process.argv[2] ?? join(dirname(fileURLToPath(import.meta.url)), '..'));
23
+
24
+ let passed = 0;
25
+ let total = 0;
26
+ async function test(label, fn) {
27
+ total += 1;
28
+ try {
29
+ await fn();
30
+ passed += 1;
31
+ console.log(' ok ' + label);
32
+ } catch (error) {
33
+ console.error(' FAIL ' + label + ': ' + error.message);
34
+ throw error;
35
+ }
36
+ }
37
+
38
+ const MACOS_MANIFEST = JSON.stringify({
39
+ version: '0.7.6',
40
+ app: { url: 'https://cdn.example/KimiCU.app.zip', sha256: 'abc', team_id: '2J9472RW75' },
41
+ });
42
+ const WINDOWS_MANIFEST = JSON.stringify({
43
+ version: '0.3.14',
44
+ runtime: { url: 'https://cdn.example/runtime.zip', sha256: 'def' },
45
+ });
46
+
47
+ await test('parseManifest 取 version 字段', () => {
48
+ assert.equal(parseManifest(MACOS_MANIFEST), '0.7.6');
49
+ assert.equal(parseManifest(WINDOWS_MANIFEST), '0.3.14');
50
+ });
51
+
52
+ await test('parseManifest 对缺字段与坏 JSON 返回 null', () => {
53
+ assert.equal(parseManifest('{"app":{}}'), null);
54
+ assert.equal(parseManifest('{"version":""}'), null);
55
+ assert.equal(parseManifest('not json'), null);
56
+ });
57
+
58
+ await test('compareVersions 按数字段比较,不按字符串', () => {
59
+ assert.equal(compareVersions('0.7.10', '0.7.9'), 1);
60
+ assert.equal(compareVersions('0.7.9', '0.7.10'), -1);
61
+ assert.equal(compareVersions('0.8.0', '0.7.5'), 1);
62
+ assert.equal(compareVersions('0.7.5', '0.7.5'), 0);
63
+ assert.equal(compareVersions('1.0', '1.0.0'), 0);
64
+ });
65
+
66
+ await test('compareVersions 对非数字版本返回 null', () => {
67
+ assert.equal(compareVersions('v0.7.5', '0.7.5'), null);
68
+ assert.equal(compareVersions('0.7.5-beta', '0.7.5'), null);
69
+ assert.equal(compareVersions('', '0.7.5'), null);
70
+ });
71
+
72
+ await test('manifestUrl 两个平台各一份清单,其余平台没有', () => {
73
+ assert.match(manifestUrl('darwin'), /kimi-computer-use\/latest\/version\.json$/);
74
+ assert.match(manifestUrl('win32'), /kimi-computer-use-windows\/latest\/version\.json$/);
75
+ assert.equal(manifestUrl('other'), null);
76
+ });
77
+
78
+ await test('parseStage 把 ==> 行映射成阶段,认不出的行不报错', () => {
79
+ assert.equal(parseStage('==> 校验代码签名与 Apple 公证 …'), 'verifying');
80
+ assert.equal(parseStage('==> 当前版本 0.7.5,线上最新 0.7.6'), 'checking');
81
+ assert.equal(parseStage('==> 下载 KimiCU.app.zip'), 'downloading');
82
+ assert.equal(parseStage('==> 替换 /Applications/KimiCU.app'), 'installing');
83
+ assert.equal(parseStage('✓ 签名 + 公证校验通过。'), 'installing');
84
+ assert.equal(parseStage(''), null);
85
+ });
86
+
87
+ await test('classifyFailure 把已知失败分到五类', () => {
88
+ assert.equal(classifyFailure('', true), 'timeout');
89
+ assert.equal(classifyFailure('✗ 另一个升级正在收尾,请稍后重试;当前没有并发替换 App。', false), 'busy');
90
+ assert.equal(classifyFailure('✗ 下载包 SHA-256 与版本清单不一致,已中止。', false), 'verify');
91
+ assert.equal(
92
+ classifyFailure('Staging failed; the existing service was not stopped. Run the installer from Terminal with administrator authorization.', false),
93
+ 'permission',
94
+ );
95
+ assert.equal(classifyFailure('✗ 下载失败,请检查网络后重试。', false), 'network');
96
+ assert.equal(classifyFailure('something else entirely', false), 'unknown');
97
+ });
98
+
99
+ /** 造一个更新器替身环境:记录每次读清单与每次 upgrade 的入参。 */
100
+ function harness(overrides = {}) {
101
+ const calls = { fetch: [], upgrade: [], reconnect: 0 };
102
+ const base = {
103
+ platform: 'darwin',
104
+ current: async () => ({ path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu', version: '0.7.5' }),
105
+ fetchManifest: async () => MACOS_MANIFEST,
106
+ runUpgrade: async (input) => {
107
+ input.onLine('==> 当前版本 0.7.5,线上最新 0.7.6');
108
+ input.onLine('==> 校验代码签名与 Apple 公证 …');
109
+ return { code: 0, raw: '✓ 升级完成', timedOut: false, whenExited: Promise.resolve() };
110
+ },
111
+ reconnect: async () => { calls.reconnect += 1; return true; },
112
+ now: () => 1,
113
+ };
114
+ const merged = { ...base, ...overrides };
115
+ const deps = {
116
+ ...merged,
117
+ fetchManifest: async (url) => {
118
+ calls.fetch.push(url);
119
+ return merged.fetchManifest(url);
120
+ },
121
+ runUpgrade: async (input) => {
122
+ calls.upgrade.push({ platform: input.platform, binaryPath: input.binaryPath, version: input.version });
123
+ return merged.runUpgrade(input);
124
+ },
125
+ };
126
+ return { updater: createUpdater(deps), calls };
127
+ }
128
+
129
+ /** 收集一次 run 的全部事件。 */
130
+ async function collect(updater) {
131
+ const events = [];
132
+ await updater.run((event) => events.push(event));
133
+ return events;
134
+ }
135
+
136
+ await test('check:清单版本更高时 hasUpdate 为 true', async () => {
137
+ const { updater } = harness();
138
+ const check = await updater.check();
139
+ assert.equal(check.current, '0.7.5');
140
+ assert.equal(check.latest, '0.7.6');
141
+ assert.equal(check.hasUpdate, true);
142
+ assert.equal(check.error, null);
143
+ });
144
+
145
+ await test('check:清单与本地同版本时 hasUpdate 为 false', async () => {
146
+ const { updater } = harness({ fetchManifest: async () => JSON.stringify({ version: '0.7.5' }) });
147
+ const check = await updater.check();
148
+ assert.equal(check.hasUpdate, false);
149
+ });
150
+
151
+ await test('check:清单读不到时记下错误,不抛', async () => {
152
+ const { updater } = harness({ fetchManifest: async () => { throw new Error('offline'); } });
153
+ const check = await updater.check();
154
+ assert.equal(check.latest, null);
155
+ assert.equal(check.hasUpdate, false);
156
+ assert.equal(check.error, 'offline');
157
+ });
158
+
159
+ await test('check:Windows 读的是 Windows 那份清单', async () => {
160
+ const { updater, calls } = harness({
161
+ platform: 'win32',
162
+ current: async () => ({ path: 'C:\\KimiCU\\kimi-cu.exe', version: '0.3.13' }),
163
+ fetchManifest: async () => WINDOWS_MANIFEST,
164
+ });
165
+ await updater.check();
166
+ assert.match(calls.fetch[0], /kimi-computer-use-windows/);
167
+ });
168
+
169
+ await test('run:已是最新时不执行 upgrade', async () => {
170
+ const { updater, calls } = harness({ fetchManifest: async () => JSON.stringify({ version: '0.7.5' }) });
171
+ const events = await collect(updater);
172
+ assert.deepEqual(events.map((event) => event.type), ['stage', 'done']);
173
+ assert.equal(events[1].upToDate, true);
174
+ assert.equal(calls.upgrade.length, 0);
175
+ });
176
+
177
+ await test('run:有新版时先报阶段再执行,版本变了才重连', async () => {
178
+ let version = '0.7.5';
179
+ const { updater, calls } = harness({
180
+ current: async () => ({ path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu', version }),
181
+ runUpgrade: async (input) => {
182
+ calls.upgrade.push({ version: input.version });
183
+ input.onLine('==> 校验代码签名与 Apple 公证 …');
184
+ version = '0.7.6';
185
+ return { code: 0, raw: '✓ 升级完成', timedOut: false, whenExited: Promise.resolve() };
186
+ },
187
+ });
188
+ const events = await collect(updater);
189
+ const stages = events.filter((event) => event.type === 'stage').map((event) => event.stage);
190
+ assert.deepEqual(stages, ['checking', 'downloading', 'verifying', 'restarting']);
191
+ const done = events.at(-1);
192
+ assert.equal(done.type, 'done');
193
+ assert.equal(done.version, '0.7.6');
194
+ assert.equal(done.reconnect, 'done');
195
+ assert.equal(calls.reconnect, 1);
196
+ assert.equal(calls.upgrade[0].version, null, 'macOS 不带版本号,让 KimiCU 自己判断');
197
+ });
198
+
199
+ await test('run:版本没变就不重连', async () => {
200
+ const { updater, calls } = harness({
201
+ runUpgrade: async () => ({ code: 0, raw: '✓ 升级完成', timedOut: false, whenExited: Promise.resolve() }),
202
+ });
203
+ await collect(updater);
204
+ assert.equal(calls.reconnect, 0);
205
+ });
206
+
207
+ await test('run:清单读不到时 macOS 照跑 upgrade', async () => {
208
+ const { updater, calls } = harness({ fetchManifest: async () => { throw new Error('offline'); } });
209
+ const events = await collect(updater);
210
+ assert.equal(calls.upgrade.length, 1);
211
+ assert.equal(events.at(-1).type, 'done');
212
+ });
213
+
214
+ await test('run:清单读不到时 Windows 报网络错误,不执行', async () => {
215
+ const { updater, calls } = harness({
216
+ platform: 'win32',
217
+ current: async () => ({ path: 'C:\\KimiCU\\kimi-cu.exe', version: '0.3.13' }),
218
+ fetchManifest: async () => { throw new Error('offline'); },
219
+ });
220
+ const events = await collect(updater);
221
+ assert.equal(calls.upgrade.length, 0);
222
+ assert.deepEqual(events.at(-1), { type: 'error', kind: 'network', raw: 'offline' });
223
+ });
224
+
225
+ await test('run:Windows 带清单版本号执行 upgrade', async () => {
226
+ const { updater, calls } = harness({
227
+ platform: 'win32',
228
+ current: async () => ({ path: 'C:\\KimiCU\\kimi-cu.exe', version: '0.3.13' }),
229
+ fetchManifest: async () => WINDOWS_MANIFEST,
230
+ });
231
+ await collect(updater);
232
+ assert.equal(calls.upgrade[0].version, '0.3.14');
233
+ });
234
+
235
+ await test('run:并发调用被单飞锁挡住', async () => {
236
+ let release;
237
+ const gate = new Promise((done) => { release = done; });
238
+ const { updater } = harness({
239
+ runUpgrade: async () => { await gate; return { code: 0, raw: '', timedOut: false, whenExited: Promise.resolve() }; },
240
+ });
241
+ const first = collect(updater);
242
+ const second = await collect(updater);
243
+ assert.deepEqual(second, [{ type: 'error', kind: 'busy', raw: '' }]);
244
+ release();
245
+ await first;
246
+ const third = await collect(updater);
247
+ assert.equal(third.at(-1).type, 'done', '锁要在结束后释放');
248
+ });
249
+
250
+ await test('run:超时归类为 timeout', async () => {
251
+ const { updater } = harness({
252
+ runUpgrade: async () => ({ code: null, raw: '部分输出', timedOut: true, whenExited: Promise.resolve() }),
253
+ });
254
+ const events = await collect(updater);
255
+ assert.deepEqual(events.at(-1), { type: 'error', kind: 'timeout', raw: '部分输出' });
256
+ });
257
+
258
+ await test('run:非零退出码按输出分类', async () => {
259
+ const { updater } = harness({
260
+ runUpgrade: async () => ({ code: 1, raw: '✗ 下载包 SHA-256 与版本清单不一致,已中止。', timedOut: false, whenExited: Promise.resolve() }),
261
+ });
262
+ const events = await collect(updater);
263
+ assert.equal(events.at(-1).kind, 'verify');
264
+ });
265
+
266
+ await test('classifyFailure 跳过进度行,只看错误行', () => {
267
+ assert.equal(
268
+ classifyFailure(
269
+ '==> 校验代码签名与 Apple 公证 …\nStaging failed; the existing service was not stopped. Run the installer from Terminal with administrator authorization.',
270
+ false,
271
+ ),
272
+ 'permission',
273
+ );
274
+ });
275
+
276
+ await test('run:超时后锁留到子进程真的退出', async () => {
277
+ let exit;
278
+ const whenExited = new Promise((done) => { exit = done; });
279
+ let first = true;
280
+ const { updater } = harness({
281
+ runUpgrade: async () => {
282
+ if (!first) return { code: 0, raw: '', timedOut: false, whenExited: Promise.resolve() };
283
+ first = false;
284
+ return { code: null, raw: '部分输出', timedOut: true, whenExited };
285
+ },
286
+ });
287
+ const events = await collect(updater);
288
+ assert.equal(events.at(-1).kind, 'timeout');
289
+ const second = await collect(updater);
290
+ assert.deepEqual(second, [{ type: 'error', kind: 'busy', raw: '' }], '超时后进程还在跑,锁不能放');
291
+ exit();
292
+ await new Promise((done) => setTimeout(done, 0));
293
+ const third = await collect(updater);
294
+ assert.equal(third.at(-1).type, 'done', '进程退出后锁要放');
295
+ });
296
+
297
+ await test('run:升级后版本读不出来不算确认变化,不重连', async () => {
298
+ let reads = 0;
299
+ const { updater, calls } = harness({
300
+ current: async () => {
301
+ reads += 1;
302
+ return reads === 1
303
+ ? { path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu', version: '0.7.5' }
304
+ : { path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu', version: null };
305
+ },
306
+ });
307
+ const events = await collect(updater);
308
+ assert.equal(calls.reconnect, 0);
309
+ assert.equal(events.at(-1).reconnect, 'skipped');
310
+ });
311
+
312
+ await test('路由常量与包内约定一致', async () => {
313
+ const shared = await import('../src/shared/update.ts');
314
+ assert.equal(shared.UPDATE_ROUTE_PATH, '/api/dsh-kimi-cu/update');
315
+ });
316
+
317
+ console.log('\ntest-update: ' + passed + '/' + total + ' 条断言通过(root=' + root + ')');
@@ -23,7 +23,7 @@ DSH 把这些工具注册为 `mcp__kimi-cu__<name>`(例如 `mcp__kimi-cu__list
23
23
 
24
24
  1. 目标不明确时优先用 `list_apps(running_only:true)` / `list_windows` 定位已打开的应用和窗口,避免输出全部安装目录。需要找尚未启动的应用时才用 `list_apps(running_only:false)`;不传参数同样包含已安装用户应用,内部 helper 和系统后台组件已过滤。需要把尚未运行的应用启动起来时用 `launch_app`,它只启动,不激活。
25
25
  2. 用 MCP `get_app_state` 观察目标;后续 index 和坐标必须来自这次观察。`mode:"full"` 返回树和图,`mode:"image"` 适合看图、浮层和视觉验证,`mode:"ax"` 适合读文本及按 index 操作;`ax_filter` 可缩小树的输出。
26
- 3. 只需要某一个窗口(尤其是浮窗)时,用 `get_window_state` 传 `window_id`,用 `include_screenshot` / `include_text` 选择截图与 AX 文本;`get_window` 只用来把窗口标识解析成 app、pid 与标题。
26
+ 3. 只需要某一个窗口(尤其是浮窗)时,用 `get_window_state` 传 `window_id`,**同时要给 `app` 或 `pid`**(只给 `window_id` 会报 `app or pid required`);用 `include_screenshot` / `include_text` 选择截图与 AX 文本;`get_window` 只用来把窗口标识解析成 app、pid 与标题。
27
27
  4. 执行动作;页面切换、滚动、弹窗或布局变化影响目标时,重新观察再决定下一步。
28
28
  5. 验证任务要求的结果。投递成功不等于生效;尤其检查 `verified`、`verification_required`、`effect`,必要时再次观察。
29
29
 
@@ -32,7 +32,7 @@ DSH 把这些工具注册为 `mcp__kimi-cu__<name>`(例如 `mcp__kimi-cu__list
32
32
  - `click` / `scroll` / `drag` / 定向 `type_text` 的 x/y 是所用截图的像素坐标,不是屏幕坐标。不要自行换算缩放比例。`mode:"ax"` 的 bbox 是窗口内点坐标,不能直接当作截图像素点击;用 index 或重新取图。
33
33
  - 多窗口及浮层从 `screenshots[]` 选正确图片,传其 `window_id`;支持 `screenshot_id` 的动作同时传图片标识(主图为响应的 `screenshot_id`,数组项为 `id`)。浮窗必须用浮窗自己的图和窗口,不能省略窗口让路由猜测,也不能借用主图坐标。
34
34
  - `rect:{x,y,width,height}` 使用窗口内点坐标,并把该窗口的当前截图锚点切到局部区域。区域图内的操作直接使用区域图像素;改回全窗坐标前重新取全窗图。歧义、过期或越界报错时重新观察,不强行换算重试。
35
- - 正常观察使用 MCP(包括其 JS facade);不要用 shell 的 `kimi-cu shot` / `app-state` / `windows` 代替。开发调试 CLI 不刷新 MCP 快照缓存。
35
+ - 正常观察使用 MCP;不要用 shell 的 `kimi-cu shot` / `app-state` / `windows` 代替。开发调试 CLI 不刷新 MCP 快照缓存。
36
36
 
37
37
  ## 输入与编辑
38
38
 
@@ -49,25 +49,11 @@ DSH 把这些工具注册为 `mcp__kimi-cu__<name>`(例如 `mcp__kimi-cu__list
49
49
  - `effect:"unverifiable"` + `verified:false` 表示投递完成但效果未验证(遮挡窗口或 CEF 原生 chrome 目标;点击已不做像素校验);不能当作任务已完成,要重新观察核对是否达到预期。
50
50
  - 动作未生效时先重新观察目标和状态,再选择界面提供的等价操作。不要连续盲重试,也不要为了绕过失败改做会产生不同结果的动作。
51
51
  - 全遮挡且已节流的 Chromium/CEF 窗口会静默吞掉或分钟级延迟窗口路由事件:自动通道点击无效时,可用 `click(channel:"public")`——整段序列(hover/primer/down/up)以带窗口号的 NSEvent 工厂事件经 postToPid 投递,导航、聚焦、按钮全有效。被吞事件可能分钟级后才执行,不要因此盲目重发同一点位;先重新观察再按次决定。
52
- - 目标稳定、后续步骤能用代码判断的循环或批量操作适合 KimiCU 自带 `js`;不按步数强制合并。下一步需要模型读新截图时,先返回观察结果,再写下一段代码。同一窗口的多条笔画可用 `drag_paths`。具体用法见下文。
52
+ - 目标稳定、后续步骤能用代码判断的批量操作逐个 `await`;DSH 注册的 KimiCU MCP 只有 18 个直接工具,没有 `js` / `js_reset`。下一步需要模型读新截图时,先返回观察结果再决定下一步。同一窗口的多条笔画用 `drag_paths`,见下文。
53
53
 
54
- ## JS 与批量操作
54
+ ## 批量操作
55
55
 
56
- ### KimiCU 自带 REPL
57
-
58
- 先确认工具列表包含 **KimiCU MCP 提供的** `js` / `js_reset`。这是随 KimiCU 打包的运行时,不能把同名的其他插件 JS 工具或系统 Node 当作此入口。未提供 JS 时使用普通 MCP 工具;不为简单操作临时搭建运行时。
59
-
60
- ```js
61
- var { kimiCU } = await import("@kimi/cu");
62
- nodeRepl.write(await kimiCU.list_apps({ running_only: true }));
63
- ```
64
-
65
- - 顶层变量和函数跨 cell 持久;输出文本/对象需 `nodeRepl.write(value)`,裸表达式不显示。观察产生的图片会作为 image content 返回。
66
- - 方法对应普通工具,但 facade 有独立参数校验和别名;不要假定所有参数完全相同。例如 JS `press_key` 用 `key`,普通工具用 `keys`;窗口可写成 `window:{app,id,title}`,index 可用 `element_index`。未知参数应检查当前接口和版本,不静默删掉有语义的参数继续操作。
67
- - JS 调用失败会抛带 `code` 的异常。用 `try/catch` 输出错误并停止依赖该结果的后续动作;抛异常不代表此前动作已回滚。成功返回也仍须按前文验证实际效果。
68
- - 同一 cell 对同一应用窗口连续读取非空 AX 树时可读 `tree_diff` / `state_diff`;检查 `mode` 和基准信息。首次观察、新窗口、禁用 diff 或纯图片观察不能假定有增量补丁。
69
- - 批量只合并目标已知且稳定的动作,逐个 `await`。新菜单、页面或截图需要模型辨认时,在该观察后结束 cell,不能预写未观察界面的坐标/index。
70
- - `js_reset` 会清空 REPL 变量并重建内核,不会清理 app 草稿、撤销动作或恢复窗口。仅在运行时异常、明确提示或升级后使用。
56
+ DSH 注册的是 KimiCU MCP 的 18 个直接工具:`list_apps`、`launch_app`、`list_windows`、`get_window`、`activate_window`、`get_app_state`、`get_window_state`、`click`、`type_text`、`paste`、`press_key`、`scroll`、`set_value`、`perform_secondary_action`、`select_text`、`drag`、`drag_paths`、`debug_tap`。没有 CodeAct 的 `js` / `js_reset`,也没有浏览器标签页工具;需要批量就逐个 `await`,不要临时搭一个运行时。
71
57
 
72
58
  ### drag_paths
73
59
 
@@ -77,7 +63,7 @@ nodeRepl.write(await kimiCU.list_apps({ running_only: true }));
77
63
  - 必须显式传 `window_id`,并使用该窗口最近一次图像观察的像素坐标。当前服务的该路径不消费 `screenshot_id`,不能靠它单独选窗或恢复旧截图锚点。批内不切换窗口/坐标系。
78
64
  - 传 `abort_if_cursor_in_window:true` 保持用户操作守卫。用户在窗口内移动真实鼠标或按住鼠标时会拒投或中途停止;光标静止在窗口内本身不触发。触发后等待用户停止相关操作,重新观察再继续,不关闭守卫硬投。
79
65
  - 批量不是事务,已投笔画不回滚。普通工具返回 `results`、`delivered`、`total`,中断时可能带 `cursor_in_window:true`。结合界面核对后,仅处理未完成路径;中途止投可从第一个 false 位置续作,其他失败须逐项检查,不能整批重放。
80
- - 当前 JS 异常只保留错误码和文字,未必包含失败响应的 `results`。无法确定哪些笔画已完成时,先核对画面和错误信息;不能猜测断点或重新提交整个批次。需要程序化读取失败明细时使用普通 `drag_paths` 工具。
66
+ - 无法确定哪些笔画已完成时,先核对画面和错误信息;不能猜测断点或重新提交整个批次。
81
67
 
82
68
  ## 排障与升级
83
69
 
@@ -85,6 +71,8 @@ nodeRepl.write(await kimiCU.list_apps({ running_only: true }));
85
71
 
86
72
  - 歧义窗口、坐标越界或旧 index:按前文重新绑定窗口和观察,不重装或抢前台。
87
73
  - 缺图/黑图:先看 `screenshot_diagnosis`,区分最小化、窗口关闭、其他 Space、锁屏、未渲染和权限问题。需要用户恢复窗口或切回所在桌面时明确说明,不自行切 Space。
74
+ - **连续两次截图字节完全相同**:窗口被遮挡或停在别的 Space 时,截图会一直返回同一帧,看着像「按键没生效」。别据此重试投递——先 `activate_window` 或看 `screenshot_diagnosis`,再判断动作到底有没有落下去。
75
+ - 窗口在另一个 Space 或另一块屏幕上时,AX 树照常可读、动作照常可投递,但截图取不到(`screenshot_diagnosis` 报 `not on-screen` 或 `no shareable content`)。这时用 AX 文本验证结果,不要据此判断权限丢失或动作失败;`activate_window` 的 `foreground_changed:true` 也不证明窗口已经来到当前 Space。
88
76
  - 空 AX 树也可能是自绘或远程渲染控件;有可用截图时可按图操作,不直接认定权限丢失。
89
77
  - `unknown field` / `KIMI_CU_UNKNOWN_FIELD`:先核对当前入口的 schema;刚升级时优先排查旧 MCP 桥和 JS 内核,不能据此直接断言新功能不存在。
90
78
  - 怀疑某个进程收不到事件时,用 `debug_tap` 在服务侧记录它的投递事件;它不改变界面,也不是常规操作入口。排查完如实报告结论,不要靠反复投递试探。
@@ -110,8 +98,8 @@ ls /Applications/KimiCU.app/Contents/MacOS/kimi-cu
110
98
 
111
99
  ### 升级后的连接
112
100
 
113
- 收到新版本提示时转告用户,已有升级授权时可运行 `kimi-cu upgrade`。不要仅因有新版就中断任务或自行升级。
101
+ 收到新版本提示时转告用户:插件页的 KimiCU 卡片上有更新按钮,也可以运行 `kimi-cu upgrade`。不要仅因有新版就中断任务或自行升级。
114
102
 
115
- 服务升级不会自动替换长寿的 MCP 桥和 NodeRepl 内核。升级后在客户端重连 KimiCU MCP(支持 `/mcp` 的客户端可用该入口);JS 用户还需 `js_reset`,然后重新 import 和观察。reset 不代替 MCP 重连,也不会清掉应用内容。
103
+ 服务升级不会自动替换长寿的 MCP 桥。插件页的更新按钮在升级成功后会自动重连 MCP;手动升级后在客户端重连 KimiCU MCP(支持 `/mcp` 的客户端可用该入口)即可。
116
104
 
117
105
  CLI 只用于排障/安装维护;日常取图、取坐标和操作仍用 MCP。
package/DETAILS.md DELETED
@@ -1,96 +0,0 @@
1
- # @lynn123411/dsh-kimi-cu 装配与验证
2
-
3
- 写给维护者。用户面向的说明在 [README.md](./README.md)。
4
-
5
- ## 三行落在哪
6
-
7
- `cordis.patch.yml` 只有一层 `insert`,三行都在根层:
8
-
9
- | 行 id | 挂的包 | 作用 |
10
- | --- | --- | --- |
11
- | `dsh-kimi-cu` | 本包 | 宿主半边(`kimi_cu_status` 工具 + `/api/dsh-kimi-cu/status` 路由 + MCP 注册)与浏览器半边(插件页状态卡) |
12
- | `skill-kimi-cu-macos` | `@deepseek-ai/dsh-skill-filesystem` | 只扫本包 `skills/macos` |
13
- | `skill-kimi-cu-windows` | `@deepseek-ai/dsh-skill-filesystem` | 只扫本包 `skills/windows` |
14
-
15
- 根层的意思是「进全局层」:profile 里每个 preset 的 agent 都能看到这批工具与这个技能。`dsh plugin --profile web add` 之后,本包名同时进 profile 的 `dependencies` 与 `dsh.profile.bundles`,`dsh.bundle.patch` 声明的这份 patch 随即并入层栈。
16
-
17
- ## MCP 连接为什么不在 patch 里
18
-
19
- 宿主半边探测到可执行文件之后调用 `mcpManager.register('kimi-cu', …)`,命令与参数取自同一次探测。这样只有一处决定「连什么」:状态卡、`kimi_cu_status` 与真正的连接都读 `resolve.ts` 的同一份结果,不会出现 patch 表达式与检测逻辑各写一遍、改一处忘另一处的漂移。
20
-
21
- 管理器还统一提供连接状态、重启与探测,KimiCU 的连接因此出现在与其他 MCP 服务器同一张表里。管理器缺失时 `ctx.inject(['mcpManager'])` 整块不激活,插件其余部分照常加载,只是没有 `mcp__kimi-cu__*` 工具。
22
-
23
- ## 为什么 MCP 要按平台分
24
-
25
- KimiCU 在 macOS 与 Windows 是两条产品线:macOS 只有 app 包,命令是 app 内的二进制,参数 `mcp -s user`;Windows 只有独立 runtime,默认装在 `%LOCALAPPDATA%\Kimi Computer Use`(0.3.8 起;旧目录 `%LOCALAPPDATA%\KimiCU` 由安装器建 junction 兼容),参数只有 `mcp`。平台判断在 `resolve.ts`:不受支持的平台给出 `mcp: null`,宿主半边就不注册,模型看到的仍是 `mcp__kimi-cu__*`。
26
-
27
- Windows 走的是旧 13 工具 MCP,不是上游主推的 code-mode 插件:code-mode 要求用户先装 Kimi Code 插件包、宿主 PATH 有 Node 24.15+,与本插件「装完即用」的目标冲突;旧 MCP 由 runtime 自带,不需要 Node,工具面与 macOS 同族。
28
-
29
- ## 为什么技能也按平台分两条
30
-
31
- 两份技能的工具面与操作语义不同:macOS 是后台静默、AX 树、`paste` / `drag_paths` / `js`;Windows 是前台真实输入、UIA 树、`turn_ended`,没有 `paste` / `drag_paths` / `js`。合成一份会让模型在错误的平台上调用不存在的工具,所以各扫各的目录,技能名都叫 `kimi-cu`。
32
-
33
- ## 检测与引导
34
-
35
- 宿主半边在 `src/server/`:
36
-
37
- - `resolve.ts`:纯函数,解析安装位置、MCP 命令与安装计划;MCP 注册与状态卡都读它这一份(`check-bundle` 会逐平台断言)。
38
- - `doctor.ts`:跑 `kimi-cu doctor` 并解析。macOS 解析 `✅`/`❌` 行;Windows 解析 `version=` 与 `mcp=true`。
39
- - `status.ts`:把上面两样合成 `KimiCuStatus`,缓存 10 秒、并发单飞、`refresh` 绕过缓存;所有失败落进状态字段,不抛。探测整体失败时返回 `notes: ['detection-failed']` 的状态,路由与工具拿到的是状态而不是异常。
40
-
41
- Windows 的路径公式只在 `resolve.ts` 的 `windowsMcpCommand` 里有一份;`test-status` 与 `check-bundle` 会逐 env 断言。覆盖值存在时只用覆盖值,不回退到默认/旧目录;旧目录安装会同时标 `legacy-install` 与 `mcp-command-missing`,卡片按「未就绪」处理,不会在连接指向的文件不存在时报「已就绪」。
42
-
43
- 浏览器半边在 `src/client/`:注册 `plugins.bundle.config`(key 是包名),卡片按「未安装 / 未就绪 / 已就绪 / 不支持」四种状态渲染,给官方命令、复制、重新检测与文档链接。卡片只给命令,不执行安装脚本。
44
-
45
- `kimi_cu_status` 工具返回同一份 JSON;MCP 工具缺失或连接失败时,技能要求模型先查它,再把安装/修复步骤转告用户。
46
-
47
- ## 为什么卡片不自动执行安装
48
-
49
- - 宿主静默执行远程脚本会绕过 DSH 的审批模型:安装器从 CDN 下载并替换运行时,失败时难以回滚。
50
- - macOS 安装器需要交互式权限授予(辅助功能、屏幕录制),后台执行拿不到用户在系统设置里的确认。
51
- - Windows 安装器会替换正在使用的运行时;如果宿主正连着它,更新与连接状态都会被打断。
52
- - 因此卡片只给官方命令与复制,由用户在终端里执行;装好后按提示开关插件。
53
-
54
- ## 连不上时看什么
55
-
56
- KimiCU 的二进制不在 PATH 上,所以「装了但没连上」是常见状态。三条信号各管一段:
57
-
58
- - 插件启动时探测一次,缺装就写一条带官方安装命令的 warning;
59
- - `kimi_cu_status` 工具随时可查,返回安装位置、版本、`doctor` 结果与安装计划;
60
- - 宿主的 `mcpManager` 记录这条连接的状态,重启与探测都在它那一处。
61
-
62
- 注册发生在探测之后,所以装好 KimiCU 之后要在插件页里把本插件关一次再开一次(或重启),注册才会重新跑一次。
63
-
64
- ## 为什么把工具调用上限设成 5 分钟
65
-
66
- 内核 `mcp-client` 的默认值是 60 秒。KimiCU 的 `js` cell 可以跑循环和批量操作,超过 60 秒会被客户端取消。5 分钟覆盖常见的批量;更长的任务拆成多个 cell。
67
-
68
- ## 一条连接服务所有 session
69
-
70
- 宿主只起一个 KimiCU MCP 连接,所有 session 共用。KimiCU 的快照与 index 缓存是连接级的:两个 session 同时操作同一个应用,后一次观察会顶掉前一次的参照。技能要求每次动作前重新观察。
71
-
72
- ## 技能目录为什么不能写相对路径
73
-
74
- bundle patch 里的 `!!js` 表达式以**声明这份 patch 的那棵树**的 `baseUrl` 求值;对 bundle 层来说那是 profile 目录。所以技能目录写成先按包名解析出包目录、再拼 `skills/<platform>`。
75
-
76
- ## 随包技能从哪来
77
-
78
- `skills/macos/kimi-cu/SKILL.md` 以 KimiCU 自带技能为底稿,另加 DSH 适配(工具前缀、窗口级工具、`activate_window` / `debug_tap` 的边界、`kimi_cu_status`)。`skills/windows/kimi-cu/SKILL.md` 按 Windows runtime 的旧 13 工具 MCP 与官方 `INSTALL.md` 写。上游改了要人工同步一次。
79
-
80
- ## 验证
81
-
82
- 包目录里跑 `pnpm check`,它由这几段组成:
83
-
84
- 1. `pnpm typecheck`。
85
- 2. `pnpm test`:构建 + `smoke-host`(真 cordis + 真 ToolRuntime)+ `smoke-client`(假 Web shell)+ `test-status`(纯逻辑)+ `test-card`(jsdom 渲染)。
86
- 3. `assert:lib-untracked`。
87
- 4. `check-bundle.mjs`:清单面、文本面与契约面(内核真 `Config` schema、两平台分支、技能目录)。
88
- 5. `tools/probes/preset-skills.mjs --skills skills/macos` 与 `--skills skills/windows`。
89
-
90
- 仓库级一次跑齐用 `node tools/check.mjs`;真装载用 `node tools/host-smoke.mjs`。
91
-
92
- ## 实测记录
93
-
94
- - 2026-11-08,内核 0.2.2-rc.1,macOS:`pnpm check` 全通过(typecheck、4 个测试脚本、check-bundle 16 条、两个技能根的 probe);`kimi-cu doctor` 五项全绿,`kimi_cu_status` 返回 0.6.8 与已就绪。
95
- - 2026-11-08,内核 0.2.2-rc.1,macOS:`node tools/host-smoke.mjs` 装载通过,插件页能取到本包的 `client.js`。
96
- - Windows 真机验收待补:卡片未安装 → 运行官方命令 → 重新检测 → 开关插件 → `mcp__kimi-cu__*` 工具出现 → `list_apps` 可用。