@copylee/dsh-computer-use 0.8.1 → 0.8.3

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
@@ -192,6 +192,69 @@ var AccessControl = class {
192
192
  }
193
193
  };
194
194
  //#endregion
195
+ //#region lib/types/browser-host.js
196
+ function isBrowser(win) {
197
+ return /^(?:chrome|msedge|firefox|brave|vivaldi|chromium)\.exe$/i.test(win.exe);
198
+ }
199
+ function httpOrigin(value) {
200
+ try {
201
+ const url = new URL(value);
202
+ if (url.protocol === "http:" || url.protocol === "https:") return url.origin;
203
+ } catch {}
204
+ }
205
+ function isHarnessAddress(address, harnessUrl) {
206
+ const expected = httpOrigin(harnessUrl);
207
+ if (!address || !expected) return false;
208
+ const actual = httpOrigin(address.includes("://") ? address : new URL(expected).protocol + "//" + address);
209
+ if (!actual) return false;
210
+ if (actual === expected) return true;
211
+ const loopback = /* @__PURE__ */ new Set([
212
+ "localhost",
213
+ "127.0.0.1",
214
+ "[::1]"
215
+ ]);
216
+ const a = new URL(actual), b = new URL(expected);
217
+ return loopback.has(a.hostname) && loopback.has(b.hostname) && a.protocol === b.protocol && a.port === b.port;
218
+ }
219
+ async function readBrowserTab(helper, win, details = false) {
220
+ return await helper.call("browser_tab", {
221
+ hwnd: win.hwnd,
222
+ pid: win.pid,
223
+ ...details ? { details } : {}
224
+ }, 2500).catch(() => null) ?? void 0;
225
+ }
226
+ function safeSharedBrowserKeys(combos) {
227
+ return combos.every((combo) => {
228
+ const key = combo.at(-1);
229
+ if (key === void 0) return false;
230
+ const modifiers = combo.slice(0, -1);
231
+ if (modifiers.includes(17)) return modifiers.length === 1 && [
232
+ 65,
233
+ 67,
234
+ 86,
235
+ 88,
236
+ 89,
237
+ 90
238
+ ].includes(key);
239
+ return modifiers.every((mod) => mod === 16) && ([
240
+ 8,
241
+ 9,
242
+ 13,
243
+ 27,
244
+ 32,
245
+ 33,
246
+ 34,
247
+ 35,
248
+ 36,
249
+ 37,
250
+ 38,
251
+ 39,
252
+ 40,
253
+ 46
254
+ ].includes(key) || key >= 48 && key <= 90);
255
+ });
256
+ }
257
+ //#endregion
195
258
  //#region lib/types/coords.js
