@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.
@@ -0,0 +1,296 @@
1
+ /**
2
+ * 检测核心自检:平台解析、安装计划、`doctor` 解析与状态缓存。
3
+ *
4
+ * 这些是纯逻辑,不 spawn 任何进程:真 `doctor` 的调用在 smoke-host 与真机验收里。
5
+ * 期望值来自官方 `INSTALL.md` 与实测输出,不是照抄实现。
6
+ *
7
+ * 跑法:node scripts/test-status.mjs
8
+ */
9
+ import assert from 'node:assert/strict';
10
+
11
+ import {
12
+ DOCS_URL,
13
+ DOCS_URL_EN,
14
+ MACOS_BINARY,
15
+ MACOS_INSTALL_COMMAND,
16
+ WINDOWS_INSTALL_COMMAND,
17
+ } from '../src/shared/status.ts';
18
+ import { installPlan, resolveInstall } from '../src/server/resolve.ts';
19
+ import { parseDoctor } from '../src/server/doctor.ts';
20
+ import { createStatusDetector, parseMacosVersion } from '../src/server/status.ts';
21
+
22
+ let passed = 0;
23
+ let total = 0;
24
+ async function test(label, fn) {
25
+ total += 1;
26
+ try {
27
+ await fn();
28
+ passed += 1;
29
+ console.log(` ok ${label}`);
30
+ } catch (error) {
31
+ console.error(` FAIL ${label}: ${error.message}`);
32
+ throw error;
33
+ }
34
+ }
35
+
36
+ const MAC_DOCTOR_OK = [
37
+ 'kimi-cu doctor',
38
+ '✅ Accessibility (AX)',
39
+ '✅ Screen Recording',
40
+ '✅ SkyLight post-to-pid',
41
+ '✅ bg-input (window-location SPI)',
42
+ '✅ signed keyboard',
43
+ '',
44
+ ].join('\n');
45
+
46
+ const MAC_DOCTOR_BAD = MAC_DOCTOR_OK.replace('✅ Screen Recording', '❌ Screen Recording');
47
+
48
+ const WIN_DOCTOR_OK = ['version=0.3.13', 'mcp=true', 'helper=embedded', ''].join('\n');
49
+ const WIN_DOCTOR_BAD = WIN_DOCTOR_OK.replace('mcp=true', 'mcp=false');
50
+
51
+ const LOCAL = 'C:\\Users\\t\\AppData\\Local';
52
+ const WIN_PRIMARY = `${LOCAL}\\Kimi Computer Use\\kimi-cu.exe`;
53
+ const WIN_LEGACY = `${LOCAL}\\KimiCU\\kimi-cu.exe`;
54
+
55
+ await test('macOS 安装计划:官方命令、权限步骤、文档地址', () => {
56
+ const plan = installPlan('darwin');
57
+ assert.equal(plan.command, MACOS_INSTALL_COMMAND);
58
+ assert.match(plan.command, /setup_macos\.sh/);
59
+ assert.deepEqual(plan.steps, ['install', 'grant-permissions', 'reload-plugin']);
60
+ assert.equal(plan.docsUrl, DOCS_URL);
61
+ assert.equal(plan.docsUrlEn, DOCS_URL_EN);
62
+ });
63
+
64
+ await test('Windows 安装计划:官方 PowerShell 命令、无权限步骤', () => {
65
+ const plan = installPlan('win32');
66
+ assert.equal(plan.command, WINDOWS_INSTALL_COMMAND);
67
+ assert.match(plan.command, /setup_windows\.ps1/);
68
+ assert.deepEqual(plan.steps, ['install', 'reload-plugin']);
69
+ });
70
+
71
+ await test('不支持的平台没有安装计划', () => {
72
+ assert.equal(installPlan('other'), null);
73
+ });
74
+
75
+ await test('macOS:找到二进制时 installed 为真,MCP 命令带 -s user', () => {
76
+ const resolved = resolveInstall({ platform: 'darwin', env: {}, exists: (path) => path === MACOS_BINARY });
77
+ assert.equal(resolved.supported, true);
78
+ assert.equal(resolved.installed, true);
79
+ assert.equal(resolved.path, MACOS_BINARY);
80
+ assert.deepEqual(resolved.mcp, { command: MACOS_BINARY, args: ['mcp', '-s', 'user'] });
81
+ assert.deepEqual(resolved.notes, []);
82
+ });
83
+
84
+ await test('macOS:没找到二进制时 installed 为假,但 MCP 命令仍是约定路径', () => {
85
+ const resolved = resolveInstall({ platform: 'darwin', env: {}, exists: () => false });
86
+ assert.equal(resolved.installed, false);
87
+ assert.equal(resolved.path, null);
88
+ assert.equal(resolved.mcp.command, MACOS_BINARY);
89
+ });
90
+
91
+ await test('Windows:新目录存在时用它,MCP 命令与 patch 表达式一致', () => {
92
+ const resolved = resolveInstall({
93
+ platform: 'win32',
94
+ env: { LOCALAPPDATA: LOCAL },
95
+ exists: (path) => path === WIN_PRIMARY,
96
+ });
97
+ assert.equal(resolved.installed, true);
98
+ assert.equal(resolved.path, WIN_PRIMARY);
99
+ assert.deepEqual(resolved.mcp, { command: WIN_PRIMARY, args: ['mcp'] });
100
+ assert.deepEqual(resolved.notes, []);
101
+ });
102
+
103
+ await test('Windows:KIMI_CU_WINDOWS_EXE 覆盖默认路径', () => {
104
+ const custom = 'D:\\tools\\kimi-cu.exe';
105
+ const resolved = resolveInstall({
106
+ platform: 'win32',
107
+ env: { LOCALAPPDATA: LOCAL, KIMI_CU_WINDOWS_EXE: custom },
108
+ exists: (path) => path === custom,
109
+ });
110
+ assert.equal(resolved.path, custom);
111
+ assert.equal(resolved.mcp.command, custom);
112
+ });
113
+
114
+ await test('Windows:只有旧目录时标记 legacy-install 与 mcp-command-missing,并给出升级步骤', () => {
115
+ const resolved = resolveInstall({
116
+ platform: 'win32',
117
+ env: { LOCALAPPDATA: LOCAL },
118
+ exists: (path) => path === WIN_LEGACY,
119
+ });
120
+ assert.equal(resolved.installed, true);
121
+ assert.equal(resolved.path, WIN_LEGACY);
122
+ assert.deepEqual(resolved.notes, ['legacy-install', 'mcp-command-missing']);
123
+ assert.equal(resolved.mcp.command, WIN_PRIMARY);
124
+ assert.ok(resolved.install.steps.includes('upgrade'), '旧目录安装要给出升级步骤');
125
+ });
126
+
127
+ await test('Windows:两个目录都没有时 installed 为假', () => {
128
+ const resolved = resolveInstall({ platform: 'win32', env: { LOCALAPPDATA: LOCAL }, exists: () => false });
129
+ assert.equal(resolved.installed, false);
130
+ assert.equal(resolved.path, null);
131
+ assert.deepEqual(resolved.notes, []);
132
+ });
133
+
134
+ await test('Windows:KIMI_CU_WINDOWS_EXE 指向不存在的文件时不再回退到默认目录', () => {
135
+ const missing = 'D:\\missing.exe';
136
+ const resolved = resolveInstall({
137
+ platform: 'win32',
138
+ env: { LOCALAPPDATA: LOCAL, KIMI_CU_WINDOWS_EXE: missing },
139
+ exists: (path) => path === WIN_PRIMARY,
140
+ });
141
+ assert.equal(resolved.installed, false);
142
+ assert.equal(resolved.path, null);
143
+ assert.deepEqual(resolved.notes, ['override-missing']);
144
+ assert.equal(resolved.mcp.command, missing, 'MCP 行启动的是覆盖值,状态必须跟着它');
145
+ });
146
+
147
+ await test('Windows:LOCALAPPDATA 缺失时命令与 patch 表达式同一公式', () => {
148
+ const resolved = resolveInstall({ platform: 'win32', env: {}, exists: () => false });
149
+ assert.equal(resolved.installed, false);
150
+ assert.equal(resolved.mcp.command, '\\Kimi Computer Use\\kimi-cu.exe');
151
+ });
152
+
153
+ await test('不支持的平台:supported 为假,没有 MCP 命令与安装计划', () => {
154
+ const resolved = resolveInstall({ platform: 'linux', env: {}, exists: () => true });
155
+ assert.equal(resolved.supported, false);
156
+ assert.equal(resolved.installed, false);
157
+ assert.equal(resolved.mcp, null);
158
+ assert.equal(resolved.install, null);
159
+ });
160
+
161
+ await test('macOS doctor:五项全绿时 ok 为真,id 映射对得上', () => {
162
+ const parsed = parseDoctor('darwin', MAC_DOCTOR_OK);
163
+ assert.equal(parsed.ok, true);
164
+ assert.deepEqual(parsed.checks.map((check) => check.id), [
165
+ 'accessibility',
166
+ 'screen-recording',
167
+ 'skylight',
168
+ 'bg-input',
169
+ 'signed-keyboard',
170
+ ]);
171
+ assert.equal(parsed.version, null);
172
+ });
173
+
174
+ await test('macOS doctor:有一项失败时 ok 为假', () => {
175
+ const parsed = parseDoctor('darwin', MAC_DOCTOR_BAD);
176
+ assert.equal(parsed.ok, false);
177
+ assert.equal(parsed.checks.find((check) => check.id === 'screen-recording').ok, false);
178
+ });
179
+
180
+ await test('Windows doctor:mcp=true 时 ok 为真,版本从输出里读', () => {
181
+ const parsed = parseDoctor('win32', WIN_DOCTOR_OK);
182
+ assert.equal(parsed.ok, true);
183
+ assert.equal(parsed.version, '0.3.13');
184
+ assert.deepEqual(parsed.checks, [{ id: 'mcp', label: 'MCP', ok: true }]);
185
+ });
186
+
187
+ await test('Windows doctor:mcp=false 时 ok 为假', () => {
188
+ const parsed = parseDoctor('win32', WIN_DOCTOR_BAD);
189
+ assert.equal(parsed.ok, false);
190
+ assert.equal(parsed.version, '0.3.13');
191
+ });
192
+
193
+ await test('Info.plist 里能读出 CFBundleShortVersionString', () => {
194
+ const plist = [
195
+ '<?xml version="1.0" encoding="UTF-8"?>',
196
+ '<plist version="1.0"><dict>',
197
+ ' <key>CFBundleShortVersionString</key>',
198
+ ' <string>0.6.8</string>',
199
+ '</dict></plist>',
200
+ ].join('\n');
201
+ assert.equal(parseMacosVersion(plist), '0.6.8');
202
+ assert.equal(parseMacosVersion('not a plist'), null);
203
+ });
204
+
205
+ /** 一个可推进的时钟与可计数的 doctor。 */
206
+ function detectorHarness(overrides = {}) {
207
+ let clock = 1_000;
208
+ let doctorCalls = 0;
209
+ const deps = {
210
+ platform: 'darwin',
211
+ env: {},
212
+ exists: () => true,
213
+ readVersion: () => '0.6.8',
214
+ runDoctor: async () => {
215
+ doctorCalls += 1;
216
+ return { ran: true, ok: true, checks: [], version: null, raw: '' };
217
+ },
218
+ now: () => clock,
219
+ ttlMs: 10_000,
220
+ ...overrides,
221
+ };
222
+ const detect = createStatusDetector(deps);
223
+ return {
224
+ detect,
225
+ advance: (ms) => { clock += ms; },
226
+ calls: () => doctorCalls,
227
+ };
228
+ }
229
+
230
+ await test('检测结果在 TTL 内复用,过期后重跑', async () => {
231
+ const harness = detectorHarness();
232
+ const first = await harness.detect();
233
+ assert.equal(first.version, '0.6.8');
234
+ assert.equal(harness.calls(), 1);
235
+ await harness.detect();
236
+ assert.equal(harness.calls(), 1, 'TTL 内不该重跑');
237
+ harness.advance(20_000);
238
+ await harness.detect();
239
+ assert.equal(harness.calls(), 2, '过期后应当重跑');
240
+ });
241
+
242
+ await test('refresh 绕过缓存', async () => {
243
+ const harness = detectorHarness();
244
+ await harness.detect();
245
+ await harness.detect(true);
246
+ assert.equal(harness.calls(), 2);
247
+ });
248
+
249
+ await test('并发调用共用一次探测', async () => {
250
+ const harness = detectorHarness();
251
+ await Promise.all([harness.detect(true), harness.detect(true), harness.detect(true)]);
252
+ assert.equal(harness.calls(), 1);
253
+ });
254
+
255
+ await test('doctor 失败时状态仍保留 installed,错误写进 doctor.error', async () => {
256
+ const harness = detectorHarness({
257
+ runDoctor: async () => ({ ran: true, ok: false, checks: [], version: null, raw: '', error: 'timeout' }),
258
+ });
259
+ const status = await harness.detect();
260
+ assert.equal(status.installed, true);
261
+ assert.equal(status.doctor.ok, false);
262
+ assert.equal(status.doctor.error, 'timeout');
263
+ });
264
+
265
+ await test('版本读不出来时回退到 doctor 输出里的版本', async () => {
266
+ const harness = detectorHarness({
267
+ readVersion: () => null,
268
+ runDoctor: async () => ({ ran: true, ok: true, checks: [], version: '0.3.13', raw: '' }),
269
+ });
270
+ const status = await harness.detect();
271
+ assert.equal(status.version, '0.3.13');
272
+ });
273
+
274
+ await test('不支持的平台不跑 doctor', async () => {
275
+ const harness = detectorHarness({ platform: 'linux', exists: () => true });
276
+ const status = await harness.detect();
277
+ assert.equal(status.supported, false);
278
+ assert.equal(harness.calls(), 0);
279
+ });
280
+
281
+ await test('exists 抛错时探测器不 reject,返回 detection-failed 状态', async () => {
282
+ const detect = createStatusDetector({
283
+ platform: 'darwin',
284
+ env: {},
285
+ exists: () => { throw new Error('boom'); },
286
+ readVersion: () => null,
287
+ runDoctor: async () => ({ ran: true, ok: true, checks: [], version: null, raw: '' }),
288
+ now: () => 1,
289
+ });
290
+ const status = await detect();
291
+ assert.equal(status.installed, false);
292
+ assert.deepEqual(status.notes, ['detection-failed']);
293
+ assert.match(status.doctor.error, /boom/);
294
+ });
295
+
296
+ console.log(`\ntest-status: ${passed}/${total} 条断言通过`);
@@ -10,6 +10,8 @@ description: |
10
10
 
