@copylee/dsh-computer-use 0.16.0 → 0.17.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/helper/Program.cs CHANGED
@@ -173,6 +173,7 @@ namespace DshComputerUse
173
173
  case "displays": return Screen2.Displays();
174
174
  case "screenshot": return Screen2.Capture(r);
175
175
  case "settle": return Screen2.Settle(r);
176
+ case "frame_delta": return Screen2.FrameDelta(r);
176
177
  case "cursor": { Native.POINT p; Native.GetCursorPos(out p); return Pt(p.X, p.Y); }
177
178
  case "move":
178
179
  using (new PassThrough())
@@ -227,6 +228,7 @@ namespace DshComputerUse
227
228
  case "ocr": return Ocr.Read(r);
228
229
  case "marks": return Uia.Marks(r);
229
230
  case "password_focus": return Uia.PasswordFocus();
231
+ case "focused_value": return Uia.FocusedValue(Math.Max(64, Math.Min(20000, Args.Int(r, "maxChars", 4000))));
230
232
  case "ui_point_click": return Uia.ClickAtPoint(r);
231
233
  case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(r); return null;
232
234
  case "overlay_pause": Overlay.SetPaused(Args.Bool(r, "paused", false)); return null;
@@ -235,7 +237,9 @@ namespace DshComputerUse
235
237
  case "window_card": CardLayer.SetOpacity(Args.Int(r, "opacity", 100)); return Windows.Card(new IntPtr(Convert.ToInt64(r["hwnd"])), Args.Int(r, "x", 0), Args.Int(r, "y", 0), Args.Int(r, "width", 0), Args.Int(r, "height", 0));
236
238
  case "window_uncard": return Windows.Uncard(new IntPtr(Convert.ToInt64(r["hwnd"])));
237
239
  case "overlay_status": Overlay.Status(Args.Str(r, "status", "")); return null;
238
- case "pet_update": Overlay.PetUpdate(Args.Str(r, "thinking", ""), Args.Str(r, "reply", ""), Args.Strs(r, "steps")); return null;
240
+ case "pet_update": Overlay.PetUpdate(Args.Str(r, "thinking", ""), Args.Str(r, "reply", ""), Args.Strs(r, "steps"), Args.Int(r, "total", 0)); return null;
241
+ case "pet_debug": Overlay.BarDebug(Args.Bool(r, "menu", false), Args.Str(r, "hover", "")); return null;
242
+ case "click_fx": Overlay.MarkResult(Args.Int(r, "x", 0), Args.Int(r, "y", 0), Args.Str(r, "button", "left"), Args.Int(r, "count", 1), Args.Str(r, "label", "")); return null;
239
243
  case "pet_finish": Overlay.Finish(Args.Int(r, "holdMs", 4000)); return null;
240
244
  case "overlay_hide": Overlay.Hide(); return null;
241
245
  default: throw new Exception("unknown command: " + cmd);
package/helper/Uia.cs CHANGED
@@ -815,6 +815,44 @@ namespace DshComputerUse
815
815
  return d;
816
816
  }
817
817
 
818
+ /**
819
+ * The focused control's ValuePattern value (capped), so a `type` can be checked
820
+ * against what the field now holds. Never reads password fields.
821
+ */
822
+ public static object FocusedValue(int maxChars)
823
+ {
824
+ bool readable = false;
825
+ string value = "", role = "", name = "";
826
+ var worker = new Thread(delegate ()
827
+ {
828
+ try
829
+ {
830
+ var focused = AutomationElement.FocusedElement;
831
+ if (focused == null || IsPasswordElement(focused)) return;
832
+ role = focused.Current.ControlType.ProgrammaticName.Replace("ControlType.", "");
833
+ name = focused.Current.Name ?? "";
834
+ object pattern;
835
+ if (focused.TryGetCurrentPattern(ValuePattern.Pattern, out pattern))
836
+ {
837
+ string v = ((ValuePattern)pattern).Current.Value ?? "";
838
+ value = v.Length > maxChars ? v.Substring(v.Length - maxChars) : v;
839
+ readable = true;
840
+ }
841
+ }
842
+ catch (Exception) { }
843
+ });
844
+ worker.IsBackground = true;
845
+ worker.SetApartmentState(ApartmentState.MTA);
846
+ worker.Start();
847
+ worker.Join(800);
848
+ var d = new Dictionary<string, object>();
849
+ d["readable"] = readable;
850
+ d["value"] = readable ? value : "";
851
+ d["role"] = role;
852
+ d["name"] = name.Length > 60 ? name.Substring(0, 60) : name;
853
+ return d;
854
+ }
855
+
818
856
  /** Lightweight bounded lookup of the UIA control at physical point (x, y) for user-takeover feedback. */
819
857
  public static void DescribeAtPoint(int x, int y, out string role, out string name, out bool isPassword)