196
259
  /**
197
260
  * The model only ever sees one coordinate space: pixels of the most recent
@@ -493,9 +556,19 @@ const ROLES = {
493
556
  文本: ["Text"],
494
557
  文字: ["Text"]
495
558
  };
496
- /** "按钮:保存" → Button named 保存; a colon that is not after a known role stays part of the name. */
559
+ /** "按钮:保存" → Button named 保存; a colon that is not after a known role stays part of the name.
560
+ * "id:NavTasksButton" / "#NavTasksButton" → match the UIA AutomationId instead of the name. */
497
561
  function parseTarget(target) {
498
562
  const text = target.trim();
563
+ if (text.startsWith("#") && text.length > 1) return {
564
+ automationId: text.slice(1).trim(),
565
+ name: text
566
+ };
567
+ const byId = /^(?:id|automationid|自动化id)\s*[::]\s*(.+)$/i.exec(text);
568
+ if (byId) return {
569
+ automationId: byId[1].trim(),
570
+ name: text
571
+ };
499
572
  const colon = text.search(/[::]/);
500
573
  if (colon > 0) {
501
574
  const roles = ROLES[text.slice(0, colon).trim().toLowerCase().replace(/[\s_-]/g, "")];
@@ -524,6 +597,19 @@ const center = (el) => `${Math.round(el.x + el.width / 2)},${Math.round(el.y + e
524
597
  */
525
598
  function matchTarget(elements, target) {
526
599
  const query = parseTarget(target);
600
+ if (query.automationId) {
601
+ const wantedId = query.automationId;
602
+ const exact = elements.filter((el) => (el.automationId ?? "") === wantedId);
603
+ const matches = exact.length > 0 ? exact : elements.filter((el) => (el.automationId ?? "").toLowerCase() === wantedId.toLowerCase());
604
+ if (matches.length === 1) return {
605
+ kind: "found",
606
+ element: matches[0]
607
+ };
608
+ if (matches.length > 1) return {
609
+ kind: "ambiguous",
610
+ candidates: matches.slice(0, 8)
611
+ };
612
+ }
527
613
  const wanted = normalizeName(query.name);
528
614
  if (wanted === "") return {
529
615
  kind: "missing",
@@ -916,17 +1002,53 @@ var Computer = class Computer {
916
1002
  if (!win) return "Foreground window: none (desktop).";
917
1003
  return `Foreground window: ${win.exe} — "${win.title.slice(0, 80)}".`;
918
1004
  }
919
- assertAllowed(call, win, verb) {
1005
+ async assertAllowed(call, win, verb) {
920
1006
  const s = this.settings();
921
1007
  const reason = this.access.denial(call.session, win, s.accessMode, s.blockedApps, verb);
922
1008
  if (reason) throw new Error(reason);
1009
+ if (win && s.harnessUrl && isBrowser(win)) {
1010
+ const shared = this.overlay.isRememberedWebWindow(win);
1011
+ const tab = await readBrowserTab(this.helper, win, shared);
1012
+ if (isHarnessAddress(tab?.url, s.harnessUrl) || shared && (!tab?.tab || !this.overlay.isWorkTab(tab.tab))) throw new Error("The DeepSeek Harness Web tab is protected. Use open_application with the target URL to open a work tab in the current browser.");
1013
+ if (typeof tab?.url !== "string" || !tab.tab) throw new Error("Could not verify the active browser tab. Use open_application with the target URL or switch to a browser window with a visible address bar.");
1014
+ if (shared) return tab;
1015
+ }
1016
+ }
1017
+ checkWebContent(tab, point) {
1018
+ if (tab && (!tab.content || !contains$1(tab.content, point))) throw new Error("Only the work tab’s page content can be operated in the window containing DeepSeek Harness.");
923
1019
  }
924
1020
  async checkPointer(call, point, verb) {
925
1021
  const target = point ?? await this.cursor();
926
- this.assertAllowed(call, await this.windowAt(target), verb);
1022
+ this.checkWebContent(await this.assertAllowed(call, await this.windowAt(target), verb), target);
927
1023
  }
928
1024
  async checkKeyboard(call, verb) {
929
- this.assertAllowed(call, await this.foreground(), verb);
1025
+ const window = await this.foreground();
1026
+ const tab = await this.assertAllowed(call, window, verb);
1027
+ if (tab && !tab.contentFocused) throw new Error("Focus a control in the work tab’s page before sending keyboard input.");
1028
+ return window;
1029
+ }
1030
+ async sendKeys(call, combos, holdMs) {
1031
+ const window = await this.checkKeyboard(call, "send keys to");
1032
+ if (window && this.overlay.isRememberedWebWindow(window) && (holdMs !== void 0 || !safeSharedBrowserKeys(combos))) throw new Error("Browser and window shortcuts are protected in the window containing DeepSeek Harness.");
1033
+ const args = holdMs === void 0 ? {} : { holdMs };
1034
+ if (!this.settings().harnessUrl || !window || !isBrowser(window) || combos.length < 2) {
1035
+ await this.helper.call("keys", {
1036
+ combos,
1037
+ ...args
1038
+ }, holdMs === void 0 ? void 0 : 2e4);
1039
+ return;
1040
+ }
1041
+ for (const [index, combo] of combos.entries()) {
1042
+ if (index > 0) {
1043
+ await setTimeout$1(100, void 0, { signal: call.signal });
1044
+ await this.checkNamed(call, window);
1045
+ if (this.overlay.isRememberedWebWindow(window)) await this.checkKeyboard(call, "send keys to");
1046
+ }
1047
+ await this.helper.call("keys", {
1048
+ combos: [combo],
1049
+ ...args
1050
+ }, holdMs === void 0 ? void 0 : 2e4);
1051
+ }
930
1052
  }
931
1053
  /** Overlay status line for an action (Chinese, shown to the user). */
932
1054
  static statusOf(input) {
@@ -957,8 +1079,9 @@ var Computer = class Computer {
957
1079
  * own). They are read separately because scanning both costs a second or
958
1080
  * more on a file dialog, and the control is nearly always in the window.
959
1081
  */
960
- async elements(where = "window") {
1082
+ async elements(where = "window", hwnd) {
961
1083
  const result = await this.helper.call("ui", {
1084
+ ...hwnd === void 0 ? {} : { hwnd },
962
1085
  includeText: true,
963
1086
  maxNodes: 400,
964
1087
  ...where === "popups" ? { popupsOnly: true } : {}
@@ -966,11 +1089,11 @@ var Computer = class Computer {
966
1089
  return Array.isArray(result.elements) ? result.elements : [];
967
1090
  }
968
1091
  /** Look for a named control in the window, and only if it is not there in its popups. */
969
- async find(target) {
970
- const inWindow = await this.elements("window").catch(() => []);
1092
+ async find(target, hwnd) {
1093
+ const inWindow = await this.elements("window", hwnd).catch(() => []);
971
1094
  const match = matchTarget(inWindow, target);
972
1095
  if (match.kind !== "missing") return match;
973
- const inPopups = await this.elements("popups").catch(() => []);
1096
+ const inPopups = await this.elements("popups", hwnd).catch(() => []);
974
1097
  if (inPopups.length === 0) return match;
975
1098
  const second = matchTarget(inPopups, target);
976
1099
  return second.kind === "missing" ? matchTarget([...inWindow, ...inPopups], target) : second;
@@ -984,7 +1107,9 @@ var Computer = class Computer {
984
1107
  const started = Date.now();
985
1108
  for (;;) {
986
1109
  if (signal.aborted) throw new Error("Cancelled.");
987
- const match = await this.find(target);
1110
+ const window = await this.foreground();
1111
+ if (!window) throw new Error("No foreground window for the named target.");
1112
+ const match = await this.find(target, window.hwnd);
988
1113
  if (match.kind === "found") {
989
1114
  const el = match.element;
990
1115
  return {
@@ -992,7 +1117,8 @@ var Computer = class Computer {
992
1117
  x: Math.round(el.x + el.width / 2),
993
1118
  y: Math.round(el.y + el.height / 2)
994
1119
  },
995
- element: el
1120
+ element: el,
1121
+ window
996
1122
  };
997
1123
  }
998
1124
  if (match.kind === "ambiguous") {
@@ -1015,9 +1141,11 @@ var Computer = class Computer {
1015
1141
  /** The point an action aims at: a named control, a coordinate, or nothing (the cursor). */
1016
1142
  async aim(input, call) {
1017
1143
  if (typeof input.target === "string" && input.target.trim() !== "") {
1018
- const { point, element } = await this.locate(input.target, call.signal);
1144
+ const named = await this.locate(input.target, call.signal);
1145
+ const { point, element } = named;
1019
1146
  return {
1020
1147
  point,
1148
+ named,
1021
1149
  label: ` on ${element.role} "${element.name.slice(0, 60)}"`
1022
1150
  };
1023
1151
  }
@@ -1030,20 +1158,75 @@ var Computer = class Computer {
1030
1158
  label: " at the cursor"
1031
1159
  };
1032
1160
  }
1161
+ async checkNamed(call, win) {
1162
+ const current = await this.foreground();
1163
+ if (current?.hwnd !== win.hwnd || current.pid !== win.pid) throw new Error("The named target window changed. Look again before acting.");
1164
+ return this.assertAllowed(call, current, "act on");
1165
+ }
1166
+ async checkNamedPoint(call, point, window, element) {
1167
+ this.checkWebContent(await this.checkNamed(call, window), point);
1168
+ const hit = await this.windowAt(point);
1169
+ if (!hit || hit.pid !== window.pid || hit.hwnd !== (element.windowHwnd ?? window.hwnd)) throw new Error("Another window covers the named target. Look again before acting.");
1170
+ if (hit.hwnd !== window.hwnd && !isBrowser(window)) await this.assertAllowed(call, hit, "click");
1171
+ return hit;
1172
+ }
1173
+ async semanticAction(call, named, action) {
1174
+ const { window, element, point } = named;
1175
+ const hit = await this.checkNamedPoint(call, point, window, element);
1176
+ if (!element.runtimeId || hit.hwnd !== window.hwnd) return false;
1177
+ if (call.signal.aborted) throw new Error("Cancelled.");
1178
+ const result = await this.helper.call("act", {
1179
+ hwnd: window.hwnd,
1180
+ pid: window.pid,
1181
+ ...point,
1182
+ runtimeId: element.runtimeId,
1183
+ action
1184
+ }, 4e3);
1185
+ if (result?.performed === true) return true;
1186
+ if (result?.performed !== false) throw new Error("UI Automation did not confirm whether the action ran. Look again before retrying.");
1187
+ return false;
1188
+ }
1189
+ async namedClickPoint(call, target, named) {
1190
+ if (!named.element.runtimeId) {
1191
+ await this.checkNamedPoint(call, named.point, named.window, named.element);
1192
+ return named.point;
1193
+ }
1194
+ const live = await this.locate(target, call.signal, 0);
1195
+ if (live.window.hwnd !== named.window.hwnd || live.window.pid !== named.window.pid || live.element.runtimeId !== named.element.runtimeId || live.element.windowHwnd !== named.element.windowHwnd) throw new Error("The named control changed. Look again before acting.");
1196
+ await this.checkNamedPoint(call, live.point, live.window, live.element);
1197
+ return live.point;
1198
+ }
1033
1199
  /** wait with `until`: done as soon as the window or control is there (or gone). */
1034
1200
  async waitUntil(input, signal) {
1035
1201
  const until = (input.until ?? "").trim();
1036
1202
  const split = until.search(/[::]/);
1037
1203
  const prefix = split > 0 ? until.slice(0, split).trim().toLowerCase() : "";
1038
- const kind = prefix === "window" ? "window" : "target";
1039
- const subject = (prefix === "window" || prefix === "target" ? until.slice(split + 1) : until).trim();
1040
- if (subject === "") throw new Error("wait until needs \"window:<title or exe>\" or \"target:<control name>\".");
1204
+ const kind = prefix === "window" || prefix === "text" ? prefix : "target";
1205
+ const subject = (prefix === "window" || prefix === "target" || prefix === "text" ? until.slice(split + 1) : until).trim();
1206
+ if (subject === "") throw new Error("wait until needs \"window:<title or exe>\", \"target:<control name>\", or \"text:<window text>\".");
1041
1207
  const gone = input.gone === true;
1042
1208
  const timeout = Math.min(60, Math.max(.2, Number(input.duration ?? 10) || 10)) * 1e3;
1043
1209
  const needle = subject.toLowerCase();
1044
1210
  let suggestions = [];
1045
1211
  let firstSeen;
1212
+ const started = Date.now();
1213
+ const textWindow = kind === "text" ? await this.foreground() : void 0;
1214
+ if (kind === "text" && !textWindow) throw new Error("No foreground window to observe for text.");
1215
+ const textTab = textWindow && isBrowser(textWindow) ? (await readBrowserTab(this.helper, textWindow))?.tab : void 0;
1046
1216
  const present = async () => {
1217
+ if (textWindow) {
1218
+ const limit = Math.max(100, Math.min(1500, timeout - (Date.now() - started)));
1219
+ if (textTab && (await readBrowserTab(this.helper, textWindow))?.tab !== textTab) return void 0;
1220
+ const result = await this.helper.call("text", {
1221
+ hwnd: textWindow.hwnd,
1222
+ timeoutMs: limit,
1223
+ tail: 2e4
1224
+ }, limit + 1500).catch(() => void 0);
1225
+ if (!result || result.hwnd !== textWindow.hwnd || result.pid !== textWindow.pid || result.source === "none") return void 0;
1226
+ if (textTab && (await readBrowserTab(this.helper, textWindow))?.tab !== textTab) return void 0;
1227
+ const found = result.text.toLowerCase().includes(needle);
1228
+ return !found && result.truncated && gone ? void 0 : found;
1229
+ }
1047
1230
  if (kind === "window") {
1048
1231
  const matches = (win) => win.title.toLowerCase().includes(needle) || win.exe.toLowerCase().includes(needle) || appMatches(subject, win);
1049
1232
  const fg = await this.foreground().catch(() => void 0);
@@ -1060,17 +1243,17 @@ var Computer = class Computer {
1060
1243
  if (match.kind === "missing") suggestions = match.suggestions;
1061
1244
  return match.kind !== "missing";
1062
1245
  };
1063
- const started = Date.now();
1064
1246
  for (;;) {
1065
1247
  if (signal.aborted) throw new Error("Cancelled.");
1066
- if (await present() !== gone) {
1067
- const text = `${kind === "window" ? "Window" : "Control"} "${subject}" ${gone ? "is gone" : "is there"} after ${((Date.now() - started) / 1e3).toFixed(1)}s.`;
1248
+ const found = await present();
1249
+ if (found !== void 0 && found !== gone) {
1250
+ const text = `${kind === "window" ? "Window" : kind === "text" ? "Text" : "Control"} "${subject}" ${gone ? "is gone" : "is there"} after ${((Date.now() - started) / 1e3).toFixed(1)}s.`;
1068
1251
  await this.settle(signal);
1069
1252
  return text;
1070
1253
  }
1071
1254
  if (Date.now() - started >= timeout) {
1072
1255
  const near = !gone && kind === "target" && suggestions.length ? ` Controls there now: ${suggestions.map((name) => `"${name.slice(0, 40)}"`).join(", ")}.` : "";
1073
- throw new Error(`Timed out after ${Math.round(timeout / 1e3)}s waiting for ${kind === "window" ? "window" : "control"} "${subject}" to ${gone ? "disappear" : "appear"}.${near}`);
1256
+ 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}`);
1074
1257
  }