11
11
  DSH 把这些工具注册为 `mcp__kimi-cu__<name>`(例如 `mcp__kimi-cu__list_apps`);下文用去掉前缀的短名指代。
12
12
 
13
+ 如果 `mcp__kimi-cu__*` 工具不存在或连接失败,先调用 DSH 的 `kimi_cu_status` 工具查安装状态与修复步骤,把结论转告用户;不要在缺装时假装能操作。
14
+
13
15
  ## 操作边界
14
16
 
15
17
  - 默认后台操作,不自行激活应用、抬窗或开启前台 fallback。永不移动真实光标、使用 HID 投递或拦截用户真实点击;不要用 AppleScript / cliclick 等绕过这些限制。
@@ -0,0 +1,76 @@
1
+ ---
2
+ name: kimi-cu
3
+ description: |
4
+ 使用 KimiCU 读取和操作本机 Windows app:查看界面或截图,点击、输入、滚动、拖拽,以及列出应用和窗口。用户需要代为操作桌面界面时使用;仅讨论或修改 app 代码时不需要。
5
+ ---
6
+
7
+ # kimi-cu — Windows 前台 GUI 操作
8
+
9
+ 通过 KimiCU MCP 的 UIA 树和截图观察界面,再定向操作目标应用。参数以当前工具 schema 为准;本 skill 说明目标绑定、操作选择和验证规则。
10
+
11
+ DSH 把这些工具注册为 `mcp__kimi-cu__<name>`(例如 `mcp__kimi-cu__list_apps`);下文用去掉前缀的短名指代。
12
+
13
+ 如果 `mcp__kimi-cu__*` 工具不存在或连接失败,先调用 DSH 的 `kimi_cu_status` 工具查安装状态与修复步骤,把结论转告用户;不要在缺装时假装能操作。
14
+
15
+ ## 与 macOS 版的关键差异
16
+
17
+ - Windows 版无法像 macOS 版那样全程后台输入:执行点击、输入等操作时可能短暂激活目标窗口、使用你的真实鼠标键盘,并在每块显示器上显示使用中提示与光晕。
18
+ - 不需要 macOS 的辅助功能/屏幕录制授权;目标应用以管理员权限运行时,KimiCU 需要同等权限(管理员模式由用户在控制面板里手动开启并确认 UAC)。
19
+ - 工具面是 13 个:`list_apps`、`launch_app`、`activate_window`、`get_app_state`、`click`、`type_text`、`press_key`、`scroll`、`set_value`、`perform_secondary_action`、`select_text`、`drag`、`turn_ended`。没有 `paste`、`drag_paths`、`js`、`js_reset`、`list_windows`、`get_window`、`debug_tap`。
20
+
21
+ ## 操作边界
22
+
23
+ - 真实输入会短暂占用键鼠;用户正在操作电脑时先说明再动手。Esc 可以停止当前 turn 的后续真实输入。
24
+ - 同一时刻只允许一个会话持有真实输入;收到 `computer_use_busy` 时停止发输入,只做只读观察,等另一会话结束后再试。
25
+ - 不向受保护的终端窗口(命令提示符、PowerShell、Windows Terminal 等)发送输入;不发 Win/Meta/Super/Command 组合键;Explorer 的桌面/任务栏外壳不可操作,普通文件资源管理器窗口可以。
26
+ - 桌面必须已解锁并处于交互式会话;锁屏、UAC 安全桌面或远程会话断开时,运行时拒绝 GUI 观察与输入,请用户解锁/重连,不要循环重试。
27
+ - 发送、提交、删除、付款等动作须在用户已明确授权的目标和范围内;已有授权不重复确认,缺少必要信息时再问。
28
+
29
+ ## 观察与目标绑定
30
+
31
+ 1. 目标不明确时用 `list_apps` 定位已打开的应用;需要启动尚未运行的应用时用 `launch_app`(可传可执行文件路径/名称、StartApps 显示名或 AppID),启动后再 `list_apps` 选窗口。
32
+ 2. 用 `get_app_state` 观察目标;后续 index 和坐标必须来自这次观察。`mode` 取当前 schema 支持的值;截图会作为图片返回。
33
+ 3. 只需要恢复最小化窗口时用 `activate_window`;普通输入会自动激活目标,不要反复激活。
34
+ 4. 执行动作;页面切换、滚动、弹窗或布局变化影响目标时,重新观察再决定下一步。
35
+ 5. 验证任务要求的结果。投递成功不等于生效;必要时再次观察。
36
+
37
+ 坐标纪律:
38
+
39
+ - `click` / `scroll` / `drag` 的 x/y 是所用截图的像素坐标,不是屏幕坐标。
40
+ - `get_app_state` 返回的 `snapshot_id` / `app_state_id` 把动作绑定到那次观察;内容变化后重新观察。
41
+ - UIA 的 bbox 可能缺失或不准确;截图与 UIA 不一致时以截图为准。
42
+
43
+ ## 输入与编辑
44
+
45
+ - 普通表单整体赋值优先 `set_value`。
46
+ - 聊天框、富文本输入优先 `type_text` 并显式指定 `index` 或截图 x/y;`type_text` 不负责聚焦、清空或提交,先建立焦点再输入。
47
+ - 需要替换时显式清空(按当前 schema 的 `clear` 参数);保留原文插入时确认插入点在末尾。
48
+ - 文本会覆盖系统剪贴板并留在那里。
49
+ - 输入和发送分开判断;仅在任务包含发送时提交。
50
+
51
+ ## 点击、滚动与批量
52
+
53
+ - 优先使用元素自带的 UIA 动作;动作名称来自观察结果。
54
+ - 滚动用 `scroll`;方向与单位以当前 schema 为准,滚动后重新定位受影响的目标。
55
+ - 动作未生效时先重新观察目标和状态,再选择界面提供的等价操作;不要连续盲重试。
56
+ - 目标稳定、后续步骤能用代码判断的批量操作,用普通工具逐个 `await`;Windows 版没有 `js`,不要假设有。
57
+
58
+ ## 结束一轮
59
+
60
+ - 本轮做过真实输入时,结束前调用 `turn_ended`,让运行时清理本轮的输入租约与停止状态;它不撤销已经投递的操作。
61
+ - 连接恢复只重建连接;已派发的点击/输入可能已经生效,不会自动重放。
62
+
63
+ ## 排障与安装
64
+
65
+ - 安装:官方 runtime 安装命令(PowerShell):
66
+
67
+ ```powershell
68
+ powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Invoke-RestMethod 'https://cdn.kimi.com/kimi-computer-use-windows/latest/setup_windows.ps1' | Invoke-Expression"
69
+ ```
70
+
71
+ 默认装到 `%LOCALAPPDATA%\Kimi Computer Use\kimi-cu.exe`;旧版目录是 `%LOCALAPPDATA%\KimiCU`。
72
+ - 检查运行时:`& "$env:LOCALAPPDATA\Kimi Computer Use\kimi-cu.exe" doctor`,应输出 `mcp=true` 与 `helper=embedded`。
73
+ - 权限诊断:`kimi-cu.exe open-panel` 打开控制面板;需要操作管理员应用时,由用户在面板里开启管理员模式并确认 UAC。不要自己操作 UAC。
74
+ - 运行时更新中会返回 `runtime_upgrading` / `reconnect_required`;按提示重连 MCP,不要在同一个 MCP 会话里重试。
75
+ - 自定义路径:启动宿主前把 `KIMI_CU_WINDOWS_EXE` 设成现有的 `kimi-cu.exe` 绝对路径。
76
+ - CLI 只用于排障/安装维护;日常取图、取坐标和操作仍用 MCP。