@copylee/dsh-computer-use 0.2.0 → 0.2.2
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 +4 -2
- package/helper/CuHelper.cs +31 -7
- package/lib/client.js +88 -4
- package/lib/index.js +442 -17
- package/lib/types/computer.d.ts +12 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/routes.d.ts +7 -0
- package/lib/types/screenshots.d.ts +41 -0
- package/lib/types/text.d.ts +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动)。卡片只给你看:AI 的截图里看到的是卡片下面的内容(通过 Windows 放大镜接口截图时把卡片排除在外,不闪烁;该接口不可用时退回为截图瞬间让卡片透明约 20 毫秒),点击和滚动也直接穿透卡片,卡片不会挪位置 |
|
|
16
16
|
| 暂停与停止 | 你亲手按 **Esc** 暂停(AI 停在下一步之前),再按 Esc 或点“继续”恢复,对话不会被中断;点“停止”才结束本轮。插件自己发出的 Esc 不会误触发 |
|
|
17
17
|
| 你随时可以插手 | 你用键盘打字时 AI 自动暂停,停手 1.5 秒后继续(单按 Shift / Ctrl 等修饰键不算);你切换或打开了别的窗口,AI 下一步不会盲目执行,而是先看新截图再决定。你只是点进 DSH 卡片看对话时不算切换,AI 的按键会自动回到它正在操作的窗口。鼠标移动不会触发,避免误触 |
|
|
18
|
-
|
|
|
18
|
+
| 文字输入 | Unicode 直接输入,不受输入法状态影响。短文字逐字打出来;长文本默认“流式”:按段落逐段粘贴(代码块不拆开),看得到一段段出现,又不会被 Typora、Obsidian、Word 的自动补全打乱。可在设置里改成逐字输入或一次粘贴。剪贴板文本统一为 CRLF,不丢换行 |
|
|
19
19
|
| 不弄乱剪贴板 | 插件写入剪贴板的内容不进 Windows 剪贴板历史(Win+V)和云剪贴板;粘贴后按原样恢复你的剪贴板(图片、文件也保留);AI 用 `clipboard` 工具写过剪贴板的,本轮结束后自动还原(期间你自己复制了新内容则不动) |
|
|
20
20
|
| 打开应用 | `open_application` 同时搜索开始菜单和桌面快捷方式(含公共桌面),便携软件也能按名字打开 |
|
|
21
21
|
| 看不见图的模型 | `ui_elements` 用 Windows UI Automation 列出可点击元素和坐标,纯文本模型也能用 |
|
|
@@ -72,14 +72,16 @@ dsh plugin --profile web add @copylee/dsh-computer-use@latest
|
|
|
72
72
|
| 操控期间 DSH 窗口 | 悬浮卡片 | 悬浮卡片 / 最小化 / 保持不变,结束后自动恢复 |
|
|
73
73
|
| 操作后自动截图 | 开 | 关闭可省 token,但模型需要自己截图 |
|
|
74
74
|
| 等待稳定 | 400 ms | 动作后至少等这么久,之后画面静止即截图(最多约 2.5 秒) |
|
|
75
|
-
| 截图最长边 / 总像素 / JPEG 质量 | 1366 / 1.15MP /
|
|
75
|
+
| 截图最长边 / 总像素 / JPEG 质量 | 1366 / 1.15MP / 70 | 越大越清晰、越费 token |
|
|
76
76
|
| 检测到你在操作时让出控制 | 开 | 键盘输入暂停、窗口被切换时重新看屏幕 |
|
|
77
|
+
| 文字输入方式 | 流式 | 流式(长文本逐段出现)/ 逐字输入(最像打字,最慢)/ 一次粘贴(最快) |
|
|
77
78
|
| 键盘静止多久后恢复 | 1500 ms | |
|
|
78
79
|
| 禁止操控的应用 | 空 | 名称或 exe,如 `alipay` |
|
|
79
80
|
|
|
80
81
|
## 数据与隐私
|
|
81
82
|
|
|
82
83
|
- 截图只作为当前会话的图片附件发给你选择的模型,插件不上传、不保存到别处。
|
|
84
|
+
- 截图附件存放在 `~/.dsh/attachments`,随会话历史保留(DSH 会校验附件,删掉仍被会话引用的截图会让该会话无法继续,所以插件不会动它们)。会话删除后留下的“孤儿”截图会在 DSH 启动几分钟后及之后每 12 小时自动清理;设置页“截图缓存”可查看占用并立即清理。
|
|
83
85
|
- helper 源码 `helper/CuHelper.cs` 随包发布,可自行审阅;编译产物缓存在 `%LOCALAPPDATA%\dsh-computer-use\`。
|
|
84
86
|
- 以管理员身份运行的窗口、UAC 弹窗、锁屏无法被控制(Windows UIPI 限制),遇到时模型会请你手动处理。
|
|
85
87
|
- 插件注入的系统提示要求模型不代填密码、支付信息、不处理验证码,遇到时交还给你。
|
package/helper/CuHelper.cs
CHANGED
|
@@ -266,8 +266,10 @@ namespace DshComputerUse
|
|
|
266
266
|
case "scroll": using (new PassThrough()) return Input.Scroll(r);
|
|
267
267
|
case "keys": return Input.Keys(r);
|
|
268
268
|
case "key_state": return Input.KeyState(r);
|
|
269
|
-
case "type": return Input.Type(Args.Str(r, "text", ""), Args.Int(r, "chunkDelay", 8));
|
|
270
|
-
case "
|
|
269
|
+
case "type": return Input.Type(Args.Str(r, "text", ""), Args.Int(r, "chunkDelay", 8), Args.Int(r, "charDelay", 0));
|
|
270
|
+
case "clipboard_hold": Clip.Hold(); return null;
|
|
271
|
+
case "clipboard_release": Clip.Release(); return null;
|
|
272
|
+
case "paste": return Input.Paste(Args.Str(r, "text", ""), Args.Bool(r, "restore", true), Args.Int(r, "waitMs", 250));
|
|
271
273
|
case "windows": return Windows.List();
|
|
272
274
|
case "foreground": return Windows.Describe(Native.GetForegroundWindow());
|
|
273
275
|
case "window_at": return Windows.At(Args.Int(r, "x", 0), Args.Int(r, "y", 0));
|
|
@@ -660,10 +662,12 @@ namespace DshComputerUse
|
|
|
660
662
|
return null;
|
|
661
663
|
}
|
|
662
664
|
|
|
663
|
-
|
|
665
|
+
/** charDelay > 0: one character at a time, like a person typing; otherwise fast batches. */
|
|
666
|
+
public static object Type(string text, int chunkDelay, int charDelay)
|
|
664
667
|
{
|
|
665
668
|
var batch = new List<Native.INPUT>();
|
|
666
|
-
|
|
669
|
+
int pause = charDelay > 0 ? charDelay : chunkDelay;
|
|
670
|
+
Action flush = delegate { if (batch.Count == 0) return; Send(batch); batch.Clear(); if (pause > 0) Thread.Sleep(pause); };
|
|
667
671
|
for (int i = 0; i < text.Length; i++)
|
|
668
672
|
{
|
|
669
673
|
char c = text[i];
|
|
@@ -671,13 +675,14 @@ namespace DshComputerUse
|
|
|
671
675
|
if (c == '\n') { flush(); batch.Add(Key(0x0D, false)); batch.Add(Key(0x0D, true)); flush(); continue; }
|
|
672
676
|
if (c == '\t') { batch.Add(Key(0x09, false)); batch.Add(Key(0x09, true)); continue; }
|
|
673
677
|
batch.Add(Unicode(c, false)); batch.Add(Unicode(c, true));
|
|
674
|
-
if (
|
|
678
|
+
if (char.IsHighSurrogate(c)) continue;
|
|
679
|
+
if (charDelay > 0 || batch.Count >= 40) flush();
|
|
675
680
|
}
|
|
676
681
|
flush();
|
|
677
682
|
return null;
|
|
678
683
|
}
|
|
679
684
|
|
|
680
|
-
public static object Paste(string text, bool restore)
|
|
685
|
+
public static object Paste(string text, bool restore, int waitMs)
|
|
681
686
|
{
|
|
682
687
|
// Keep every format the user had (images, files, rich text), not just text.
|
|
683
688
|
DataObject previous = null;
|
|
@@ -687,7 +692,7 @@ namespace DshComputerUse
|
|
|
687
692
|
Send(new List<Native.INPUT> { Key(0x11, false), Key(0x56, false) });
|
|
688
693
|
Thread.Sleep(30);
|
|
689
694
|
Send(new List<Native.INPUT> { Key(0x56, true), Key(0x11, true) });
|
|
690
|
-
Thread.Sleep(
|
|
695
|
+
Thread.Sleep(Math.Max(60, waitMs)); // the app reads the clipboard asynchronously
|
|
691
696
|
if (restore) { try { Clip.Put(previous); } catch (Exception) { } }
|
|
692
697
|
return null;
|
|
693
698
|
}
|
|
@@ -764,6 +769,25 @@ namespace DshComputerUse
|
|
|
764
769
|
throw new Exception("clipboard is busy");
|
|
765
770
|
}
|
|
766
771
|
|
|
772
|
+
/** The user's clipboard, kept aside while a streamed paste runs. */
|
|
773
|
+
static DataObject held;
|
|
774
|
+
static bool holding;
|
|
775
|
+
|
|
776
|
+
public static void Hold()
|
|
777
|
+
{
|
|
778
|
+
if (holding) return;
|
|
779
|
+
held = Snapshot();
|
|
780
|
+
holding = true;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
public static void Release()
|
|
784
|
+
{
|
|
785
|
+
if (!holding) return;
|
|
786
|
+
var data = held;
|
|
787
|
+
held = null; holding = false;
|
|
788
|
+
Put(data);
|
|
789
|
+
}
|
|
790
|
+
|
|
767
791
|
public static void Set(string text, bool isPrivate)
|
|
768
792
|
{
|
|
769
793
|
text = Normalize(text);
|
package/lib/client.js
CHANGED
|
@@ -40,10 +40,11 @@ window.__ModuleLoader__.load({
|
|
|
40
40
|
settleMs: 400,
|
|
41
41
|
maxLongEdge: 1366,
|
|
42
42
|
maxPixels: 115e4,
|
|
43
|
-
jpegQuality:
|
|
43
|
+
jpegQuality: 70,
|
|
44
44
|
blockedApps: [],
|
|
45
45
|
pauseOnUserInput: true,
|
|
46
|
-
userIdleMs: 1500
|
|
46
|
+
userIdleMs: 1500,
|
|
47
|
+
typingMode: "stream"
|
|
47
48
|
};
|
|
48
49
|
/** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
|
|
49
50
|
function resolveConfig(raw) {
|
|
@@ -66,6 +67,7 @@ window.__ModuleLoader__.load({
|
|
|
66
67
|
jpegQuality: num("jpegQuality", 30, 100),
|
|
67
68
|
pauseOnUserInput: bool("pauseOnUserInput"),
|
|
68
69
|
userIdleMs: num("userIdleMs", 300, 1e4),
|
|
70
|
+
typingMode: out.typingMode === "stream" || out.typingMode === "type" || out.typingMode === "paste" ? out.typingMode : DEFAULTS.typingMode,
|
|
69
71
|
blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
|
|
70
72
|
};
|
|
71
73
|
}
|
|
@@ -303,6 +305,9 @@ window.__ModuleLoader__.load({
|
|
|
303
305
|
* from the host routes in ../routes.ts.
|
|
304
306
|
*/
|
|
305
307
|
const STATUS_ROUTE = "/api/dsh-computer-use/status";
|
|
308
|
+
const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
|
|
309
|
+
const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
|
|
310
|
+
const mb = (bytes) => `${(bytes / 1048576).toFixed(1)} MB`;
|
|
306
311
|
const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
|
|
307
312
|
const h = react.createElement;
|
|
308
313
|
function draftFrom(value) {
|
|
@@ -313,6 +318,7 @@ window.__ModuleLoader__.load({
|
|
|
313
318
|
overlay: s.overlay,
|
|
314
319
|
overlayLabel: s.overlayLabel,
|
|
315
320
|
hostWindow: s.hostWindow,
|
|
321
|
+
typingMode: s.typingMode,
|
|
316
322
|
pauseOnUserInput: s.pauseOnUserInput,
|
|
317
323
|
userIdleMs: String(s.userIdleMs),
|
|
318
324
|
autoScreenshot: s.autoScreenshot,
|
|
@@ -343,6 +349,7 @@ window.__ModuleLoader__.load({
|
|
|
343
349
|
overlay: d.overlay,
|
|
344
350
|
overlayLabel: d.overlayLabel.trim() || DEFAULTS.overlayLabel,
|
|
345
351
|
hostWindow: d.hostWindow,
|
|
352
|
+
typingMode: d.typingMode,
|
|
346
353
|
pauseOnUserInput: d.pauseOnUserInput,
|
|
347
354
|
userIdleMs: Math.round(Number(d.userIdleMs)),
|
|
348
355
|
autoScreenshot: d.autoScreenshot,
|
|
@@ -533,6 +540,9 @@ window.__ModuleLoader__.load({
|
|
|
533
540
|
const [saving, setSaving] = react.useState(false);
|
|
534
541
|
const [message, setMessage] = react.useState(null);
|
|
535
542
|
const [status, setStatus] = react.useState(null);
|
|
543
|
+
const [cache, setCache] = react.useState(null);
|
|
544
|
+
const [cacheBusy, setCacheBusy] = react.useState(false);
|
|
545
|
+
const [cacheNote, setCacheNote] = react.useState(null);
|
|
536
546
|
const dirtyRef = react.useRef(false);
|
|
537
547
|
dirtyRef.current = dirty;
|
|
538
548
|
const load = react.useCallback(async (reset) => {
|
|
@@ -563,9 +573,44 @@ window.__ModuleLoader__.load({
|
|
|
563
573
|
setStatus(null);
|
|
564
574
|
}
|
|
565
575
|
}, []);
|
|
576
|
+
const refreshCache = react.useCallback(async () => {
|
|
577
|
+
setCacheBusy(true);
|
|
578
|
+
try {
|
|
579
|
+
const response = await fetch(SCREENSHOTS_ROUTE, { credentials: "same-origin" });
|
|
580
|
+
setCache(await response.json());
|
|
581
|
+
} catch {
|
|
582
|
+
setCache(null);
|
|
583
|
+
} finally {
|
|
584
|
+
setCacheBusy(false);
|
|
585
|
+
}
|
|
586
|
+
}, []);
|
|
587
|
+
const cleanCache = async () => {
|
|
588
|
+
setCacheBusy(true);
|
|
589
|
+
setCacheNote(null);
|
|
590
|
+
try {
|
|
591
|
+
const result = await (await fetch(SCREENSHOTS_CLEAN_ROUTE, {
|
|
592
|
+
method: "POST",
|
|
593
|
+
credentials: "same-origin"
|
|
594
|
+
})).json();
|
|
595
|
+
if (!result.ok) throw new Error(result.error ?? "清理失败");
|
|
596
|
+
setCacheNote({
|
|
597
|
+
kind: "ok",
|
|
598
|
+
text: result.removed ? `已清理 ${result.removed} 张截图` : "没有可清理的截图"
|
|
599
|
+
});
|
|
600
|
+
await refreshCache();
|
|
601
|
+
} catch (error) {
|
|
602
|
+
setCacheNote({
|
|
603
|
+
kind: "error",
|
|
604
|
+
text: `清理失败:${error.message}`
|
|
605
|
+
});
|
|
606
|
+
} finally {
|
|
607
|
+
setCacheBusy(false);
|
|
608
|
+
}
|
|
609
|
+
};
|
|
566
610
|
react.useEffect(() => {
|
|
567
611
|
load(true);
|
|
568
612
|
refreshStatus();
|
|
613
|
+
refreshCache();
|
|
569
614
|
return ctx.remote.$on?.("settings/document-updated", (ns) => {
|
|
570
615
|
if (ns === "copylee-computer-use") {
|
|
571
616
|
load(false);
|
|
@@ -720,7 +765,29 @@ window.__ModuleLoader__.load({
|
|
|
720
765
|
}), h("span", { style: {
|
|
721
766
|
...S.hint,
|
|
722
767
|
fontWeight: 400
|
|
723
|
-
} }, "操控结束后自动恢复原尺寸和位置。"))
|
|
768
|
+
} }, "操控结束后自动恢复原尺寸和位置。")), h("div", { style: S.label }, "文字输入方式", h(Select, {
|
|
769
|
+
label: "文字输入方式",
|
|
770
|
+
disabled,
|
|
771
|
+
value: draft.typingMode,
|
|
772
|
+
options: [
|
|
773
|
+
{
|
|
774
|
+
value: "stream",
|
|
775
|
+
label: "流式:长文本逐段出现(推荐)"
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
value: "type",
|
|
779
|
+
label: "逐字输入:像人打字,最慢"
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
value: "paste",
|
|
783
|
+
label: "一次粘贴:最快"
|
|
784
|
+
}
|
|
785
|
+
],
|
|
786
|
+
onChange: (value) => edit("typingMode", value)
|
|
787
|
+
}), h("span", { style: {
|
|
788
|
+
...S.hint,
|
|
789
|
+
fontWeight: 400
|
|
790
|
+
} }, "短文字都会逐字打出来。长文本逐字输入在 Typora、Obsidian、Word 等编辑器里可能被自动补全括号、自动续列表打乱;流式按段落粘贴,既看得到过程又不会乱。")))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "让出控制"), h(ToggleRow, {
|
|
724
791
|
title: "检测到你在操作时暂停",
|
|
725
792
|
hint: "你用键盘打字时 AI 等你停手;你切换了窗口时 AI 先重新看屏幕。鼠标移动不会触发。",
|
|
726
793
|
checked: draft.pauseOnUserInput,
|
|
@@ -767,7 +834,24 @@ window.__ModuleLoader__.load({
|
|
|
767
834
|
error: errors.jpegQuality,
|
|
768
835
|
disabled,
|
|
769
836
|
onChange: (value) => edit("jpegQuality", value)
|
|
770
|
-
})), h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。默认值(最长边 1366、1.15 百万像素)适合大多数模型。")), h("div", { style: S.actions }, h("button", {
|
|
837
|
+
})), h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。默认值(最长边 1366、1.15 百万像素)适合大多数模型。")), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "截图缓存"), h("p", { style: S.hint }, cache === null ? cacheBusy ? "正在统计…" : "无法统计截图缓存。" : !cache.ok ? `统计失败:${cache.error ?? ""}` : `本插件的截图共 ${cache.count} 张,占用 ${mb(cache.bytes)};其中 ${cache.orphans} 张(${mb(cache.orphanBytes)})所属会话已删除,可以安全清理。`), h("p", { style: S.hint }, "截图作为附件保存在会话历史里。仍在会话中的截图不会被删除:删除后继续那个会话会直接报错。删除会话后,它留下的截图会在启动 DeepSeek Harness 几分钟后及之后每 12 小时自动清理,也可以在这里立即清理。"), h("div", { style: S.actions }, h("button", {
|
|
838
|
+
type: "button",
|
|
839
|
+
style: {
|
|
840
|
+
...S.secondary,
|
|
841
|
+
opacity: cacheBusy || !cache?.orphans ? .5 : 1
|
|
842
|
+
},
|
|
843
|
+
disabled: cacheBusy || !cache?.orphans,
|
|
844
|
+
onClick: () => {
|
|
845
|
+
cleanCache();
|
|
846
|
+
}
|
|
847
|
+
}, "清理已删除会话的截图"), h("button", {
|
|
848
|
+
type: "button",
|
|
849
|
+
style: S.secondary,
|
|
850
|
+
disabled: cacheBusy,
|
|
851
|
+
onClick: () => {
|
|
852
|
+
refreshCache();
|
|
853
|
+
}
|
|
854
|
+
}, cacheBusy ? "统计中…" : "重新统计"), cacheNote === null ? null : h("span", { style: cacheNote.kind === "ok" ? S.ok : S.error }, cacheNote.text))), h("div", { style: S.actions }, h("button", {
|
|
771
855
|
type: "button",
|
|
772
856
|
style: {
|
|
773
857
|
...S.primary,
|
package/lib/index.js
CHANGED
|
@@ -4,10 +4,11 @@ import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
|
4
4
|
import { execFile, spawn } from "node:child_process";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { existsSync } from "node:fs";
|
|
7
|
-
import { mkdir, readFile, rename, rm } from "node:fs/promises";
|
|
8
|
-
import { tmpdir } from "node:os";
|
|
7
|
+
import { chmod, mkdir, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
8
|
+
import { homedir, tmpdir } from "node:os";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
|
+
import * as zlib from "node:zlib";
|
|
11
12
|
import { Context, Service } from "@deepseek-ai/cordis";
|
|
12
13
|
//#region lib/types/access.js
|
|
13
14
|
/**
|
|
@@ -444,12 +445,67 @@ function parseModifiers(text) {
|
|
|
444
445
|
return parseKeys(text.replace(/\s+/g, "")).flat();
|
|
445
446
|
}
|
|
446
447
|
//#endregion
|
|
448
|
+
//#region lib/types/text.js
|
|
449
|
+
/**
|
|
450
|
+
* Split text for streamed entry: paste block by block so the user watches it
|
|
451
|
+
* appear, while each block still goes in literally (typing Markdown key by key
|
|
452
|
+
* into Typora / Obsidian / Word trips their auto-formatting).
|
|
453
|
+
*
|
|
454
|
+
* Blocks end after a blank-line separator, never inside a ``` / ~~~ fence and
|
|
455
|
+
* never inside a paragraph (a half-pasted **bold** or link may not re-render).
|
|
456
|
+
* Joining the blocks gives back the original text exactly.
|
|
457
|
+
*/
|
|
458
|
+
function splitBlocks(text, minChars = 80) {
|
|
459
|
+
const lines = text.split(/(?<=\n)/);
|
|
460
|
+
const blocks = [];
|
|
461
|
+
let current = "";
|
|
462
|
+
let fence;
|
|
463
|
+
let previousBlank = false;
|
|
464
|
+
for (const line of lines) {
|
|
465
|
+
const bare = line.replace(/\r?\n$/, "");
|
|
466
|
+
const marker = /^\s*(```+|~~~+)/.exec(bare)?.[1];
|
|
467
|
+
if (marker !== void 0) {
|
|
468
|
+
if (fence === void 0) fence = marker[0].repeat(marker.length);
|
|
469
|
+
else if (marker.startsWith(fence)) fence = void 0;
|
|
470
|
+
}
|
|
471
|
+
const blank = bare.trim() === "";
|
|
472
|
+
if (fence === void 0 && !blank && previousBlank && current.length >= minChars) {
|
|
473
|
+
blocks.push(current);
|
|
474
|
+
current = "";
|
|
475
|
+
}
|
|
476
|
+
current += line;
|
|
477
|
+
if (marker === void 0 || fence !== void 0) previousBlank = blank && fence === void 0;
|
|
478
|
+
else previousBlank = false;
|
|
479
|
+
}
|
|
480
|
+
if (current !== "") blocks.push(current);
|
|
481
|
+
return blocks;
|
|
482
|
+
}
|
|
483
|
+
/** Pieces of at most ~`size` characters, broken after whitespace where possible (for paced typing). */
|
|
484
|
+
function typingPieces(text, size = 60) {
|
|
485
|
+
const out = [];
|
|
486
|
+
let rest = text;
|
|
487
|
+
while (rest.length > size) {
|
|
488
|
+
let cut = Math.max(rest.lastIndexOf(" ", size), rest.lastIndexOf("\n", size));
|
|
489
|
+
if (cut < size / 2) cut = size;
|
|
490
|
+
else cut += 1;
|
|
491
|
+
if (/[\uD800-\uDBFF]/.test(rest[cut - 1] ?? "")) cut += 1;
|
|
492
|
+
out.push(rest.slice(0, cut));
|
|
493
|
+
rest = rest.slice(cut);
|
|
494
|
+
}
|
|
495
|
+
if (rest !== "") out.push(rest);
|
|
496
|
+
return out;
|
|
497
|
+
}
|
|
498
|
+
//#endregion
|
|
447
499
|
//#region lib/types/computer.js
|
|
448
500
|
/**
|
|
449
501
|
* The computer-use engine behind the tools: one coordinate space (the latest
|
|
450
502
|
* screenshot of the current display), access checks against the window that
|
|
451
503
|
* will receive the input, overlay status, and post-action screenshots.
|
|
452
504
|
*/
|
|
505
|
+
/** Visible typing pace (ms per character). */
|
|
506
|
+
const CHAR_DELAY_MS = 12;
|
|
507
|
+
/** Text longer than this is pasted (stream / paste modes). */
|
|
508
|
+
const PASTE_OVER = 200;
|
|
453
509
|
const ACTIONS = [
|
|
454
510
|
"screenshot",
|
|
455
511
|
"left_click",
|
|
@@ -852,12 +908,7 @@ var Computer = class Computer {
|
|
|
852
908
|
const text = input.text ?? "";
|
|
853
909
|
if (text === "") throw new Error("type needs text.");
|
|
854
910
|
await this.checkKeyboard(call, "type into");
|
|
855
|
-
|
|
856
|
-
text,
|
|
857
|
-
restore: true
|
|
858
|
-
});
|
|
859
|
-
else await this.helper.call("type", { text }, 6e4);
|
|
860
|
-
return { text: `Typed ${text.length} characters.` };
|
|
911
|
+
return { text: await this.enterText(text, call) };
|
|
861
912
|
}
|
|
862
913
|
case "key": {
|
|
863
914
|
const combos = parseKeys(input.text ?? "");
|
|
@@ -877,6 +928,59 @@ var Computer = class Computer {
|
|
|
877
928
|
}
|
|
878
929
|
}
|
|
879
930
|
}
|
|
931
|
+
/**
|
|
932
|
+
* Enter text the way the settings ask. Long text is pasted (literally: typing
|
|
933
|
+
* Markdown key by key trips editors' auto-formatting); in stream mode block
|
|
934
|
+
* by block so the user watches it appear. Between pieces the user can pause
|
|
935
|
+
* (Esc / typing); if another window comes to the front meanwhile, stop.
|
|
936
|
+
*/
|
|
937
|
+
async enterText(text, call) {
|
|
938
|
+
const mode = this.settings().typingMode;
|
|
939
|
+
if (mode === "paste" && text.length > PASTE_OVER) {
|
|
940
|
+
await this.helper.call("paste", {
|
|
941
|
+
text,
|
|
942
|
+
restore: true
|
|
943
|
+
});
|
|
944
|
+
return `Typed ${text.length} characters (pasted).`;
|
|
945
|
+
}
|
|
946
|
+
if (mode === "stream" && text.length > PASTE_OVER) {
|
|
947
|
+
const blocks = splitBlocks(text);
|
|
948
|
+
await this.helper.call("clipboard_hold");
|
|
949
|
+
try {
|
|
950
|
+
await this.pieces(blocks, call, async (block, i) => {
|
|
951
|
+
await this.overlay.status(`输入中 ${i + 1}/${blocks.length}`);
|
|
952
|
+
await this.helper.call("paste", {
|
|
953
|
+
text: block,
|
|
954
|
+
restore: false,
|
|
955
|
+
waitMs: 220
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
} finally {
|
|
959
|
+
await this.helper.call("clipboard_release").catch(() => {});
|
|
960
|
+
}
|
|
961
|
+
return `Typed ${text.length} characters (streamed in ${blocks.length} blocks).`;
|
|
962
|
+
}
|
|
963
|
+
const delay = mode === "paste" ? 0 : CHAR_DELAY_MS;
|
|
964
|
+
await this.pieces(typingPieces(text), call, (part) => this.helper.call("type", {
|
|
965
|
+
text: part,
|
|
966
|
+
charDelay: delay
|
|
967
|
+
}, 12e4).then(() => {}));
|
|
968
|
+
return `Typed ${text.length} characters.`;
|
|
969
|
+
}
|
|
970
|
+
/** Run `step` per piece; between pieces yield to the user and make sure the target window is still in front. */
|
|
971
|
+
async pieces(items, call, step) {
|
|
972
|
+
const target = await this.foreground().catch(() => void 0);
|
|
973
|
+
let done = 0;
|
|
974
|
+
for (const [index, item] of items.entries()) {
|
|
975
|
+
if (call.signal.aborted) throw new Error("Cancelled.");
|
|
976
|
+
if (index > 0 && await this.overlay.yieldToUser(call.signal, this.settings().pauseOnUserInput)) {
|
|
977
|
+
const now = await this.foreground().catch(() => void 0);
|
|
978
|
+
if (target && now && now.hwnd !== target.hwnd) throw new Error(`Stopped after ${done} of ${items.join("").length} characters: the user paused and ${now.exe} is now in front. Check the screen and continue from where the text stops.`);
|
|
979
|
+
}
|
|
980
|
+
await step(item, index);
|
|
981
|
+
done += item.length;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
880
984
|
/** Release a mouse button left down by an aborted run. */
|
|
881
985
|
async releaseHeld() {
|
|
882
986
|
if (!this.heldButton) return;
|
|
@@ -1334,7 +1438,7 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
|
|
|
1334
1438
|
- 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.
|
|
1335
1439
|
- 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).
|
|
1336
1440
|
- 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.
|
|
1337
|
-
-
|
|
1441
|
+
- 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.
|
|
1338
1442
|
- Office apps: F12 opens the classic Save As dialog, where you can type a full path in the file name box.
|
|
1339
1443
|
- 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.
|
|
1340
1444
|
- 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.
|
|
@@ -1355,10 +1459,11 @@ const DEFAULTS = {
|
|
|
1355
1459
|
settleMs: 400,
|
|
1356
1460
|
maxLongEdge: 1366,
|
|
1357
1461
|
maxPixels: 115e4,
|
|
1358
|
-
jpegQuality:
|
|
1462
|
+
jpegQuality: 70,
|
|
1359
1463
|
blockedApps: [],
|
|
1360
1464
|
pauseOnUserInput: true,
|
|
1361
|
-
userIdleMs: 1500
|
|
1465
|
+
userIdleMs: 1500,
|
|
1466
|
+
typingMode: "stream"
|
|
1362
1467
|
};
|
|
1363
1468
|
/** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
|
|
1364
1469
|
function resolveConfig(raw) {
|
|
@@ -1381,6 +1486,7 @@ function resolveConfig(raw) {
|
|
|
1381
1486
|
jpegQuality: num("jpegQuality", 30, 100),
|
|
1382
1487
|
pauseOnUserInput: bool("pauseOnUserInput"),
|
|
1383
1488
|
userIdleMs: num("userIdleMs", 300, 1e4),
|
|
1489
|
+
typingMode: out.typingMode === "stream" || out.typingMode === "type" || out.typingMode === "paste" ? out.typingMode : DEFAULTS.typingMode,
|
|
1384
1490
|
blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
|
|
1385
1491
|
};
|
|
1386
1492
|
}
|
|
@@ -1388,6 +1494,8 @@ function resolveConfig(raw) {
|
|
|
1388
1494
|
//#region lib/types/routes.js
|
|
1389
1495
|
const STATUS_ROUTE = "/api/dsh-computer-use/status";
|
|
1390
1496
|
const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
|
|
1497
|
+
const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
|
|
1498
|
+
const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
|
|
1391
1499
|
function json(res, status, body) {
|
|
1392
1500
|
res.writeHead(status, {
|
|
1393
1501
|
"content-type": "application/json; charset=utf-8",
|
|
@@ -1456,6 +1564,286 @@ function previewRoute(helper, settings, overlay, iconPath) {
|
|
|
1456
1564
|
json(res, 200, { ok: true });
|
|
1457
1565
|
};
|
|
1458
1566
|
}
|
|
1567
|
+
/** Screenshot cache size and how much of it is orphaned. */
|
|
1568
|
+
function screenshotsRoute(cache) {
|
|
1569
|
+
return async (_req, res) => {
|
|
1570
|
+
try {
|
|
1571
|
+
json(res, 200, {
|
|
1572
|
+
ok: true,
|
|
1573
|
+
...await cache.stats()
|
|
1574
|
+
});
|
|
1575
|
+
} catch (error) {
|
|
1576
|
+
json(res, 200, {
|
|
1577
|
+
ok: false,
|
|
1578
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
/** Delete orphaned screenshots now. */
|
|
1584
|
+
function screenshotsCleanRoute(cache) {
|
|
1585
|
+
return async (req, res) => {
|
|
1586
|
+
if (req.method !== "POST") {
|
|
1587
|
+
json(res, 405, {
|
|
1588
|
+
ok: false,
|
|
1589
|
+
error: "POST only"
|
|
1590
|
+
});
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
try {
|
|
1594
|
+
json(res, 200, {
|
|
1595
|
+
ok: true,
|
|
1596
|
+
...await cache.clean(),
|
|
1597
|
+
...await cache.stats()
|
|
1598
|
+
});
|
|
1599
|
+
} catch (error) {
|
|
1600
|
+
json(res, 200, {
|
|
1601
|
+
ok: false,
|
|
1602
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
//#endregion
|
|
1608
|
+
//#region lib/types/screenshots.js
|
|
1609
|
+
/**
|
|
1610
|
+
* Screenshot cache housekeeping. Every screenshot is an image attachment in
|
|
1611
|
+
* DeepSeek Harness's content-addressed store (<DSH_HOME>/attachments/v1/objects/<2>/<sha256>),
|
|
1612
|
+
* which has no retention policy yet. Attachments still referenced by a session
|
|
1613
|
+
* must stay byte-for-byte (DSH verifies their hash, and a missing one fails the
|
|
1614
|
+
* whole turn), so only orphans are removed: screenshots this plugin made that
|
|
1615
|
+
* no session, archive or plugin store references any more (e.g. the session
|
|
1616
|
+
* was deleted).
|
|
1617
|
+
*/
|
|
1618
|
+
const HEX = /^[0-9a-f]{64}$/;
|
|
1619
|
+
/** Newly saved screenshots may not be in a session log yet. */
|
|
1620
|
+
const GRACE_MS = 864e5;
|
|
1621
|
+
/** Places outside the session logs that can reference attachments. */
|
|
1622
|
+
const OTHER_REFERENCE_DIRS = [
|
|
1623
|
+
"storages",
|
|
1624
|
+
"rewind-snapshots",
|
|
1625
|
+
"dsh-session-archive",
|
|
1626
|
+
"task-board"
|
|
1627
|
+
];
|
|
1628
|
+
const MAX_SCANNED_FILE = 67108864;
|
|
1629
|
+
var ScreenshotCache = class {
|
|
1630
|
+
dshHome;
|
|
1631
|
+
indexFile;
|
|
1632
|
+
log;
|
|
1633
|
+
index;
|
|
1634
|
+
saving = Promise.resolve();
|
|
1635
|
+
busy = Promise.resolve();
|
|
1636
|
+
constructor(dshHome = process.env.DSH_HOME || join(homedir(), ".dsh"), indexFile = join(process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local"), "dsh-computer-use", "screenshots.json"), log = () => {}) {
|
|
1637
|
+
this.dshHome = dshHome;
|
|
1638
|
+
this.indexFile = indexFile;
|
|
1639
|
+
this.log = log;
|
|
1640
|
+
}
|
|
1641
|
+
get objects() {
|
|
1642
|
+
return join(this.dshHome, "attachments", "v1", "objects");
|
|
1643
|
+
}
|
|
1644
|
+
path(hex) {
|
|
1645
|
+
return join(this.objects, hex.slice(0, 2), hex);
|
|
1646
|
+
}
|
|
1647
|
+
/** Remember a screenshot attachment ("sha256:<hex>") this plugin saved. */
|
|
1648
|
+
record(attachmentId) {
|
|
1649
|
+
const hex = attachmentId.replace(/^sha256:/, "");
|
|
1650
|
+
if (!HEX.test(hex)) return;
|
|
1651
|
+
this.load().then((index) => {
|
|
1652
|
+
index.set(hex, Date.now());
|
|
1653
|
+
this.persist();
|
|
1654
|
+
}).catch(() => {});
|
|
1655
|
+
}
|
|
1656
|
+
async stats() {
|
|
1657
|
+
return this.exclusive(async () => {
|
|
1658
|
+
const { candidates, orphans } = await this.classify();
|
|
1659
|
+
const sizes = await Promise.all([...candidates].map((hex) => this.size(hex)));
|
|
1660
|
+
let count = 0, bytes = 0, orphanCount = 0, orphanBytes = 0;
|
|
1661
|
+
[...candidates].forEach((hex, i) => {
|
|
1662
|
+
const size = sizes[i];
|
|
1663
|
+
if (size === void 0) return;
|
|
1664
|
+
count++;
|
|
1665
|
+
bytes += size;
|
|
1666
|
+
if (orphans.has(hex)) {
|
|
1667
|
+
orphanCount++;
|
|
1668
|
+
orphanBytes += size;
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1671
|
+
return {
|
|
1672
|
+
count,
|
|
1673
|
+
bytes,
|
|
1674
|
+
orphans: orphanCount,
|
|
1675
|
+
orphanBytes
|
|
1676
|
+
};
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
/** Delete orphaned screenshots. */
|
|
1680
|
+
async clean() {
|
|
1681
|
+
return this.exclusive(async () => {
|
|
1682
|
+
const { orphans } = await this.classify();
|
|
1683
|
+
const index = await this.load();
|
|
1684
|
+
let removed = 0, bytes = 0;
|
|
1685
|
+
for (const hex of orphans) {
|
|
1686
|
+
const size = await this.size(hex);
|
|
1687
|
+
if (size !== void 0) try {
|
|
1688
|
+
const file = this.path(hex);
|
|
1689
|
+
await chmod(file, 438).catch(() => {});
|
|
1690
|
+
await unlink(file);
|
|
1691
|
+
removed++;
|
|
1692
|
+
bytes += size;
|
|
1693
|
+
} catch (error) {
|
|
1694
|
+
this.log(`screenshot cleanup: ${String(error)}`);
|
|
1695
|
+
continue;
|
|
1696
|
+
}
|
|
1697
|
+
index.delete(hex);
|
|
1698
|
+
}
|
|
1699
|
+
this.persist();
|
|
1700
|
+
await this.saving;
|
|
1701
|
+
if (removed > 0) this.log(`screenshot cleanup: removed ${removed} orphaned screenshots (${(bytes / 1048576).toFixed(1)} MB)`);
|
|
1702
|
+
return {
|
|
1703
|
+
removed,
|
|
1704
|
+
bytes
|
|
1705
|
+
};
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
async classify() {
|
|
1709
|
+
const index = await this.load();
|
|
1710
|
+
const scan = await this.scan();
|
|
1711
|
+
let added = false;
|
|
1712
|
+
for (const hex of scan.ours) if (!index.has(hex)) {
|
|
1713
|
+
index.set(hex, 0);
|
|
1714
|
+
added = true;
|
|
1715
|
+
}
|
|
1716
|
+
if (added) this.persist();
|
|
1717
|
+
const now = Date.now();
|
|
1718
|
+
const candidates = new Set(index.keys());
|
|
1719
|
+
const orphans = /* @__PURE__ */ new Set();
|
|
1720
|
+
for (const [hex, savedAt] of index) {
|
|
1721
|
+
if (scan.referenced.has(hex)) continue;
|
|
1722
|
+
if (savedAt > 0 && now - savedAt < GRACE_MS) continue;
|
|
1723
|
+
orphans.add(hex);
|
|
1724
|
+
}
|
|
1725
|
+
return {
|
|
1726
|
+
candidates,
|
|
1727
|
+
orphans
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
/** Every attachment id referenced anywhere DSH keeps conversation state. */
|
|
1731
|
+
async scan() {
|
|
1732
|
+
const zstd = zlib.zstdDecompressSync;
|
|
1733
|
+
if (typeof zstd !== "function") throw new Error("This runtime cannot read DeepSeek Harness session logs (no zstd); cleanup skipped.");
|
|
1734
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
1735
|
+
const ours = /* @__PURE__ */ new Set();
|
|
1736
|
+
const sessions = join(this.dshHome, "sessions");
|
|
1737
|
+
for (const file of await walk(sessions)) {
|
|
1738
|
+
const text = await readText(file, zstd);
|
|
1739
|
+
if (text === void 0) throw new Error(`Could not read ${file}; cleanup skipped to stay safe.`);
|
|
1740
|
+
collect(text, referenced, ours);
|
|
1741
|
+
}
|
|
1742
|
+
for (const dir of OTHER_REFERENCE_DIRS) for (const file of await walk(join(this.dshHome, dir))) {
|
|
1743
|
+
const text = await readText(file, zstd);
|
|
1744
|
+
if (text !== void 0) collect(text, referenced, ours);
|
|
1745
|
+
}
|
|
1746
|
+
return {
|
|
1747
|
+
referenced,
|
|
1748
|
+
ours
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
async size(hex) {
|
|
1752
|
+
try {
|
|
1753
|
+
return (await stat(this.path(hex))).size;
|
|
1754
|
+
} catch {
|
|
1755
|
+
return;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
async load() {
|
|
1759
|
+
if (this.index) return this.index;
|
|
1760
|
+
try {
|
|
1761
|
+
const raw = JSON.parse(await readFile(this.indexFile, "utf8"));
|
|
1762
|
+
this.index = new Map(Object.entries(raw.screenshots ?? {}).filter(([hex]) => HEX.test(hex)));
|
|
1763
|
+
} catch {
|
|
1764
|
+
this.index = /* @__PURE__ */ new Map();
|
|
1765
|
+
}
|
|
1766
|
+
return this.index;
|
|
1767
|
+
}
|
|
1768
|
+
persist() {
|
|
1769
|
+
const index = this.index;
|
|
1770
|
+
if (!index) return;
|
|
1771
|
+
this.saving = this.saving.then(async () => {
|
|
1772
|
+
await mkdir(join(this.indexFile, ".."), { recursive: true });
|
|
1773
|
+
const tmp = `${this.indexFile}.${process.pid}.tmp`;
|
|
1774
|
+
await writeFile(tmp, JSON.stringify({
|
|
1775
|
+
version: 1,
|
|
1776
|
+
screenshots: Object.fromEntries(index)
|
|
1777
|
+
}));
|
|
1778
|
+
await rename(tmp, this.indexFile);
|
|
1779
|
+
}).catch((error) => this.log(`screenshot index: ${String(error)}`));
|
|
1780
|
+
}
|
|
1781
|
+
exclusive(task) {
|
|
1782
|
+
const run = this.busy.then(task, task);
|
|
1783
|
+
this.busy = run.catch(() => {});
|
|
1784
|
+
return run;
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
/** Ids in `text`; ids of our own screenshots (tool results named screenshot.jpg) also go to `ours`. */
|
|
1788
|
+
function collect(text, referenced, ours) {
|
|
1789
|
+
for (const match of text.matchAll(/sha256:([0-9a-f]{64})/g)) referenced.add(match[1]);
|
|
1790
|
+
for (const line of text.split("\n")) {
|
|
1791
|
+
if (!line.includes("\"tool/result\"") || !line.includes("\"screenshot.jpg\"")) continue;
|
|
1792
|
+
for (const match of line.matchAll(/"attachmentId":"sha256:([0-9a-f]{64})"[^{}]*?"name":"screenshot\.jpg"/g)) ours.add(match[1]);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
async function walk(dir) {
|
|
1796
|
+
const out = [];
|
|
1797
|
+
let entries;
|
|
1798
|
+
try {
|
|
1799
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
1800
|
+
} catch {
|
|
1801
|
+
return out;
|
|
1802
|
+
}
|
|
1803
|
+
for (const entry of entries) {
|
|
1804
|
+
const full = join(dir, entry.name);
|
|
1805
|
+
if (entry.isDirectory()) out.push(...await walk(full));
|
|
1806
|
+
else if (entry.isFile()) out.push(full);
|
|
1807
|
+
}
|
|
1808
|
+
return out;
|
|
1809
|
+
}
|
|
1810
|
+
const ZSTD_MAGIC = Buffer.from([
|
|
1811
|
+
40,
|
|
1812
|
+
181,
|
|
1813
|
+
47,
|
|
1814
|
+
253
|
|
1815
|
+
]);
|
|
1816
|
+
/** File text; zstd logs are a sequence of frames (decoded one by one). */
|
|
1817
|
+
async function readText(file, zstd) {
|
|
1818
|
+
try {
|
|
1819
|
+
if ((await stat(file)).size > MAX_SCANNED_FILE) return "";
|
|
1820
|
+
const data = await readFile(file);
|
|
1821
|
+
if (!file.endsWith(".zstd")) return data.toString("utf8");
|
|
1822
|
+
return decodeFrames(data, zstd);
|
|
1823
|
+
} catch {
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
/** Split at frame magics; when a split falls inside a frame, merge with the next piece and retry. */
|
|
1828
|
+
function decodeFrames(data, zstd) {
|
|
1829
|
+
const starts = [];
|
|
1830
|
+
for (let i = data.indexOf(ZSTD_MAGIC); i >= 0; i = data.indexOf(ZSTD_MAGIC, i + 1)) starts.push(i);
|
|
1831
|
+
if (starts.length === 0) return data.length === 0 ? "" : void 0;
|
|
1832
|
+
const parts = [];
|
|
1833
|
+
let from = 0;
|
|
1834
|
+
while (from < starts.length) {
|
|
1835
|
+
let decoded;
|
|
1836
|
+
let to = from + 1;
|
|
1837
|
+
for (; to <= starts.length; to++) try {
|
|
1838
|
+
decoded = zstd(data.subarray(starts[from], starts[to] ?? data.length));
|
|
1839
|
+
break;
|
|
1840
|
+
} catch {}
|
|
1841
|
+
if (decoded === void 0) return void 0;
|
|
1842
|
+
parts.push(decoded);
|
|
1843
|
+
from = to;
|
|
1844
|
+
}
|
|
1845
|
+
return Buffer.concat(parts).toString("utf8");
|
|
1846
|
+
}
|
|
1459
1847
|
//#endregion
|
|
1460
1848
|
//#region node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-invariants_0d6b19188928ab894325adc32e18b0b5/node_modules/@deepseek-ai/dsh-scope/lib/index.js
|
|
1461
1849
|
/**
|
|
@@ -7555,6 +7943,23 @@ const Config = z.object({
|
|
|
7555
7943
|
"zh-CN": { $description: "操控期间 DeepSeek Harness 窗口怎么摆放(结束后自动恢复原尺寸和位置)" },
|
|
7556
7944
|
"en-US": { $description: "What to do with the DeepSeek Harness window while controlling (restored afterwards)" }
|
|
7557
7945
|
}),
|
|
7946
|
+
typingMode: z.union([
|
|
7947
|
+
z.const("stream").i18n({
|
|
7948
|
+
"zh-CN": { $description: "流式:长文本按段落逐段粘贴,看得到一段段出现(推荐)" },
|
|
7949
|
+
"en-US": { $description: "Stream: paste long text paragraph by paragraph (recommended)" }
|
|
7950
|
+
}),
|
|
7951
|
+
z.const("type").i18n({
|
|
7952
|
+
"zh-CN": { $description: "逐字输入:像人打字,慢;Markdown 编辑器里可能被自动格式化打乱" },
|
|
7953
|
+
"en-US": { $description: "Type key by key: like a person, slow; Markdown editors may auto-format it" }
|
|
7954
|
+
}),
|
|
7955
|
+
z.const("paste").i18n({
|
|
7956
|
+
"zh-CN": { $description: "一次粘贴:最快" },
|
|
7957
|
+
"en-US": { $description: "Paste at once: fastest" }
|
|
7958
|
+
})
|
|
7959
|
+
]).default("stream").volatile().i18n({
|
|
7960
|
+
"zh-CN": { $description: "文字输入方式" },
|
|
7961
|
+
"en-US": { $description: "How text is entered" }
|
|
7962
|
+
}),
|
|
7558
7963
|
autoScreenshot: z.boolean().default(true).volatile().i18n({
|
|
7559
7964
|
"zh-CN": { $description: "每次操作后自动回传截图(省去一轮调用)" },
|
|
7560
7965
|
"en-US": { $description: "Return a screenshot after every action (saves a round trip)" }
|
|
@@ -7571,7 +7976,7 @@ const Config = z.object({
|
|
|
7571
7976
|
"zh-CN": { $description: "截图总像素上限" },
|
|
7572
7977
|
"en-US": { $description: "Screenshot total pixel limit" }
|
|
7573
7978
|
}),
|
|
7574
|
-
jpegQuality: z.natural().min(30).max(100).default(
|
|
7979
|
+
jpegQuality: z.natural().min(30).max(100).default(70).volatile().i18n({
|
|
7575
7980
|
"zh-CN": { $description: "截图 JPEG 质量" },
|
|
7576
7981
|
"en-US": { $description: "Screenshot JPEG quality" }
|
|
7577
7982
|
}),
|
|
@@ -7622,13 +8027,31 @@ function apply(ctx, config = {}) {
|
|
|
7622
8027
|
return cached;
|
|
7623
8028
|
};
|
|
7624
8029
|
const attachments = () => ctx.attachments;
|
|
8030
|
+
const screenshots = new ScreenshotCache(void 0, void 0, log);
|
|
8031
|
+
ctx.effect(() => {
|
|
8032
|
+
const sweep = () => {
|
|
8033
|
+
screenshots.clean().catch((error) => log(`screenshot cleanup skipped: ${String(error)}`));
|
|
8034
|
+
};
|
|
8035
|
+
const first = setTimeout(sweep, 12e4);
|
|
8036
|
+
const every = setInterval(sweep, 432e5);
|
|
8037
|
+
first.unref();
|
|
8038
|
+
every.unref();
|
|
8039
|
+
return () => {
|
|
8040
|
+
clearTimeout(first);
|
|
8041
|
+
clearInterval(every);
|
|
8042
|
+
};
|
|
8043
|
+
}, "computer-use: screenshot cleanup");
|
|
7625
8044
|
const tools = createTools({
|
|
7626
8045
|
computer,
|
|
7627
|
-
saveImage
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
8046
|
+
async saveImage(shot, fileName) {
|
|
8047
|
+
const ref = await attachments().saveImage({
|
|
8048
|
+
data: shot.data,
|
|
8049
|
+
mediaType: "image/jpeg",
|
|
8050
|
+
name: fileName
|
|
8051
|
+
});
|
|
8052
|
+
screenshots.record(String(ref.attachmentId));
|
|
8053
|
+
return ref;
|
|
8054
|
+
},
|
|
7632
8055
|
async context(raw) {
|
|
7633
8056
|
const exec = raw;
|
|
7634
8057
|
return {
|
|
@@ -7699,6 +8122,8 @@ function apply(ctx, config = {}) {
|
|
|
7699
8122
|
};
|
|
7700
8123
|
route(STATUS_ROUTE, statusRoute(helper, settings, overlay));
|
|
7701
8124
|
route(PREVIEW_ROUTE, previewRoute(helper, settings, overlay, iconPath));
|
|
8125
|
+
route(SCREENSHOTS_ROUTE, screenshotsRoute(screenshots));
|
|
8126
|
+
route(SCREENSHOTS_CLEAN_ROUTE, screenshotsCleanRoute(screenshots));
|
|
7702
8127
|
});
|
|
7703
8128
|
ctx.inject(["systemPrompt"], (promptCtx) => {
|
|
7704
8129
|
let registered;
|
package/lib/types/computer.d.ts
CHANGED
|
@@ -17,7 +17,10 @@ export interface Settings {
|
|
|
17
17
|
pauseOnUserInput: boolean;
|
|
18
18
|
/** How long the keyboard must be quiet before resuming. */
|
|
19
19
|
userIdleMs: number;
|
|
20
|
+
/** How text is entered: stream = paste block by block, type = key by key, paste = at once. */
|
|
21
|
+
typingMode: TypingMode;
|
|
20
22
|
}
|
|
23
|
+
export type TypingMode = 'stream' | 'type' | 'paste';
|
|
21
24
|
export interface WindowInfo extends WindowLike {
|
|
22
25
|
hwnd: number;
|
|
23
26
|
pid: number;
|
|
@@ -132,6 +135,15 @@ export declare class Computer {
|
|
|
132
135
|
static statusOf(input: ActionInput): string;
|
|
133
136
|
/** Run one action. Returns text plus an image for screenshot/zoom. */
|
|
134
137
|
run(input: ActionInput, call: CallContext): Promise<ActionOutcome>;
|
|
138
|
+
/**
|
|
139
|
+
* Enter text the way the settings ask. Long text is pasted (literally: typing
|
|
140
|
+
* Markdown key by key trips editors' auto-formatting); in stream mode block
|
|
141
|
+
* by block so the user watches it appear. Between pieces the user can pause
|
|
142
|
+
* (Esc / typing); if another window comes to the front meanwhile, stop.
|
|
143
|
+
*/
|
|
144
|
+
private enterText;
|
|
145
|
+
/** Run `step` per piece; between pieces yield to the user and make sure the target window is still in front. */
|
|
146
|
+
private pieces;
|
|
135
147
|
/** Release a mouse button left down by an aborted run. */
|
|
136
148
|
releaseHeld(): Promise<void>;
|
|
137
149
|
/**
|
package/lib/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import type { Context } from '@deepseek-ai/cordis';
|
|
8
8
|
import z from '@deepseek-ai/schemastery';
|
|
9
9
|
import { type AccessMode } from './access.js';
|
|
10
|
+
import { type TypingMode } from './computer.js';
|
|
10
11
|
import { type HostWindowMode } from './overlay.js';
|
|
11
12
|
export { DEFAULTS, ENTRY_ID, resolveConfig } from './settings.js';
|
|
12
13
|
export declare const name = "@copylee/dsh-computer-use";
|
|
@@ -26,6 +27,7 @@ export interface Config {
|
|
|
26
27
|
blockedApps?: string[];
|
|
27
28
|
pauseOnUserInput?: boolean;
|
|
28
29
|
userIdleMs?: number;
|
|
30
|
+
typingMode?: TypingMode;
|
|
29
31
|
}
|
|
30
32
|
export declare const Config: z<Config>;
|
|
31
33
|
export declare function apply(ctx: Context, config?: Config): void;
|
package/lib/types/routes.d.ts
CHANGED
|
@@ -7,8 +7,11 @@ import { type Display } from './coords.js';
|
|
|
7
7
|
import type { Settings } from './computer.js';
|
|
8
8
|
import type { HelperLike } from './helper-client.js';
|
|
9
9
|
import type { OverlayController } from './overlay.js';
|
|
10
|
+
import type { ScreenshotCache } from './screenshots.js';
|
|
10
11
|
export declare const STATUS_ROUTE = "/api/dsh-computer-use/status";
|
|
11
12
|
export declare const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
|
|
13
|
+
export declare const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
|
|
14
|
+
export declare const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
|
|
12
15
|
type Handler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
13
16
|
export interface StatusBody {
|
|
14
17
|
ok: true;
|
|
@@ -26,4 +29,8 @@ export interface StatusBody {
|
|
|
26
29
|
export declare function statusRoute(helper: HelperLike, settings: () => Settings, overlay: OverlayController): Handler;
|
|
27
30
|
/** Show the overlay for a few seconds so the user can see how it looks (skipped while an agent is controlling). */
|
|
28
31
|
export declare function previewRoute(helper: HelperLike, settings: () => Settings, overlay: OverlayController, iconPath: string): Handler;
|
|
32
|
+
/** Screenshot cache size and how much of it is orphaned. */
|
|
33
|
+
export declare function screenshotsRoute(cache: ScreenshotCache): Handler;
|
|
34
|
+
/** Delete orphaned screenshots now. */
|
|
35
|
+
export declare function screenshotsCleanRoute(cache: ScreenshotCache): Handler;
|
|
29
36
|
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface ScreenshotStats {
|
|
2
|
+
/** Screenshots this plugin knows about that still exist on disk. */
|
|
3
|
+
count: number;
|
|
4
|
+
bytes: number;
|
|
5
|
+
/** Of those, the ones no longer referenced anywhere (safe to delete). */
|
|
6
|
+
orphans: number;
|
|
7
|
+
orphanBytes: number;
|
|
8
|
+
}
|
|
9
|
+
export interface CleanResult {
|
|
10
|
+
removed: number;
|
|
11
|
+
bytes: number;
|
|
12
|
+
}
|
|
13
|
+
type ZstdDecompress = (data: Uint8Array) => Buffer;
|
|
14
|
+
export declare class ScreenshotCache {
|
|
15
|
+
private readonly dshHome;
|
|
16
|
+
private readonly indexFile;
|
|
17
|
+
private readonly log;
|
|
18
|
+
private index;
|
|
19
|
+
private saving;
|
|
20
|
+
private busy;
|
|
21
|
+
constructor(dshHome?: string, indexFile?: string, log?: (message: string) => void);
|
|
22
|
+
private get objects();
|
|
23
|
+
private path;
|
|
24
|
+
/** Remember a screenshot attachment ("sha256:<hex>") this plugin saved. */
|
|
25
|
+
record(attachmentId: string): void;
|
|
26
|
+
stats(): Promise<ScreenshotStats>;
|
|
27
|
+
/** Delete orphaned screenshots. */
|
|
28
|
+
clean(): Promise<CleanResult>;
|
|
29
|
+
private classify;
|
|
30
|
+
/** Every attachment id referenced anywhere DSH keeps conversation state. */
|
|
31
|
+
private scan;
|
|
32
|
+
private size;
|
|
33
|
+
private load;
|
|
34
|
+
private persist;
|
|
35
|
+
private exclusive;
|
|
36
|
+
}
|
|
37
|
+
/** Ids in `text`; ids of our own screenshots (tool results named screenshot.jpg) also go to `ours`. */
|
|
38
|
+
export declare function collect(text: string, referenced: Set<string>, ours: Set<string>): void;
|
|
39
|
+
/** Split at frame magics; when a split falls inside a frame, merge with the next piece and retry. */
|
|
40
|
+
export declare function decodeFrames(data: Buffer, zstd: ZstdDecompress): string | undefined;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split text for streamed entry: paste block by block so the user watches it
|
|
3
|
+
* appear, while each block still goes in literally (typing Markdown key by key
|
|
4
|
+
* into Typora / Obsidian / Word trips their auto-formatting).
|
|
5
|
+
*
|
|
6
|
+
* Blocks end after a blank-line separator, never inside a ``` / ~~~ fence and
|
|
7
|
+
* never inside a paragraph (a half-pasted **bold** or link may not re-render).
|
|
8
|
+
* Joining the blocks gives back the original text exactly.
|
|
9
|
+
*/
|
|
10
|
+
export declare function splitBlocks(text: string, minChars?: number): string[];
|
|
11
|
+
/** Pieces of at most ~`size` characters, broken after whitespace where possible (for paced typing). */
|
|
12
|
+
export declare function typingPieces(text: string, size?: number): string[];
|
package/package.json
CHANGED