@copylee/dsh-computer-use 0.1.1 → 0.1.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/lib/index.js CHANGED
@@ -465,6 +465,8 @@ const MUTATING = /* @__PURE__ */ new Set([
465
465
  "hold_key",
466
466
  "mouse_move"
467
467
  ]);
468
+ /** Actions that wait for the user to stop typing before they run. */
469
+ const INPUT = new Set([...MUTATING].filter((action) => action !== "mouse_move"));
468
470
  var Computer = class Computer {
469
471
  helper;
470
472
  access;
@@ -525,7 +527,24 @@ var Computer = class Computer {
525
527
  await this.refreshDisplays();
526
528
  const display = await this.display();
527
529
  const size = this.shotSize(display);
528
- return this.capture(display, size);
530
+ const shot = await this.capture(display, size);
531
+ await this.remember();
532
+ return shot;
533
+ }
534
+ /** The foreground window as of the model's latest look at the screen. */
535
+ seen;
536
+ async remember() {
537
+ this.seen = await this.foreground().catch(() => void 0);
538
+ }
539
+ /**
540
+ * Did another window come to the front since the model last looked, without
541
+ * the agent acting in between? Then the user (or a popup) changed the screen.
542
+ */
543
+ async foregroundChanged() {
544
+ const seen = this.seen;
545
+ if (!seen) return void 0;
546
+ const now = await this.foreground().catch(() => void 0);
547
+ return now && now.hwnd !== seen.hwnd ? now : void 0;
529
548
  }
530
549
  async capture(rect, out) {
531
550
  const result = await this.helper.call("screenshot", {
@@ -571,6 +590,7 @@ var Computer = class Computer {
571
590
  /** Short description of the frontmost window, for result text. */
572
591
  async describeForeground() {
573
592
  const win = await this.foreground().catch(() => void 0);
593
+ this.seen = win;
574
594
  if (!win) return "Foreground window: none (desktop).";
575
595
  return `Foreground window: ${win.exe} — "${win.title.slice(0, 80)}".`;
576
596
  }
@@ -614,6 +634,28 @@ var Computer = class Computer {
614
634
  if (call.signal.aborted) throw new Error("Cancelled.");
615
635
  await this.overlay.begin(call.agent, Computer.statusOf(input));
616
636
  const { action } = input;
637
+ const s = this.settings();
638
+ if (s.pauseOnUserInput && INPUT.has(action) && await this.overlay.waitForUserIdle(call.signal, s.userIdleMs)) {
639
+ await this.overlay.begin(call.agent, Computer.statusOf(input));
640
+ return {
641
+ text: `Not done: the user was typing on the keyboard, so you were paused until they stopped. ${action} was NOT performed. Look at the new screenshot and re-plan before acting.`,
642
+ ...call.vision ? { image: await this.screenshot() } : {},
643
+ skipped: true
644
+ };
645
+ }
646
+ if (s.pauseOnUserInput && INPUT.has(action)) {
647
+ const changed = await this.foregroundChanged();
648
+ if (changed) {
649
+ const image = call.vision ? await this.screenshot() : void 0;
650
+ if (!image) this.seen = changed;
651
+ return {
652
+ text: `Not done: since your last look the foreground window changed to ${changed.exe} ("${changed.title.slice(0, 60)}") without you acting, most likely the user opened it. ${action} was NOT performed. Look at the new screenshot and decide whether to continue there, switch back, or ask the user.`,
653
+ ...image ? { image } : {},
654
+ skipped: true
655
+ };
656
+ }
657
+ }
658
+ if (INPUT.has(action)) this.seen = void 0;
617
659
  switch (action) {
618
660
  case "screenshot": {
619
661
  const shot = await this.screenshot();
@@ -1004,8 +1046,31 @@ var OverlayController = class {
1004
1046
  this.log = log;
1005
1047
  helper.onEvent((event) => {
1006
1048
  if (event.event === "stop") this.stop(event.reason ?? "user");
1049
+ else if (event.event === "user_input") this.lastUserInput = Date.now();
1007
1050
  });
1008
1051
  }
1052
+ /** When the user last typed on the physical keyboard while the overlay was up (ms epoch). */
1053
+ lastUserInput = 0;
1054
+ /** Did the user type after `since`? */
1055
+ userTypedSince(since) {
1056
+ return this.lastUserInput > since;
1057
+ }
1058
+ /**
1059
+ * If the user is typing, pause until the keyboard has been quiet for
1060
+ * `idleMs`. Throws after `maxMs` so the model can tell the user. Returns
1061
+ * whether it had to wait.
1062
+ */
1063
+ async waitForUserIdle(signal, idleMs, maxMs = 12e4) {
1064
+ if (Date.now() - this.lastUserInput >= idleMs) return false;
1065
+ const started = Date.now();
1066
+ if (this.settings().overlay && this.visible) await this.helper.call("overlay_status", { status: "你正在操作,已暂停" }).catch(() => {});
1067
+ while (Date.now() - this.lastUserInput < idleMs) {
1068
+ if (signal.aborted) throw new Error("Cancelled.");
1069
+ if (Date.now() - started > maxMs) throw new Error("The user has been typing on the keyboard for a while, so computer use is paused. Ask the user whether to continue.");
1070
+ await new Promise((resolve) => setTimeout(resolve, 200));
1071
+ }
1072
+ return true;
1073
+ }
1009
1074
  /** The agent currently driving the computer, if any. */
1010
1075
  get controller() {
1011
1076
  return this.agent;
@@ -1091,10 +1156,10 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
1091
1156
  - Actions return a fresh screenshot. Check it before continuing and verify the result instead of assuming success. Use computer_batch for several confident steps in a row.
1092
1157
  - If the user has a dedicated tool for a website or service (browser automation, an API tool), prefer it over driving the desktop.
1093
1158
  - Do not enter passwords, payment details or solve CAPTCHAs: stop and ask the user to do that step. Ask before irreversible actions (sending messages, deleting, purchasing) unless the user clearly asked for them.
1094
- - The user sees an orange border and can press Esc at any time to stop you.`;
1159
+ - The user sees an orange border and can press Esc at any time to stop you. If they type on the keyboard you are paused; when an action reports it was not performed, re-check the screen instead of repeating it blindly.`;
1095
1160
  }
1096
1161
  //#endregion
1097
- //#region node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2._0d6b19188928ab894325adc32e18b0b5/node_modules/@deepseek-ai/dsh-scope/lib/index.js
1162
+ //#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
1098
1163
  /**
1099
1164
  * Shared insertion-ordered storage and effect ownership for scope-aware registries.
1100
1165
  *
@@ -1373,7 +1438,7 @@ function scopeTarget(base, key) {
1373
1438
  return carrier;
1374
1439
  }
1375
1440
  //#endregion
1376
- //#region node_modules/.pnpm/@deepseek-ai+dsh-typert-pro_0ed6bf01f07b8aa74e2681abf2790db7/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
1441
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
1377
1442
  /** The one Remote failure class shared by owners, the Gateway, and consumers. */
1378
1443
  /**
1379
1444
  * One Remote call failure: a real Error carrying its stable code and typed
@@ -1533,7 +1598,7 @@ function validateName(subject, value) {
1533
1598
  if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
1534
1599
  }
1535
1600
  //#endregion
1536
- //#region node_modules/.pnpm/@deepseek-ai+dsh-util-value_a1b445b943dd6f2898d88d6b9ffb1320/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
1601
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
1537
1602
  /** Duplicate-install-safe JSON and immutable-value helpers. @module @deepseek-ai/dsh-util-values */
1538
1603
  /**
1539
1604
  * Mark an unreachable closed-union branch.
@@ -1745,7 +1810,7 @@ function deepFreeze(value) {
1745
1810
  return value;
1746
1811
  }
1747
1812
  //#endregion
1748
- //#region node_modules/.pnpm/@deepseek-ai+dsh-util-crypt_566393aaceb27aff7afe31ca52cb276c/node_modules/@deepseek-ai/dsh-util-crypto/lib/index.js
1813
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-util-crypto@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-util-crypto/lib/index.js
1749
1814
  /**
1750
1815
  * Random v4 UUID, minted from `crypto.getRandomValues`.
1751
1816
  * @returns the UUID string.
@@ -1781,7 +1846,7 @@ function brandString(value) {
1781
1846
  return value;
1782
1847
  }
1783
1848
  //#endregion
1784
- //#region node_modules/.pnpm/@deepseek-ai+dsh-timeout@0._b8424359025b5f3ee36fc59cc7db98be/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
1849
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
1785
1850
  /** Largest delay Node schedules without clamping it to one millisecond. */
1786
1851
  const MAX_TIMER_DELAY_MS = 2147483647;
1787
1852
  //#endregion
@@ -2962,7 +3027,7 @@ function adapterFailureChunk(error, signal) {
2962
3027
  };
2963
3028
  }
2964
3029
  //#endregion
2965
- //#region node_modules/.pnpm/@deepseek-ai+dsh-sandbox@0._2cc6ce11d95db65b014013a78bf96eaa/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js
3030
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-sandbox@0.2.0-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-llm@0.2._2cc6ce11d95db65b014013a78bf96eaa/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js
2966
3031
  /**
2967
3032
  * The escalation vocabulary and choreography shared by every sandbox-enforcing
2968
3033
  * tool family (`@deepseek-ai/dsh-tool-bash`, `@deepseek-ai/dsh-tool-fs`): the
@@ -3048,7 +3113,7 @@ async function approveEscalation(request, approval) {
3048
3113
  }
3049
3114
  }
3050
3115
  //#endregion
3051
- //#region node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2._0055658947bc774f21f98df07f5a8468/node_modules/@deepseek-ai/dsh-tools/lib/index.js
3116
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.0-rc.2_c6e351a6a6cfd1c2a664558bffcd410d/node_modules/@deepseek-ai/dsh-tools/lib/index.js
3052
3117
  /**
3053
3118
  * Enforced JSON Schema subset shared by tool outputs, generated PTC mode
3054
3119
  * types, subagents, and workflows. The subset accepts any JSON root, an
@@ -6882,9 +6947,18 @@ function createTools(host) {
6882
6947
  break;
6883
6948
  }
6884
6949
  try {
6950
+ const stepStart = Date.now();
6885
6951
  const outcome = await computer.run(input, call);
6952
+ if (outcome.skipped) {
6953
+ failure = `#${index + 1} ${input.action} skipped: the user was typing on the keyboard. Re-check the screen before continuing.`;
6954
+ break;
6955
+ }
6886
6956
  lines.push(`#${index + 1} ${outcome.text}`);
6887
6957
  await setTimeout$1(60, void 0, { signal: call.signal });
6958
+ if (computer.settings().pauseOnUserInput && computer.overlay.userTypedSince(stepStart - 1)) {
6959
+ failure = `#${index + 1} done, but the user typed on the keyboard meanwhile; remaining actions stopped. Re-check the screen before continuing.`;
6960
+ break;
6961
+ }
6888
6962
  } catch (error) {
6889
6963
  if (call.signal.aborted) {
6890
6964
  await computer.releaseHeld();
@@ -7147,7 +7221,9 @@ const DEFAULTS = {
7147
7221
  maxLongEdge: 1366,
7148
7222
  maxPixels: 115e4,
7149
7223
  jpegQuality: 80,
7150
- blockedApps: []
7224
+ blockedApps: [],
7225
+ pauseOnUserInput: true,
7226
+ userIdleMs: 1500
7151
7227
  };
7152
7228
  const Config = z.object({
7153
7229
  accessMode: z.union([z.const("per-app").i18n({
@@ -7192,6 +7268,14 @@ const Config = z.object({
7192
7268
  "zh-CN": { $description: "截图 JPEG 质量" },
7193
7269
  "en-US": { $description: "Screenshot JPEG quality" }
7194
7270
  }),
7271
+ pauseOnUserInput: z.boolean().default(true).volatile().i18n({
7272
+ "zh-CN": { $description: "检测到你在操作时让出控制:你用键盘打字时暂停、停手后继续;你切换或打开了新窗口时,AI 重新看屏幕再决定(鼠标移动不会触发)" },
7273
+ "en-US": { $description: "Yield to you: pause while you type, and re-check the screen when you bring up another window (mouse movement is ignored)" }
7274
+ }),
7275
+ userIdleMs: z.natural().min(300).max(1e4).default(1500).volatile().i18n({
7276
+ "zh-CN": { $description: "键盘停止多少毫秒后恢复操作" },
7277
+ "en-US": { $description: "Milliseconds of keyboard quiet before resuming" }
7278
+ }),
7195
7279
  blockedApps: z.array(z.string()).default([]).volatile().i18n({
7196
7280
  "zh-CN": { $description: "禁止操控的应用(名称或 exe,如 “alipay”)。常见密码管理器默认已禁止。" },
7197
7281
  "en-US": { $description: "Apps that may never be controlled (names or exe). Common password managers are always blocked." }
@@ -7216,6 +7300,8 @@ function resolveConfig(raw) {
7216
7300
  maxLongEdge: num("maxLongEdge", 640, 3840),
7217
7301
  maxPixels: num("maxPixels", 3e5, 8e6),
7218
7302
  jpegQuality: num("jpegQuality", 30, 100),
7303
+ pauseOnUserInput: bool("pauseOnUserInput"),
7304
+ userIdleMs: num("userIdleMs", 300, 1e4),
7219
7305
  blockedApps: Array.isArray(out.blockedApps) ? out.blockedApps.filter((item) => typeof item === "string" && item.trim() !== "") : []
7220
7306
  };
7221
7307
  }
@@ -13,6 +13,10 @@ export interface Settings {
13
13
  jpegQuality: number;
14
14
  autoScreenshot: boolean;
15
15
  settleMs: number;
16
+ /** Pause while the user types on the physical keyboard. */
17
+ pauseOnUserInput: boolean;
18
+ /** How long the keyboard must be quiet before resuming. */
19
+ userIdleMs: number;
16
20
  }
17
21
  export interface WindowInfo extends WindowLike {
18
22
  hwnd: number;
@@ -57,6 +61,8 @@ export interface ActionOutcome {
57
61
  text: string;
58
62
  /** A screenshot or zoom image to return to the model. */
59
63
  image?: Shot;
64
+ /** The action was not performed because the user took over the keyboard. */
65
+ skipped?: boolean;
60
66
  }
61
67
  export declare class Computer {
62
68
  readonly helper: HelperLike;
@@ -77,6 +83,14 @@ export declare class Computer {
77
83
  offscreen: boolean;
78
84
  }>;
79
85
  screenshot(): Promise<Shot>;
86
+ /** The foreground window as of the model's latest look at the screen. */
87
+ private seen;
88
+ private remember;
89
+ /**
90
+ * Did another window come to the front since the model last looked, without
91
+ * the agent acting in between? Then the user (or a popup) changed the screen.
92
+ */
93
+ private foregroundChanged;
80
94
  private capture;
81
95
  zoom(region: number[] | undefined): Promise<Shot>;
82
96
  foreground(): Promise<WindowInfo | undefined>;
@@ -21,6 +21,8 @@ export interface Config {
21
21
  maxPixels?: number;
22
22
  jpegQuality?: number;
23
23
  blockedApps?: string[];
24
+ pauseOnUserInput?: boolean;
25
+ userIdleMs?: number;
24
26
  }
25
27
  export declare const Config: z<Config>;
26
28
  /** Unwrap `.volatile()` refs (`{ get() }`) and fall back to defaults for bad values. */
@@ -19,6 +19,16 @@ export declare class OverlayController {
19
19
  private minimizedHost;
20
20
  private stopping;
21
21
  constructor(helper: HelperLike, settings: () => OverlaySettings, log: (message: string) => void);
22
+ /** When the user last typed on the physical keyboard while the overlay was up (ms epoch). */
23
+ lastUserInput: number;
24
+ /** Did the user type after `since`? */
25
+ userTypedSince(since: number): boolean;
26
+ /**
27
+ * If the user is typing, pause until the keyboard has been quiet for
28
+ * `idleMs`. Throws after `maxMs` so the model can tell the user. Returns
29
+ * whether it had to wait.
30
+ */
31
+ waitForUserIdle(signal: AbortSignal, idleMs: number, maxMs?: number): Promise<boolean>;
22
32
  /** The agent currently driving the computer, if any. */
23
33
  get controller(): CancellableAgent | undefined;
24
34
  /** Called before every action: shows the overlay once and updates its status line. */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.1.1",
4
- "description": "DeepSeek Harness Computer Use 插件(Windows):像 Claude 一样看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek 正在使用你的电脑”,按 Esc 立即停止。",
3
+ "version": "0.1.2",
4
+ "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek 正在使用你的电脑”,按 Esc 立即停止。",
5
5
  "type": "module",
6
6
  "author": "copylee",
7
7
  "repository": {