1075
1258
  await setTimeout$1(POLL_MS, void 0, { signal });
1076
1259
  }
@@ -1141,11 +1324,17 @@ var Computer = class Computer {
1141
1324
  case "middle_click":
1142
1325
  case "double_click":
1143
1326
  case "triple_click": {
1144
- const { point: p, label } = await this.aim(input, call);
1145
- await this.checkPointer(call, p, "click");
1327
+ const { point, label, named } = await this.aim(input, call);
1328
+ let p = point;
1329
+ if (!named) await this.checkPointer(call, p, "click");
1146
1330
  const button = action === "right_click" ? "right" : action === "middle_click" ? "middle" : "left";
1147
1331
  const count = action === "double_click" ? 2 : action === "triple_click" ? 3 : 1;
1148
1332
  const modifiers = parseModifiers(input.modifiers ?? input.text);
1333
+ if (action === "left_click" && named && modifiers.length === 0) {
1334
+ const semantic = named.element.role === "Edit" || named.element.editable ? "focus" : "invoke";
1335
+ if (await this.semanticAction(call, named, semantic)) return { text: `${semantic === "focus" ? "Focused" : "Invoked"}${label}.` };
1336
+ }
1337
+ if (named) p = await this.namedClickPoint(call, input.target, named);
1149
1338
  await this.helper.call("click", {
1150
1339
  ...p ?? {},
1151
1340
  button,
@@ -1158,6 +1347,7 @@ var Computer = class Computer {
1158
1347
  const from = await this.point(input.start_coordinate, "start_coordinate");
1159
1348
  const to = await this.point(input.coordinate);
1160
1349
  await this.checkPointer(call, from, "drag in");
1350
+ if (this.settings().harnessUrl) await this.checkPointer(call, to, "drag to");
1161
1351
  await this.helper.call("drag", {
1162
1352
  x1: from.x,
1163
1353
  y1: from.y,
@@ -1170,7 +1360,11 @@ var Computer = class Computer {
1170
1360
  case "left_mouse_down":
1171
1361
  case "left_mouse_up": {
1172
1362
  const p = input.coordinate ? await this.point(input.coordinate) : void 0;
1173
- if (action === "left_mouse_down") await this.checkPointer(call, p, "press the mouse in");
1363
+ if (action === "left_mouse_down") {
1364
+ const window = await this.windowAt(p ?? await this.cursor());
1365
+ if (window && this.overlay.isRememberedWebWindow(window)) throw new Error("Use a single drag action within the work page instead of holding the mouse button in this browser window.");
1366
+ await this.assertAllowed(call, window, "press the mouse in");
1367
+ }
1174
1368
  await this.helper.call("button", {
1175
1369
  ...p ?? {},
1176
1370
  button: "left",
@@ -1199,34 +1393,35 @@ var Computer = class Computer {
1199
1393
  if (text === "") throw new Error("type needs text.");
1200
1394
  let into = "";
1201
1395
  if (input.target || input.coordinate) {
1202
- const { point: p, label } = await this.aim(input, call);
1203
- await this.checkPointer(call, p, "click");
1204
- await this.helper.call("click", {
1205
- ...p ?? {},
1206
- button: "left",
1207
- count: 1,
1208
- modifiers: []
1209
- });
1396
+ const { point, label, named } = await this.aim(input, call);
1397
+ let p = point;
1398
+ const focused = named && await this.semanticAction(call, named, "focus");
1399
+ if (!focused) {
1400
+ if (named) p = await this.namedClickPoint(call, input.target, named);
1401
+ else await this.checkPointer(call, p, "click");
1402
+ await this.helper.call("click", {
1403
+ ...p ?? {},
1404
+ button: "left",
1405
+ count: 1,
1406
+ modifiers: []
1407
+ });
1408
+ }
1210
1409
  await setTimeout$1(120, void 0, { signal: call.signal });
1211
- into = ` (clicked${label} first)`;
1410
+ if (named) await this.checkNamed(call, named.window);
1411
+ into = ` (${focused ? "focused" : "clicked"}${label} first)`;
1212
1412
  }
1213
1413
  await this.checkKeyboard(call, "type into");
1214
1414
  return { text: `${await this.enterText(text, call)}${into}` };
1215
1415
  }
1216
1416
  case "key": {
1217
1417
  const combos = parseKeys(input.text ?? "");
1218
- await this.checkKeyboard(call, "send keys to");
1219
- await this.helper.call("keys", { combos });
1418
+ await this.sendKeys(call, combos);
1220
1419
  return { text: `Pressed ${input.text}.` };
1221
1420
  }
1222
1421
  case "hold_key": {
1223
1422
  const combos = parseKeys(input.text ?? "");
1224
1423
  const seconds = Math.min(10, Math.max(.05, input.duration ?? .5));
1225
- await this.checkKeyboard(call, "send keys to");
1226
- await this.helper.call("keys", {
1227
- combos,
1228
- holdMs: Math.round(seconds * 1e3)
1229
- }, 2e4);
1424
+ await this.sendKeys(call, combos, Math.round(seconds * 1e3));
1230
1425
  return { text: `Held ${input.text} for ${seconds}s.` };
1231
1426
  }
1232
1427
  }
@@ -1280,6 +1475,7 @@ var Computer = class Computer {
1280
1475
  const now = await this.foreground().catch(() => void 0);
1281
1476
  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.`);
1282
1477
  }
1478
+ if (index > 0 && target && this.overlay.isRememberedWebWindow(target)) await this.checkKeyboard(call, "type into");
1283
1479
  await step(item, index);
1284
1480
  done += item.length;
1285
1481
  }
@@ -1844,21 +2040,23 @@ var OverlayController = class {
1844
2040
  unusedTimer;
1845
2041
  otherTools = 0;
1846
2042
  hostWindows = [];
2043
+ returnTo;
2044
+ ending;
2045
+ workTab;
2046
+ starting;
1847
2047
  stopping = false;
1848
- /** Progress card lines: the reply as it streams, and what the agent is doing. */
2048
+ /** Progress card lines: host-provided reasoning and recent operations. */
1849
2049
  streamAgent;
1850
- text = "";
1851
2050
  thinking = "";
1852
2051
  /** Recent steps (tool actions), oldest first. */
1853
2052
  steps = [];
1854
- /** Whether the agent is thinking now (newer than the last step). */
1855
- thinkingLatest = false;
1856
- freshAttempt = true;
2053
+ resume;
1857
2054
  pushTimer;
1858
2055
  /** An instruction the user typed into the progress card. */
1859
2056
  onMessage;
1860
2057
  /** Called when control starts (before the first action), e.g. to remember the window layout. */
1861
2058
  onStart;
2059
+ onRelease;
1862
2060
  /** Opacity the card was last given, to apply setting changes while it floats. */
1863
2061
  cardOpacity = 100;
1864
2062
  /** Paused by Esc or the pill; actions wait until resumed. */
@@ -1914,6 +2112,8 @@ var OverlayController = class {
1914
2112
  }
1915
2113
  /** Called before every action: shows the overlay once and updates its status line. */
1916
2114
  async begin(agent, status) {
2115
+ await this.ending;
2116
+ await this.starting;
1917
2117
  if (agent) this.agent = agent;
1918
2118
  this.armIdle();
1919
2119
  this.armUnused();
@@ -1921,27 +2121,11 @@ var OverlayController = class {
1921
2121
  if (!this.visible) {
1922
2122
  this.visible = true;
1923
2123
  this.paused = false;
1924
- await this.onStart?.().catch((error) => this.log(`overlay start: ${String(error)}`));
1925
- await this.shrinkHost(settings.hostWindow);
1926
- const pet = settings.hostWindow === "pet";
1927
- if (settings.overlay || pet) {
1928
- if (this.streamAgent !== agent) {
1929
- this.text = "";
1930
- this.thinking = "";
1931
- }
1932
- this.steps = status ? [status] : [];
1933
- this.thinkingLatest = false;
1934
- await this.helper.call("overlay_show", {
1935
- label: pet ? `${settings.overlayLabel || "DeepSeek Harness"} 正在操控` : `${settings.overlayLabel || "DeepSeek Harness"} 正在操控你的电脑`,
1936
- status,
1937
- icon: this.iconPath,
1938
- iconLight: this.iconPath.replace(/deepseek-white\.png$/, "deepseek-black.png"),
1939
- idleMs: settings.userIdleMs,
1940
- glow: settings.overlay,
1941
- pet,
1942
- petOpacity: settings.cardOpacity,
1943
- text: this.text
1944
- }).catch((error) => this.log(`overlay: ${String(error)}`));
2124
+ this.starting = this.start(agent, status, settings);
2125
+ try {
2126
+ await this.starting;
2127
+ } finally {
2128
+ this.starting = void 0;
1945
2129
  }
1946
2130
  return;
1947
2131
  }
@@ -1952,6 +2136,44 @@ var OverlayController = class {
1952
2136
  }
1953
2137
  await this.status(status);
1954
2138
  }
2139
+ async start(agent, status, settings) {
2140
+ await this.rememberHost(settings.harnessUrl).catch((error) => this.log(`remember host: ${String(error)}`));
2141
+ const resume = this.resume;
2142
+ this.resume = void 0;
2143
+ const host = this.returnTo?.window;
2144
+ const foreground = resume && await this.helper.call("foreground").catch(() => null);
2145
+ await this.onStart?.().catch((error) => this.log(`overlay start: ${String(error)}`));
2146
+ await this.shrinkHost(settings.hostWindow);
2147
+ if (resume && resume.agent === agent && host?.hwnd === resume.host.hwnd && host.pid === resume.host.pid && foreground?.hwnd === host.hwnd && foreground.pid === host.pid) {
2148
+ const { hwnd, pid } = resume.target;
2149
+ if ((await this.helper.call("focus", {
2150
+ hwnd,
2151
+ pid
2152
+ }, 3e3).catch(() => void 0))?.focused && resume.tab) {
2153
+ if ((await this.helper.call("browser_tab", {
2154
+ hwnd,
2155
+ pid,
2156
+ select: resume.tab
2157
+ }, 2500).catch(() => void 0))?.selected) this.rememberWorkTab(resume.target, resume.tab);
2158
+ }
2159
+ }
2160
+ const pet = settings.hostWindow === "pet";
2161
+ if (settings.overlay || pet) {
2162
+ if (this.streamAgent !== agent) this.thinking = "";
2163
+ this.steps = status ? [status] : [];
2164
+ await this.helper.call("overlay_show", {
2165
+ label: pet ? `${settings.overlayLabel || "DeepSeek Harness"} 正在操控` : `${settings.overlayLabel || "DeepSeek Harness"} 正在操控你的电脑`,
2166
+ status,
2167
+ icon: this.iconPath,
2168
+ iconLight: this.iconPath.replace(/deepseek-white\.png$/, "deepseek-black.png"),
2169
+ idleMs: settings.userIdleMs,
2170
+ glow: settings.overlay,
2171
+ pet,
2172
+ petOpacity: settings.cardOpacity,
2173
+ thinking: this.thinking
2174
+ }).catch((error) => this.log(`overlay: ${String(error)}`));
2175
+ }
2176
+ }
1955
2177
  async status(status) {
1956
2178
  const settings = this.settings();
1957
2179
  if (!this.visible) return;
@@ -1967,35 +2189,30 @@ var OverlayController = class {
1967
2189
  const line = plainLine(text).trim();
1968
2190
  if (line === "" || this.steps.at(-1) === line) return;
1969
2191
  this.steps = [...this.steps, line].slice(-8);
1970
- this.thinkingLatest = false;
1971
2192
  this.schedulePush();
1972
2193
  }
1973
2194
  /** Live model output (DSH agent/assistant-stream) for the progress card. */
1974
2195
  stream(agent, frame) {
2196
+ if (this.visible && agent !== this.agent) return;
1975
2197
  if (agent !== this.streamAgent) {
1976
2198
  this.streamAgent = agent;
1977
- this.text = "";
1978
2199
  this.thinking = "";
1979
2200
  this.steps = [];
1980
2201
  }
1981
2202
  if (frame.type === "start") {
1982
- this.freshAttempt = true;
1983
2203
  this.thinking = "";
2204
+ this.schedulePush();
1984
2205
  return;
1985
2206
  }
1986
2207
  if (this.visible && agent === this.agent) this.armIdle();
1987
2208
  const chunk = frame.type === "chunk" ? frame.chunk : void 0;
1988
2209
  if (!chunk) return;
1989
- if (chunk.type === "text-delta" && chunk.text) {
1990
- if (this.freshAttempt) {
1991
- this.text = "";
1992
- this.freshAttempt = false;
1993
- }
1994
- this.text = plainLine(this.text + chunk.text).slice(-2e3);
1995
- } else if (chunk.type === "reasoning-delta" && chunk.text) {
1996
- this.thinking = plainLine(this.thinking + chunk.text).slice(-300);
1997
- this.thinkingLatest = true;
1998
- } else return;
2210
+ if (chunk.type === "text-delta" && chunk.text?.trim()) {
2211
+ if (this.visible && this.agent && agent === this.agent && !this.paused && !this.stopping) this.end(this.agent, true).catch((error) => this.log(`reply handoff: ${String(error)}`));
2212
+ return;
2213
+ }
2214
+ if (chunk.type !== "reasoning-delta" || !chunk.text) return;
2215
+ this.thinking = plainLine(this.thinking + chunk.text).slice(-300);
1999
2216
  this.schedulePush();
2000
2217
  }
2001
2218
  /** A tool of another plugin started (computer-use tools report their own steps). */
@@ -2017,16 +2234,15 @@ var OverlayController = class {
2017
2234
  this.pushTimer = void 0;
2018
2235
  if (!this.visible) return;
2019
2236
  this.helper.call("pet_update", {
2020
- text: this.text,
2021
2237
  thinking: this.thinking.trim(),
2022
- steps: this.steps,
2023
- thinkingLatest: this.thinkingLatest
2238
+ steps: this.steps
2024
2239
  }).catch(() => {});
2025
2240
  }, 80);
2026
2241
  this.pushTimer.unref?.();
2027
2242
  }
2028
2243
  /** Agent finished (idle), was cancelled, or the plugin is stopping. */
2029
- async end(agent) {
2244
+ async end(agent, replying = false) {
2245
+ if (this.starting) await this.starting;
2030
2246
  if (agent !== void 0 && this.agent !== void 0 && agent !== this.agent) return;
2031
2247
  if (this.idleTimer) clearTimeout(this.idleTimer);
2032
2248
  this.idleTimer = void 0;
@@ -2035,18 +2251,99 @@ var OverlayController = class {
2035
2251
  this.otherTools = 0;
2036
2252
  this.agent = void 0;
2037
2253
  this.paused = false;
2038
- if (!this.visible) return;
2254
+ if (!this.visible) return this.ending;
2039
2255
  this.visible = false;
2040
2256
  if (this.pushTimer) {
2041
2257
  clearTimeout(this.pushTimer);
2042
2258
  this.pushTimer = void 0;
2043
2259
  }
2044
- if (this.settings().hostWindow === "pet" && !this.stopping) await this.helper.call("pet_finish", {
2045
- text: this.text,
2046
- holdMs: FINISH_HOLD_MS
2047
- }).catch(() => {});
2048
- else await this.helper.call("overlay_hide").catch(() => {});
2049
- await this.restoreHost();
2260
+ this.ending = (async () => {
2261
+ await this.onRelease?.().catch((error) => this.log(`release input: ${String(error)}`));
2262
+ if (replying && agent && this.returnTo) {
2263
+ const host = this.returnTo.window;
2264
+ const target = await this.helper.call("foreground").catch(() => null);
2265
+ if (target?.hwnd && (target.hwnd !== host.hwnd || this.workTab)) this.resume = {
2266
+ agent,
2267
+ host,
2268
+ target,
2269
+ tab: target.hwnd === host.hwnd ? this.workTab : void 0
2270
+ };
2271
+ }
2272
+ if (!replying && this.settings().hostWindow === "pet" && !this.stopping) await this.helper.call("pet_finish", { holdMs: FINISH_HOLD_MS }).catch(() => {});
2273
+ else await this.helper.call("overlay_hide").catch(() => {});
2274
+ await this.restoreHost();
2275
+ await this.focusRememberedHost().catch((error) => this.log(`restore focus: ${String(error)}`));
2276
+ })();
2277
+ try {
2278
+ await this.ending;
2279
+ } finally {
2280
+ this.ending = void 0;
2281
+ }
2282
+ }
2283
+ isRememberedWebWindow(win) {
2284
+ const target = this.returnTo;
2285
+ return target?.web === true && target.window.hwnd === win.hwnd && target.window.pid === win.pid;
2286
+ }
2287
+ forgetResume(agent) {
2288
+ const clear = () => {
2289
+ if (this.resume?.agent === agent) this.resume = void 0;
2290
+ };
2291
+ if (this.ending) this.ending.then(clear, clear);
2292
+ else clear();
2293
+ }
2294
+ rememberWorkTab(win, tab) {
2295
+ if (this.isRememberedWebWindow(win)) this.workTab = tab;
2296
+ }
2297
+ rememberWebHost(win, tab) {
2298
+ if (!this.returnTo) this.returnTo = {
2299
+ window: win,
2300
+ web: true,
2301
+ tab
2302
+ };
2303
+ }
2304
+ isWorkTab(tab) {
2305
+ return this.workTab === tab && this.returnTo?.tab !== tab;
2306
+ }
2307
+ async rememberHost(harnessUrl) {
2308
+ const foreground = await this.helper.call("foreground");
2309
+ if (foreground?.hwnd && isHostWindow(foreground)) {
2310
+ this.returnTo = {
2311
+ window: foreground,
2312
+ web: false
2313
+ };
2314
+ return;
2315
+ }
2316
+ if (foreground?.hwnd && harnessUrl && isBrowser(foreground)) {
2317
+ const state = await readBrowserTab(this.helper, foreground);
2318
+ if (isHarnessAddress(state?.url, harnessUrl)) {
2319
+ this.returnTo = {
2320
+ window: foreground,
2321
+ web: true,
2322
+ tab: state?.tab
2323
+ };
2324
+ return;
2325
+ }
2326
+ }
2327
+ const desktop = (await this.helper.call("windows")).filter((win) => isHostWindow(win) && !win.minimized).sort((a, b) => b.width * b.height - a.width * a.height)[0];
2328
+ if (desktop) this.returnTo = {
2329
+ window: desktop,
2330
+ web: false
2331
+ };
2332
+ }
2333
+ async focusRememberedHost() {
2334
+ const target = this.returnTo;
2335
+ this.returnTo = void 0;
2336
+ this.workTab = void 0;
2337
+ if (!target) return;
2338
+ const { hwnd, pid } = target.window;
2339
+ if ((await this.helper.call("focus", {
2340
+ hwnd,
2341
+ pid
2342
+ }, 3e3))?.focused && target.web && target.tab) await this.helper.call("browser_tab", {
2343
+ hwnd,
2344
+ pid,
2345
+ select: target.tab
2346
+ }, 2500);
2050
2347
  }
2051
2348
  stop(reason) {
2052
2349
  if (this.stopping) return;
@@ -2096,7 +2393,8 @@ var OverlayController = class {
2096
2393
  });
2097
2394
  this.hostWindows = rows.map((row) => ({
2098
2395
  hwnd: row.hwnd,
2099
- mode: "minimize"
2396
+ mode: "minimize",
2397
+ maximized: row.maximized
2100
2398
  }));
2101
2399
  return;
2102
2400
  }
@@ -2148,7 +2446,7 @@ var OverlayController = class {
2148
2446
  }, 1200).unref();
2149
2447
  } else await this.helper.call("window_cmd", {
2150
2448
  hwnd: win.hwnd,
2151
- op: "restore"
2449
+ op: win.maximized ? "maximize" : "restore"
2152
2450
  }).catch(() => {});
2153
2451
  }
2154
2452
  };
@@ -2168,6 +2466,8 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
2168
2466
  - App skills: open_application returns your saved notes for the app it opens; follow them instead of rediscovering how the app behaves. After working out an unfamiliar app (or finding a note wrong), record the reusable part with app_skill rather than in general memory.
2169
2467
  - Saving: in any Save As dialog do not click through folders; press alt+n (file name box), ctrl+a, type the full path including the file name, then Return. Office apps: F12 opens that classic dialog directly. To check a saved file, look at the exact path; never search a whole drive or user profile recursively.
2170
2468
  - Be fast: what the user waits for is mostly the number of calls you make (each costs seconds). Once you have seen the app's window, put everything predictable into ONE computer_batch, including steps whose target is not on screen yet: name the control with target ("保存", "按钮:确定") instead of a coordinate, and use wait with until ("window:另存为") for a dialog to appear before keys meant for it. Do not end a batch with wait or follow it with a wait or a screenshot: its result already is the settled screen. Do not split work into two batches just to look in between when the second does not depend on what you would see (type the text and format it in the same batch). If you will need to read small text, end the batch with zoom; to read what a window says (a document, a page, a reply, a log) use ui_elements with text: true or finish: "text" instead of scrolling and zooming screenshots. Keep your own text between calls to a line. Avoid shell commands for things you can see on screen.
2469
+ - When two controls share a name, ui_elements reports automationId; use target "id:<AutomationId>" (or "#<AutomationId>") to pick the intended one.
2470
+ - Open HTTP(S) URLs with open_application. To use the user's current Chrome, bring it forward by name first and then pass the URL. This opens a work tab in the current verified browser window when supported. Keep browser chrome and the DeepSeek Harness Web tab untouched. Use new_instance only if the user asks for a separate window.
2171
2471
  - 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.
2172
2472
  - If a dedicated tool fits the whole task better (an API, or browser automation attached to the user's own browser), choose it at the start; do not switch tools halfway through a task that is going fine on screen.
2173
2473
  - 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.
@@ -2407,6 +2707,7 @@ function resolveConfig(raw) {
2407
2707
  };
2408
2708
  const bool = (key) => typeof out[key] === "boolean" ? out[key] : DEFAULTS[key];
2409
2709
  return {
2710
+ harnessUrl: typeof out.harnessUrl === "string" ? httpOrigin(out.harnessUrl.trim()) : void 0,
2410
2711
  accessMode: out.accessMode === "allow-all" || out.accessMode === "per-app" ? out.accessMode : DEFAULTS.accessMode,
2411
2712
  overlay: bool("overlay"),
2412
2713
  overlayLabel: typeof out.overlayLabel === "string" && out.overlayLabel.trim() !== "" ? out.overlayLabel.trim().slice(0, 40) : DEFAULTS.overlayLabel,
@@ -2567,18 +2868,15 @@ function previewRoute(helper, settings, overlay, iconPath) {
2567
2868
  idleMs: s.userIdleMs,
2568
2869
  glow: s.overlay,
2569
2870
  pet,
2570
- petOpacity: s.cardOpacity,
2571
- text: ""
2871
+ petOpacity: s.cardOpacity
2572
2872
  });
2573
2873
  if (pet) await helper.call("pet_update", {
2574
- text: "这是预览:操控电脑时,这里滚动显示 AI 的回复正文。",
2575
- thinking: "第二行显示思考过程和最近几步操作",
2874
+ thinking: "先确认表单内容,再核对提交结果。",
2576
2875
  steps: [
2577
2876
  "打开应用",
2578
2877
  "输入文字",
2579
2878
  "预览 · 4 秒后消失"
2580
- ],
2581
- thinkingLatest: false
2879
+ ]
2582
2880
  }).catch(() => {});
2583
2881
  setTimeout(() => {
2584
2882
  if (overlay.controller === void 0) helper.call("overlay_hide").catch(() => {});
@@ -8662,7 +8960,7 @@ const actionProperties = {
8662
8960
  },
8663
8961
  until: {
8664
8962
  type: "string",
8665
- description: "wait: return as soon as this is there, \"window:<title or exe part>\" or \"target:<control name>\", instead of waiting a fixed time."
8963
+ description: "wait: observe \"window:<title or exe part>\", \"target:<control name>\", or \"text:<window text>\" instead of waiting a fixed time."
8666
8964
  },
8667
8965
  gone: {
8668
8966
  type: "boolean",
@@ -8794,7 +9092,7 @@ function createTools(host) {
8794
9092
  },
8795
9093
  new_instance: {
8796
9094
  type: "boolean",
8797
- description: "Start another copy even though the app is already running. Only when the user explicitly asks for a second window / instance / account."
9095
+ description: "Open a separate browser window for a URL, or start another app instance. Use only when explicitly requested."
8798
9096
  }
8799
9097
  },
8800
9098
  output,
@@ -8825,12 +9123,40 @@ function createTools(host) {
8825
9123
  await computer.overlay.begin(call.agent, `打开 ${name}`);
8826
9124
  await computer.overlay.yieldToUser(call.signal, false);
8827
9125
  const before = await computer.foreground();
9126
+ if (isUrl && !newInstance && before?.exe.toLowerCase() === "chrome.exe" && before.className.startsWith("Chrome_WidgetWin")) {
9127
+ const tab = await readBrowserTab(computer.helper, before);
9128
+ if (tab?.tab && typeof tab.url === "string") {
9129
+ const denial = computer.access.denial(call.session, before, call.autoApprove ? "allow-all" : settings.accessMode, settings.blockedApps, "open a new tab in");
9130
+ if (denial) throw new Error(denial);
9131
+ if (settings.harnessUrl && isHarnessAddress(tab.url, settings.harnessUrl)) {
9132
+ computer.overlay.rememberWebHost(before, tab.tab);
9133
+ if (!computer.overlay.isRememberedWebWindow(before)) throw new Error("The current browser shows another DeepSeek Harness session. Switch to the intended browser window before opening the URL.");
9134
+ }
9135
+ if (call.signal.aborted) throw new Error("Cancelled.");
9136
+ const opened = await computer.helper.call("browser_open_tab", {
9137
+ hwnd: before.hwnd,
9138
+ pid: before.pid,
9139
+ tab: tab.tab,
9140
+ url: name
9141
+ }, 12e3);
9142
+ if (!opened?.tab || opened.tab === tab.tab) throw new Error("The browser did not confirm a separate work tab.");
9143
+ computer.overlay.rememberWorkTab(before, opened.tab);
9144
+ if (settings.accessMode === "per-app" && call.autoApprove) computer.access.grant(call.session, [before.exe]);
9145
+ return `Opened ${name} in a new tab of the current ${before.exe} window. ${await computer.describeForeground()}${skillNote(call.session, name, before)}`;
9146
+ }
9147
+ throw new Error("Could not verify the current browser tab. Bring a regular browser tab into view and retry. Use new_instance only if a separate window is wanted.");
9148
+ }
8828
9149
  let how;
9150
+ let openedUrlWindow;
8829
9151
  const isUri = isUrl || /^[a-z][a-z0-9+.-]+:(?![\/])/i.test(name);
8830
- const running = isUri || newInstance ? void 0 : (await computer.windows()).find((win) => !isHostWindow(win) && appMatches(name, win));
9152
+ const matches = (win) => !isHostWindow(win) && appMatches(name, win);
9153
+ const running = isUri || newInstance ? void 0 : before && matches(before) ? before : (await computer.windows()).find(matches);
8831
9154
  const hidden = running || isUri || newInstance ? void 0 : (await computer.backgroundApps(false)).find((win) => !isHostWindow(win) && appMatches(name, win));
8832
- if (running) how = (await computer.focus(running)).focused ? `Brought ${running.exe} ("${running.title.slice(0, 60)}") to the front.` : `Tried to bring ${running.exe} to the front, but Windows kept another window focused.`;
8833
- else if (hidden) {
9155
+ if (running) {
9156
+ const denial = computer.access.denial(call.session, running, settings.accessMode, settings.blockedApps, "focus");
9157
+ if (denial) throw new Error(denial);
9158
+ how = (await computer.focus(running)).focused ? `Brought ${running.exe} ("${running.title.slice(0, 60)}") to the front.` : `Tried to bring ${running.exe} to the front, but Windows kept another window focused.`;
9159
+ } else if (hidden) {
8834
9160
  const restored = await computer.helper.call("tray_restore", { exe: hidden.exe }, 2e4);
8835
9161
  if (restored.window) computer.noteFromTray(restored.window.hwnd);
8836
9162
  how = restored.window ? `${hidden.exe} was already running in the system tray: restored its window from the tray icon (no second instance started).` : `${hidden.exe} is already running in the background${restored.icon ? " (system tray)" : ""}, but its window did not come back automatically. Open it from its notification-area icon (click ^ "show hidden icons" on the taskbar first). Do not launch it again (that starts a second instance and login), and never force its hidden window visible from a shell (Electron / Qt apps freeze).`;
@@ -8839,12 +9165,22 @@ function createTools(host) {
8839
9165
  query: name,
8840
9166
  limit: 5
8841
9167
  }, 3e4))[0];
9168
+ const existing = isUrl ? new Set((await computer.windows()).map((win) => win.hwnd)) : void 0;
9169
+ const browser = isUrl ? await computer.helper.call("open_url", { url: name }) : void 0;
8842
9170
  if (app) await computer.helper.call("launch", { appId: app.id });
8843
- else await computer.helper.call("launch", { target: name });
8844
- how = app ? `Launched "${app.name}".` : isUrl ? `Opened ${name} in the default browser.` : `Started "${name}".`;
9171
+ else if (!isUrl) await computer.helper.call("launch", { target: name });
9172
+ how = app ? `Launched "${app.name}".` : isUrl ? `Requested a new browser window for ${name}.` : `Started "${name}".`;
8845
9173
  for (let i = 0; i < 80; i++) {
8846
9174
  await setTimeout$1(100, void 0, { signal: call.signal });
8847
9175
  const now = await computer.foreground();
9176
+ if (browser) {
9177
+ if (now?.exe.toLowerCase() === browser.exe && !existing.has(now.hwnd)) {
9178
+ openedUrlWindow = now;
9179
+ how = `Opened ${name} in a new browser window.`;
9180
+ break;
9181
+ }
9182
+ continue;
9183
+ }
8848
9184
  if (now && now.hwnd !== before?.hwnd && !isHostWindow(now) && !isTransientShell(now) && (now.exe.toLowerCase() !== "explorer.exe" || now.className === "CabinetWClass")) break;
8849
9185
  if (i >= 10 && i % 10 === 0 && !isUri) {
8850
9186
  const opened = (await computer.windows()).find((win) => !isHostWindow(win) && appMatches(name, win));
@@ -8856,7 +9192,7 @@ function createTools(host) {
8856
9192
  }
8857
9193
  }
8858
9194
  const fg = await computer.foreground();
8859
- if (fg && !isHostWindow(fg) && settings.accessMode === "per-app" && (computer.access.missing(call.session, [appName]).length === 0 || isUrl)) computer.access.grant(call.session, [fg.exe]);
9195
+ if (fg && !isHostWindow(fg) && settings.accessMode === "per-app" && (isUrl ? openedUrlWindow?.hwnd === fg.hwnd && openedUrlWindow.pid === fg.pid : computer.access.missing(call.session, [appName]).length === 0)) computer.access.grant(call.session, [fg.exe]);
8860
9196
  return `${how} ${await computer.describeForeground()}${skillNote(call.session, name, fg)}`;
8861
9197
  }
8862
9198
  }
@@ -8935,6 +9271,10 @@ function createTools(host) {
8935
9271
  if (denial && action !== "minimize") throw new Error(denial);
8936
9272
  await computer.overlay.begin(call.agent, `窗口 ${action}`);
8937
9273
  await computer.overlay.yieldToUser(call.signal, false);
9274
+ if (action === "close") {
9275
+ if (computer.overlay.isRememberedWebWindow(target)) throw new Error("This window contains the protected DeepSeek Harness Web tab.");
9276
+ await computer.assertAllowed(call, target, "close");
9277
+ }
8938
9278
  let text;
8939
9279
  if (action === "focus") text = (await computer.focus(target)).focused ? `Focused ${target.exe} ("${target.title.slice(0, 60)}").` : `Windows refused to focus ${target.exe}; try clicking it.`;
8940
9280
  else {
@@ -9176,6 +9516,10 @@ function createTools(host) {
9176
9516
  const name = "@copylee/dsh-computer-use";
9177
9517
  const inject = ["tools", "attachments"];
9178
9518
  const Config = z.object({
9519
+ harnessUrl: z.string().default("").volatile().i18n({
9520
+ "zh-CN": { $description: "DSH Web GUI 地址。留空时使用本地 Web 服务端口。反代或自定义域名请填写实际访问地址。" },
9521
+ "en-US": { $description: "DSH Web GUI URL. Leave blank to use the local Web server port. Set the actual URL when using a reverse proxy or custom domain." }
9522
+ }),
9179
9523
  accessMode: z.union([z.const("per-app").i18n({
9180
9524
  "zh-CN": { $description: "按应用授权(每个会话由你批准要操控的应用)" },
9181
9525
  "en-US": { $description: "Per app (approve the apps each session)" }
@@ -9196,8 +9540,8 @@ const Config = z.object({
9196
9540
  }),
9197
9541
  hostWindow: z.union([
9198
9542
  z.const("pet").i18n({
9199
- "zh-CN": { $description: "最小化,改用右下角迷你进度卡片(两行滚动显示回复和思考 / 工具调用)" },
9200
- "en-US": { $description: "Minimize it and show a mini progress card (reply + thinking / tool calls)" }
9543
+ "zh-CN": { $description: "最小化,改用右下角迷你进度卡片(思考与操作时间线)" },
9544
+ "en-US": { $description: "Minimize it and show a mini progress card (reasoning and action timeline)" }
9201
9545
  }),
9202
9546
  z.const("card").i18n({
9203
9547
  "zh-CN": { $description: "缩成右下角置顶悬浮卡片" },
@@ -9282,13 +9626,19 @@ function apply(ctx, config = {}) {
9282
9626
  ctx.logger.warn("dsh-computer-use only supports Windows; no tools registered.");
9283
9627
  return;
9284
9628
  }
9285
- const settings = () => resolveConfig(config);
9629
+ const settings = () => {
9630
+ const resolved = resolveConfig(config);
9631
+ const port = ctx.get("webServer")?.port;
9632
+ if (!resolved.harnessUrl && port) resolved.harnessUrl = `http://127.0.0.1:${port}`;
9633
+ return resolved;
9634
+ };
9286
9635
  const log = (message) => ctx.logger.info(message);
9287
9636
  const helper = new NativeHelper(new HelperClient((message) => ctx.logger.warn(message)), (message) => ctx.logger.warn(message), () => settings().nativeHelper);
9288
9637
  const access = new AccessControl();
9289
9638
  const iconPath = helperAssetPath("deepseek-white.png");
9290
9639
  const overlay = new OverlayController(helper, settings, log, iconPath);
9291
9640
  const computer = new Computer(helper, access, overlay, settings);
9641
+ overlay.onRelease = () => computer.releaseHeld();
9292
9642
  ctx.effect(() => () => {
9293
9643
  overlay.end().finally(() => helper.dispose());
9294
9644
  }, "computer-use: helper");
@@ -9449,6 +9799,7 @@ function apply(ctx, config = {}) {
9449
9799
  };
9450
9800
  ctx.on("agent/status", ({ agent, status }) => {
9451
9801
  if (status === "running") computer.resetLook();
9802
+ if (status === "idle") overlay.forgetResume(agent);
9452
9803
  if (status === "idle" && computer.clipboardAgent === agent) {
9453
9804
  computer.clipboardAgent = void 0;
9454
9805
  helper.call("clipboard_restore").catch(() => {});
@@ -9456,6 +9807,7 @@ function apply(ctx, config = {}) {
9456
9807
  if (status === "idle" && overlay.controller === agent) overlay.end(agent);
9457
9808
  });
9458
9809
  ctx.on("agent/disposed", ({ agent }) => {
9810
+ overlay.forgetResume(agent);
9459
9811
  access.forget(agent.session.id);
9460
9812
  if (overlay.controller === agent) overlay.end();
9461
9813
  });