@copylee/dsh-computer-use 0.13.1 → 0.14.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/README.md CHANGED
@@ -13,9 +13,9 @@
13
13
 
14
14
  ## 典型场景与核心特色
15
15
 
16
- ### 1. Codex 风格协作光标 + Set-of-Marks 编号标图(密集同名按钮精准定位)
16
+ ### 1. 常驻 Codex 协作光标 + Set-of-Marks 编号标图(密集同名按钮精准定位)
17
17
 
18
- 面对表格、后台系统里多个同名「编辑 / 通过」按钮,调用 `ui_elements({ marks: true })` 为每个交互控件叠加编号角标(`#1`、`#2`…),模型按 `#编号` 直接精准操作;操作时 Codex 风格指针沿缓动曲线滑行到落点,点击后按手势变色带细微涟漪,并优先走后台 UIA 语义触发(可选物理点击后毫秒级还原真实鼠标)。
18
+ 面对表格、后台系统里多个同名「编辑 / 通过」按钮,调用 `ui_elements({ marks: true })` 为每个交互控件叠加编号角标(`#1`、`#2`…),模型按 `#编号` 直接精准操作(页面变更或执行动作后自动失效防误点);进入操控模式后,Codex 风格光晕与徽章全程伴随指针无重影,点击后按手势变色带细微涟漪,并优先走后台 UIA 语义触发(三态防双点,超时绝不重复物理点击)。
19
19
 
20
20
  ![Set-of-Marks 编号标图与 Codex 协作光标滑行点击演示](assets/demo-codex-cursor-som.gif)
21
21
 
@@ -41,15 +41,15 @@
41
41
 
42
42
  ## 一次操作是怎么完成的
43
43
 
44
- - **多通道看清界面。** 支持窗口截图(画面未变自动去重、紧凑/标准清晰度分档)、Windows UI Automation 控件树、**Set-of-Marks 编号标图**、**Windows 内置 OCR** 以及可选本地 **Chromium CDP** 网页通道;截图坐标自动换算 DPI 缩放与多显示器偏移。
45
- - **连续完成几步,可复用为宏。** 「填字段 → 提交 → 等成功提示」可放入同一个 `computer_batch`;跑通的固定流程还能存为参数化动作宏一键重放。
46
- - **应用经验自动沉淀。** 内置 Word、Excel、Chrome、微信等应用技能笔记,打开对应应用时自动附带;输入框内也可直接 `@` 引用运行中的 Windows 窗口。
44
+ - **按需惰性感知 + 省 Token。** 支持窗口截图(画面未变自动去重、紧凑/标准清晰度分档)、Windows UI Automation 定向查询(`ui_elements({ query, role })`)与**增量 Diff(`diff: true`,重复观察最高省 94% 字符)**、**Set-of-Marks 编号标图**、**Windows 内置 OCR** 以及可选本地 **Chromium CDP** 严格单标签快车道。
45
+ - **确定性语义操作 + 参数化宏。** 支持 `ui_action` 幂等 UIA Pattern(`set_checked`、`expand`/`collapse`、`select`、`set_value`),「填字段 → 提交 → 等成功提示」可放入同一个 `computer_batch`;跑通的固定流程还能存为参数化动作宏一键重放。
46
+ - **生态协同与经验沉淀。** 内置 7 模块零依赖 C# Helper(系统自带 `csc.exe` ~350ms 编译);检测到已安装 [`@copylee/dsh-office`](https://github.com/copylee711/dsh-office) 时自动协同路由 Word/Excel/PPT 到原生 COM 后台编辑;设置页「应用技能」支持折叠搜索与弹窗编辑,输入框支持 `@` 引用运行中窗口。
47
47
 
48
48
  ## 操控期间,你仍然掌握主动权
49
49
 
50
50
  - **三档会话启用方式**:在 **设置 → 电脑控制** 可选「按会话开启(默认关闭)」「新会话默认开启」或「总是开启(隐藏输入框左下角「电脑控制」胶囊)」;也支持 `/cu on|off|toggle|status|reset|stop|revoke <应用>` 快捷控制。
51
- - **可见、可停、可接管**:开始操控后,屏幕四周亮起橙色光晕,迷你卡片上方显示思考内容、下方保留操作时间线;按 **Esc** 暂停/继续,点 **停止** 结束本轮,或直接在卡片上打字纠偏。
52
- - **内置安全边界与排障**:默认按应用授权,自动拦截密码管理器、密码框与命令解释器启动(`cmd`/`powershell`/`mshta` 等);设置页提供**一键检查更新**(并发探测 npmjs 与 npmmirror)及**一键导出脱敏诊断报告**。
51
+ - **实时接管感知 + 三档尺寸迷你卡片**:开始操控后,屏幕四周亮起橙色光晕,迷你进度卡片支持**紧凑 / 标准 / 详情**三档尺寸与按钮悬停中文提示,简短中间回复直接留在卡片内不闪弹主窗口;你随时可按 **Esc** 暂停,或直接用鼠标点击/滚轮/键盘接管——插件会自动将脱敏操作语义(控件名称、窗口、坐标,绝不记录密码与输入明文)实时同步给 AI,让它顺着你的意图继续。
52
+ - **多会话租约与纵深安全**:全工具覆盖单机桌面控制租约(防止多 Agent 并发互抢鼠标),统一拦截密码管理器、密码框(UIA `IsPassword` + Win32 `ES_PASSWORD`)、命令解释器启动及跨标签页 CDP 读取;内置 `pnpm run bench` 8 场景基准回归测试与一键导出脱敏诊断报告。
53
53
 
