@lynn123411/dsh-kimi-cu 0.3.6 → 0.3.8
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/README.md +5 -5
- package/lib/client.js +178 -45
- package/lib/client.js.map +2 -2
- package/lib/index.js +121 -92
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
- package/scripts/check-bundle.mjs +1 -1
- package/scripts/test-card.mjs +228 -44
- package/scripts/test-exclusivity.mjs +46 -3
- package/scripts/test-status.mjs +87 -20
- package/scripts/test-update.mjs +6 -1
- package/skills/macos/kimi-cu/SKILL.md +29 -18
- package/skills/windows/kimi-cu/SKILL.md +21 -61
package/lib/index.js
CHANGED
|
@@ -113,12 +113,15 @@ function createMcpConnection(warn) {
|
|
|
113
113
|
};
|
|
114
114
|
const reconcile = async () => {
|
|
115
115
|
const status = lastDetection;
|
|
116
|
-
const command = status?.supported && status.installed
|
|
116
|
+
const command = status?.supported && status.installed ? status.mcp : null;
|
|
117
|
+
const outcome = status?.doctor.outcome;
|
|
117
118
|
if (current !== void 0) {
|
|
118
|
-
|
|
119
|
+
const sameProviders = current.manager === manager && current.registry === registry;
|
|
120
|
+
const sameCommand = command !== null && current.command.command === command.command && current.command.args.length === command.args.length && current.command.args.every((arg, index) => arg === command.args[index]);
|
|
121
|
+
if (sameProviders && (status?.notes.includes("detection-failed") || sameCommand && (outcome === "passed" || outcome === "unknown"))) return;
|
|
119
122
|
await disconnect(current);
|
|
120
123
|
}
|
|
121
|
-
if (command === null || manager === void 0) {
|
|
124
|
+
if (outcome !== "passed" || command === null || manager === void 0) {
|
|
122
125
|
failure = null;
|
|
123
126
|
return;
|
|
124
127
|
}
|
|
@@ -173,7 +176,10 @@ function createMcpConnection(warn) {
|
|
|
173
176
|
lastDetection = status;
|
|
174
177
|
await reconcile();
|
|
175
178
|
const registration = current;
|
|
176
|
-
if (registration !== void 0 && registration === previous)
|
|
179
|
+
if (registration !== void 0 && registration === previous) {
|
|
180
|
+
if (status.doctor.outcome !== "passed") return void 0;
|
|
181
|
+
await registration.manager.restart(MCP_SERVER_NAME);
|
|
182
|
+
}
|
|
177
183
|
return registration;
|
|
178
184
|
}).then(async (registration) => {
|
|
179
185
|
if (registration === void 0) return false;
|
|
@@ -214,52 +220,51 @@ function installPlan(platform) {
|
|
|
214
220
|
}
|
|
215
221
|
return null;
|
|
216
222
|
}
|
|
217
|
-
function windowsPrimary(env) {
|
|
218
|
-
return (env.LOCALAPPDATA || "") + "\\" + WINDOWS_DIR_NAME + "\\" + WINDOWS_EXE_NAME;
|
|
219
|
-
}
|
|
220
|
-
function windowsMcpCommand(env) {
|
|
221
|
-
return env.KIMI_CU_WINDOWS_EXE || "" || windowsPrimary(env);
|
|
222
|
-
}
|
|
223
223
|
function resolveInstall(input) {
|
|
224
224
|
const platform = toPlatform(input.platform);
|
|
225
225
|
if (platform === "darwin") {
|
|
226
226
|
const installed = input.exists(MACOS_BINARY);
|
|
227
|
+
const launcher = installed && input.exists(MACOS_MCP_LAUNCHER);
|
|
227
228
|
return {
|
|
228
229
|
platform,
|
|
229
230
|
supported: true,
|
|
230
231
|
installed,
|
|
231
232
|
path: installed ? MACOS_BINARY : null,
|
|
232
|
-
mcp: { command: MACOS_MCP_LAUNCHER, args: ["mcp", "-s", "user", "--surface", "codeact"] },
|
|
233
|
+
mcp: launcher ? { command: MACOS_MCP_LAUNCHER, args: ["mcp", "-s", "user", "--surface", "codeact"] } : null,
|
|
233
234
|
install: installPlan("darwin"),
|
|
234
|
-
notes: installed && !
|
|
235
|
+
notes: installed && !launcher ? ["mcp-command-missing"] : []
|
|
235
236
|
};
|
|
236
237
|
}
|
|
237
238
|
if (platform === "win32") {
|
|
238
|
-
const base = input.env.LOCALAPPDATA ||
|
|
239
|
-
const primary =
|
|
240
|
-
const legacy = base + "\\" + WINDOWS_LEGACY_DIR_NAME + "\\" + WINDOWS_EXE_NAME;
|
|
241
|
-
const override = input.env.KIMI_CU_WINDOWS_EXE ||
|
|
242
|
-
const
|
|
239
|
+
const base = input.env.LOCALAPPDATA || null;
|
|
240
|
+
const primary = base === null ? null : base + "\\" + WINDOWS_DIR_NAME + "\\" + WINDOWS_EXE_NAME;
|
|
241
|
+
const legacy = base === null ? null : base + "\\" + WINDOWS_LEGACY_DIR_NAME + "\\" + WINDOWS_EXE_NAME;
|
|
242
|
+
const override = input.env.KIMI_CU_WINDOWS_EXE || null;
|
|
243
|
+
const notes = [];
|
|
243
244
|
let path = null;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
let command = null;
|
|
246
|
+
if (override !== null && input.exists(override)) {
|
|
247
|
+
path = command = override;
|
|
248
|
+
} else {
|
|
249
|
+
if (override !== null) notes.push("override-missing");
|
|
250
|
+
if (base === null) notes.push("localappdata-missing");
|
|
251
|
+
if (primary !== null && input.exists(primary)) {
|
|
252
|
+
path = primary;
|
|
253
|
+
if (override === null) command = primary;
|
|
254
|
+
} else if (legacy !== null && input.exists(legacy)) {
|
|
255
|
+
path = legacy;
|
|
256
|
+
notes.push("legacy-install");
|
|
257
|
+
if (override === null) notes.push("mcp-command-missing");
|
|
258
|
+
}
|
|
250
259
|
}
|
|
251
|
-
const notes = [];
|
|
252
|
-
if (path !== null && path === legacy) notes.push("legacy-install");
|
|
253
|
-
if (override !== "" && path === null) notes.push("override-missing");
|
|
254
|
-
if (path !== null && command !== "" && !input.exists(command)) notes.push("mcp-command-missing");
|
|
255
260
|
const install = installPlan("win32");
|
|
256
|
-
if (install !== null && notes.includes("legacy-install")) install.steps = [
|
|
261
|
+
if (install !== null && notes.includes("legacy-install")) install.steps = ["upgrade", "recheck"];
|
|
257
262
|
return {
|
|
258
263
|
platform,
|
|
259
264
|
supported: true,
|
|
260
265
|
installed: path !== null,
|
|
261
266
|
path,
|
|
262
|
-
mcp: command ===
|
|
267
|
+
mcp: command === null ? null : { command, args: ["mcp"] },
|
|
263
268
|
install,
|
|
264
269
|
notes
|
|
265
270
|
};
|
|
@@ -276,7 +281,7 @@ function resolveInstall(input) {
|
|
|
276
281
|
}
|
|
277
282
|
|
|
278
283
|
// src/server/status.ts
|
|
279
|
-
import {
|
|
284
|
+
import { readFileSync, statSync } from "node:fs";
|
|
280
285
|
import { dirname, join } from "node:path";
|
|
281
286
|
|
|
282
287
|
// src/server/doctor.ts
|
|
@@ -290,49 +295,70 @@ var MACOS_CHECK_IDS = {
|
|
|
290
295
|
"bg-input (window-location spi)": "bg-input",
|
|
291
296
|
"signed keyboard": "signed-keyboard"
|
|
292
297
|
};
|
|
298
|
+
var MACOS_PERMISSIONS = [
|
|
299
|
+
{ id: "accessibility", label: "Accessibility (AX)" },
|
|
300
|
+
{ id: "screen-recording", label: "Screen Recording" }
|
|
301
|
+
];
|
|
302
|
+
var MACOS_CONTROL_CHANNEL = { id: "runtime-control", label: "Runtime control channel" };
|
|
303
|
+
function parseMacosCheck(line, index) {
|
|
304
|
+
const mark = line.slice(0, 1);
|
|
305
|
+
if (mark !== "\u2705" && mark !== "\u274C") return null;
|
|
306
|
+
const label = line.slice(1).trim();
|
|
307
|
+
if (label === "") return null;
|
|
308
|
+
const lower = label.toLowerCase();
|
|
309
|
+
const id = /^runtime control channel(?:$|:)/.test(lower) ? MACOS_CONTROL_CHANNEL.id : MACOS_CHECK_IDS[lower] ?? "check-" + String(index + 1);
|
|
310
|
+
return { id, label, ok: mark === "\u2705" };
|
|
311
|
+
}
|
|
312
|
+
function doctorOutcome(checks) {
|
|
313
|
+
if (checks.some((check) => check.ok === false)) return "failed";
|
|
314
|
+
return checks.length > 0 && checks.every((check) => check.ok === true) ? "passed" : "unknown";
|
|
315
|
+
}
|
|
293
316
|
function parseDoctor(platform, raw) {
|
|
294
317
|
const lines = raw.split("\n").map((line) => line.trim());
|
|
295
318
|
if (platform === "darwin") {
|
|
296
319
|
const checks = [];
|
|
297
|
-
const
|
|
298
|
-
|
|
320
|
+
const diagnosticChecks = [];
|
|
321
|
+
const isServiceHeading = (line) => /^Service \(authoritative/i.test(line);
|
|
322
|
+
const isProcessHeading = (line) => /^This process \(diagnostic/i.test(line);
|
|
323
|
+
const scoped = lines.some((line) => isServiceHeading(line) || isProcessHeading(line));
|
|
324
|
+
let section = scoped ? void 0 : checks;
|
|
299
325
|
for (const line of lines) {
|
|
300
|
-
if (
|
|
301
|
-
|
|
326
|
+
if (isServiceHeading(line)) {
|
|
327
|
+
section = checks;
|
|
302
328
|
continue;
|
|
303
329
|
}
|
|
304
|
-
if (
|
|
305
|
-
|
|
330
|
+
if (isProcessHeading(line)) {
|
|
331
|
+
section = diagnosticChecks;
|
|
306
332
|
continue;
|
|
307
333
|
}
|
|
308
|
-
if (
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
checks.
|
|
334
|
+
if (section === void 0) continue;
|
|
335
|
+
const check = parseMacosCheck(line, section.length);
|
|
336
|
+
if (check !== null) section.push(check);
|
|
337
|
+
}
|
|
338
|
+
const required = scoped ? [...MACOS_PERMISSIONS, MACOS_CONTROL_CHANNEL] : MACOS_PERMISSIONS;
|
|
339
|
+
for (const check of required) {
|
|
340
|
+
if (!checks.some(({ id }) => id === check.id)) checks.push({ ...check, ok: null });
|
|
315
341
|
}
|
|
316
|
-
|
|
342
|
+
const outcome = doctorOutcome(checks);
|
|
343
|
+
return { outcome, ok: outcome === "passed", checks, diagnosticChecks, version: null };
|
|
317
344
|
}
|
|
318
345
|
if (platform === "win32") {
|
|
319
346
|
let version = null;
|
|
320
|
-
|
|
347
|
+
const mcpValues = /* @__PURE__ */ new Set();
|
|
321
348
|
for (const line of lines) {
|
|
322
349
|
if (line.startsWith("version=")) version = line.slice("version=".length).trim() || null;
|
|
323
|
-
else if (line.startsWith("mcp="))
|
|
350
|
+
else if (line.startsWith("mcp=")) mcpValues.add(line.slice("mcp=".length).trim());
|
|
324
351
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
};
|
|
352
|
+
const mcp = mcpValues.size === 1 ? mcpValues.values().next().value : void 0;
|
|
353
|
+
const checks = [{ id: "mcp", label: "MCP", ok: mcp === "true" ? true : mcp === "false" ? false : null }];
|
|
354
|
+
const outcome = doctorOutcome(checks);
|
|
355
|
+
return { outcome, ok: outcome === "passed", checks, diagnosticChecks: [], version };
|
|
330
356
|
}
|
|
331
|
-
return { ok: false, checks: [], version: null };
|
|
357
|
+
return { outcome: "not-run", ok: false, checks: [], diagnosticChecks: [], version: null };
|
|
332
358
|
}
|
|
333
359
|
async function runDoctor(platform, binaryPath) {
|
|
334
360
|
if (platform === "other" || binaryPath === "") {
|
|
335
|
-
return {
|
|
361
|
+
return { ...parseDoctor("other", ""), ran: false, raw: "" };
|
|
336
362
|
}
|
|
337
363
|
try {
|
|
338
364
|
const { stdout, stderr } = await execFileAsync(binaryPath, ["doctor"], {
|
|
@@ -340,14 +366,19 @@ async function runDoctor(platform, binaryPath) {
|
|
|
340
366
|
windowsHide: true,
|
|
341
367
|
encoding: "utf8"
|
|
342
368
|
});
|
|
343
|
-
const raw =
|
|
369
|
+
const raw = [stdout, stderr].filter(Boolean).join("\n");
|
|
344
370
|
return { ran: true, ...parseDoctor(platform, raw), raw };
|
|
345
371
|
} catch (error) {
|
|
346
372
|
const record = error;
|
|
347
|
-
const raw =
|
|
373
|
+
const raw = [record.stdout, record.stderr].filter(Boolean).join("\n");
|
|
374
|
+
const parsed = parseDoctor(platform, raw);
|
|
375
|
+
const exited = typeof record.code === "number" && !record.killed && record.signal == null;
|
|
376
|
+
const outcome = exited && parsed.outcome === "failed" ? "failed" : "unknown";
|
|
348
377
|
return {
|
|
349
|
-
|
|
350
|
-
|
|
378
|
+
...parsed,
|
|
379
|
+
ran: exited || record.killed === true || record.signal != null || raw !== "",
|
|
380
|
+
outcome,
|
|
381
|
+
ok: false,
|
|
351
382
|
raw,
|
|
352
383
|
error: error instanceof Error ? error.message : String(error)
|
|
353
384
|
};
|
|
@@ -355,6 +386,17 @@ async function runDoctor(platform, binaryPath) {
|
|
|
355
386
|
}
|
|
356
387
|
|
|
357
388
|
// src/server/status.ts
|
|
389
|
+
function doctorUnavailable(error) {
|
|
390
|
+
return {
|
|
391
|
+
ran: false,
|
|
392
|
+
outcome: error === void 0 ? "not-run" : "unknown",
|
|
393
|
+
ok: false,
|
|
394
|
+
checks: [],
|
|
395
|
+
diagnosticChecks: [],
|
|
396
|
+
raw: "",
|
|
397
|
+
...error === void 0 ? {} : { error: error instanceof Error ? error.message : String(error) }
|
|
398
|
+
};
|
|
399
|
+
}
|
|
358
400
|
function parseMacosVersion(plist) {
|
|
359
401
|
const key = plist.indexOf("CFBundleShortVersionString");
|
|
360
402
|
if (key === -1) return null;
|
|
@@ -385,13 +427,7 @@ function createStatusDetector(deps) {
|
|
|
385
427
|
installed: false,
|
|
386
428
|
path: null,
|
|
387
429
|
version: null,
|
|
388
|
-
doctor:
|
|
389
|
-
ran: false,
|
|
390
|
-
ok: false,
|
|
391
|
-
checks: [],
|
|
392
|
-
raw: "",
|
|
393
|
-
error: error instanceof Error ? error.message : String(error)
|
|
394
|
-
},
|
|
430
|
+
doctor: doctorUnavailable(error),
|
|
395
431
|
mcp: null,
|
|
396
432
|
install: installPlan(platform),
|
|
397
433
|
notes: ["detection-failed"],
|
|
@@ -409,26 +445,14 @@ function createStatusDetector(deps) {
|
|
|
409
445
|
version = null;
|
|
410
446
|
}
|
|
411
447
|
}
|
|
412
|
-
let doctor =
|
|
448
|
+
let doctor = doctorUnavailable();
|
|
413
449
|
if (resolved.supported && resolved.path !== null) {
|
|
414
450
|
try {
|
|
415
|
-
const
|
|
416
|
-
doctor =
|
|
417
|
-
|
|
418
|
-
ok: run.ok,
|
|
419
|
-
checks: run.checks,
|
|
420
|
-
raw: run.raw,
|
|
421
|
-
...run.error === void 0 ? {} : { error: run.error }
|
|
422
|
-
};
|
|
423
|
-
version = version ?? run.version;
|
|
451
|
+
const { version: doctorVersion, ...report } = await deps.runDoctor(resolved.platform, resolved.path);
|
|
452
|
+
doctor = report;
|
|
453
|
+
version = version ?? doctorVersion;
|
|
424
454
|
} catch (error) {
|
|
425
|
-
doctor =
|
|
426
|
-
ran: true,
|
|
427
|
-
ok: false,
|
|
428
|
-
checks: [],
|
|
429
|
-
raw: "",
|
|
430
|
-
error: error instanceof Error ? error.message : String(error)
|
|
431
|
-
};
|
|
455
|
+
doctor = doctorUnavailable(error);
|
|
432
456
|
}
|
|
433
457
|
}
|
|
434
458
|
return {
|
|
@@ -448,9 +472,9 @@ function createStatusDetector(deps) {
|
|
|
448
472
|
}
|
|
449
473
|
};
|
|
450
474
|
return async (refresh = false) => {
|
|
451
|
-
|
|
452
|
-
if (!refresh && cached !== void 0 && at - cached.at < ttl) return cached.value;
|
|
475
|
+
if (refresh === "after-upgrade" && inflight !== void 0) await inflight;
|
|
453
476
|
if (inflight !== void 0) return inflight;
|
|
477
|
+
if (!refresh && cached !== void 0 && now() - cached.at < ttl) return cached.value;
|
|
454
478
|
inflight = build().then((value) => {
|
|
455
479
|
cached = { at: now(), value };
|
|
456
480
|
return value;
|
|
@@ -464,7 +488,7 @@ function defaultStatusDetector() {
|
|
|
464
488
|
return createStatusDetector({
|
|
465
489
|
platform: process.platform,
|
|
466
490
|
env: process.env,
|
|
467
|
-
exists:
|
|
491
|
+
exists: (path) => statSync(path, { throwIfNoEntry: false })?.isFile() ?? false,
|
|
468
492
|
readVersion: (platform, path) => platform === "darwin" ? readMacosVersion(path) : null,
|
|
469
493
|
runDoctor
|
|
470
494
|
});
|
|
@@ -633,7 +657,7 @@ function createUpdater(deps) {
|
|
|
633
657
|
const exited = await outcome.whenExited;
|
|
634
658
|
outcome = { ...outcome, code: exited?.code ?? null, raw: exited?.raw ?? outcome.raw, timedOut: false };
|
|
635
659
|
}
|
|
636
|
-
const after = await readCurrent(
|
|
660
|
+
const after = await readCurrent("after-upgrade");
|
|
637
661
|
if (outcome.code !== 0) {
|
|
638
662
|
if (after.path !== null && after.version !== null && after.version !== current.version && deps.reconnect !== null) {
|
|
639
663
|
emit({ type: "stage", stage: "restarting" });
|
|
@@ -817,7 +841,7 @@ function apply(ctx, options) {
|
|
|
817
841
|
parameters: {
|
|
818
842
|
refresh: {
|
|
819
843
|
type: "boolean",
|
|
820
|
-
description: "Re-run detection instead of using the cached result."
|
|
844
|
+
description: "Re-run detection instead of using the cached result and reconcile the MCP connection."
|
|
821
845
|
}
|
|
822
846
|
},
|
|
823
847
|
output: {
|
|
@@ -863,12 +887,17 @@ function apply(ctx, options) {
|
|
|
863
887
|
});
|
|
864
888
|
void detectBase().then(async (status) => {
|
|
865
889
|
await mcp.sync(status);
|
|
866
|
-
if (!status.supported
|
|
867
|
-
|
|
868
|
-
"KimiCU
|
|
869
|
-
)
|
|
870
|
-
|
|
871
|
-
|
|
890
|
+
if (!status.supported) return;
|
|
891
|
+
if (status.notes.includes("detection-failed")) {
|
|
892
|
+
ctx.logger.warn("KimiCU detection failed: " + (status.doctor.error ?? "unknown error"));
|
|
893
|
+
} else if (status.notes.includes("override-missing")) {
|
|
894
|
+
ctx.logger.warn("KIMI_CU_WINDOWS_EXE does not point to an installed KimiCU executable.");
|
|
895
|
+
} else if (status.notes.includes("localappdata-missing")) {
|
|
896
|
+
ctx.logger.warn("KimiCU cannot check the default Windows install path because LOCALAPPDATA is missing.");
|
|
897
|
+
} else if (!status.installed) {
|
|
898
|
+
ctx.logger.warn("KimiCU is not installed. Install it with: " + (status.install?.command ?? ""));
|
|
899
|
+
}
|
|
900
|
+
}).catch(logFailure);
|
|
872
901
|
}
|
|
873
902
|
export {
|
|
874
903
|
apply,
|