@copylee/dsh-computer-use 0.2.2 → 0.5.0
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 +9 -5
- package/helper/CuHelper.cs +863 -24
- package/helper/deepseek-black.png +0 -0
- package/helper/skills/notepad.md +8 -0
- package/helper/skills/obsidian.md +11 -0
- package/helper/skills/qq.md +11 -0
- package/helper/skills/typora.md +9 -0
- package/helper/skills/weixin.md +11 -0
- package/helper/skills/word.md +10 -0
- package/lib/client.js +294 -13
- package/lib/index.js +633 -39
- package/lib/types/client/skills-card.d.ts +9 -0
- package/lib/types/computer.d.ts +14 -0
- package/lib/types/index.d.ts +1 -6
- package/lib/types/overlay.d.ts +42 -1
- package/lib/types/routes.d.ts +4 -0
- package/lib/types/skills.d.ts +59 -0
- package/lib/types/tools.d.ts +3 -0
- package/package.json +3 -1
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
3
|
import z from "@deepseek-ai/schemastery";
|
|
3
4
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
4
5
|
import { execFile, spawn } from "node:child_process";
|
|
5
|
-
import {
|
|
6
|
-
import { existsSync } from "node:fs";
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { chmod, mkdir, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
8
8
|
import { homedir, tmpdir } from "node:os";
|
|
9
9
|
import { join } from "node:path";
|
|
@@ -125,7 +125,7 @@ function sameApp(a, b) {
|
|
|
125
125
|
*/
|
|
126
126
|
function isTransientShell(win) {
|
|
127
127
|
const exe = win.exe.toLowerCase();
|
|
128
|
-
if (exe === "textinputhost.exe") return true;
|
|
128
|
+
if (exe === "textinputhost.exe" || exe === "cu-helper.exe") return true;
|
|
129
129
|
return exe === "explorer.exe" && (win.className === "XamlExplorerHostIslandWindow" || /贴靠助手|snap assist/i.test(win.title));
|
|
130
130
|
}
|
|
131
131
|
function isHostWindow(win) {
|
|
@@ -426,7 +426,8 @@ function keyCode(name) {
|
|
|
426
426
|
*/
|
|
427
427
|
function parseKeys(text) {
|
|
428
428
|
const combos = [];
|
|
429
|
-
|
|
429
|
+
const joined = text.trim().replace(/\b(page|print|caps|num|scroll)\s+(up|down|screen|lock)\b/gi, "$1$2");
|
|
430
|
+
for (const chord of joined.split(/\s+/).filter(Boolean)) {
|
|
430
431
|
const parts = chord === "+" ? ["+"] : chord.split(/(?<!^)\+(?!$)/);
|
|
431
432
|
const combo = [];
|
|
432
433
|
for (const part of parts) {
|
|
@@ -568,6 +569,7 @@ var Computer = class Computer {
|
|
|
568
569
|
this.access = access;
|
|
569
570
|
this.overlay = overlay;
|
|
570
571
|
this.settings = settings;
|
|
572
|
+
overlay.onStart = () => this.noteStart();
|
|
571
573
|
}
|
|
572
574
|
async refreshDisplays() {
|
|
573
575
|
const rows = await this.helper.call("displays");
|
|
@@ -643,7 +645,8 @@ var Computer = class Computer {
|
|
|
643
645
|
this.seen = void 0;
|
|
644
646
|
}
|
|
645
647
|
async remember() {
|
|
646
|
-
|
|
648
|
+
const now = await this.foreground().catch(() => void 0);
|
|
649
|
+
if (!now || !isTransientShell(now)) this.seen = now;
|
|
647
650
|
}
|
|
648
651
|
/**
|
|
649
652
|
* Did another window come to the front since the model last looked, without
|
|
@@ -653,7 +656,7 @@ var Computer = class Computer {
|
|
|
653
656
|
const seen = this.seen;
|
|
654
657
|
if (!seen) return void 0;
|
|
655
658
|
const now = await this.foreground().catch(() => void 0);
|
|
656
|
-
return now && now.hwnd !== seen.hwnd ? now : void 0;
|
|
659
|
+
return now && now.hwnd !== seen.hwnd && now.pid !== seen.pid ? now : void 0;
|
|
657
660
|
}
|
|
658
661
|
async capture(rect, out, options = {}) {
|
|
659
662
|
const result = await this.helper.call("screenshot", {
|
|
@@ -742,6 +745,31 @@ var Computer = class Computer {
|
|
|
742
745
|
async windows() {
|
|
743
746
|
return this.helper.call("windows");
|
|
744
747
|
}
|
|
748
|
+
/** Windows when control started (hwnd -> minimized), and windows brought back from the tray since. */
|
|
749
|
+
before;
|
|
750
|
+
fromTray = /* @__PURE__ */ new Set();
|
|
751
|
+
/** Remember the window layout at the start of a task, to tell what the agent opened or restored. */
|
|
752
|
+
async noteStart() {
|
|
753
|
+
const rows = await this.windows().catch(() => []);
|
|
754
|
+
this.before = new Map((Array.isArray(rows) ? rows : []).map((row) => [row.hwnd, row.minimized]));
|
|
755
|
+
this.fromTray.clear();
|
|
756
|
+
}
|
|
757
|
+
noteFromTray(hwnd) {
|
|
758
|
+
this.fromTray.add(hwnd);
|
|
759
|
+
}
|
|
760
|
+
/** How a window relates to the layout before the task: opened by the agent, or restored from minimized / tray. */
|
|
761
|
+
origin(win) {
|
|
762
|
+
if (this.fromTray.has(win.hwnd)) return win.minimized ? void 0 : "tray";
|
|
763
|
+
if (!this.before) return void 0;
|
|
764
|
+
const was = this.before.get(win.hwnd);
|
|
765
|
+
if (was === void 0) return "opened";
|
|
766
|
+
return was && !win.minimized ? "minimized" : void 0;
|
|
767
|
+
}
|
|
768
|
+
/** Programs running without any visible window (closed to the system tray); `tray` = has a tray icon. */
|
|
769
|
+
async backgroundApps() {
|
|
770
|
+
const rows = await this.helper.call("background", {}, 15e3).catch(() => []);
|
|
771
|
+
return Array.isArray(rows) ? rows : [];
|
|
772
|
+
}
|
|
745
773
|
async cursor() {
|
|
746
774
|
return this.helper.call("cursor");
|
|
747
775
|
}
|
|
@@ -1247,8 +1275,37 @@ var HelperClient = class {
|
|
|
1247
1275
|
* agent, and typing on the keyboard makes the agent wait. While controlling,
|
|
1248
1276
|
* the DeepSeek Harness window can shrink into an always-on-top card.
|
|
1249
1277
|
*/
|
|
1250
|
-
/**
|
|
1251
|
-
|
|
1278
|
+
/** Markdown reduced to one plain line for the progress card. */
|
|
1279
|
+
function plainLine(text) {
|
|
1280
|
+
return text.replace(/```[\s\S]*?(```|$)/g, " ").replace(/!\[[^\]]*\]\([^)]*\)/g, " ").replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/^\s{0,3}(#{1,6}|>|[-*+]|\d+[.)])\s+/gm, "").replace(/(\*\*|__|`|~~)/g, "").replace(/\s+/g, " ");
|
|
1281
|
+
}
|
|
1282
|
+
/** Friendly names of common tools on the card's activity line. */
|
|
1283
|
+
const TOOL_NAMES = {
|
|
1284
|
+
computer: "操作电脑",
|
|
1285
|
+
computer_batch: "批量操作",
|
|
1286
|
+
open_application: "打开应用",
|
|
1287
|
+
windows: "窗口",
|
|
1288
|
+
ui_elements: "读取界面元素",
|
|
1289
|
+
clipboard: "剪贴板",
|
|
1290
|
+
request_access: "请求授权",
|
|
1291
|
+
pwsh: "运行命令",
|
|
1292
|
+
bash: "运行命令",
|
|
1293
|
+
shell: "运行命令",
|
|
1294
|
+
read: "读取文件",
|
|
1295
|
+
write: "写入文件",
|
|
1296
|
+
edit: "编辑文件",
|
|
1297
|
+
web_search: "搜索网页",
|
|
1298
|
+
web_fetch: "读取网页",
|
|
1299
|
+
todo_write: "更新待办"
|
|
1300
|
+
};
|
|
1301
|
+
/** How long the "done" card stays up after a run (longer while the pointer rests on it). */
|
|
1302
|
+
const FINISH_HOLD_MS = 4e3;
|
|
1303
|
+
/**
|
|
1304
|
+
* Fallback only (the host normally reports the agent going idle): hide after
|
|
1305
|
+
* this long without any sign of life from the agent. Model output and tool
|
|
1306
|
+
* starts of any plugin count, so a slow shell command does not end the run.
|
|
1307
|
+
*/
|
|
1308
|
+
const IDLE_HIDE_MS = 6e5;
|
|
1252
1309
|
/** A pause longer than this ends the tool call with a message for the model. */
|
|
1253
1310
|
const MAX_PAUSE_MS = 15e5;
|
|
1254
1311
|
/** Card rectangle in the bottom-right corner of a display's work area. */
|
|
@@ -1274,6 +1331,22 @@ var OverlayController = class {
|
|
|
1274
1331
|
idleTimer;
|
|
1275
1332
|
hostWindows = [];
|
|
1276
1333
|
stopping = false;
|
|
1334
|
+
/** Progress card lines: the reply as it streams, and what the agent is doing. */
|
|
1335
|
+
streamAgent;
|
|
1336
|
+
text = "";
|
|
1337
|
+
thinking = "";
|
|
1338
|
+
/** Recent steps (tool actions), oldest first. */
|
|
1339
|
+
steps = [];
|
|
1340
|
+
/** Whether the agent is thinking now (newer than the last step). */
|
|
1341
|
+
thinkingLatest = false;
|
|
1342
|
+
freshAttempt = true;
|
|
1343
|
+
pushTimer;
|
|
1344
|
+
/** An instruction the user typed into the progress card. */
|
|
1345
|
+
onMessage;
|
|
1346
|
+
/** Called when control starts (before the first action), e.g. to remember the window layout. */
|
|
1347
|
+
onStart;
|
|
1348
|
+
/** Opacity the card was last given, to apply setting changes while it floats. */
|
|
1349
|
+
cardOpacity = 100;
|
|
1277
1350
|
/** Paused by Esc or the pill; actions wait until resumed. */
|
|
1278
1351
|
paused = false;
|
|
1279
1352
|
/** When the user last typed on the physical keyboard while the overlay was up (ms epoch). */
|
|
@@ -1292,6 +1365,11 @@ var OverlayController = class {
|
|
|
1292
1365
|
else if (event.event === "user_input") {
|
|
1293
1366
|
this.lastUserInput = Date.now();
|
|
1294
1367
|
this.lastUserKey = event.reason ?? "";
|
|
1368
|
+
} else if (event.event === "message" && event.reason) {
|
|
1369
|
+
const agent = this.agent;
|
|
1370
|
+
if (!agent) return;
|
|
1371
|
+
this.step(`你:${event.reason}`);
|
|
1372
|
+
this.onMessage?.(agent, event.reason);
|
|
1295
1373
|
}
|
|
1296
1374
|
});
|
|
1297
1375
|
}
|
|
@@ -1328,19 +1406,101 @@ var OverlayController = class {
|
|
|
1328
1406
|
if (!this.visible) {
|
|
1329
1407
|
this.visible = true;
|
|
1330
1408
|
this.paused = false;
|
|
1409
|
+
await this.onStart?.().catch((error) => this.log(`overlay start: ${String(error)}`));
|
|
1331
1410
|
await this.shrinkHost(settings.hostWindow);
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1411
|
+
const pet = settings.hostWindow === "pet";
|
|
1412
|
+
if (settings.overlay || pet) {
|
|
1413
|
+
if (this.streamAgent !== agent) {
|
|
1414
|
+
this.text = "";
|
|
1415
|
+
this.thinking = "";
|
|
1416
|
+
}
|
|
1417
|
+
this.steps = status ? [status] : [];
|
|
1418
|
+
this.thinkingLatest = false;
|
|
1419
|
+
await this.helper.call("overlay_show", {
|
|
1420
|
+
label: pet ? `${settings.overlayLabel || "DeepSeek Harness"} 正在操控` : `${settings.overlayLabel || "DeepSeek Harness"} 正在操控你的电脑`,
|
|
1421
|
+
status,
|
|
1422
|
+
icon: this.iconPath,
|
|
1423
|
+
iconLight: this.iconPath.replace(/deepseek-white\.png$/, "deepseek-black.png"),
|
|
1424
|
+
idleMs: settings.userIdleMs,
|
|
1425
|
+
glow: settings.overlay,
|
|
1426
|
+
pet,
|
|
1427
|
+
petOpacity: settings.cardOpacity,
|
|
1428
|
+
text: this.text
|
|
1429
|
+
}).catch((error) => this.log(`overlay: ${String(error)}`));
|
|
1430
|
+
}
|
|
1338
1431
|
return;
|
|
1339
1432
|
}
|
|
1433
|
+
if (settings.hostWindow === "pet" && !this.hostWindows.some((win) => win.mode === "card")) await this.cardIfShown();
|
|
1434
|
+
if (this.hostWindows.some((win) => win.mode === "card") && settings.cardOpacity !== this.cardOpacity) {
|
|
1435
|
+
this.cardOpacity = settings.cardOpacity;
|
|
1436
|
+
await this.helper.call("card_opacity", { opacity: settings.cardOpacity }).catch(() => {});
|
|
1437
|
+
}
|
|
1340
1438
|
await this.status(status);
|
|
1341
1439
|
}
|
|
1342
1440
|
async status(status) {
|
|
1343
|
-
|
|
1441
|
+
const settings = this.settings();
|
|
1442
|
+
if (!this.visible) return;
|
|
1443
|
+
if (settings.hostWindow === "pet") {
|
|
1444
|
+
this.step(status);
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
if (settings.overlay) await this.helper.call("overlay_status", { status }).catch(() => {});
|
|
1448
|
+
}
|
|
1449
|
+
/** One more step on the card's timeline. */
|
|
1450
|
+
step(text) {
|
|
1451
|
+
const line = plainLine(text).trim();
|
|
1452
|
+
if (line === "" || this.steps.at(-1) === line) return;
|
|
1453
|
+
this.steps = [...this.steps, line].slice(-8);
|
|
1454
|
+
this.thinkingLatest = false;
|
|
1455
|
+
this.schedulePush();
|
|
1456
|
+
}
|
|
1457
|
+
/** Live model output (DSH agent/assistant-stream) for the progress card. */
|
|
1458
|
+
stream(agent, frame) {
|
|
1459
|
+
if (agent !== this.streamAgent) {
|
|
1460
|
+
this.streamAgent = agent;
|
|
1461
|
+
this.text = "";
|
|
1462
|
+
this.thinking = "";
|
|
1463
|
+
this.steps = [];
|
|
1464
|
+
}
|
|
1465
|
+
if (frame.type === "start") {
|
|
1466
|
+
this.freshAttempt = true;
|
|
1467
|
+
this.thinking = "";
|
|
1468
|
+
return;
|
|
1469
|
+
}
|
|
1470
|
+
if (this.visible && agent === this.agent) this.armIdle();
|
|
1471
|
+
const chunk = frame.type === "chunk" ? frame.chunk : void 0;
|
|
1472
|
+
if (!chunk) return;
|
|
1473
|
+
if (chunk.type === "text-delta" && chunk.text) {
|
|
1474
|
+
if (this.freshAttempt) {
|
|
1475
|
+
this.text = "";
|
|
1476
|
+
this.freshAttempt = false;
|
|
1477
|
+
}
|
|
1478
|
+
this.text = plainLine(this.text + chunk.text).slice(-2e3);
|
|
1479
|
+
} else if (chunk.type === "reasoning-delta" && chunk.text) {
|
|
1480
|
+
this.thinking = plainLine(this.thinking + chunk.text).slice(-300);
|
|
1481
|
+
this.thinkingLatest = true;
|
|
1482
|
+
} else return;
|
|
1483
|
+
this.schedulePush();
|
|
1484
|
+
}
|
|
1485
|
+
/** A tool of another plugin started (computer-use tools report their own steps). */
|
|
1486
|
+
toolStarted(agent, name, detail) {
|
|
1487
|
+
if (agent !== this.streamAgent) return;
|
|
1488
|
+
if (this.visible && agent === this.agent) this.armIdle();
|
|
1489
|
+
this.step(`${TOOL_NAMES[name] ?? name}${detail ? `:${detail}` : ""}`);
|
|
1490
|
+
}
|
|
1491
|
+
schedulePush() {
|
|
1492
|
+
if (!this.visible || this.settings().hostWindow !== "pet" || this.agent !== this.streamAgent || this.pushTimer) return;
|
|
1493
|
+
this.pushTimer = setTimeout(() => {
|
|
1494
|
+
this.pushTimer = void 0;
|
|
1495
|
+
if (!this.visible) return;
|
|
1496
|
+
this.helper.call("pet_update", {
|
|
1497
|
+
text: this.text,
|
|
1498
|
+
thinking: this.thinking.trim(),
|
|
1499
|
+
steps: this.steps,
|
|
1500
|
+
thinkingLatest: this.thinkingLatest
|
|
1501
|
+
}).catch(() => {});
|
|
1502
|
+
}, 80);
|
|
1503
|
+
this.pushTimer.unref?.();
|
|
1344
1504
|
}
|
|
1345
1505
|
/** Agent finished (idle), was cancelled, or the plugin is stopping. */
|
|
1346
1506
|
async end(agent) {
|
|
@@ -1351,7 +1511,15 @@ var OverlayController = class {
|
|
|
1351
1511
|
this.paused = false;
|
|
1352
1512
|
if (!this.visible) return;
|
|
1353
1513
|
this.visible = false;
|
|
1354
|
-
|
|
1514
|
+
if (this.pushTimer) {
|
|
1515
|
+
clearTimeout(this.pushTimer);
|
|
1516
|
+
this.pushTimer = void 0;
|
|
1517
|
+
}
|
|
1518
|
+
if (this.settings().hostWindow === "pet" && !this.stopping) await this.helper.call("pet_finish", {
|
|
1519
|
+
text: this.text,
|
|
1520
|
+
holdMs: FINISH_HOLD_MS
|
|
1521
|
+
}).catch(() => {});
|
|
1522
|
+
else await this.helper.call("overlay_hide").catch(() => {});
|
|
1355
1523
|
await this.restoreHost();
|
|
1356
1524
|
}
|
|
1357
1525
|
stop(reason) {
|
|
@@ -1381,7 +1549,7 @@ var OverlayController = class {
|
|
|
1381
1549
|
try {
|
|
1382
1550
|
const rows = (await this.helper.call("windows")).filter((row) => isHostWindow(row) && !row.minimized);
|
|
1383
1551
|
if (rows.length === 0) return;
|
|
1384
|
-
if (mode === "minimize") {
|
|
1552
|
+
if (mode === "minimize" || mode === "pet") {
|
|
1385
1553
|
for (const row of rows) await this.helper.call("window_cmd", {
|
|
1386
1554
|
hwnd: row.hwnd,
|
|
1387
1555
|
op: "minimize"
|
|
@@ -1398,8 +1566,10 @@ var OverlayController = class {
|
|
|
1398
1566
|
const cy = main.y + main.height / 2;
|
|
1399
1567
|
const display = displays.find((d) => cx >= d.x && cx < d.x + d.width && cy >= d.y && cy < d.y + d.height) ?? displays.find((d) => d.primary) ?? displays[0];
|
|
1400
1568
|
if (!display) return;
|
|
1569
|
+
this.cardOpacity = this.settings().cardOpacity;
|
|
1401
1570
|
await this.helper.call("window_card", {
|
|
1402
1571
|
hwnd: main.hwnd,
|
|
1572
|
+
opacity: this.cardOpacity,
|
|
1403
1573
|
...cardRect(display)
|
|
1404
1574
|
});
|
|
1405
1575
|
this.hostWindows = [{
|
|
@@ -1410,6 +1580,21 @@ var OverlayController = class {
|
|
|
1410
1580
|
this.log(`host window ${mode}: ${String(error)}`);
|
|
1411
1581
|
}
|
|
1412
1582
|
}
|
|
1583
|
+
/**
|
|
1584
|
+
* Pet mode minimizes DeepSeek Harness; if the user opens it again while the
|
|
1585
|
+
* agent works, it floats as the see-through card instead of covering the
|
|
1586
|
+
* screen (the agent neither sees nor clicks it).
|
|
1587
|
+
*/
|
|
1588
|
+
async cardIfShown() {
|
|
1589
|
+
try {
|
|
1590
|
+
if ((await this.helper.call("windows")).filter((row) => isHostWindow(row) && !row.minimized).length === 0) return;
|
|
1591
|
+
const before = this.hostWindows;
|
|
1592
|
+
await this.shrinkHost("card");
|
|
1593
|
+
this.hostWindows = [...this.hostWindows, ...before.filter((win) => !this.hostWindows.some((card) => card.hwnd === win.hwnd))];
|
|
1594
|
+
} catch (error) {
|
|
1595
|
+
this.log(`host window card: ${String(error)}`);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1413
1598
|
async restoreHost() {
|
|
1414
1599
|
const windows = this.hostWindows;
|
|
1415
1600
|
this.hostWindows = [];
|
|
@@ -1431,15 +1616,17 @@ var OverlayController = class {
|
|
|
1431
1616
|
//#region lib/types/prompt.js
|
|
1432
1617
|
function promptText(mode) {
|
|
1433
1618
|
return `# Computer use (Windows desktop)
|
|
1434
|
-
You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements and
|
|
1619
|
+
You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements, clipboard and app_skill tools.
|
|
1435
1620
|
${mode === "per-app" ? "- Before acting on an app, call request_access once with every app the task needs; the user approves it. Input to apps that are not granted is refused.\n" : ""}- Start with a screenshot (computer action "screenshot") unless you just received one. All coordinates are pixels of the latest screenshot; the plugin converts them for DPI and scaling.
|
|
1436
|
-
- Open or switch apps with open_application (by name; it also finds desktop shortcuts) rather than hunting through the taskbar or Start menu or starting GUI apps from a shell. Use windows to see which windows exist; each line shows the process .exe.
|
|
1621
|
+
- Open or switch apps with open_application (by name; it also finds desktop shortcuts) rather than hunting through the taskbar or Start menu or starting GUI apps from a shell. Use windows to see which windows exist; each line shows the process .exe. Apps closed to the system tray (QQ, 微信...) are still running: open_application restores them from their tray icon. Do not start a second copy of a running app unless the user explicitly asks for one (then pass new_instance: true), and never show or kill its hidden windows from a shell (Electron / Qt apps freeze, and a second QQ / WeChat asks for another login).
|
|
1622
|
+
- When the task is done, tidy up: close windows and dialogs you opened that the user no longer needs (keep the one showing the result they asked for), and call windows tidy to minimize again the apps that were minimized or in the tray before you started. Never close windows the user already had open.
|
|
1437
1623
|
- The "DeepSeek Harness.exe" window is your own chat interface. While you control the computer it floats as a card that only the user sees: your screenshots show what is underneath it and your clicks and scrolls pass through it, so simply ignore it. Never type into DeepSeek Harness; keys go to the window you were working in.
|
|
1438
1624
|
- If the target window is small or partly covered by other windows, maximize it (windows maximize) or minimize what is in the way (windows minimize works for any window) instead of working around it.
|
|
1439
1625
|
- Prefer reliable keyboard shortcuts (ctrl+l for a browser address bar, ctrl+s, alt+F4, ctrl+t). Click the center of targets. When text is too small to read, zoom once on a generous region that contains everything you need (zooming step by step wastes calls).
|
|
1440
1626
|
- Actions return a fresh screenshot taken once the screen stops changing (page loads included, up to a few seconds), so you rarely need wait. If something is still loading, use wait: it also returns a screenshot, so never follow it with a separate screenshot call.
|
|
1441
1627
|
- When the user asks you to write something in an app, enter it there with type, even long or multi-line Markdown: the user watches it appear (long text is streamed in paragraph by paragraph, literally, without the editor's auto-formatting getting in the way). Do not write the file from a shell and reopen it instead, and do not put text on the clipboard with shell commands (Set-Clipboard, clip): that clutters the user's clipboard history.
|
|
1442
|
-
-
|
|
1628
|
+
- App skills: open_application returns your saved notes for the app it opens; follow them instead of rediscovering how the app behaves. After working out an unfamiliar app (or finding a note wrong), record the reusable part with app_skill rather than in general memory.
|
|
1629
|
+
- Saving: in any Save As dialog do not click through folders; press alt+n (file name box), ctrl+a, type the full path including the file name, then Return. Office apps: F12 opens that classic dialog directly. To check a saved file, look at the exact path; never search a whole drive or user profile recursively.
|
|
1443
1630
|
- Be efficient: every tool call costs the user several seconds. Put predictable sequences (click a field, type, press Return; open a menu and pick an item you can already see) into one computer_batch. Avoid shell commands for things you can see on screen.
|
|
1444
1631
|
- To see more of a page or list, scroll (action "scroll" with coordinate over the area, scroll_direction, scroll_amount 5-10) instead of hunting with zoom; for long web pages Page Down / End keys also work.
|
|
1445
1632
|
- If a dedicated tool fits the whole task better (an API, or browser automation attached to the user's own browser), choose it at the start; do not switch tools halfway through a task that is going fine on screen.
|
|
@@ -1447,6 +1634,184 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
|
|
|
1447
1634
|
- The user sees an orange border and can press Esc to pause you at any time. If they pause, type on the keyboard or switch windows, you wait; when an action reports it was not performed, re-check the screen instead of repeating it blindly.`;
|
|
1448
1635
|
}
|
|
1449
1636
|
//#endregion
|
|
1637
|
+
//#region lib/types/skills.js
|
|
1638
|
+
/**
|
|
1639
|
+
* App skills: short notes on how to operate one application, kept by the agent
|
|
1640
|
+
* (and editable by the user) as one Markdown file per app. Only a one-line
|
|
1641
|
+
* catalog goes into the system prompt; the notes themselves are handed over
|
|
1642
|
+
* when the app is opened, or read on demand.
|
|
1643
|
+
*
|
|
1644
|
+
* File format (front matter is optional):
|
|
1645
|
+
* ---
|
|
1646
|
+
* app: Obsidian
|
|
1647
|
+
* match: obsidian.exe, obsidian
|
|
1648
|
+
* summary: 打字规律、新建笔记
|
|
1649
|
+
* ---
|
|
1650
|
+
* - notes...
|
|
1651
|
+
*
|
|
1652
|
+
* The plugin ships a few built-in skills; a user file with the same id
|
|
1653
|
+
* overrides one, and `disabled: true` hides it.
|
|
1654
|
+
*/
|
|
1655
|
+
/** Notes longer than this must be condensed before more is added. */
|
|
1656
|
+
const SKILL_MAX_CHARS = 4e3;
|
|
1657
|
+
/** Host processes shared by many apps: never a way to recognise one app. */
|
|
1658
|
+
const GENERIC_HOSTS = /^(applicationframehost|explorer|msedgewebview2|javaw?|python\w*|electron)(\.exe)?$/i;
|
|
1659
|
+
function skillId(app) {
|
|
1660
|
+
return app.trim().toLowerCase().replace(/\.exe$/, "").replace(/[\\/:*?"<>|\s.]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "app";
|
|
1661
|
+
}
|
|
1662
|
+
function parseSkill(text, fallbackApp) {
|
|
1663
|
+
const out = {
|
|
1664
|
+
app: fallbackApp,
|
|
1665
|
+
match: [],
|
|
1666
|
+
summary: "",
|
|
1667
|
+
content: text.trim(),
|
|
1668
|
+
disabled: false
|
|
1669
|
+
};
|
|
1670
|
+
const front = /^?---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text);
|
|
1671
|
+
if (!front) return out;
|
|
1672
|
+
out.content = text.slice(front[0].length).trim();
|
|
1673
|
+
for (const line of front[1].split(/\r?\n/)) {
|
|
1674
|
+
const pair = /^([a-z]+)\s*:\s*(.*)$/i.exec(line.trim());
|
|
1675
|
+
if (!pair) continue;
|
|
1676
|
+
const key = pair[1].toLowerCase();
|
|
1677
|
+
const value = pair[2].trim();
|
|
1678
|
+
if (key === "app" && value) out.app = value;
|
|
1679
|
+
else if (key === "match") out.match = value.split(/[,,]/).map((item) => item.trim()).filter(Boolean);
|
|
1680
|
+
else if (key === "summary") out.summary = value;
|
|
1681
|
+
else if (key === "disabled") out.disabled = value === "true";
|
|
1682
|
+
}
|
|
1683
|
+
return out;
|
|
1684
|
+
}
|
|
1685
|
+
function formatSkill(skill, disabled = false) {
|
|
1686
|
+
const head = [
|
|
1687
|
+
`app: ${skill.app}`,
|
|
1688
|
+
`match: ${skill.match.join(", ")}`,
|
|
1689
|
+
`summary: ${skill.summary.replace(/\r?\n/g, " ")}`
|
|
1690
|
+
];
|
|
1691
|
+
if (disabled) head.push("disabled: true");
|
|
1692
|
+
return `---\n${head.join("\n")}\n---\n${skill.content.trim()}\n`;
|
|
1693
|
+
}
|
|
1694
|
+
var SkillStore = class {
|
|
1695
|
+
builtinDir;
|
|
1696
|
+
userDir;
|
|
1697
|
+
constructor(builtinDir, userDir = join(process.env.DSH_HOME ?? join(homedir(), ".dsh"), "computer-use-skills")) {
|
|
1698
|
+
this.builtinDir = builtinDir;
|
|
1699
|
+
this.userDir = userDir;
|
|
1700
|
+
}
|
|
1701
|
+
load(dir, source) {
|
|
1702
|
+
const map = /* @__PURE__ */ new Map();
|
|
1703
|
+
if (!existsSync(dir)) return map;
|
|
1704
|
+
for (const name of readdirSync(dir)) {
|
|
1705
|
+
if (!name.toLowerCase().endsWith(".md")) continue;
|
|
1706
|
+
try {
|
|
1707
|
+
const path = join(dir, name);
|
|
1708
|
+
const parsed = parseSkill(readFileSync(path, "utf8"), name.slice(0, -3));
|
|
1709
|
+
const id = skillId(name.slice(0, -3));
|
|
1710
|
+
map.set(id, {
|
|
1711
|
+
id,
|
|
1712
|
+
app: parsed.app,
|
|
1713
|
+
match: parsed.match.length > 0 ? parsed.match : [parsed.app],
|
|
1714
|
+
summary: parsed.summary,
|
|
1715
|
+
content: parsed.content,
|
|
1716
|
+
source,
|
|
1717
|
+
overrides: false,
|
|
1718
|
+
updatedAt: statSync(path).mtimeMs,
|
|
1719
|
+
disabled: parsed.disabled
|
|
1720
|
+
});
|
|
1721
|
+
} catch {}
|
|
1722
|
+
}
|
|
1723
|
+
return map;
|
|
1724
|
+
}
|
|
1725
|
+
/** Every active skill, user files first in precedence, sorted by app name. */
|
|
1726
|
+
list() {
|
|
1727
|
+
const builtin = this.load(this.builtinDir, "builtin");
|
|
1728
|
+
const user = this.load(this.userDir, "user");
|
|
1729
|
+
const out = [];
|
|
1730
|
+
for (const [id, skill] of user) {
|
|
1731
|
+
if (skill.disabled) continue;
|
|
1732
|
+
const { disabled: _disabled, ...rest } = skill;
|
|
1733
|
+
out.push({
|
|
1734
|
+
...rest,
|
|
1735
|
+
overrides: builtin.has(id)
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
for (const [id, skill] of builtin) {
|
|
1739
|
+
if (user.has(id)) continue;
|
|
1740
|
+
const { disabled: _disabled, ...rest } = skill;
|
|
1741
|
+
out.push(rest);
|
|
1742
|
+
}
|
|
1743
|
+
return out.sort((a, b) => a.app.localeCompare(b.app, "zh-CN"));
|
|
1744
|
+
}
|
|
1745
|
+
get(id) {
|
|
1746
|
+
const wanted = skillId(id);
|
|
1747
|
+
return this.list().find((skill) => skill.id === wanted);
|
|
1748
|
+
}
|
|
1749
|
+
/** The skill for an app by name, or for a window by its executable. */
|
|
1750
|
+
find(name, win) {
|
|
1751
|
+
const skills = this.list();
|
|
1752
|
+
const wanted = skillId(name);
|
|
1753
|
+
return skills.find((skill) => skill.id === wanted) ?? skills.find((skill) => skill.match.some((item) => skillId(item) === wanted)) ?? (win ? skills.find((skill) => skill.match.some((item) => !GENERIC_HOSTS.test(item) && appMatches(item, win))) : void 0);
|
|
1754
|
+
}
|
|
1755
|
+
/** One line per skill for the system prompt. */
|
|
1756
|
+
catalog() {
|
|
1757
|
+
return this.list().map((skill) => `${skill.app}${skill.summary ? ` (${skill.summary})` : ""}`).join("; ");
|
|
1758
|
+
}
|
|
1759
|
+
save(input, id = skillId(input.app)) {
|
|
1760
|
+
const app = input.app.trim();
|
|
1761
|
+
if (app === "") throw new Error("app is required.");
|
|
1762
|
+
const content = input.content.trim();
|
|
1763
|
+
if (content === "") throw new Error("content is empty.");
|
|
1764
|
+
if (content.length > 4e3) throw new Error(`The skill would be ${content.length} characters; the limit is ${SKILL_MAX_CHARS}. Condense it (merge duplicates, drop one-off details) and write it again.`);
|
|
1765
|
+
const previous = this.get(id);
|
|
1766
|
+
const match = [...new Set([
|
|
1767
|
+
...input.match ?? [],
|
|
1768
|
+
...previous?.match ?? [],
|
|
1769
|
+
app
|
|
1770
|
+
].map((item) => item.trim()).filter((item) => item !== "" && !GENERIC_HOSTS.test(item)))];
|
|
1771
|
+
const summary = (input.summary ?? previous?.summary ?? "").trim().slice(0, 80);
|
|
1772
|
+
mkdirSync(this.userDir, { recursive: true });
|
|
1773
|
+
const path = join(this.userDir, `${skillId(id)}.md`);
|
|
1774
|
+
const tmp = `${path}.tmp`;
|
|
1775
|
+
writeFileSync(tmp, formatSkill({
|
|
1776
|
+
app,
|
|
1777
|
+
match,
|
|
1778
|
+
summary,
|
|
1779
|
+
content
|
|
1780
|
+
}), "utf8");
|
|
1781
|
+
renameSync(tmp, path);
|
|
1782
|
+
return this.get(id);
|
|
1783
|
+
}
|
|
1784
|
+
append(app, text, extra = {}) {
|
|
1785
|
+
const previous = this.find(app);
|
|
1786
|
+
const content = previous ? `${previous.content}\n${text.trim()}` : text.trim();
|
|
1787
|
+
return this.save({
|
|
1788
|
+
app: previous?.app ?? app,
|
|
1789
|
+
content,
|
|
1790
|
+
...extra
|
|
1791
|
+
}, previous?.id ?? skillId(app));
|
|
1792
|
+
}
|
|
1793
|
+
/** Delete a user skill; a built-in one is hidden by a disabled override. */
|
|
1794
|
+
remove(id) {
|
|
1795
|
+
const wanted = skillId(id);
|
|
1796
|
+
const path = join(this.userDir, `${wanted}.md`);
|
|
1797
|
+
const builtin = this.load(this.builtinDir, "builtin").get(wanted);
|
|
1798
|
+
if (builtin) {
|
|
1799
|
+
mkdirSync(this.userDir, { recursive: true });
|
|
1800
|
+
writeFileSync(path, formatSkill({
|
|
1801
|
+
app: builtin.app,
|
|
1802
|
+
match: builtin.match,
|
|
1803
|
+
summary: builtin.summary,
|
|
1804
|
+
content: ""
|
|
1805
|
+
}, true), "utf8");
|
|
1806
|
+
} else if (existsSync(path)) unlinkSync(path);
|
|
1807
|
+
}
|
|
1808
|
+
/** Drop the user's override so the built-in skill applies again. */
|
|
1809
|
+
reset(id) {
|
|
1810
|
+
const path = join(this.userDir, `${skillId(id)}.md`);
|
|
1811
|
+
if (existsSync(path)) unlinkSync(path);
|
|
1812
|
+
}
|
|
1813
|
+
};
|
|
1814
|
+
//#endregion
|
|
1450
1815
|
//#region lib/types/settings.js
|
|
1451
1816
|
/** The Loader entry id (settings namespace); see cordis.patch.yml. */
|
|
1452
1817
|
const ENTRY_ID = "copylee-computer-use";
|
|
@@ -1454,7 +1819,8 @@ const DEFAULTS = {
|
|
|
1454
1819
|
accessMode: "per-app",
|
|
1455
1820
|
overlay: true,
|
|
1456
1821
|
overlayLabel: "DeepSeek Harness",
|
|
1457
|
-
hostWindow: "
|
|
1822
|
+
hostWindow: "pet",
|
|
1823
|
+
cardOpacity: 80,
|
|
1458
1824
|
autoScreenshot: true,
|
|
1459
1825
|
settleMs: 400,
|
|
1460
1826
|
maxLongEdge: 1366,
|
|
@@ -1478,7 +1844,8 @@ function resolveConfig(raw) {
|
|
|
1478
1844
|
accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
|
|
1479
1845
|
overlay: bool("overlay"),
|
|
1480
1846
|
overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
|
|
1481
|
-
hostWindow: out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
|
|
1847
|
+
hostWindow: out.hostWindow === "pet" || out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
|
|
1848
|
+
cardOpacity: num("cardOpacity", 30, 100),
|
|
1482
1849
|
autoScreenshot: bool("autoScreenshot"),
|
|
1483
1850
|
settleMs: num("settleMs", 0, 5e3),
|
|
1484
1851
|
maxLongEdge: num("maxLongEdge", 640, 3840),
|
|
@@ -1496,6 +1863,7 @@ const STATUS_ROUTE = "/api/dsh-computer-use/status";
|
|
|
1496
1863
|
const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
|
|
1497
1864
|
const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
|
|
1498
1865
|
const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
|
|
1866
|
+
const SKILLS_ROUTE = "/api/dsh-computer-use/skills";
|
|
1499
1867
|
function json(res, status, body) {
|
|
1500
1868
|
res.writeHead(status, {
|
|
1501
1869
|
"content-type": "application/json; charset=utf-8",
|
|
@@ -1604,6 +1972,54 @@ function screenshotsCleanRoute(cache) {
|
|
|
1604
1972
|
}
|
|
1605
1973
|
};
|
|
1606
1974
|
}
|
|
1975
|
+
async function body(req) {
|
|
1976
|
+
const chunks = [];
|
|
1977
|
+
let size = 0;
|
|
1978
|
+
for await (const chunk of req) {
|
|
1979
|
+
size += chunk.length;
|
|
1980
|
+
if (size > 2e5) throw new Error("request too large");
|
|
1981
|
+
chunks.push(chunk);
|
|
1982
|
+
}
|
|
1983
|
+
const parsed = chunks.length === 0 ? {} : JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
1984
|
+
return parsed !== null && typeof parsed === "object" ? parsed : {};
|
|
1985
|
+
}
|
|
1986
|
+
/** App skills for the settings page: GET lists them; POST { op: 'save' | 'delete' | 'reset', ... } changes one. */
|
|
1987
|
+
function skillsRoute(skills) {
|
|
1988
|
+
return async (req, res) => {
|
|
1989
|
+
if (req.method === "POST") {
|
|
1990
|
+
const input = await body(req);
|
|
1991
|
+
const id = typeof input.id === "string" ? input.id : "";
|
|
1992
|
+
try {
|
|
1993
|
+
if (input.op === "delete") skills.remove(id);
|
|
1994
|
+
else if (input.op === "reset") skills.reset(id);
|
|
1995
|
+
else if (input.op === "save") skills.save({
|
|
1996
|
+
app: String(input.app ?? ""),
|
|
1997
|
+
match: String(input.match ?? "").split(/[,,]/).map((item) => item.trim()).filter(Boolean),
|
|
1998
|
+
summary: String(input.summary ?? ""),
|
|
1999
|
+
content: String(input.content ?? "")
|
|
2000
|
+
}, id || void 0);
|
|
2001
|
+
else {
|
|
2002
|
+
json(res, 400, {
|
|
2003
|
+
ok: false,
|
|
2004
|
+
error: "unknown op"
|
|
2005
|
+
});
|
|
2006
|
+
return;
|
|
2007
|
+
}
|
|
2008
|
+
} catch (error) {
|
|
2009
|
+
json(res, 200, {
|
|
2010
|
+
ok: false,
|
|
2011
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2012
|
+
});
|
|
2013
|
+
return;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
json(res, 200, {
|
|
2017
|
+
ok: true,
|
|
2018
|
+
dir: skills.userDir,
|
|
2019
|
+
skills: skills.list()
|
|
2020
|
+
});
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
1607
2023
|
//#endregion
|
|
1608
2024
|
//#region lib/types/screenshots.js
|
|
1609
2025
|
/**
|
|
@@ -2501,7 +2917,7 @@ function deepFreeze(value) {
|
|
|
2501
2917
|
* Random v4 UUID, minted from `crypto.getRandomValues`.
|
|
2502
2918
|
* @returns the UUID string.
|
|
2503
2919
|
*/
|
|
2504
|
-
function randomUUID() {
|
|
2920
|
+
function randomUUID$1() {
|
|
2505
2921
|
const bytes = globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
2506
2922
|
const hex = Array.from(bytes, (byte, index) => {
|
|
2507
2923
|
return (index === 6 ? byte & 15 | 64 : index === 8 ? byte & 63 | 128 : byte).toString(16).padStart(2, "0");
|
|
@@ -2553,7 +2969,7 @@ function freezeMessage(message) {
|
|
|
2553
2969
|
function createMessage(input) {
|
|
2554
2970
|
return deepFreeze(structuredClone({
|
|
2555
2971
|
...input,
|
|
2556
|
-
id: brandString(randomUUID())
|
|
2972
|
+
id: brandString(randomUUID$1())
|
|
2557
2973
|
}));
|
|
2558
2974
|
}
|
|
2559
2975
|
/**
|
|
@@ -7473,6 +7889,12 @@ function attachmentSchema() {
|
|
|
7473
7889
|
}
|
|
7474
7890
|
};
|
|
7475
7891
|
}
|
|
7892
|
+
/** windows list notes about the layout before the task. */
|
|
7893
|
+
const ORIGIN = {
|
|
7894
|
+
opened: " | opened during this task",
|
|
7895
|
+
minimized: " | was minimized before this task",
|
|
7896
|
+
tray: " | was in the system tray before this task"
|
|
7897
|
+
};
|
|
7476
7898
|
const output = {
|
|
7477
7899
|
schema: {
|
|
7478
7900
|
type: "object",
|
|
@@ -7666,22 +8088,29 @@ function createTools(host) {
|
|
|
7666
8088
|
tools.push(defineTool({
|
|
7667
8089
|
name: "open_application",
|
|
7668
8090
|
description: "Open an app by name (e.g. \"Chrome\", \"记事本\", \"微信\", \"Excel\"), an .exe path, or a URL, or bring it to the front if it is already running. Faster and more reliable than clicking the taskbar or Start menu. Returns a screenshot.",
|
|
7669
|
-
parameters: {
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
8091
|
+
parameters: {
|
|
8092
|
+
name: {
|
|
8093
|
+
type: "string",
|
|
8094
|
+
required: true,
|
|
8095
|
+
description: "App name as shown in the Start menu, an executable path, or an http(s) URL."
|
|
8096
|
+
},
|
|
8097
|
+
new_instance: {
|
|
8098
|
+
type: "boolean",
|
|
8099
|
+
description: "Start another copy even though the app is already running. Only when the user explicitly asks for a second window / instance / account."
|
|
8100
|
+
}
|
|
8101
|
+
},
|
|
7674
8102
|
output,
|
|
7675
8103
|
timeoutMs: 18e5,
|
|
7676
8104
|
async execute(args, exec) {
|
|
7677
8105
|
const call = await host.context(exec);
|
|
7678
8106
|
const name = String(args.name ?? "").trim();
|
|
8107
|
+
const newInstance = args.new_instance === true;
|
|
7679
8108
|
if (name === "") throw new Error("name is required.");
|
|
7680
8109
|
const settings = computer.settings();
|
|
7681
8110
|
const isUrl = /^https?:\/\//i.test(name);
|
|
7682
8111
|
const appName = /^ms-settings:/i.test(name) ? "设置" : name;
|
|
7683
8112
|
if (settings.accessMode === "per-app" && !isUrl && computer.access.missing(call.session, [appName]).length > 0) {
|
|
7684
|
-
const running = (await computer.windows()).find((win) => appMatches(appName, win));
|
|
8113
|
+
const running = (await computer.windows()).find((win) => appMatches(appName, win)) ?? (await computer.backgroundApps()).find((win) => appMatches(appName, win));
|
|
7685
8114
|
if (!running || !computer.access.isGranted(call.session, running)) throw new Error(`"${appName}" is not granted for this session. Call request_access with ["${appName}"] first.`);
|
|
7686
8115
|
}
|
|
7687
8116
|
await computer.overlay.begin(call.agent, `打开 ${name}`);
|
|
@@ -7689,9 +8118,14 @@ function createTools(host) {
|
|
|
7689
8118
|
const before = await computer.foreground();
|
|
7690
8119
|
let how;
|
|
7691
8120
|
const isUri = isUrl || /^[a-z][a-z0-9+.-]+:(?![\/])/i.test(name);
|
|
7692
|
-
const running = isUri ? void 0 : (await computer.windows()).find((win) => !isHostWindow(win) && appMatches(name, win));
|
|
8121
|
+
const running = isUri || newInstance ? void 0 : (await computer.windows()).find((win) => !isHostWindow(win) && appMatches(name, win));
|
|
8122
|
+
const hidden = running || isUri || newInstance ? void 0 : (await computer.backgroundApps()).find((win) => !isHostWindow(win) && appMatches(name, win));
|
|
7693
8123
|
if (running) how = (await computer.focus(running)).focused ? `Brought ${running.exe} ("${running.title.slice(0, 60)}") to the front.` : `Tried to bring ${running.exe} to the front, but Windows kept another window focused.`;
|
|
7694
|
-
else {
|
|
8124
|
+
else if (hidden) {
|
|
8125
|
+
const restored = await computer.helper.call("tray_restore", { exe: hidden.exe }, 2e4);
|
|
8126
|
+
if (restored.window) computer.noteFromTray(restored.window.hwnd);
|
|
8127
|
+
how = restored.window ? `${hidden.exe} was already running in the system tray: restored its window from the tray icon (no second instance started).` : `${hidden.exe} is already running in the background${restored.icon ? " (system tray)" : ""}, but its window did not come back automatically. Open it from its notification-area icon (click ^ "show hidden icons" on the taskbar first). Do not launch it again (that starts a second instance and login), and never force its hidden window visible from a shell (Electron / Qt apps freeze).`;
|
|
8128
|
+
} else {
|
|
7695
8129
|
const app = (isUri ? [] : await computer.helper.call("apps", {
|
|
7696
8130
|
query: name,
|
|
7697
8131
|
limit: 5
|
|
@@ -7703,16 +8137,52 @@ function createTools(host) {
|
|
|
7703
8137
|
await setTimeout$1(250, void 0, { signal: call.signal });
|
|
7704
8138
|
const now = await computer.foreground();
|
|
7705
8139
|
if (now && now.hwnd !== before?.hwnd && !isHostWindow(now) && !isTransientShell(now) && (now.exe.toLowerCase() !== "explorer.exe" || now.className === "CabinetWClass")) break;
|
|
8140
|
+
if (i >= 4 && i % 4 === 0 && !isUri) {
|
|
8141
|
+
const opened = (await computer.windows()).find((win) => !isHostWindow(win) && appMatches(name, win));
|
|
8142
|
+
if (opened) {
|
|
8143
|
+
await computer.focus(opened).catch(() => void 0);
|
|
8144
|
+
break;
|
|
8145
|
+
}
|
|
8146
|
+
}
|
|
7706
8147
|
}
|
|
7707
8148
|
}
|
|
7708
8149
|
const fg = await computer.foreground();
|
|
7709
8150
|
if (fg && !isHostWindow(fg) && settings.accessMode === "per-app" && (computer.access.missing(call.session, [appName]).length === 0 || isUrl)) computer.access.grant(call.session, [fg.exe]);
|
|
7710
8151
|
await computer.settle(call.signal);
|
|
7711
8152
|
const shot = call.vision ? await computer.screenshot() : void 0;
|
|
7712
|
-
return withShot(host, `${how} ${await computer.describeForeground()}`, shot, call);
|
|
8153
|
+
return withShot(host, `${how} ${await computer.describeForeground()}${skillNote(call.session, name, fg)}`, shot, call);
|
|
7713
8154
|
},
|
|
7714
8155
|
presentCall: (args) => card(`打开应用 · ${args.name ?? ""}`)
|
|
7715
8156
|
}));
|
|
8157
|
+
/** Skills already handed to a session, so each is attached once. */
|
|
8158
|
+
const told = /* @__PURE__ */ new Map();
|
|
8159
|
+
/** The app's skill, appended to open_application's result the first time in a session. */
|
|
8160
|
+
function skillNote(session, name, win) {
|
|
8161
|
+
const skill = host.skills?.find(name, win && !isHostWindow(win) ? win : void 0);
|
|
8162
|
+
if (!skill) return host.skills ? "\n(No app skill for this app yet: if you have to work out how it behaves, record the reusable part with app_skill append when you are done.)" : "";
|
|
8163
|
+
let seen = told.get(session);
|
|
8164
|
+
if (!seen) told.set(session, seen = /* @__PURE__ */ new Set());
|
|
8165
|
+
if (seen.has(skill.id)) return "";
|
|
8166
|
+
seen.add(skill.id);
|
|
8167
|
+
return `\n\nYour skill notes for ${skill.app} (app_skill; correct them if they turn out wrong):\n${skill.content}`;
|
|
8168
|
+
}
|
|
8169
|
+
/** Put back what the task changed: re-minimize restored windows, report the ones it opened. */
|
|
8170
|
+
async function tidy(call) {
|
|
8171
|
+
await computer.overlay.begin(call.agent, "整理窗口");
|
|
8172
|
+
const rows = (await computer.windows()).filter((win) => !isHostWindow(win));
|
|
8173
|
+
const minimized = [];
|
|
8174
|
+
for (const win of rows) {
|
|
8175
|
+
const origin = computer.origin(win);
|
|
8176
|
+
if (origin !== "minimized" && origin !== "tray") continue;
|
|
8177
|
+
await computer.helper.call("window_cmd", {
|
|
8178
|
+
hwnd: win.hwnd,
|
|
8179
|
+
op: "minimize"
|
|
8180
|
+
}).catch(() => {});
|
|
8181
|
+
minimized.push(`${win.exe} ("${win.title.slice(0, 40)}")`);
|
|
8182
|
+
}
|
|
8183
|
+
const opened = rows.filter((win) => computer.origin(win) === "opened");
|
|
8184
|
+
return { text: [minimized.length ? `Minimized again (they were minimized or in the tray before): ${minimized.join(", ")}.` : "Nothing to minimize again.", opened.length ? `Opened during this task, still open:\n${opened.map((win) => `hwnd=${win.hwnd} | ${win.exe} | "${win.title.slice(0, 60)}"`).join("\n")}\nClose the ones the user does not need (windows close); keep any that shows the result they asked for.` : "No windows opened during this task are left."].join("\n") };
|
|
8185
|
+
}
|
|
7716
8186
|
tools.push(defineTool({
|
|
7717
8187
|
name: "windows",
|
|
7718
8188
|
description: "List top-level windows (with process .exe names), or focus / minimize / maximize / restore / close one. Use it to find the right window instead of guessing from titles; the \"DeepSeek Harness.exe\" window is your own chat UI.",
|
|
@@ -7725,9 +8195,11 @@ function createTools(host) {
|
|
|
7725
8195
|
"minimize",
|
|
7726
8196
|
"maximize",
|
|
7727
8197
|
"restore",
|
|
7728
|
-
"close"
|
|
8198
|
+
"close",
|
|
8199
|
+
"tidy"
|
|
7729
8200
|
],
|
|
7730
|
-
required: true
|
|
8201
|
+
required: true,
|
|
8202
|
+
description: "tidy: when the task is done, minimize again every window that was minimized or in the system tray before you started, and list the windows you opened."
|
|
7731
8203
|
},
|
|
7732
8204
|
hwnd: {
|
|
7733
8205
|
type: "integer",
|
|
@@ -7743,9 +8215,15 @@ function createTools(host) {
|
|
|
7743
8215
|
const call = await host.context(exec);
|
|
7744
8216
|
const { action, hwnd, name } = args;
|
|
7745
8217
|
const rows = await computer.windows();
|
|
7746
|
-
if (action === "list")
|
|
8218
|
+
if (action === "list") {
|
|
8219
|
+
const lines = await Promise.all(rows.map(async (win) => `hwnd=${win.hwnd} | ${win.exe} | "${win.title.slice(0, 70)}"${win.foreground ? " | FOREGROUND" : ""}${win.minimized ? " | minimized" : ` | ${await computer.windowBox(win)}`}${isHostWindow(win) ? " | (your own DeepSeek Harness chat window)" : ""}${ORIGIN[computer.origin(win) ?? ""] ?? ""}`));
|
|
8220
|
+
const tray = (await computer.backgroundApps()).filter((win) => win.tray && !isHostWindow(win));
|
|
8221
|
+
if (tray.length > 0) lines.push(`Running in the system tray without a window (open_application restores them; never relaunch them): ${tray.map((win) => `${win.exe} ("${win.title.slice(0, 30)}")`).join(", ")}`);
|
|
8222
|
+
return { text: lines.join("\n") || "No windows." };
|
|
8223
|
+
}
|
|
8224
|
+
if (action === "tidy") return tidy(call);
|
|
7747
8225
|
const target = hwnd !== void 0 ? rows.find((win) => win.hwnd === hwnd) : name ? rows.find((win) => !isHostWindow(win) && appMatches(name, win)) ?? rows.find((win) => !isHostWindow(win) && win.title.toLowerCase().includes(name.toLowerCase())) ?? rows.find((win) => appMatches(name, win)) : void 0;
|
|
7748
|
-
if (!target) throw new Error("Window not found; call windows with action \"list\".");
|
|
8226
|
+
if (!target) throw new Error("Window not found; call windows with action \"list\". An app closed to the system tray has no window: bring it back with open_application.");
|
|
7749
8227
|
const settings = computer.settings();
|
|
7750
8228
|
const denial = computer.access.denial(call.session, target, settings.accessMode, settings.blockedApps, action);
|
|
7751
8229
|
if (denial && action !== "minimize") throw new Error(denial);
|
|
@@ -7763,7 +8241,7 @@ function createTools(host) {
|
|
|
7763
8241
|
const shot = await computer.after([{ action: "key" }], call);
|
|
7764
8242
|
return withShot(host, shot ? text : `${text} ${await computer.describeForeground()}`, shot, call);
|
|
7765
8243
|
},
|
|
7766
|
-
presentCall: (args) => card(`窗口 · ${args.action ?? ""}`)
|
|
8244
|
+
presentCall: (args) => card(args.action === "tidy" ? "整理窗口" : `窗口 · ${args.action ?? ""}`)
|
|
7767
8245
|
}));
|
|
7768
8246
|
tools.push(defineTool({
|
|
7769
8247
|
name: "ui_elements",
|
|
@@ -7887,6 +8365,71 @@ function createTools(host) {
|
|
|
7887
8365
|
},
|
|
7888
8366
|
presentCall: (args) => card(`请求操控 · ${(args.apps ?? []).join("、")}`)
|
|
7889
8367
|
}));
|
|
8368
|
+
if (host.skills) {
|
|
8369
|
+
const skills = host.skills;
|
|
8370
|
+
tools.push(defineTool({
|
|
8371
|
+
name: "app_skill",
|
|
8372
|
+
description: `Your notes on how to operate specific apps (one skill per app, kept across sessions; the user can edit them). open_application already returns the skill of the app it opens. Use "list" to see which apps have one, "read" for an app you reach another way, and "append" / "write" to record what you worked out about an unfamiliar app: reusable operating knowledge only (where things are, shortcuts, quirks, what failed and what works), never task content, personal data or pixel coordinates (they change with the window). Keep each skill under ${SKILL_MAX_CHARS} characters; rewrite it with "write" when it gets long or wrong.`,
|
|
8373
|
+
parameters: {
|
|
8374
|
+
action: {
|
|
8375
|
+
type: "string",
|
|
8376
|
+
enum: [
|
|
8377
|
+
"list",
|
|
8378
|
+
"read",
|
|
8379
|
+
"append",
|
|
8380
|
+
"write"
|
|
8381
|
+
],
|
|
8382
|
+
required: true
|
|
8383
|
+
},
|
|
8384
|
+
app: {
|
|
8385
|
+
type: "string",
|
|
8386
|
+
description: "App name, e.g. \"Obsidian\" (read / append / write)."
|
|
8387
|
+
},
|
|
8388
|
+
content: {
|
|
8389
|
+
type: "string",
|
|
8390
|
+
description: "Markdown bullet points: the lines to add (append) or the whole skill (write)."
|
|
8391
|
+
},
|
|
8392
|
+
summary: {
|
|
8393
|
+
type: "string",
|
|
8394
|
+
description: "A few words on what the skill covers, shown in the list (write, or the first append)."
|
|
8395
|
+
}
|
|
8396
|
+
},
|
|
8397
|
+
output,
|
|
8398
|
+
isConcurrencySafe: () => false,
|
|
8399
|
+
async execute(args) {
|
|
8400
|
+
const { action, app, content, summary } = args;
|
|
8401
|
+
if (action === "list") {
|
|
8402
|
+
const rows = skills.list();
|
|
8403
|
+
return { text: rows.length === 0 ? "No app skills yet." : rows.map((skill) => `${skill.app}${skill.summary ? ` — ${skill.summary}` : ""} (${skill.content.length} chars)`).join("\n") };
|
|
8404
|
+
}
|
|
8405
|
+
const name = String(app ?? "").trim();
|
|
8406
|
+
if (name === "") throw new Error("app is required.");
|
|
8407
|
+
if (action === "read") {
|
|
8408
|
+
const skill = skills.find(name, await computer.foreground().catch(() => void 0));
|
|
8409
|
+
return { text: skill ? `Skill for ${skill.app}:\n${skill.content}` : `No skill for "${name}" yet. If you work out how this app behaves, record it with app_skill append.` };
|
|
8410
|
+
}
|
|
8411
|
+
const text = String(content ?? "").trim();
|
|
8412
|
+
if (text === "") throw new Error("content is required.");
|
|
8413
|
+
const fg = await computer.foreground().catch(() => void 0);
|
|
8414
|
+
const extra = {
|
|
8415
|
+
match: fg && !isHostWindow(fg) && appMatches(name, fg) && !/^applicationframehost/i.test(fg.exe) ? [fg.exe] : [],
|
|
8416
|
+
...summary ? { summary } : {}
|
|
8417
|
+
};
|
|
8418
|
+
const saved = action === "write" ? skills.save({
|
|
8419
|
+
app: name,
|
|
8420
|
+
content: text,
|
|
8421
|
+
...extra
|
|
8422
|
+
}, skills.find(name)?.id) : skills.append(name, text, extra);
|
|
8423
|
+
return { text: `Skill for ${saved.app} saved (${saved.content.length} of ${SKILL_MAX_CHARS} characters).` };
|
|
8424
|
+
},
|
|
8425
|
+
presentCall: (args) => card(`应用技能 · ${{
|
|
8426
|
+
list: "列表",
|
|
8427
|
+
read: "读取",
|
|
8428
|
+
append: "记录",
|
|
8429
|
+
write: "重写"
|
|
8430
|
+
}[args.action ?? ""] ?? ""}${args.app ? ` · ${args.app}` : ""}`)
|
|
8431
|
+
}));
|
|
8432
|
+
}
|
|
7890
8433
|
tools.push(defineTool({
|
|
7891
8434
|
name: "list_granted_applications",
|
|
7892
8435
|
description: "List the apps you may control in this session.",
|
|
@@ -7905,6 +8448,12 @@ function createTools(host) {
|
|
|
7905
8448
|
}
|
|
7906
8449
|
//#endregion
|
|
7907
8450
|
//#region lib/types/index.js
|
|
8451
|
+
/**
|
|
8452
|
+
* @copylee/dsh-computer-use host bundle: Claude-style computer use for the
|
|
8453
|
+
* Windows desktop — screenshots in, mouse and keyboard out, per-app grants
|
|
8454
|
+
* through DSH approvals, and an orange "DeepSeek is using your computer"
|
|
8455
|
+
* overlay that a physical Esc dismisses.
|
|
8456
|
+
*/
|
|
7908
8457
|
const name = "@copylee/dsh-computer-use";
|
|
7909
8458
|
const inject = ["tools", "attachments"];
|
|
7910
8459
|
const Config = z.object({
|
|
@@ -7927,6 +8476,10 @@ const Config = z.object({
|
|
|
7927
8476
|
"en-US": { $description: "Name in the pill: \"<name> 正在操控你的电脑\"" }
|
|
7928
8477
|
}),
|
|
7929
8478
|
hostWindow: z.union([
|
|
8479
|
+
z.const("pet").i18n({
|
|
8480
|
+
"zh-CN": { $description: "最小化,改用右下角迷你进度卡片(两行滚动显示回复和思考 / 工具调用)" },
|
|
8481
|
+
"en-US": { $description: "Minimize it and show a mini progress card (reply + thinking / tool calls)" }
|
|
8482
|
+
}),
|
|
7930
8483
|
z.const("card").i18n({
|
|
7931
8484
|
"zh-CN": { $description: "缩成右下角置顶悬浮卡片" },
|
|
7932
8485
|
"en-US": { $description: "Shrink to an always-on-top card" }
|
|
@@ -7939,10 +8492,14 @@ const Config = z.object({
|
|
|
7939
8492
|
"zh-CN": { $description: "保持不变" },
|
|
7940
8493
|
"en-US": { $description: "Leave it as is" }
|
|
7941
8494
|
})
|
|
7942
|
-
]).default("
|
|
8495
|
+
]).default("pet").volatile().i18n({
|
|
7943
8496
|
"zh-CN": { $description: "操控期间 DeepSeek Harness 窗口怎么摆放(结束后自动恢复原尺寸和位置)" },
|
|
7944
8497
|
"en-US": { $description: "What to do with the DeepSeek Harness window while controlling (restored afterwards)" }
|
|
7945
8498
|
}),
|
|
8499
|
+
cardOpacity: z.natural().min(30).max(100).default(80).volatile().i18n({
|
|
8500
|
+
"zh-CN": { $description: "悬浮卡片不透明度(%):调低可透过卡片看清下面的操作过程;鼠标停在卡片上时变为不透明" },
|
|
8501
|
+
"en-US": { $description: "Card opacity (%): lower lets you watch the work underneath; it turns opaque while the pointer rests on it" }
|
|
8502
|
+
}),
|
|
7946
8503
|
typingMode: z.union([
|
|
7947
8504
|
z.const("stream").i18n({
|
|
7948
8505
|
"zh-CN": { $description: "流式:长文本按段落逐段粘贴,看得到一段段出现(推荐)" },
|
|
@@ -8041,8 +8598,10 @@ function apply(ctx, config = {}) {
|
|
|
8041
8598
|
clearInterval(every);
|
|
8042
8599
|
};
|
|
8043
8600
|
}, "computer-use: screenshot cleanup");
|
|
8601
|
+
const skills = new SkillStore(helperAssetPath("skills"));
|
|
8044
8602
|
const tools = createTools({
|
|
8045
8603
|
computer,
|
|
8604
|
+
skills,
|
|
8046
8605
|
async saveImage(shot, fileName) {
|
|
8047
8606
|
const ref = await attachments().saveImage({
|
|
8048
8607
|
data: shot.data,
|
|
@@ -8063,6 +8622,7 @@ function apply(ctx, config = {}) {
|
|
|
8063
8622
|
}
|
|
8064
8623
|
});
|
|
8065
8624
|
for (const tool of tools) ctx.effect(() => ctx.tools.register(tool), `computer-use: tool ${tool.name}`);
|
|
8625
|
+
const OWN_TOOLS = new Set(tools.map((tool) => tool.name));
|
|
8066
8626
|
ctx.on("tools/pre-execute", async (exec, next) => {
|
|
8067
8627
|
if (exec.name !== "request_access" || settings().accessMode !== "per-app") return next();
|
|
8068
8628
|
const agent = exec.agent;
|
|
@@ -8082,6 +8642,39 @@ function apply(ctx, config = {}) {
|
|
|
8082
8642
|
}
|
|
8083
8643
|
};
|
|
8084
8644
|
});
|
|
8645
|
+
ctx.on("agent/assistant-stream", ({ agent, frame }) => {
|
|
8646
|
+
overlay.stream(agent, frame);
|
|
8647
|
+
});
|
|
8648
|
+
ctx.on("tools/pre-execute", (exec, next) => {
|
|
8649
|
+
if (!OWN_TOOLS.has(exec.name)) {
|
|
8650
|
+
const args = exec.arguments ?? {};
|
|
8651
|
+
const detail = [
|
|
8652
|
+
args.command,
|
|
8653
|
+
args.description,
|
|
8654
|
+
args.query,
|
|
8655
|
+
args.path,
|
|
8656
|
+
args.url
|
|
8657
|
+
].find((value) => typeof value === "string");
|
|
8658
|
+
overlay.toolStarted(exec.agent, exec.name, (detail ?? "").split("\n")[0].slice(0, 120));
|
|
8659
|
+
}
|
|
8660
|
+
return next();
|
|
8661
|
+
});
|
|
8662
|
+
overlay.onMessage = (agent, text) => {
|
|
8663
|
+
const steer = agent.steer;
|
|
8664
|
+
if (typeof steer !== "function") {
|
|
8665
|
+
log("progress card: this agent cannot take steering");
|
|
8666
|
+
return;
|
|
8667
|
+
}
|
|
8668
|
+
steer.call(agent, Object.freeze({
|
|
8669
|
+
id: randomUUID(),
|
|
8670
|
+
role: "user",
|
|
8671
|
+
content: [{
|
|
8672
|
+
type: "text",
|
|
8673
|
+
text
|
|
8674
|
+
}],
|
|
8675
|
+
source: { kind: "user" }
|
|
8676
|
+
}));
|
|
8677
|
+
};
|
|
8085
8678
|
ctx.on("agent/status", ({ agent, status }) => {
|
|
8086
8679
|
if (status === "running") computer.resetLook();
|
|
8087
8680
|
if (status === "idle" && computer.clipboardAgent === agent) {
|
|
@@ -8124,6 +8717,7 @@ function apply(ctx, config = {}) {
|
|
|
8124
8717
|
route(PREVIEW_ROUTE, previewRoute(helper, settings, overlay, iconPath));
|
|
8125
8718
|
route(SCREENSHOTS_ROUTE, screenshotsRoute(screenshots));
|
|
8126
8719
|
route(SCREENSHOTS_CLEAN_ROUTE, screenshotsCleanRoute(screenshots));
|
|
8720
|
+
route(SKILLS_ROUTE, skillsRoute(skills));
|
|
8127
8721
|
});
|
|
8128
8722
|
ctx.inject(["systemPrompt"], (promptCtx) => {
|
|
8129
8723
|
let registered;
|