54
54
  正文一开始输出,就回到 DSH 对话阅读。可查看[暂停时的卡片](assets/demo-paused.png)和[任务结束的画面](assets/demo-complete.png)。授权范围、截图和剪贴板的处理规则见[数据与权限](docs/privacy.md)。
55
55
 
package/helper/Capture.cs CHANGED
@@ -111,30 +111,65 @@ namespace DshComputerUse
111
111
  * Wait until the screen stops changing: at least minMs, then until two
112
112
  * consecutive samples (quietMs apart in total) differ in under 0.2% of
113
113
  * the sampled pixels, or maxMs passes (videos, spinners).
114
+ * When waitForChange is true (explicit multi-second waits for async replies),
115
+ * never exit early until the screen actually updates relative to t=0, then
116
+ * settle cleanly as soon as the burst finishes (or user skips wait).
114
117
  */
115
118
  public static Dictionary<string, object> Settle(Dictionary<string, object> r)
116
119
  {
117
120
  int x = Args.Int(r, "x", 0), y = Args.Int(r, "y", 0), w = Args.Int(r, "width", 0), h = Args.Int(r, "height", 0);
118
121
  int minMs = Args.Int(r, "minMs", 300), maxMs = Args.Int(r, "maxMs", 2500), interval = Args.Int(r, "intervalMs", 120), quietMs = Args.Int(r, "quietMs", 240);
122
+ bool waitForChange = Args.Bool(r, "waitForChange", false);
123
+ int checkpointMs = Args.Int(r, "checkpointMs", 0);
124
+ int noChangeMaxMs = Args.Int(r, "noChangeMaxMs", 0);
119
125
  if (w <= 0 || h <= 0) throw new Exception("invalid settle rect");
120
126
  var watch = System.Diagnostics.Stopwatch.StartNew();
121
- byte[] prev = Sample(x, y, w, h);
127
+ byte[] initial = Sample(x, y, w, h);
128
+ byte[] prev = initial;
122
129
  long quietSince = -1;
130
+ long firstChangeAt = -1;
123
131
  bool stable = false;
132
+ bool skipped = false;
133
+ bool sawChange = false;
134
+ bool checkpoint = false;
124
135
  while (true)
125
136
  {
137
+ if (Overlay.SkipWaitRequested) { skipped = true; break; }
126
138
  Thread.Sleep(interval);
139
+ if (Overlay.SkipWaitRequested) { skipped = true; break; }
127
140
  byte[] cur = Sample(x, y, w, h);
128
141
  long now = watch.ElapsedMilliseconds;
129
- if (Changed(prev, cur) < 0.002) { if (quietSince < 0) quietSince = now - interval; }
142
+ bool stepDiff = Changed(prev, cur) >= 0.002;
143
+ if (stepDiff || (!sawChange && Changed(initial, cur) >= 0.002))
144
+ {
145
+ if (!sawChange) { sawChange = true; firstChangeAt = now; }
146
+ }
147
+ if (!stepDiff) { if (quietSince < 0) quietSince = now - interval; }
130
148
  else quietSince = -1;
131
149
  prev = cur;
132
- if (now >= minMs && quietSince >= 0 && now - quietSince >= quietMs) { stable = true; break; }
150
+ if (now >= minMs && quietSince >= 0 && now - quietSince >= quietMs && (!waitForChange || sawChange))
151
+ {
152
+ stable = true;
153
+ break;
154
+ }
155
+ if (sawChange && checkpointMs > 0 && firstChangeAt >= 0 && now - firstChangeAt >= checkpointMs)
156
+ {
157
+ checkpoint = true;
158
+ break;
159
+ }
160
+ if (waitForChange && !sawChange && noChangeMaxMs > 0 && now >= noChangeMaxMs)
161
+ {
162
+ checkpoint = true;
163
+ break;
164
+ }
133
165
  if (now >= maxMs) break;
134
166
  }
135
167
  var d = new Dictionary<string, object>();
136
168
  d["ms"] = (int)watch.ElapsedMilliseconds;
137
169
  d["stable"] = stable;
170
+ d["changed"] = sawChange;
171
+ if (checkpoint) d["checkpoint"] = true;
172
+ if (skipped) d["skipped"] = true;
138
173
  return d;
139
174
  }
140
175
 
package/helper/Native.cs CHANGED
@@ -42,6 +42,16 @@ namespace DshComputerUse
42
42
  [DllImport("user32.dll")] public static extern bool SetCursorPos(int x, int y);
43
43
  [DllImport("user32.dll")] public static extern bool GetCursorPos(out POINT p);
44
44
  [DllImport("user32.dll")] public static extern uint MapVirtualKey(uint code, uint mapType);
45
+ [StructLayout(LayoutKind.Sequential)]
46
+ public struct ICONINFO { public bool fIcon; public int xHotspot; public int yHotspot; public IntPtr hbmMask; public IntPtr hbmColor; }
47
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO piconinfo);
48
+ [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr CreateIconIndirect(ref ICONINFO piconinfo);
49
+ [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr CopyIcon(IntPtr hIcon);
50
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool DestroyIcon(IntPtr hIcon);
51
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool SetSystemCursor(IntPtr hcur, uint id);
52
+ [DllImport("user32.dll", SetLastError = true)] public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, IntPtr pvParam, uint fWinIni);
53
+ public const uint SPI_SETCURSORS = 0x0057;
54
+ public const uint OCR_NORMAL = 32512, OCR_IBEAM = 32513, OCR_HAND = 32649;
45
55
 
46
56
  public delegate bool MonitorEnumProc(IntPtr hMonitor, IntPtr hdc, ref RECT rect, IntPtr data);
47
57
  [DllImport("user32.dll")] public static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr clip, MonitorEnumProc proc, IntPtr data);