@copylee/dsh-computer-use 0.6.0 → 0.6.1

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/client.js CHANGED
@@ -1073,7 +1073,7 @@ window.__ModuleLoader__.load({
1073
1073
  onClick: () => {
1074
1074
  refreshStatus();
1075
1075
  }
1076
- }, "刷新状态"), h("span", { style: S.hint }, "预览会显示 3 秒光晕和提示条(按已保存的设置)。"))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "授权"), h("div", { style: S.label }, "授权方式", h(Select, {
1076
+ }, "刷新状态"), h("span", { style: S.hint }, "预览 4 秒:按已保存的设置显示光晕,以及迷你进度卡片或提示条。"))), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "授权"), h("div", { style: S.label }, "授权方式", h(Select, {
1077
1077
  label: "授权方式",
1078
1078
  disabled,
1079
1079
  value: draft.accessMode,
package/lib/index.js CHANGED
@@ -582,10 +582,13 @@ function suggest(elements, wanted) {
582
582
  *
583
583
  * Blocks end after a blank-line separator, never inside a ``` / ~~~ fence and
584
584
  * never inside a paragraph (a half-pasted **bold** or link may not re-render).
585
- * Joining the blocks gives back the original text exactly.
585
+ * Text with no blank line at all (a story written one paragraph per line) is
586
+ * split at its line ends instead, or it would go in as a single block; a table
587
+ * keeps its rows together. Joining the blocks gives back the original text exactly.
586
588
  */
587
589
  function splitBlocks(text, minChars = 80) {
588
590
  const lines = text.split(/(?<=\n)/);
591
+ const byLine = !/\n[ \t]*\r?\n/.test(text) && !/^\s*(```|~~~|\|)/m.test(text);
589
592
  const blocks = [];
590
593
  let current = "";
591
594
  let fence;
@@ -598,7 +601,7 @@ function splitBlocks(text, minChars = 80) {
598
601
  else if (marker.startsWith(fence)) fence = void 0;
599
602
  }
600
603
  const blank = bare.trim() === "";
601
- if (fence === void 0 && !blank && previousBlank && current.length >= minChars) {
604
+ if (fence === void 0 && !blank && (previousBlank || byLine && current !== "") && current.length >= minChars) {
602
605
  blocks.push(current);
603
606
  current = "";
604
607
  }
@@ -1059,7 +1062,11 @@ var Computer = class Computer {
1059
1062
  const started = Date.now();
1060
1063
  for (;;) {
1061
1064
  if (signal.aborted) throw new Error("Cancelled.");
1062
- if (await present() !== gone) return `${kind === "window" ? "Window" : "Control"} "${subject}" ${gone ? "is gone" : "is there"} after ${((Date.now() - started) / 1e3).toFixed(1)}s.`;
1065
+ if (await present() !== gone) {
1066
+ const text = `${kind === "window" ? "Window" : "Control"} "${subject}" ${gone ? "is gone" : "is there"} after ${((Date.now() - started) / 1e3).toFixed(1)}s.`;
1067
+ await this.settle(signal);
1068
+ return text;
1069
+ }
1063
1070
  if (Date.now() - started >= timeout) {
1064
1071
  const near = !gone && kind === "target" && suggestions.length ? ` Controls there now: ${suggestions.map((name) => `"${name.slice(0, 40)}"`).join(", ")}.` : "";
1065
1072
  throw new Error(`Timed out after ${Math.round(timeout / 1e3)}s waiting for ${kind === "window" ? "window" : "control"} "${subject}" to ${gone ? "disappear" : "appear"}.${near}`);
@@ -1884,7 +1891,7 @@ var OverlayController = class {
1884
1891
  function promptText(mode) {
1885
1892
  return `# Computer use (Windows desktop)
1886
1893
  You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements, clipboard and app_skill tools.
1887
- ${mode === "per-app" ? "- Before acting on an app, call request_access once with every app the task needs; the user approves it. Input to apps that are not granted is refused.\n" : ""}- Start with a screenshot (computer action "screenshot") unless you just received one. All coordinates are pixels of the latest screenshot; the plugin converts them for DPI and scaling.
1894
+ ${mode === "per-app" ? "- Before acting on an app, call request_access once with every app the task needs; the user approves it. Input to apps that are not granted is refused.\n" : ""}- If the task begins with an app, open it right away with open_application (after request_access when the app is not granted yet): it returns the screenshot, so do not take one first. Otherwise start with a screenshot (computer action "screenshot") unless you just received one. All coordinates are pixels of the latest screenshot; the plugin converts them for DPI and scaling.
1888
1895
  - Open or switch apps with open_application (by name; it also finds desktop shortcuts) rather than hunting through the taskbar or Start menu or starting GUI apps from a shell. Use windows to see which windows exist; each line shows the process .exe. Apps closed to the system tray (QQ, 微信...) are still running: open_application restores them from their tray icon. Do not start a second copy of a running app unless the user explicitly asks for one (then pass new_instance: true), and never show or kill its hidden windows from a shell (Electron / Qt apps freeze, and a second QQ / WeChat asks for another login).
1889
1896
  - When the task is done, tidy up: close windows and dialogs you opened that the user no longer needs (keep the one showing the result they asked for), and call windows tidy to minimize again the apps that were minimized or in the tray before you started. Never close windows the user already had open.
1890
1897
  - The "DeepSeek Harness.exe" window is your own chat interface. While you control the computer it floats as a card that only the user sees: your screenshots show what is underneath it and your clicks and scrolls pass through it, so simply ignore it. Never type into DeepSeek Harness; keys go to the window you were working in.
@@ -1894,7 +1901,7 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
1894
1901
  - When the user asks you to write something in an app, enter it there with type, even long or multi-line Markdown: the user watches it appear (long text is streamed in paragraph by paragraph, literally, without the editor's auto-formatting getting in the way). Do not write the file from a shell and reopen it instead, and do not put text on the clipboard with shell commands (Set-Clipboard, clip): that clutters the user's clipboard history.
1895
1902
  - 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.
1896
1903
  - 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.
1897
- - 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 screenshot: its result already is the settled screen. 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.
1904
+ - 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.
1898
1905
  - 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.
1899
1906
  - 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.
1900
1907
  - 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.
@@ -2210,16 +2217,31 @@ function previewRoute(helper, settings, overlay, iconPath) {
2210
2217
  return;
2211
2218
  }
2212
2219
  const s = settings();
2220
+ const pet = s.hostWindow === "pet";
2213
2221
  await helper.call("overlay_show", {
2214
- label: `${s.overlayLabel} 正在操控你的电脑`,
2215
- status: "预览 · 3 秒后消失",
2222
+ label: pet ? `${s.overlayLabel} 正在操控` : `${s.overlayLabel} 正在操控你的电脑`,
2223
+ status: pet ? "预览" : "预览 · 4 秒后消失",
2216
2224
  icon: iconPath,
2225
+ iconLight: iconPath.replace(/deepseek-white\.png$/, "deepseek-black.png"),
2217
2226
  idleMs: s.userIdleMs,
2218
- glow: s.overlay
2227
+ glow: s.overlay,
2228
+ pet,
2229
+ petOpacity: s.cardOpacity,
2230
+ text: ""
2219
2231
  });
2232
+ if (pet) await helper.call("pet_update", {
2233
+ text: "这是预览:操控电脑时,这里滚动显示 AI 的回复正文。",
2234
+ thinking: "第二行显示思考过程和最近几步操作",
2235
+ steps: [
2236
+ "打开应用",
2237
+ "输入文字",
2238
+ "预览 · 4 秒后消失"
2239
+ ],
2240
+ thinkingLatest: false
2241
+ }).catch(() => {});
2220
2242
  setTimeout(() => {
2221
2243
  if (overlay.controller === void 0) helper.call("overlay_hide").catch(() => {});
2222
- }, 3e3).unref();
2244
+ }, 4e3).unref();
2223
2245
  json(res, 200, { ok: true });
2224
2246
  };
2225
2247
  }
@@ -8454,7 +8476,10 @@ function createTools(host) {
8454
8476
  const appName = /^ms-settings:/i.test(name) ? "设置" : name;
8455
8477
  if (settings.accessMode === "per-app" && !isUrl && computer.access.missing(call.session, [appName]).length > 0) {
8456
8478
  const running = (await computer.windows()).find((win) => appMatches(appName, win)) ?? (await computer.backgroundApps(false)).find((win) => appMatches(appName, win));
8457
- if (!running || !computer.access.isGranted(call.session, running)) throw new Error(`"${appName}" is not granted for this session. Call request_access with ["${appName}"] first.`);
8479
+ if (!running || !computer.access.isGranted(call.session, running)) {
8480
+ if (call.autoApprove !== true || normalizeApp(appName).includes("deepseek harness")) throw new Error(`"${appName}" is not granted for this session. Call request_access with ["${appName}"] first.`);
8481
+ computer.access.grant(call.session, [appName]);
8482
+ }
8458
8483
  }
8459
8484
  await computer.overlay.begin(call.agent, `打开 ${name}`);
8460
8485
  await computer.overlay.yieldToUser(call.signal, false);
@@ -8934,6 +8959,15 @@ function apply(ctx, config = {}) {
8934
8959
  return cached;
8935
8960
  };
8936
8961
  const attachments = () => ctx.attachments;
8962
+ /** "never" comes from the full-access / auto presets: the user opted out of approval prompts. */
8963
+ const approvalPolicy = (agent) => {
8964
+ const approval = ctx.get("approval");
8965
+ try {
8966
+ return approval?.effectivePolicy?.(agent.session);
8967
+ } catch {
8968
+ return;
8969
+ }
8970
+ };
8937
8971
  const screenshots = new ScreenshotCache(void 0, void 0, log);
8938
8972
  ctx.effect(() => {
8939
8973
  const sweep = () => {
@@ -8967,7 +9001,8 @@ function apply(ctx, config = {}) {
8967
9001
  session: exec.agent?.session.id ?? "default",
8968
9002
  agent: exec.agent,
8969
9003
  signal: exec.signal,
8970
- vision: await supportsVision(exec.agent, exec.signal)
9004
+ vision: await supportsVision(exec.agent, exec.signal),
9005
+ autoApprove: exec.agent !== void 0 && approvalPolicy(exec.agent) === "never"
8971
9006
  };
8972
9007
  }
8973
9008
  });
@@ -49,6 +49,8 @@ export interface CallContext {
49
49
  signal: AbortSignal;
50
50
  /** Whether the conversation model can look at images. */
51
51
  vision: boolean;
52
+ /** The session never prompts for approval (full access / auto review): access requests are granted as they come. */
53
+ autoApprove?: boolean;
52
54
  }
53
55
  export declare const ACTIONS: readonly ["screenshot", "left_click", "right_click", "middle_click", "double_click", "triple_click", "mouse_move", "left_click_drag", "left_mouse_down", "left_mouse_up", "scroll", "type", "key", "hold_key", "wait", "zoom", "cursor_position"];
54
56
  export type Action = typeof ACTIONS[number];
@@ -5,7 +5,9 @@
5
5
  *
6
6
  * Blocks end after a blank-line separator, never inside a ``` / ~~~ fence and
7
7
  * never inside a paragraph (a half-pasted **bold** or link may not re-render).
8
- * Joining the blocks gives back the original text exactly.
8
+ * Text with no blank line at all (a story written one paragraph per line) is
9
+ * split at its line ends instead, or it would go in as a single block; a table
10
+ * keeps its rows together. Joining the blocks gives back the original text exactly.
9
11
  */
10
12
  export declare function splitBlocks(text: string, minChars?: number): string[];
11
13
  /** Pieces of at most ~`size` characters, broken after whitespace where possible (for paced typing). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",