820
858
  {
package/lib/client.js CHANGED
@@ -72,7 +72,7 @@ window.__ModuleLoader__.load({
72
72
  overlay: true,
73
73
  overlayLabel: "DeepSeek Harness",
74
74
  hostWindow: "pet",
75
- petSize: "standard",
75
+ petSize: "bar",
76
76
  cardOpacity: 80,
77
77
  autoScreenshot: true,
78
78
  autoScreenshotDetail: "standard",
@@ -115,7 +115,7 @@ window.__ModuleLoader__.load({
115
115
  overlay: bool("overlay"),
116
116
  overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
117
117
  hostWindow: out.hostWindow === "pet" || out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
118
- petSize: out.petSize === "compact" || out.petSize === "standard" || out.petSize === "detailed" ? out.petSize : DEFAULTS.petSize,
118
+ petSize: out.petSize === "bar" || out.petSize === "compact" || out.petSize === "standard" || out.petSize === "detailed" ? out.petSize : DEFAULTS.petSize,
119
119
  cardOpacity: num("cardOpacity", 30, 100),
120
120
  autoScreenshot: bool("autoScreenshot"),
121
121
  autoScreenshotDetail: out.autoScreenshotDetail === "compact" || out.autoScreenshotDetail === "standard" ? out.autoScreenshotDetail : DEFAULTS.autoScreenshotDetail,
@@ -1888,13 +1888,17 @@ window.__ModuleLoader__.load({
1888
1888
  disabled: disabled || draft.hostWindow !== "pet",
1889
1889
  value: draft.petSize,
1890
1890
  options: [
1891
+ {
1892
+ value: "bar",
1893
+ label: "顶部胶囊(一行思考 + 最近两步,推荐)"
1894
+ },
1891
1895
  {
1892
1896
  value: "compact",
1893
1897
  label: "紧凑小卡片(最省视野 · 单行动作)"
1894
1898
  },
1895
1899
  {
1896
1900
  value: "standard",
1897
- label: "标准卡片(单行思考 + 操作进度,推荐)"
1901
+ label: "标准卡片(单行思考 + 操作进度)"
1898
1902
  },
1899
1903
  {
1900
1904
  value: "detailed",
@@ -1905,7 +1909,7 @@ window.__ModuleLoader__.load({
1905
1909
  }), h("span", { style: {
1906
1910
  ...S.hint,
1907
1911
  fontWeight: 400
1908
- } }, draft.petSize === "compact" ? "约 320px 宽,只展示当前动作与控制按钮;点展开可临时看详情。" : draft.petSize === "detailed" ? "约 484px 宽,默认展示双行思考与最近 3 步时间线(展开可达 8 步)。" : "约 420px 宽,平衡视野与信息量,展开可查看多行思考与 5 步时间线。")), h("div", { style: S.label }, "悬浮卡片透明度", h(Select, {
1912
+ } }, draft.petSize === "bar" ? "屏幕顶部居中的胶囊:思考时图标上出现 … 气泡;⋯ 菜单里有暂停、跳过等待、展开、输入新指令;橙色按钮停止控制。可拖动。" : draft.petSize === "compact" ? "约 320px 宽,只展示当前动作与控制按钮;点展开可临时看详情。" : draft.petSize === "detailed" ? "约 484px 宽,默认展示双行思考与最近 3 步时间线(展开可达 8 步)。" : "约 420px 宽,平衡视野与信息量,展开可查看多行思考与 5 步时间线。")), h("div", { style: S.label }, "悬浮卡片透明度", h(Select, {
1909
1913
  label: "悬浮卡片透明度",
1910
1914
  disabled: disabled || draft.hostWindow !== "card" && draft.hostWindow !== "pet",
1911
1915
  value: String(draft.cardOpacity),
package/lib/index.js CHANGED
@@ -1128,6 +1128,13 @@ const TOOL_NAMES = {
1128
1128
  web_fetch: "读取网页",
1129
1129
  todo_write: "更新待办"
1130
1130
  };
1131
+ /**
1132
+ * Reply text hands focus back to DeepSeek Harness only once it keeps streaming on its own:
1133
+ * this long after the first reply character with no reasoning or tool call in between, and
1134
+ * at least REPLY_HANDOFF_CHARS long. A sentence or two before the next tool call does not
1135
+ * flip the window back and forth. A reply this long hands over at once.
1136
+ */
1137
+ const REPLY_HANDOFF_MS = 2200;
1131
1138
  /** How long the "done" card stays up after a run (longer while the pointer rests on it). */
1132
1139
  const FINISH_HOLD_MS = 4e3;
1133
1140
  /**
@@ -1184,8 +1191,12 @@ var OverlayController = class {
1184
1191
  reply = "";
1185
1192
  /** Recent steps (tool actions), oldest first. */
1186
1193
  steps = [];
1194
+ /** Steps this run in all (the list keeps only the last few). */
1195
+ stepTotal = 0;
1187
1196
  resume;
1188
1197
  pushTimer;
1198
+ /** Pending hand-back to DSH while a reply streams (see REPLY_HANDOFF_MS). */
1199
+ replyTimer;
1189
1200
  /** An instruction the user typed into the progress card. */
1190
1201
  onMessage;
1191
1202
  /** Called when control starts (before the first action), e.g. to remember the window layout. */
@@ -1210,6 +1221,7 @@ var OverlayController = class {
1210
1221
  if (event.event === "stop") this.stopControl(event.reason ?? "user");
1211
1222
  else if (event.event === "skip_wait") this.skipActiveWaits();
1212
1223
  else if (event.event === "pause") this.paused = true;
1224
+ else if (event.event === "open_host") this.openHost();
1213
1225
  else if (event.event === "resume") this.paused = false;
1214
1226
  else if (event.event === "user_input") {
1215
1227
  this.lastUserInput = Date.now();
@@ -1353,6 +1365,7 @@ var OverlayController = class {
1353
1365
  await this.starting;
1354
1366
  if (agent && this.stoppedAgents.has(agent)) throw new Error(CONTROL_STOPPED_MESSAGE);
1355
1367
  if (agent) this.agent = agent;
1368
+ this.cancelReplyHandoff();
1356
1369
  if (!this.controlAbort || this.controlAbort.signal.aborted) this.controlAbort = new AbortController();
1357
1370
  this.reply = "";
1358
1371
  this.armIdle();
@@ -1403,6 +1416,7 @@ var OverlayController = class {
1403
1416
  if (settings.overlay || pet) {
1404
1417
  if (this.streamAgent !== agent) this.thinking = "";
1405
1418
  this.steps = status ? [status] : [];
1419
+ this.stepTotal = this.steps.length;
1406
1420
  await this.helper.call("overlay_show", {
1407
1421
  label: pet ? `${settings.overlayLabel || "DeepSeek Harness"} 正在操控` : `${settings.overlayLabel || "DeepSeek Harness"} 正在操控你的电脑`,
1408
1422
  status,
@@ -1432,6 +1446,7 @@ var OverlayController = class {
1432
1446
  const line = plainLine(text).trim();
1433
1447
  if (line === "" || this.steps.at(-1) === line) return;
1434
1448
  this.steps = [...this.steps, line].slice(-8);
1449
+ this.stepTotal++;
1435
1450
  this.schedulePush();
1436
1451
  }
1437
1452
  /** Live model output (DSH agent/assistant-stream) for the progress card. */
@@ -1444,6 +1459,7 @@ var OverlayController = class {
1444
1459
  this.steps = [];
1445
1460
  }
1446
1461
  if (frame.type === "start") {
1462
+ this.cancelReplyHandoff();
1447
1463
  this.thinking = "";
1448
1464
  this.reply = "";
1449
1465
  if (this.visible && agent === this.agent) this.helper.call("overlay_phase", { phase: "llm" }).catch(() => {});
@@ -1459,21 +1475,42 @@ var OverlayController = class {
1459
1475
  if (this.settings().hostWindow === "pet") {
1460
1476
  this.reply = plainLine(this.reply + chunk.text).slice(-300);
1461
1477
  this.schedulePush();
1462
- if (this.reply.length >= 260) this.end(this.agent, true).catch((error) => this.log(`reply handoff: ${String(error)}`));
1463
- return;
1464
1478
  }
1465
- if (chunk.text.trim()) this.end(this.agent, true).catch((error) => this.log(`reply handoff: ${String(error)}`));
1479
+ this.replyChars += chunk.text.length;
1480
+ if (this.replyChars >= 260) this.handOffReply();
1481
+ else if (!this.replyTimer && chunk.text.trim()) {
1482
+ this.replyTimer = setTimeout(() => {
1483
+ this.replyTimer = void 0;
1484
+ if (this.replyChars >= 40) this.handOffReply();
1485
+ else this.replyChars = 0;
1486
+ }, REPLY_HANDOFF_MS);
1487
+ this.replyTimer.unref?.();
1488
+ }
1466
1489
  }
1467
1490
  return;
1468
1491
  }
1492
+ this.cancelReplyHandoff();
1469
1493
  if (chunk.type !== "reasoning-delta" || !chunk.text) return;
1470
1494
  if (this.thinking === "" && this.visible && agent === this.agent) this.helper.call("overlay_phase", { phase: "" }).catch(() => {});
1471
1495
  this.reply = "";
1472
1496
  this.thinking = plainLine(this.thinking + chunk.text).slice(-300);
1473
1497
  this.schedulePush();
1474
1498
  }
1499
+ replyChars = 0;
1500
+ cancelReplyHandoff() {
1501
+ if (this.replyTimer) clearTimeout(this.replyTimer);
1502
+ this.replyTimer = void 0;
1503
+ this.replyChars = 0;
1504
+ }
1505
+ handOffReply() {
1506
+ this.cancelReplyHandoff();
1507
+ const agent = this.agent;
1508
+ if (!agent || !this.visible || this.paused || this.stopping) return;
1509
+ this.end(agent, true).catch((error) => this.log(`reply handoff: ${String(error)}`));
1510
+ }
1475
1511
  /** A tool of another plugin started (computer-use tools report their own steps). */
1476
1512
  toolStarted(agent, name, detail) {
1513
+ if (agent === this.agent) this.cancelReplyHandoff();
1477
1514
  if (agent !== this.streamAgent) return;
1478
1515
  if (this.visible && agent === this.agent) {
1479
1516
  this.armIdle();
@@ -1493,7 +1530,8 @@ var OverlayController = class {
1493
1530
  this.helper.call("pet_update", {
1494
1531
  thinking: this.thinking.trim(),
1495
1532
  ...this.reply.trim() ? { reply: this.reply.trim() } : {},
1496
- steps: this.steps
1533
+ steps: this.steps,
1534
+ total: this.stepTotal
1497
1535
  }).catch(() => {});
1498
1536
  }, 80);
1499
1537
  this.pushTimer.unref?.();
@@ -1507,6 +1545,7 @@ var OverlayController = class {
1507
1545
  if (this.unusedTimer) clearTimeout(this.unusedTimer);
1508
1546
  this.unusedTimer = void 0;
1509
1547
  this.otherTools = 0;
1548
+ this.cancelReplyHandoff();
1510
1549
  this.agent = void 0;
1511
1550
  this.paused = false;
1512
1551
  if (this.waitSkippers.size > 0) {
@@ -1701,6 +1740,19 @@ var OverlayController = class {
1701
1740
  this.log(`host window card: ${String(error)}`);
1702
1741
  }
1703
1742
  }
1743
+ /** The card's menu asked for DeepSeek Harness: bring it back as the see-through corner card. */
1744
+ async openHost() {
1745
+ if (!this.visible) return;
1746
+ try {
1747
+ for (const win of this.hostWindows.filter((win) => win.mode === "minimize")) await this.helper.call("window_cmd", {
1748
+ hwnd: win.hwnd,
1749
+ op: "restore"
1750
+ });
1751
+ await this.cardIfShown();
1752
+ } catch (error) {
1753
+ this.log(`open host: ${String(error)}`);
1754
+ }
1755
+ }
1704
1756
  async restoreHost() {
1705
1757
  const windows = this.hostWindows;
1706
1758
  this.hostWindows = [];
@@ -1768,6 +1820,14 @@ const MUTATING = /* @__PURE__ */ new Set([
1768
1820
  "mouse_move",
1769
1821
  "ui_action"
1770
1822
  ]);
1823
+ /** Whitespace-insensitive tail of typed text, as it should appear in the field afterwards. */
1824
+ function typedTextLanded(typed, fieldValue) {
1825
+ const norm = (v) => v.replace(/\s+/g, "");
1826
+ const want = norm(typed);
1827
+ if (want === "") return true;
1828
+ const tail = want.length > 24 ? want.slice(-24) : want;
1829
+ return norm(fieldValue).includes(tail);
1830
+ }
1771
1831
  /** Actions that wait for the user to stop typing before they run. */
1772
1832
  const INPUT = new Set([...MUTATING].filter((action) => action !== "mouse_move"));
1773
1833
  /** Actions whose input goes to the foreground window. */
@@ -1784,6 +1844,9 @@ const UNCHANGED_TEXT = "The screen looks exactly as in your previous screenshot:
1784
1844
  const TARGET_WAIT_MS = 3e3;
1785
1845
  /** Pause between looks while waiting for a control or a window. */
1786
1846
  const POLL_MS = 200;
1847
+ /** wait until: give up early once the screen and window text have been still this long. */
1848
+ const WAIT_STILL_MS = 6e3;
1849
+ const WAIT_STILL_WINDOW_MS = 15e3;
1787
1850
  /** Same-spot click warning window (2 minutes) and radius (±24 physical pixels). */
1788
1851
  const REPEAT_WINDOW_MS = 12e4;
1789
1852
  const REPEAT_RADIUS_PX = 24;
@@ -2659,6 +2722,18 @@ var Computer = class Computer {
2659
2722
  const textWindow = kind === "text" ? await this.foreground() : void 0;
2660
2723
  if (kind === "text" && !textWindow) throw new Error("No foreground window to observe for text.");
2661
2724
  const textTab = textWindow && isBrowser(textWindow) ? (await readBrowserTab(this.helper, textWindow))?.tab : void 0;
2725
+ const stillMs = kind === "window" ? WAIT_STILL_WINDOW_MS : WAIT_STILL_MS;
2726
+ const watchRect = await this.settleRect().catch(() => void 0);
2727
+ let lastMotion = started;
2728
+ let lastText;
2729
+ const noteMotion = async () => {
2730
+ if (!watchRect) return;
2731
+ const delta = await this.helper.call("frame_delta", {
2732
+ ...watchRect,
2733
+ key: "wait"
2734
+ }, 3e3).catch(() => void 0);
2735
+ if (!delta || typeof delta.changed !== "number" || delta.changed >= .002) lastMotion = Date.now();
2736
+ };
2662
2737
  const present = async () => {
2663
2738
  if (textWindow) {
2664
2739
  const limit = Math.max(100, Math.min(1500, timeout - (Date.now() - started)));
@@ -2670,6 +2745,8 @@ var Computer = class Computer {
2670
2745
  }, limit + 1500).catch(() => void 0);
2671
2746
  if (!result || result.hwnd !== textWindow.hwnd || result.pid !== textWindow.pid || result.source === "none") return void 0;
2672
2747
  if (textTab && (await readBrowserTab(this.helper, textWindow))?.tab !== textTab) return void 0;
2748
+ if (lastText !== void 0 && result.text !== lastText) lastMotion = Date.now();
2749
+ lastText = result.text;
2673
2750
  const found = result.text.toLowerCase().includes(needle);
2674
2751
  return !found && result.truncated && gone ? void 0 : found;
2675
2752
  }
@@ -2702,6 +2779,11 @@ var Computer = class Computer {
2702
2779
  await this.settle(signal);
2703
2780
  return text;
2704
2781
  }
2782
+ await noteMotion();
2783
+ if (found !== void 0 && Date.now() - lastMotion >= stillMs && !wait?.skipped()) {
2784
+ const what = `${kind === "window" ? "window" : kind === "text" ? "text" : "control"} "${subject}"`;
2785
+ return `Stopped waiting after ${((Date.now() - started) / 1e3).toFixed(1)}s: the screen has not changed for ${Math.round(stillMs / 1e3)}s and ${what} ${gone ? "is still there" : "has not appeared"}. The page has most likely finished — check the screenshot instead of waiting again; ${gone ? "this text may be a permanent part of the page (a button or label), so it never disappears." : "it may be worded differently or never appear."}`;
2786
+ }
2705
2787
  if (Date.now() - started >= timeout) {
2706
2788
  const near = !gone && kind === "target" && suggestions.length ? ` Controls there now: ${suggestions.map((name) => `"${name.slice(0, 40)}"`).join(", ")}.` : "";
2707
2789
  throw new Error(`Timed out after ${Math.round(timeout / 1e3)}s waiting for ${kind === "window" ? "window" : kind === "text" ? "text" : "control"} "${subject}" to ${gone ? "disappear" : "appear"}.${near}`);
@@ -2741,6 +2823,22 @@ var Computer = class Computer {
2741
2823
  }
2742
2824
  return `\nRecent user actions during takeover (screenshot coordinates):\n${lines.join("\n")}\nRespect what the user just did and adapt your plan accordingly (do not undo or overwrite their changes).`;
2743
2825
  }
2826
+ /** Compare the focused field with what was just typed (ValuePattern only; rich editors report 'sent'). */
2827
+ async readBackTyped(text) {
2828
+ const field = await this.helper.call("focused_value", { maxChars: Math.min(2e4, text.length + 4e3) }, 1500).catch(() => null);
2829
+ if (!field?.readable) return {
2830
+ verification: "sent",
2831
+ note: ""
2832
+ };
2833
+ if (typedTextLanded(text, field.value ?? "")) return {
2834
+ verification: "observed",
2835
+ note: " Verified: the focused field contains it."
2836
+ };
2837
+ return {
2838
+ verification: "unconfirmed",
2839
+ note: ` Unconfirmed: the focused ${`${field.role || "field"}${field.name ? ` "${field.name.slice(0, 40)}"` : ""}`} does not show the typed text (autocomplete, an input method or a different focus may have taken it). Check before continuing.`
2840
+ };
2841
+ }
2744
2842
  /** Run one action. Returns text plus an image for screenshot/zoom. */
2745
2843
  async run(input, call) {
2746
2844
  if (call.signal.aborted) throw new Error("Cancelled.");
@@ -2998,7 +3096,12 @@ var Computer = class Computer {
2998
3096
  await this.sendKeys(call, parseKeys("ctrl+a"));
2999
3097
  await setTimeout$1(50, void 0, { signal: call.signal });
3000
3098
  }
3001
- return { text: `${await this.enterText(text, call)}${input.replace === true ? " (replaced existing text)" : ""}${into}` };
3099
+ const entered = `${await this.enterText(text, call)}${input.replace === true ? " (replaced existing text)" : ""}${into}`;
3100
+ const check = await this.readBackTyped(text);
3101
+ return {
3102
+ text: `${entered}${check.note}`,
3103
+ verification: check.verification
3104
+ };
3002
3105
  }
3003
3106
  case "key": {
3004
3107
  const combos = parseKeys(input.text ?? "");
@@ -4123,7 +4226,7 @@ const DEFAULTS = {
4123
4226
  overlay: true,
4124
4227
  overlayLabel: "DeepSeek Harness",
4125
4228
  hostWindow: "pet",
4126
- petSize: "standard",
4229
+ petSize: "bar",
4127
4230
  cardOpacity: 80,
4128
4231
  autoScreenshot: true,
4129
4232
  autoScreenshotDetail: "standard",
@@ -4166,7 +4269,7 @@ function resolveConfig(raw) {
4166
4269
  overlay: bool("overlay"),
4167
4270
  overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
4168
4271
  hostWindow: out.hostWindow === "pet" || out.hostWindow === "card" || out.hostWindow === "minimize" || out.hostWindow === "keep" ? out.hostWindow : out.minimizeHostWindow === true ? "minimize" : DEFAULTS.hostWindow,
4169
- petSize: out.petSize === "compact" || out.petSize === "standard" || out.petSize === "detailed" ? out.petSize : DEFAULTS.petSize,
4272
+ petSize: out.petSize === "bar" || out.petSize === "compact" || out.petSize === "standard" || out.petSize === "detailed" ? out.petSize : DEFAULTS.petSize,
4170
4273
  cardOpacity: num("cardOpacity", 30, 100),
4171
4274
  autoScreenshot: bool("autoScreenshot"),
4172
4275
  autoScreenshotDetail: out.autoScreenshotDetail === "compact" || out.autoScreenshotDetail === "standard" ? out.autoScreenshotDetail : DEFAULTS.autoScreenshotDetail,
@@ -11105,6 +11208,34 @@ function toJson(ref) {
11105
11208
  } }
11106
11209
  };
11107
11210
  }
11211
+ /** A mouse action aimed by coordinate (not by target): only valid on the screen the model last saw. */
11212
+ function usesScreenCoordinates(input) {
11213
+ if (input.target !== void 0 && input.target !== "") return false;
11214
+ return (input.action === "left_click" || input.action === "right_click" || input.action === "middle_click" || input.action === "double_click" || input.action === "triple_click" || input.action === "mouse_move" || input.action === "left_click_drag" || input.action === "scroll" || input.action === "left_mouse_down") && Array.isArray(input.coordinate);
11215
+ }
11216
+ /** How the foreground changed in a way that invalidates planned coordinates, or undefined. */
11217
+ function screenChange(before, after) {
11218
+ if (!before || !after) return void 0;
11219
+ if (after.hwnd !== before.hwnd) return `the foreground switched to ${after.exe} ("${after.title.slice(0, 50)}") — a new window or dialog`;
11220
+ if (isBrowser(after) && after.title !== before.title) return `${after.exe} navigated to "${after.title.slice(0, 50)}"`;
11221
+ }
11222
+ /** Observation budget for element lists: every row stays short, and the list stops at a size the model can afford. */
11223
+ const OBSERVATION_MAX_CHARS = 12e3;
11224
+ const OBSERVATION_MAX_LINE = 300;
11225
+ function capObservation(text, maxChars = OBSERVATION_MAX_CHARS, maxLine = OBSERVATION_MAX_LINE) {
11226
+ const lines = text.split("\n").map((line) => line.length > maxLine ? `${line.slice(0, maxLine - 1)}…` : line);
11227
+ const out = [];
11228
+ let used = 0;
11229
+ for (const [index, line] of lines.entries()) {
11230
+ if (index > 0 && used + line.length + 1 > maxChars) {
11231
+ out.push(`… ${lines.length - index} more lines omitted (output capped at ${Math.round(maxChars / 1e3)}k characters). Narrow it with query, role, hwnd or max.`);
11232
+ break;
11233
+ }
11234
+ out.push(line);
11235
+ used += line.length + 1;
11236
+ }
11237
+ return out.join("\n");
11238
+ }
11108
11239
  async function withShot(host, text, shot, call) {
11109
11240
  if (shot === void 0) return { text };
11110
11241
  if (shot === "unchanged") return { text: `${text}
@@ -11227,7 +11358,7 @@ const actionProperties = {
11227
11358
  },
11228
11359
  gone: {
11229
11360
  type: "boolean",
11230
- description: "wait until: wait for it to disappear instead."
11361
+ description: "wait until: wait for it to disappear instead (never a label that is always on the page). Ends early once the screen is still for 6s."
11231
11362
  },
11232
11363
  region: {
11233
11364
  type: "array",
@@ -11310,7 +11441,7 @@ function createTools(host) {
11310
11441
  }));
11311
11442
  tools.push(defineTool({
11312
11443
  name: "computer_batch",
11313
- description: "Run several computer actions in order in one call (or replay a saved macro by name), then get one screenshot (taken once the screen settles, so do not end with a wait). Stops at the first failing action and shows you the screen. The screen is not shown to you between actions, so for steps whose target only appears along the way (a menu item, a dialog button) use target instead of coordinate, and wait with until for a window or control to appear. Example: [key \"ctrl+s\", wait until \"window:另存为\", type target \"文件名\" text \"C:\\a.txt\", left_click target \"保存\"].",
11444
+ description: "Run several computer actions in order in one call (or replay a saved macro by name), then get one screenshot (taken once the screen settles, so do not end with a wait). Stops at the first failing action, or before a coordinate action once another window or dialog takes the foreground or the browser navigates, and shows you the screen. The screen is not shown to you between actions, so for steps whose target only appears along the way (a menu item, a dialog button) use target instead of coordinate, and wait with until for a window or control to appear. Example: [key \"ctrl+s\", wait until \"window:另存为\", type target \"文件名\" text \"C:\\a.txt\", left_click target \"保存\"].",
11314
11445
  parameters: {
11315
11446
  actions: {
11316
11447
  type: "array",
@@ -11374,11 +11505,19 @@ function createTools(host) {
11374
11505
  let endedWithZoom = false;
11375
11506
  const lines = [];
11376
11507
  let failure;
11508
+ const startWindow = await computer.foreground().catch(() => void 0);
11377
11509
  for (const [index, input] of actions.entries()) {
11378
11510
  if (input.action === "screenshot" || input.action === "zoom" && index !== actions.length - 1) {
11379
11511
  failure = `#${index + 1} ${input.action}: ${input.action === "zoom" ? "only allowed as the last action of a batch" : "not allowed in a batch"}.`;
11380
11512
  break;
11381
11513
  }
11514
+ if (index > 0 && usesScreenCoordinates(input)) {
11515
+ const change = screenChange(startWindow, await computer.foreground().catch(() => void 0));
11516
+ if (change) {
11517
+ failure = `#${index + 1} ${input.action} not run: ${change} since the batch started, so its coordinates may point at the wrong thing.`;
11518
+ break;
11519
+ }
11520
+ }
11382
11521
  try {
11383
11522
  const stepStart = Date.now();
11384
11523
  if (input.action === "zoom" && index > 0) await computer.settle(call.signal);
@@ -11393,6 +11532,10 @@ function createTools(host) {
11393
11532
  break;
11394
11533
  }
11395
11534
  lines.push(`#${index + 1} ${outcome.text}`);
11535
+ if (outcome.verification === "unconfirmed" && index < actions.length - 1) {
11536
+ failure = `#${index + 1} ${input.action} could not be confirmed; later actions depend on it.`;
11537
+ break;
11538
+ }
11396
11539
  await setTimeout$1(60, void 0, { signal: call.signal });
11397
11540
  if (computer.settings().pauseOnUserInput && (computer.overlay.userTypedSince(stepStart - 1) || computer.overlay.hasUserActions?.())) {
11398
11541
  const notes = await computer.drainUserActionNotes();
@@ -11864,6 +12007,9 @@ function createTools(host) {
11864
12007
  for (const [index, el] of result.elements.entries()) lines.push(await formatEl(`[${index}]`, el));
11865
12008
  const head = `${result.exe} — "${String(result.title ?? "").slice(0, 80)}": ${result.elements.length} elements${diff === true ? " (baseline captured; next diff: true returns changes only)" : ""}.`;
11866
12009
  return { text: lines.length ? `${head}\n${lines.join("\n")}` : `${head} This window exposes no UI Automation elements; use ui_elements with ocr: true or screenshots.` };
12010
+ }).then((value) => text === true ? value : {
12011
+ ...value,
12012
+ text: capObservation(value.text)
11867
12013
  });
11868
12014
  },
11869
12015
  presentCall: (args) => {
@@ -12187,19 +12333,23 @@ const Config = z.object({
12187
12333
  "en-US": { $description: "What to do with the DeepSeek Harness window while controlling (restored afterwards)" }
12188
12334
  }),
12189
12335
  petSize: z.union([
12336
+ z.const("bar").i18n({
12337
+ "zh-CN": { $description: "顶部胶囊(图标 + 一行滚动思考 + 最近两步,推荐)" },
12338
+ "en-US": { $description: "Top bar (icon, one scrolling line of reasoning, the last two steps; recommended)" }
12339
+ }),
12190
12340
  z.const("compact").i18n({
12191
12341
  "zh-CN": { $description: "紧凑小卡片(最省视野,单行当前操作)" },
12192
12342
  "en-US": { $description: "Compact (minimal footprint, current action line only)" }
12193
12343
  }),
12194
12344
  z.const("standard").i18n({
12195
- "zh-CN": { $description: "标准卡片(单行思考 + 操作进度,推荐)" },
12196
- "en-US": { $description: "Standard (one-line thinking + action breadcrumb, recommended)" }
12345
+ "zh-CN": { $description: "标准卡片(单行思考 + 操作进度)" },
12346
+ "en-US": { $description: "Standard card (one-line thinking + action breadcrumb)" }
12197
12347
  }),
12198
12348
  z.const("detailed").i18n({
12199
12349
  "zh-CN": { $description: "详情大卡片(双行思考 + 最近 3 步时间线)" },
12200
12350
  "en-US": { $description: "Detailed (two-line thinking + recent 3-step timeline)" }
12201
12351
  })
12202
- ]).default("standard").volatile().i18n({
12352
+ ]).default("bar").volatile().i18n({
12203
12353
  "zh-CN": { $description: "迷你进度卡片尺寸与默认展示的信息量" },
12204
12354
  "en-US": { $description: "Size and default information density of the mini progress card" }
12205
12355
  }),
@@ -130,7 +130,12 @@ export interface ActionOutcome {
130
130
  skipped?: boolean;
131
131
  /** True when a deterministic UIA Control Pattern read back and verified the desired post-state. */
132
132
  verified?: boolean;
133
+ /** For input actions: 'observed' = read back from the control, 'unconfirmed' = read back and it does not match, 'sent' = input sent, nothing to read back. */
134
+ verification?: Verification;
133
135
  }
136
+ export type Verification = 'observed' | 'unconfirmed' | 'sent';
137
+ /** Whitespace-insensitive tail of typed text, as it should appear in the field afterwards. */
138
+ export declare function typedTextLanded(typed: string, fieldValue: string): boolean;
134
139
  export interface ClickResult {
135
140
  x?: number;
136
141
  y?: number;
@@ -159,6 +164,9 @@ export interface OcrResult extends Partial<WindowInfo> {
159
164
  }
160
165
  /** Text returned instead of an identical screenshot. */
161
166
  export declare const UNCHANGED_TEXT = "The screen looks exactly as in your previous screenshot: the action had no visible effect.";
167
+ /** wait until: give up early once the screen and window text have been still this long. */
168
+ export declare const WAIT_STILL_MS = 6000;
169
+ export declare const WAIT_STILL_WINDOW_MS = 15000;
162
170
  /** Longest adaptive wait for the screen to settle after an action. */
163
171
  export declare const MAX_SETTLE_MS = 2500;
164
172
  export declare class Computer {
@@ -348,6 +356,8 @@ export declare class Computer {
348
356
  drainUserActionNotes(): Promise<string>;
349
357
  /** Format physical user takeover actions into concise screenshot-coordinate context for the model. */
350
358
  private formatUserActions;
359
+ /** Compare the focused field with what was just typed (ValuePattern only; rich editors report 'sent'). */
360
+ private readBackTyped;
351
361
  /** Run one action. Returns text plus an image for screenshot/zoom. */
352
362
  run(input: ActionInput, call: CallContext): Promise<ActionOutcome>;
353
363
  /**
@@ -5,7 +5,7 @@ export interface CancellableAgent {
5
5
  }): void;
6
6
  }
7
7
  export type HostWindowMode = 'pet' | 'card' | 'minimize' | 'keep';
8
- export type PetCardSize = 'compact' | 'standard' | 'detailed';
8
+ export type PetCardSize = 'bar' | 'compact' | 'standard' | 'detailed';
9
9
  /** Sanitized semantic summary of a physical user takeover action during computer control. */
10
10
  export interface UserActionEvent {
11
11
  at: number;
@@ -32,6 +32,15 @@ export interface StreamFrame {
32
32
  }
33
33
  /** Markdown reduced to one plain line for the progress card. */
34
34
  export declare function plainLine(text: string): string;
35
+ /**
36
+ * Reply text hands focus back to DeepSeek Harness only once it keeps streaming on its own:
37
+ * this long after the first reply character with no reasoning or tool call in between, and
38
+ * at least REPLY_HANDOFF_CHARS long. A sentence or two before the next tool call does not
39
+ * flip the window back and forth. A reply this long hands over at once.
40
+ */
41
+ export declare const REPLY_HANDOFF_MS = 2200;
42
+ export declare const REPLY_HANDOFF_CHARS = 40;
43
+ export declare const REPLY_HANDOFF_LONG = 260;
35
44
  export interface OverlaySettings {
36
45
  harnessUrl?: string | undefined;
37
46
  overlay: boolean;
@@ -107,8 +116,12 @@ export declare class OverlayController {
107
116
  private reply;
108
117
  /** Recent steps (tool actions), oldest first. */
109
118
  private steps;
119
+ /** Steps this run in all (the list keeps only the last few). */
120
+ private stepTotal;
110
121
  private resume;
111
122
  private pushTimer;
123
+ /** Pending hand-back to DSH while a reply streams (see REPLY_HANDOFF_MS). */
124
+ private replyTimer;
112
125
  /** An instruction the user typed into the progress card. */
113
126
  onMessage: ((agent: CancellableAgent, text: string) => void) | undefined;
114
127
  /** Called when control starts (before the first action), e.g. to remember the window layout. */
@@ -159,6 +172,9 @@ export declare class OverlayController {
159
172
  private step;
160
173
  /** Live model output (DSH agent/assistant-stream) for the progress card. */
161
174
  stream(agent: unknown, frame: StreamFrame): void;
175
+ private replyChars;
176
+ private cancelReplyHandoff;
177
+ private handOffReply;
162
178
  /** A tool of another plugin started (computer-use tools report their own steps). */
163
179
  toolStarted(agent: unknown, name: string, detail: string): void;
164
180
  private schedulePush;
@@ -195,6 +211,8 @@ export declare class OverlayController {
195
211
  * screen (the agent neither sees nor clicks it).
196
212
  */
197
213
  private cardIfShown;
214
+ /** The card's menu asked for DeepSeek Harness: bring it back as the see-through corner card. */
215
+ private openHost;
198
216
  private restoreHost;
199
217
  }
200
218
  export {};
@@ -2,7 +2,7 @@ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
2
2
  import { defineTool } from '@deepseek-ai/dsh-tools';
3
3
  import { type MacroStore } from './macros.js';
4
4
  import { type SkillStore } from './skills.js';
5
- import { Computer, type CallContext, type Shot } from './computer.js';
5
+ import { Computer, type ActionInput, type CallContext, type Shot, type WindowInfo } from './computer.js';
6
6
  type ToolDefinition = ReturnType<typeof defineTool>;
7
7
  export interface ToolHost {
8
8
  computer: Computer;
@@ -17,5 +17,12 @@ export interface ToolHost {
17
17
  /** True when the sibling `@copylee/dsh-office` COM plugin is active in DSH. */
18
18
  hasOfficePlugin?: () => boolean;
19
19
  }
20
+ /** A mouse action aimed by coordinate (not by target): only valid on the screen the model last saw. */
21
+ export declare function usesScreenCoordinates(input: ActionInput): boolean;
22
+ /** How the foreground changed in a way that invalidates planned coordinates, or undefined. */
23
+ export declare function screenChange(before: WindowInfo | undefined, after: WindowInfo | undefined): string | undefined;
24
+ /** Observation budget for element lists: every row stays short, and the list stops at a size the model can afford. */
25
+ export declare const OBSERVATION_MAX_CHARS = 12000;
26
+ export declare function capObservation(text: string, maxChars?: number, maxLine?: number): string;
20
27
  export declare function createTools(host: ToolHost): ToolDefinition[];
21
28
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "icon": "assets/icon.svg",
6
6
  "type": "module",