@copylee/dsh-computer-use 0.4.0 → 0.5.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
@@ -18,6 +18,7 @@
18
18
  | 你随时可以插手 | 你用键盘打字时 AI 自动暂停,停手 1.5 秒后继续(单按 Shift / Ctrl 等修饰键不算);你切换或打开了别的窗口,AI 下一步不会盲目执行,而是先看新截图再决定。你只是点进 DSH 卡片看对话时不算切换,AI 的按键会自动回到它正在操作的窗口。鼠标移动不会触发,避免误触 |
19
19
  | 文字输入 | Unicode 直接输入,不受输入法状态影响。短文字逐字打出来;长文本默认“流式”:按段落逐段粘贴(代码块不拆开),看得到一段段出现,又不会被 Typora、Obsidian、Word 的自动补全打乱。可在设置里改成逐字输入或一次粘贴。剪贴板文本统一为 CRLF,不丢换行 |
20
20
  | 不弄乱剪贴板 | 插件写入剪贴板的内容不进 Windows 剪贴板历史(Win+V)和云剪贴板;粘贴后按原样恢复你的剪贴板(图片、文件也保留);AI 用 `clipboard` 工具写过剪贴板的,本轮结束后自动还原(期间你自己复制了新内容则不动) |
21
+ | 应用技能 | AI 对各个应用的操作笔记,每个应用一份 Markdown(`~/.dsh/computer-use-skills/`)。AI 摸索清楚一个不熟悉的应用后用 `app_skill` 自己记下来(只记操作规律,不记任务内容),以后 `open_application` 打开该应用时自动附带,不占系统提示。自带 Word、PowerPoint、Excel、Chrome、文件资源管理器、Obsidian、Typora、微信、QQ、记事本十份内置技能(含各应用的快捷键清单,PowerPoint 含原生公式和动画的做法);AI 在内置技能上追加的笔记单独保存,内置部分随插件更新;设置页“应用技能”里可以查看、修改、删除、新建,内置技能可覆盖和恢复 |
21
22
  | 打开应用 | `open_application` 同时搜索开始菜单和桌面快捷方式(含公共桌面),便携软件也能按名字打开。已经关到系统托盘的应用(QQ、微信等)会像人一样点托盘图标把窗口叫回来(必要时先展开“显示隐藏的图标”),不会再启动第二个实例、也不会重复登录;你明确要多开时(如微信双开)AI 会用 `new_instance` 另开一个。任务结束时 AI 会收拾现场:关掉自己打开、你不再需要的窗口,`windows tidy` 把原本最小化或在托盘里的应用重新最小化 |
22
23
  | 看不见图的模型 | `ui_elements` 用 Windows UI Automation 列出可点击元素和坐标,纯文本模型也能用 |
23
24
  | 零原生依赖 | 首次使用时用 Windows 自带的 .NET Framework `csc.exe` 编译一个小 helper(约 1 秒,之后缓存),不需要 node-gyp、不受 Electron ABI 影响 |
@@ -54,6 +55,7 @@ dsh plugin --profile web add @copylee/dsh-computer-use@latest
54
55
  |---|---|
55
56
  | `computer` | 单个动作:`screenshot` `left_click` `double_click` `triple_click` `right_click` `middle_click` `mouse_move` `left_click_drag` `left_mouse_down/up` `scroll` `type` `key` `hold_key` `wait` `zoom` `cursor_position`(沿用通用 computer-use 动作命名,模型上手即会) |
56
57
  | `computer_batch` | 顺序执行多个动作,遇错即停,最后回传一张截图 |
58
+ | `app_skill` | 应用技能:`list` 列出、`read` 读取、`append` 追加、`write` 重写某个应用的操作笔记(单份上限 4000 字) |
57
59
  | `open_application` | 按名称(“Chrome”“记事本”“微信”)、exe 路径或网址打开应用;已运行则切到前台,在托盘里则从托盘图标恢复 |
58
60
  | `windows` | 列出窗口(含进程 exe 名)、聚焦 / 最小化 / 最大化 / 还原 / 关闭 |
59
61
  | `ui_elements` | 前台窗口的 UI Automation 元素列表,坐标已换算到截图坐标系 |
@@ -0,0 +1,11 @@
1
+ ---
2
+ app: Chrome
3
+ match: Chrome, Google Chrome, chrome.exe
4
+ summary: 地址栏导航、标签页、页内查找、快捷键
5
+ ---
6
+ - 打开网址最快的方式:ctrl+l 聚焦地址栏,输入完整网址,Return。不要去点书签或一层层点链接;知道确切地址就直接输入(例如 GitHub 仓库的 PR 列表是 仓库地址/pulls)。
7
+ - 页面内容多时用 ctrl+f 页内查找定位,Return / shift+Return 跳到下一个 / 上一个,Escape 关闭查找条。
8
+ - 看长页面:Page Down / Page Up 翻页,End / Home 到底部 / 顶部;也可以 scroll。
9
+ - 用户的 Chrome 通常已经开着很多标签页:新任务用 ctrl+t 开新标签页,不要占用或关闭用户原有的标签页;自己开的标签页用完 ctrl+w 关掉。
10
+ - 登录、支付、验证码交给用户处理。
11
+ - 快捷键:ctrl+t 新标签页;ctrl+w 关闭标签页;ctrl+shift+t 恢复刚关闭的标签页;ctrl+Tab / ctrl+shift+Tab 下一个 / 上一个标签页;ctrl+1…8 切到第 N 个标签页;ctrl+l 地址栏;alt+Left / alt+Right 后退 / 前进;F5 或 ctrl+r 刷新,ctrl+shift+r 强制刷新;ctrl+f 页内查找;ctrl++ / ctrl+- / ctrl+0 放大 / 缩小 / 恢复缩放;ctrl+j 下载内容;ctrl+h 历史记录;ctrl+shift+n 无痕窗口;F12 开发者工具。
@@ -0,0 +1,10 @@
1
+ ---
2
+ app: Excel
3
+ match: Excel, EXCEL.EXE
4
+ summary: 单元格录入、公式、另存为、快捷键
5
+ ---
6
+ - 定位单元格最稳的方式:点左上角“名称框”(或按 ctrl+g),输入地址如 B3,Return。
7
+ - 录入:输入内容后 Return 到下一行,Tab 到右边一格;一行数据用 Tab 分隔、行末 Return,可以整块连续输入。F2 进入当前单元格编辑。
8
+ - 公式以 = 开头,如 =SUM(A1:A10)、=AVERAGE(B2:B9);输入后 Return 确认,Escape 取消。
9
+ - 另存为:F12 → alt+n → ctrl+a → 输入完整路径(含 .xlsx)→ Return。
10
+ - 快捷键:ctrl+Home 回到 A1;ctrl+End 到已用区域末尾;ctrl+方向键 跳到数据边缘,加 shift 则选中;ctrl+a 选中当前数据区域;ctrl+space 选整列,shift+space 选整行;ctrl+c / ctrl+v / ctrl+x 复制 / 粘贴 / 剪切;ctrl+z / ctrl+y 撤销 / 重做;ctrl+d 向下填充,ctrl+r 向右填充;ctrl+1 设置单元格格式;ctrl+b 粗体;ctrl+shift+l 筛选开关;ctrl+t 转为表格;alt+= 自动求和;ctrl+; 输入当天日期;ctrl+Page Down / ctrl+Page Up 切换工作表;shift+F11 新建工作表;ctrl+f 查找,ctrl+h 替换;ctrl+s 保存;ctrl+w 关闭工作簿。
@@ -0,0 +1,8 @@
1
+ ---
2
+ app: 文件资源管理器
3
+ match: 文件资源管理器, File Explorer, 资源管理器, explorer
4
+ summary: 直接输入路径、新建与重命名、快捷键
5
+ ---
6
+ - 去某个文件夹:ctrl+l(或 alt+d)聚焦地址栏,输入完整路径,Return。不要一层层双击。
7
+ - 只是查看、复制、移动、重命名文件,用 shell 命令更快更准;只有用户想看到窗口里的结果时才操作资源管理器。
8
+ - 快捷键:win+e 打开新窗口;ctrl+l 地址栏;ctrl+e 或 ctrl+f 搜索框;alt+Up 上一级,alt+Left / alt+Right 后退 / 前进;ctrl+shift+n 新建文件夹;F2 重命名;Delete 删到回收站;ctrl+c / ctrl+x / ctrl+v 复制 / 剪切 / 粘贴;ctrl+a 全选;alt+Return 属性;F5 刷新;ctrl+t 新标签页,ctrl+w 关闭标签页。
@@ -0,0 +1,9 @@
1
+ ---
2
+ app: 记事本
3
+ match: 记事本, Notepad, notepad.exe
4
+ summary: 标签页、核对字数、关闭未保存内容
5
+ ---
6
+ - Windows 11 的记事本是多标签页的:ctrl+n 新建标签页,ctrl+w 关闭当前标签页;重新打开时会恢复上次未保存的标签页,别动用户原有的标签页。
7
+ - 状态栏显示“行 X,列 Y”和字符数,可以用它核对输入是否完整。
8
+ - 关闭有未保存内容的标签页会询问是否保存;任务不要求保存时选“不保存”。
9
+ - 快捷键:ctrl+n 新标签页;ctrl+shift+n 新窗口;ctrl+w 关闭标签页;ctrl+Tab 切换标签页;ctrl+s 保存,ctrl+shift+s 另存为;ctrl+f 查找,ctrl+h 替换;ctrl+g 转到行;ctrl+a 全选;ctrl+Home / ctrl+End 开头 / 结尾。
@@ -0,0 +1,12 @@
1
+ ---
2
+ app: Obsidian
3
+ match: Obsidian, obsidian.exe
4
+ summary: 新建笔记、Markdown 打字规律
5
+ ---
6
+ - 新建或打开笔记:ctrl+o 打开快速切换,输入笔记名,Return;不存在的名字会直接创建。ctrl+n 新建无标题笔记。
7
+ - 笔记是库目录下的 .md 纯文本文件,写完可以直接读文件核对内容(不要用写文件代替打字)。
8
+ - 长文本直接用 type 输入(按段落流式粘贴),$...$、$$...$$、**粗体**、标题都按原文进入,不会被自动补全打乱。
9
+ - 列表会自动续行:在“- 甲”后按 Return 会自动出现下一个“- ”。逐行打字时只在第一项写“- ”,后面各项直接写内容;连按两次 Return 退出列表。
10
+ - 标题(## )前最好留一个空行,否则渲染可能和上一段粘在一起。
11
+ - ctrl+f 在当前笔记内查找,ctrl+Home 回到开头。
12
+ - 快捷键:ctrl+o 快速切换 / 新建;ctrl+n 新建笔记;ctrl+p 命令面板;ctrl+e 切换编辑 / 阅读视图;ctrl+f 当前笔记内查找,ctrl+shift+f 全库搜索;ctrl+b / ctrl+i 粗体 / 斜体;ctrl+k 插入链接;ctrl+w 关闭当前标签页;ctrl+Home / ctrl+End 笔记开头 / 结尾;ctrl+z 撤销;ctrl+, 设置。
@@ -0,0 +1,16 @@
1
+ ---
2
+ app: PowerPoint
3
+ match: PowerPoint, POWERPNT.EXE
4
+ summary: 建页、原生公式、动画与切换、插图、另存为、快捷键
5
+ ---
6
+ - 启动后在开始页点“空白演示文稿”。ctrl+m 新建幻灯片(沿用当前版式);正文框里 Tab / shift+Tab 升降大纲级别。
7
+ - 原生公式(不要把公式当普通文本打):光标放在文本框里 → “插入”选项卡 → 最右侧“公式”(π 图标),出现“在此处键入公式”。用 type 输入线性格式,分子分母各自加括号,然后点“公式”选项卡“转换”组里的“专业”,整条公式一次排成原生样式。
8
+ - 写法示例:`dy/dx=-(F_x (x,y))/(F_y (x,y))`、`(\partial F)/(\partial y)\ne 0`、`x^2+y^2=1`、`\sqrt(1-x^2)`、`\sum_(i=1)^n a_i`、`F\in C^1`、`\nabla F=(F_x,F_y)`、`\int_a^b f(x)dx`、`\lim_(x\to 0)`。希腊字母用 `\alpha` `\delta` 等,后面跟一个空格。
9
+ - 不要输入 LaTeX 的 `\frac{}{}`:边打边被套用格式,会乱掉,“LaTeX 转换”按钮也救不回来。
10
+ - 公式写完按 End 再 Return 回到普通文本的新段落;alt+= 在本机不起作用,走功能区。
11
+ - 动画:先选中对象。给整个正文框按段落加动画,要选中文本框本身(在文字里按 Escape,直到四周出现控制点),再到“动画”选项卡点效果(出现 / 淡化 / 飞入 / 浮入 / 擦除);如果只是光标停在某一段,只有那一段会加上动画。加好后段落左侧出现序号 1、2、3。
12
+ - 页面切换:“切换”选项卡选一个效果(淡入/淡出、推入、平滑),再点“应用到全部”。
13
+ - 小写字母开头的段落会被自动改成大写(f → F);写完用 ctrl+h 替换改回。
14
+ - 插图:“插入”→“图片”→“此设备”,菜单弹出后等约 1 秒再点;在对话框里 alt+n,输入图片完整路径,Return。过大的图会自动缩到铺满幻灯片;想要精确尺寸就先把图片文件做成目标大小。图片挡住文字时,选中图片,“图片格式”→“下移一层”。
15
+ - 另存为:F12 → alt+n → ctrl+a → 输入完整路径(含 .pptx)→ Return。
16
+ - 快捷键:ctrl+m 新幻灯片;ctrl+d 复制所选幻灯片或对象;ctrl+z / ctrl+y 撤销 / 重做;ctrl+b / ctrl+i / ctrl+u 粗体 / 斜体 / 下划线;ctrl+e / ctrl+l / ctrl+r 居中 / 左对齐 / 右对齐;ctrl+] / ctrl+[ 增大 / 减小字号;ctrl+a 全选当前框内文字或当前页对象;ctrl+g 组合;Page Down / Page Up 下一页 / 上一页;ctrl+Home / ctrl+End 第一页 / 最后一页(焦点在缩略图栏或幻灯片上、不在文本框里时);F5 从头放映,shift+F5 从当前页放映,Escape 退出放映;ctrl+f 查找,ctrl+h 替换;ctrl+s 保存;ctrl+w 关闭当前演示文稿。
@@ -0,0 +1,12 @@
1
+ ---
2
+ app: QQ
3
+ match: QQ, QQ.exe
4
+ summary: 从托盘恢复、群文件批量另存
5
+ ---
6
+ - QQ 关闭后缩到系统托盘,用 open_application 恢复。绝对不要再启动一个 QQ(会弹出第二个登录窗),也不要用 shell 显示它的隐藏窗口(界面会卡死)。
7
+ - QQ 的界面不暴露界面元素(ui_elements 为空),只能靠截图操作。
8
+ - 找群:点左上角搜索框输入群名,点结果进入。
9
+ - 群文件:进入群后点聊天窗口右上角的“群文件”图标,会打开单独的“群文件”窗口,文件按上传时间排列。
10
+ - 批量保存:在群文件窗口里选中多个文件,右键选“另存为”,在对话框里输入目标文件夹的完整路径后确认。
11
+ - 已下载的文件在:文档\Tencent Files\<QQ号>\nt_qq\nt_data\File\。
12
+ - 快捷键:在输入框里 Return 或 ctrl+Return 发送(以用户设置为准,发送前先确认用户确实要发);Escape 关闭当前菜单或弹窗。
@@ -0,0 +1,10 @@
1
+ ---
2
+ app: Typora
3
+ match: Typora, typora.exe
4
+ summary: Markdown 打字规律、源码模式
5
+ ---
6
+ - 长 Markdown 文本直接用 type 输入:内容按段落粘贴进入,标题、列表、代码块会按原文正确渲染。
7
+ - 逐字敲 Markdown 符号会被自动补全(** 变成 ****、括号成对、列表自动续行),所以不要自己一个字符一个字符地敲格式符号。
8
+ - ctrl+/ 切换源码模式;在源码模式下看到的是原始 Markdown。
9
+ - 保存:ctrl+s,新文件会弹出另存为对话框,alt+n、ctrl+a 后输入完整路径再 Return。
10
+ - 快捷键:ctrl+n 新建;ctrl+s 保存,ctrl+shift+s 另存为;ctrl+1…6 标题 1…6,ctrl+0 正文;ctrl+b / ctrl+i 粗体 / 斜体;ctrl+shift+k 代码块,ctrl+shift+m 公式块,ctrl+t 表格,ctrl+k 链接;ctrl+f 查找,ctrl+h 替换;ctrl+Home / ctrl+End 文首 / 文末;ctrl+shift+l 侧边栏。
@@ -0,0 +1,12 @@
1
+ ---
2
+ app: 微信
3
+ match: 微信, WeChat, Weixin.exe
4
+ summary: 从托盘恢复、找群、保存群文件
5
+ ---
6
+ - 微信关闭后只是缩到系统托盘,用 open_application 恢复,不要再次启动(会要求重新登录)。
7
+ - 找聊天或群:点左上角搜索框,输入名称,在结果里点对应的群;搜索结果列表可能需要滚动。
8
+ - 看群里的文件:打开群后点右上角“…”(聊天信息),选“查找聊天内容”,再切到“文件”页签,可以按发送人筛选。
9
+ - 保存文件:在文件上右键,选“另存为...”,在对话框里 alt+n、ctrl+a,输入完整路径后 Return。左键单击文件会直接用默认程序打开它。
10
+ - 已接收过的文件在本地缓存:文档\xwechat_files\<微信号目录>\msg\file\<年-月>\,批量归档时可以直接从这里复制。
11
+ - 发送消息、撤回、删除属于不可逆操作,除非用户明确要求,否则先问。
12
+ - 快捷键:ctrl+f 搜索;在输入框里 Return 发送、ctrl+Return 换行(以用户设置为准,发送前先确认用户确实要发);Escape 关闭当前弹出的小窗口。
@@ -0,0 +1,12 @@
1
+ ---
2
+ app: Word
3
+ match: Word, winword.exe
4
+ summary: 新建文档、打字排版、另存为
5
+ ---
6
+ - 启动后停在开始页:点“空白文档”(或直接按 Return)进入文档,窗口会换成“文档1 - Word”。
7
+ - 保存:按 F12 直接打开经典“另存为”对话框,alt+n 聚焦文件名框,ctrl+a,输入完整路径(如 C:\Users\<用户>\Desktop\标题.docx),Return。不要点左侧文件夹导航,也不要三击文件名框(会只选中一部分,文件名被拼接)。
8
+ - 打字:以“一、”“1.”开头的段落按 Return 后会触发自动编号和缩进;想保留原样,回车后立刻 ctrl+z 一次撤销自动套用,或写完后 ctrl+a 再 ctrl+q 清除段落格式。
9
+ - 标题格式:ctrl+Home 到开头,shift+End 选中该行,ctrl+b 加粗,ctrl+] 逐级放大字号,ctrl+e 居中。不要去点功能区的字号框再打字,容易把选中的标题文字替换掉。
10
+ - 查找用 ctrl+f(左侧导航窗格),用完按 Escape 关闭。
11
+ - 快捷键:ctrl+n 新建;ctrl+s 保存;F12 另存为;ctrl+z / ctrl+y 撤销 / 重做;ctrl+b / ctrl+i / ctrl+u 粗体 / 斜体 / 下划线;ctrl+e / ctrl+l / ctrl+r / ctrl+j 居中 / 左对齐 / 右对齐 / 两端对齐;ctrl+] / ctrl+[ 增大 / 减小字号;ctrl+alt+1 / 2 / 3 标题 1 / 2 / 3,ctrl+shift+n 正文样式;ctrl+Return 分页;ctrl+Home / ctrl+End 文首 / 文末;shift+End 选到行尾,ctrl+shift+Down 选到段尾,ctrl+a 全选;ctrl+f 查找,ctrl+h 替换;ctrl+q 清除段落格式,ctrl+space 清除字符格式;ctrl+w 关闭文档。
12
+ - 原生公式:“插入”→“公式”,输入线性格式(如 `dy/dx=-(F_x)/(F_y)`、`x^2`、`\sqrt(x)`、`\sum_(i=1)^n a_i`),再点“公式”选项卡里的“专业”排版。
package/lib/client.js CHANGED
@@ -135,7 +135,7 @@ window.__ModuleLoader__.load({
135
135
  }
136
136
  //#endregion
137
137
  //#region lib/types/client/select.js
138
- const h$1 = react.createElement;
138
+ const h$2 = react.createElement;
139
139
  /** Menu appearance and fixed-position behavior follow dsh-free-search / dsh-proxy. */
140
140
  const selectCss = `
141
141
  .dshcu-select{box-sizing:border-box;width:100%;height:36px;padding:0 12px;display:flex;align-items:center;gap:8px;text-align:left;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.3));border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer}
@@ -206,7 +206,7 @@ window.__ModuleLoader__.load({
206
206
  react.useEffect(() => {
207
207
  list.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView({ block: "nearest" });
208
208
  }, [active, open]);
209
- return h$1("div", { style: { minWidth: 0 } }, h$1("button", {
209
+ return h$2("div", { style: { minWidth: 0 } }, h$2("button", {
210
210
  ref: trigger,
211
211
  type: "button",
212
212
  className: "dshcu-select",
@@ -248,31 +248,31 @@ window.__ModuleLoader__.load({
248
248
  choose(active);
249
249
  }
250
250
  }
251
- }, h$1("span", { style: {
251
+ }, h$2("span", { style: {
252
252
  flex: 1,
253
253
  minWidth: 0,
254
254
  overflow: "hidden",
255
255
  textOverflow: "ellipsis",
256
256
  whiteSpace: "nowrap"
257
- } }, options[selected]?.label), h$1("svg", {
257
+ } }, options[selected]?.label), h$2("svg", {
258
258
  width: 14,
259
259
  height: 14,
260
260
  viewBox: "0 0 16 16",
261
261
  "aria-hidden": true,
262
262
  style: { transform: open ? "rotate(180deg)" : void 0 }
263
- }, h$1("path", {
263
+ }, h$2("path", {
264
264
  d: "M4 6l4 4 4-4",
265
265
  fill: "none",
266
266
  stroke: "currentColor",
267
267
  strokeWidth: 1.6
268
- }))), open ? h$1("div", {
268
+ }))), open ? h$2("div", {
269
269
  ref: list,
270
270
  id: `${id}-list`,
271
271
  role: "listbox",
272
272
  "aria-label": label,
273
273
  className: "dshcu-menu",
274
274
  style: pos
275
- }, ...options.map((option, i) => h$1("div", {
275
+ }, ...options.map((option, i) => h$2("div", {
276
276
  key: option.value,
277
277
  id: `${id}-${i}`,
278
278
  role: "option",
@@ -283,12 +283,12 @@ window.__ModuleLoader__.load({
283
283
  onPointerMove: () => setActive(i),
284
284
  onPointerDown: (e) => e.preventDefault(),
285
285
  onClick: () => choose(i)
286
- }, h$1("span", { style: { flex: 1 } }, option.label), h$1("span", { style: { width: 14 } }, i === selected ? h$1("svg", {
286
+ }, h$2("span", { style: { flex: 1 } }, option.label), h$2("span", { style: { width: 14 } }, i === selected ? h$2("svg", {
287
287
  width: 14,
288
288
  height: 14,
289
289
  viewBox: "0 0 16 16",
290
290
  "aria-hidden": true
291
- }, h$1("path", {
291
+ }, h$2("path", {
292
292
  d: "M3.5 8.5 6.5 11.5 12.5 4.5",
293
293
  fill: "none",
294
294
  stroke: "currentColor",
@@ -298,6 +298,245 @@ window.__ModuleLoader__.load({
298
298
  })) : null)))) : null);
299
299
  }
300
300
  //#endregion
301
+ //#region lib/types/client/skills-card.js
302
+ /**
303
+ * "应用技能" card: the per-app notes the agent keeps (see ../skills.ts). The
304
+ * user can read, edit, add and delete them here; built-in skills can be
305
+ * overridden and restored.
306
+ */
307
+ const SKILLS_ROUTE = "/api/dsh-computer-use/skills";
308
+ const MAX_CHARS = 4e3;
309
+ const h$1 = react.createElement;
310
+ function SkillsCard({ S }) {
311
+ const [skills, setSkills] = react.useState(null);
312
+ const [dir, setDir] = react.useState("");
313
+ const [draft, setDraft] = react.useState(null);
314
+ const [busy, setBusy] = react.useState(false);
315
+ const [note, setNote] = react.useState(null);
316
+ const call = react.useCallback(async (body) => {
317
+ setBusy(true);
318
+ try {
319
+ const result = await (await fetch(SKILLS_ROUTE, body ? {
320
+ method: "POST",
321
+ credentials: "same-origin",
322
+ headers: { "content-type": "application/json" },
323
+ body: JSON.stringify(body)
324
+ } : { credentials: "same-origin" })).json();
325
+ if (!result.ok) throw new Error(result.error ?? "请求失败");
326
+ setSkills(result.skills ?? []);
327
+ setDir(result.dir ?? "");
328
+ return true;
329
+ } catch (error) {
330
+ setNote({
331
+ kind: "error",
332
+ text: error.message
333
+ });
334
+ return false;
335
+ } finally {
336
+ setBusy(false);
337
+ }
338
+ }, []);
339
+ react.useEffect(() => {
340
+ call();
341
+ }, [call]);
342
+ const edit = (skill) => {
343
+ setNote(null);
344
+ setDraft({
345
+ id: skill.id,
346
+ app: skill.app,
347
+ match: skill.match.join(", "),
348
+ summary: skill.summary,
349
+ content: skill.content,
350
+ isNew: false
351
+ });
352
+ };
353
+ const save = async () => {
354
+ if (!draft) return;
355
+ setNote(null);
356
+ if (await call({
357
+ op: "save",
358
+ id: draft.isNew ? "" : draft.id,
359
+ app: draft.app,
360
+ match: draft.match,
361
+ summary: draft.summary,
362
+ content: draft.content
363
+ })) {
364
+ setDraft(null);
365
+ setNote({
366
+ kind: "ok",
367
+ text: "已保存"
368
+ });
369
+ }
370
+ };
371
+ const remove = async (skill) => {
372
+ setNote(null);
373
+ if (await call({
374
+ op: "delete",
375
+ id: skill.id
376
+ })) {
377
+ if (draft?.id === skill.id) setDraft(null);
378
+ setNote({
379
+ kind: "ok",
380
+ text: `已删除“${skill.app}”`
381
+ });
382
+ }
383
+ };
384
+ const reset = async (skill) => {
385
+ setNote(null);
386
+ if (await call({
387
+ op: "reset",
388
+ id: skill.id
389
+ })) {
390
+ if (draft?.id === skill.id) setDraft(null);
391
+ setNote({
392
+ kind: "ok",
393
+ text: `已恢复“${skill.app}”的内置版本`
394
+ });
395
+ }
396
+ };
397
+ const row = {
398
+ display: "flex",
399
+ gap: 10,
400
+ alignItems: "center",
401
+ padding: "8px 0",
402
+ borderTop: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.18))"
403
+ };
404
+ const small = {
405
+ ...S.secondary,
406
+ padding: "4px 10px",
407
+ fontSize: 12
408
+ };
409
+ const tag = {
410
+ fontSize: 11,
411
+ padding: "1px 7px",
412
+ borderRadius: 999,
413
+ border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.3))",
414
+ color: "var(--dsw-alias-label-tertiary, #888)",
415
+ whiteSpace: "nowrap"
416
+ };
417
+ const invalid = draft !== null && (draft.app.trim() === "" || draft.content.trim() === "" || draft.content.length > MAX_CHARS);
418
+ return h$1("section", { style: S.card }, h$1("h3", { style: S.cardTitle }, "应用技能"), h$1("p", { style: S.hint }, "AI 对各个应用的操作笔记:每个应用一份,AI 摸索清楚一个不熟悉的应用后会自己记下来,以后打开这个应用时自动读取,不占用系统提示。你可以在这里查看、修改、删除或新建。"), skills === null ? h$1("p", { style: S.hint }, busy ? "正在读取…" : "无法读取应用技能。") : skills.length === 0 ? h$1("p", { style: S.hint }, "还没有应用技能。") : h$1("div", null, ...skills.map((skill) => h$1("div", {
419
+ key: skill.id,
420
+ style: row
421
+ }, h$1("div", { style: {
422
+ flex: 1,
423
+ minWidth: 0
424
+ } }, h$1("div", { style: {
425
+ fontSize: 13,
426
+ fontWeight: 600,
427
+ display: "flex",
428
+ gap: 8,
429
+ alignItems: "center"
430
+ } }, skill.app, h$1("span", { style: tag }, skill.source === "builtin" ? "内置" : skill.overrides ? "已修改" : "AI / 自定义")), h$1("div", { style: {
431
+ ...S.hint,
432
+ overflow: "hidden",
433
+ textOverflow: "ellipsis",
434
+ whiteSpace: "nowrap"
435
+ } }, `${skill.summary || "(无摘要)"} · ${skill.content.length} 字`)), h$1("button", {
436
+ type: "button",
437
+ style: small,
438
+ disabled: busy,
439
+ onClick: () => edit(skill)
440
+ }, "查看 / 编辑"), skill.overrides ? h$1("button", {
441
+ type: "button",
442
+ style: small,
443
+ disabled: busy,
444
+ onClick: () => {
445
+ reset(skill);
446
+ }
447
+ }, "恢复内置") : null, h$1("button", {
448
+ type: "button",
449
+ style: small,
450
+ disabled: busy,
451
+ onClick: () => {
452
+ remove(skill);
453
+ }
454
+ }, "删除")))), draft === null ? null : h$1("div", { style: {
455
+ display: "grid",
456
+ gap: 10,
457
+ paddingTop: 4
458
+ } }, h$1("div", { style: S.grid2 }, h$1("label", { style: S.label }, "应用名称", h$1("input", {
459
+ style: S.input,
460
+ value: draft.app,
461
+ disabled: !draft.isNew,
462
+ maxLength: 60,
463
+ placeholder: "如 Obsidian",
464
+ onChange: (e) => setDraft({
465
+ ...draft,
466
+ app: e.target.value
467
+ })
468
+ })), h$1("label", { style: S.label }, "匹配的程序(逗号分隔)", h$1("input", {
469
+ style: S.input,
470
+ value: draft.match,
471
+ maxLength: 200,
472
+ placeholder: "如 Obsidian, obsidian.exe",
473
+ onChange: (e) => setDraft({
474
+ ...draft,
475
+ match: e.target.value
476
+ })
477
+ }))), h$1("label", { style: S.label }, "摘要", h$1("input", {
478
+ style: S.input,
479
+ value: draft.summary,
480
+ maxLength: 80,
481
+ placeholder: "几个词说明这份技能讲什么",
482
+ onChange: (e) => setDraft({
483
+ ...draft,
484
+ summary: e.target.value
485
+ })
486
+ })), h$1("label", { style: S.label }, `内容(${draft.content.length} / ${MAX_CHARS} 字)`, h$1("textarea", {
487
+ style: {
488
+ ...S.input,
489
+ minHeight: 200,
490
+ resize: "vertical",
491
+ fontFamily: "inherit",
492
+ lineHeight: 1.55
493
+ },
494
+ value: draft.content,
495
+ placeholder: "- 一条一条写操作规律:入口在哪、快捷键、容易踩的坑",
496
+ onChange: (e) => setDraft({
497
+ ...draft,
498
+ content: e.target.value
499
+ })
500
+ })), h$1("div", { style: S.actions }, h$1("button", {
501
+ type: "button",
502
+ style: {
503
+ ...S.primary,
504
+ opacity: busy || invalid ? .5 : 1
505
+ },
506
+ disabled: busy || invalid,
507
+ onClick: () => {
508
+ save();
509
+ }
510
+ }, "保存技能"), h$1("button", {
511
+ type: "button",
512
+ style: S.secondary,
513
+ disabled: busy,
514
+ onClick: () => setDraft(null)
515
+ }, "取消"), draft.content.length > MAX_CHARS ? h$1("span", { style: S.error }, "内容过长,请精简") : null)), h$1("div", { style: S.actions }, draft === null ? h$1("button", {
516
+ type: "button",
517
+ style: S.secondary,
518
+ disabled: busy,
519
+ onClick: () => {
520
+ setNote(null);
521
+ setDraft({
522
+ id: "",
523
+ app: "",
524
+ match: "",
525
+ summary: "",
526
+ content: "",
527
+ isNew: true
528
+ });
529
+ }
530
+ }, "新建技能") : null, h$1("button", {
531
+ type: "button",
532
+ style: S.secondary,
533
+ disabled: busy,
534
+ onClick: () => {
535
+ call();
536
+ }
537
+ }, "刷新"), note === null ? null : h$1("span", { style: note.kind === "ok" ? S.ok : S.error }, note.text)), dir ? h$1("p", { style: S.hint }, `保存位置:${dir}(每个应用一个 .md 文件,也可以直接用编辑器改)。删除内置技能后,新建同名技能即可重新启用。`) : null);
538
+ }
539
+ //#endregion
301
540
  //#region lib/types/client/index.js
302
541
  /**
303
542
  * Browser half: the "电脑控制" (Computer use) section in Settings. It reads the
@@ -876,7 +1115,7 @@ window.__ModuleLoader__.load({
876
1115
  error: errors.jpegQuality,
877
1116
  disabled,
878
1117
  onChange: (value) => edit("jpegQuality", value)
879
- })), h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。默认值(最长边 1366、1.15 百万像素)适合大多数模型。")), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "截图缓存"), h("p", { style: S.hint }, cache === null ? cacheBusy ? "正在统计…" : "无法统计截图缓存。" : !cache.ok ? `统计失败:${cache.error ?? ""}` : `本插件的截图共 ${cache.count} 张,占用 ${mb(cache.bytes)};其中 ${cache.orphans} 张(${mb(cache.orphanBytes)})所属会话已删除,可以安全清理。`), h("p", { style: S.hint }, "截图作为附件保存在会话历史里。仍在会话中的截图不会被删除:删除后继续那个会话会直接报错。删除会话后,它留下的截图会在启动 DeepSeek Harness 几分钟后及之后每 12 小时自动清理,也可以在这里立即清理。"), h("div", { style: S.actions }, h("button", {
1118
+ })), h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。默认值(最长边 1366、1.15 百万像素)适合大多数模型。")), h(SkillsCard, { S }), h("section", { style: S.card }, h("h3", { style: S.cardTitle }, "截图缓存"), h("p", { style: S.hint }, cache === null ? cacheBusy ? "正在统计…" : "无法统计截图缓存。" : !cache.ok ? `统计失败:${cache.error ?? ""}` : `本插件的截图共 ${cache.count} 张,占用 ${mb(cache.bytes)};其中 ${cache.orphans} 张(${mb(cache.orphanBytes)})所属会话已删除,可以安全清理。`), h("p", { style: S.hint }, "截图作为附件保存在会话历史里。仍在会话中的截图不会被删除:删除后继续那个会话会直接报错。删除会话后,它留下的截图会在启动 DeepSeek Harness 几分钟后及之后每 12 小时自动清理,也可以在这里立即清理。"), h("div", { style: S.actions }, h("button", {
880
1119
  type: "button",
881
1120
  style: {
882
1121
  ...S.secondary,
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@ import { createHash, randomUUID } from "node:crypto";
3
3
  import z from "@deepseek-ai/schemastery";
4
4
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
5
5
  import { execFile, spawn } from "node:child_process";
6
- import { existsSync } from "node:fs";
6
+ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
7
7
  import { chmod, mkdir, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
8
8
  import { homedir, tmpdir } from "node:os";
9
9
  import { join } from "node:path";
@@ -1616,7 +1616,7 @@ var OverlayController = class {
1616
1616
  //#region lib/types/prompt.js
1617
1617
  function promptText(mode) {
1618
1618
  return `# Computer use (Windows desktop)
1619
- You can see and operate the user's Windows computer with the computer, computer_batch, open_application, windows, ui_elements and clipboard tools.
1619
+ 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.
1620
1620
  ${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.
1621
1621
  - 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).
1622
1622
  - 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.
@@ -1625,6 +1625,7 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
1625
1625
  - Prefer reliable keyboard shortcuts (ctrl+l for a browser address bar, ctrl+s, alt+F4, ctrl+t). Click the center of targets. When text is too small to read, zoom once on a generous region that contains everything you need (zooming step by step wastes calls).
1626
1626
  - Actions return a fresh screenshot taken once the screen stops changing (page loads included, up to a few seconds), so you rarely need wait. If something is still loading, use wait: it also returns a screenshot, so never follow it with a separate screenshot call.
1627
1627
  - 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.
1628
+ - 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.
1628
1629
  - 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.
1629
1630
  - Be efficient: every tool call costs the user several seconds. Put predictable sequences (click a field, type, press Return; open a menu and pick an item you can already see) into one computer_batch. Avoid shell commands for things you can see on screen.
1630
1631
  - 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.
@@ -1633,6 +1634,208 @@ ${mode === "per-app" ? "- Before acting on an app, call request_access once with
1633
1634
  - The user sees an orange border and can press Esc to pause you at any time. If they pause, type on the keyboard or switch windows, you wait; when an action reports it was not performed, re-check the screen instead of repeating it blindly.`;
1634
1635
  }
1635
1636
  //#endregion
1637
+ //#region lib/types/skills.js
1638
+ /**
1639
+ * App skills: short notes on how to operate one application, kept by the agent
1640
+ * (and editable by the user) as one Markdown file per app. Only a one-line
1641
+ * catalog goes into the system prompt; the notes themselves are handed over
1642
+ * when the app is opened, or read on demand.
1643
+ *
1644
+ * File format (front matter is optional):
1645
+ * ---
1646
+ * app: Obsidian
1647
+ * match: obsidian.exe, obsidian
1648
+ * summary: 打字规律、新建笔记
1649
+ * ---
1650
+ * - notes...
1651
+ *
1652
+ * The plugin ships a few built-in skills; a user file with the same id
1653
+ * overrides one, and `disabled: true` hides it.
1654
+ */
1655
+ /** Notes longer than this must be condensed before more is added. */
1656
+ const SKILL_MAX_CHARS = 4e3;
1657
+ /** Host processes shared by many apps: never a way to recognise one app. */
1658
+ const GENERIC_HOSTS = /^(applicationframehost|explorer|msedgewebview2|javaw?|python\w*|electron)(\.exe)?$/i;
1659
+ function skillId(app) {
1660
+ return app.trim().toLowerCase().replace(/\.exe$/, "").replace(/[\\/:*?"<>|\s.]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "app";
1661
+ }
1662
+ function parseSkill(text, fallbackApp) {
1663
+ const out = {
1664
+ app: fallbackApp,
1665
+ match: [],
1666
+ summary: "",
1667
+ content: text.trim(),
1668
+ disabled: false,
1669
+ extend: false
1670
+ };
1671
+ const front = /^?---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text);
1672
+ if (!front) return out;
1673
+ out.content = text.slice(front[0].length).trim();
1674
+ for (const line of front[1].split(/\r?\n/)) {
1675
+ const pair = /^([a-z]+)\s*:\s*(.*)$/i.exec(line.trim());
1676
+ if (!pair) continue;
1677
+ const key = pair[1].toLowerCase();
1678
+ const value = pair[2].trim();
1679
+ if (key === "app" && value) out.app = value;
1680
+ else if (key === "match") out.match = value.split(/[,,]/).map((item) => item.trim()).filter(Boolean);
1681
+ else if (key === "summary") out.summary = value;
1682
+ else if (key === "disabled") out.disabled = value === "true";
1683
+ else if (key === "extends") out.extend = value === "builtin";
1684
+ }
1685
+ return out;
1686
+ }
1687
+ function formatSkill(skill, disabled = false, extend = false) {
1688
+ const head = [
1689
+ `app: ${skill.app}`,
1690
+ `match: ${skill.match.join(", ")}`,
1691
+ `summary: ${skill.summary.replace(/\r?\n/g, " ")}`
1692
+ ];
1693
+ if (disabled) head.push("disabled: true");
1694
+ if (extend) head.push("extends: builtin");
1695
+ return `---\n${head.join("\n")}\n---\n${skill.content.trim()}\n`;
1696
+ }
1697
+ var SkillStore = class {
1698
+ builtinDir;
1699
+ userDir;
1700
+ constructor(builtinDir, userDir = join(process.env.DSH_HOME ?? join(homedir(), ".dsh"), "computer-use-skills")) {
1701
+ this.builtinDir = builtinDir;
1702
+ this.userDir = userDir;
1703
+ }
1704
+ load(dir, source) {
1705
+ const map = /* @__PURE__ */ new Map();
1706
+ if (!existsSync(dir)) return map;
1707
+ for (const name of readdirSync(dir)) {
1708
+ if (!name.toLowerCase().endsWith(".md")) continue;
1709
+ try {
1710
+ const path = join(dir, name);
1711
+ const parsed = parseSkill(readFileSync(path, "utf8"), name.slice(0, -3));
1712
+ const id = skillId(name.slice(0, -3));
1713
+ map.set(id, {
1714
+ id,
1715
+ app: parsed.app,
1716
+ match: parsed.match.length > 0 ? parsed.match : [parsed.app],
1717
+ summary: parsed.summary,
1718
+ content: parsed.content,
1719
+ source,
1720
+ overrides: false,
1721
+ updatedAt: statSync(path).mtimeMs,
1722
+ disabled: parsed.disabled,
1723
+ extend: parsed.extend
1724
+ });
1725
+ } catch {}
1726
+ }
1727
+ return map;
1728
+ }
1729
+ /** Every active skill, user files first in precedence, sorted by app name. */
1730
+ list() {
1731
+ const builtin = this.load(this.builtinDir, "builtin");
1732
+ const user = this.load(this.userDir, "user");
1733
+ const out = [];
1734
+ for (const [id, skill] of user) {
1735
+ if (skill.disabled) continue;
1736
+ const { disabled: _disabled, extend, ...rest } = skill;
1737
+ const base = extend ? builtin.get(id) : void 0;
1738
+ if (base) out.push({
1739
+ ...rest,
1740
+ app: base.app,
1741
+ match: [.../* @__PURE__ */ new Set([...base.match, ...rest.match])],
1742
+ summary: rest.summary || base.summary,
1743
+ content: `${base.content}\n${rest.content}`.trim(),
1744
+ overrides: true
1745
+ });
1746
+ else out.push({
1747
+ ...rest,
1748
+ overrides: builtin.has(id)
1749
+ });
1750
+ }
1751
+ for (const [id, skill] of builtin) {
1752
+ if (user.has(id)) continue;
1753
+ const { disabled: _disabled, extend: _extend, ...rest } = skill;
1754
+ out.push(rest);
1755
+ }
1756
+ return out.sort((a, b) => a.app.localeCompare(b.app, "zh-CN"));
1757
+ }
1758
+ get(id) {
1759
+ const wanted = skillId(id);
1760
+ return this.list().find((skill) => skill.id === wanted);
1761
+ }
1762
+ /** The skill for an app by name, or for a window by its executable. */
1763
+ find(name, win) {
1764
+ const skills = this.list();
1765
+ const wanted = skillId(name);
1766
+ return skills.find((skill) => skill.id === wanted) ?? skills.find((skill) => skill.match.some((item) => skillId(item) === wanted)) ?? (win ? skills.find((skill) => skill.match.some((item) => !GENERIC_HOSTS.test(item) && appMatches(item, win))) : void 0);
1767
+ }
1768
+ /** One line per skill for the system prompt. */
1769
+ catalog() {
1770
+ return this.list().map((skill) => `${skill.app}${skill.summary ? ` (${skill.summary})` : ""}`).join("; ");
1771
+ }
1772
+ save(input, id = skillId(input.app), extend = false) {
1773
+ const app = input.app.trim();
1774
+ if (app === "") throw new Error("app is required.");
1775
+ const content = input.content.trim();
1776
+ if (content === "") throw new Error("content is empty.");
1777
+ const total = content.length + (extend ? (this.load(this.builtinDir, "builtin").get(skillId(id))?.content.length ?? 0) + 1 : 0);
1778
+ if (total > 4e3) throw new Error(`The skill would be ${total} characters; the limit is ${SKILL_MAX_CHARS}. Condense it (merge duplicates, drop one-off details) and write it again.`);
1779
+ const previous = this.get(id);
1780
+ const match = [...new Set([
1781
+ ...input.match ?? [],
1782
+ ...previous?.match ?? [],
1783
+ app
1784
+ ].map((item) => item.trim()).filter((item) => item !== "" && !GENERIC_HOSTS.test(item)))];
1785
+ const summary = (input.summary ?? previous?.summary ?? "").trim().slice(0, 80);
1786
+ mkdirSync(this.userDir, { recursive: true });
1787
+ const path = join(this.userDir, `${skillId(id)}.md`);
1788
+ const tmp = `${path}.tmp`;
1789
+ writeFileSync(tmp, formatSkill({
1790
+ app,
1791
+ match,
1792
+ summary,
1793
+ content
1794
+ }, false, extend), "utf8");
1795
+ renameSync(tmp, path);
1796
+ return this.get(id);
1797
+ }
1798
+ append(app, text, extra = {}) {
1799
+ const previous = this.find(app);
1800
+ if (!previous) return this.save({
1801
+ app,
1802
+ content: text.trim(),
1803
+ ...extra
1804
+ });
1805
+ const own = this.load(this.userDir, "user").get(previous.id);
1806
+ if (this.load(this.builtinDir, "builtin").has(previous.id) && (!own || own.extend)) return this.save({
1807
+ app: previous.app,
1808
+ content: own ? `${own.content}\n${text.trim()}` : text.trim(),
1809
+ ...extra
1810
+ }, previous.id, true);
1811
+ return this.save({
1812
+ app: previous.app,
1813
+ content: `${previous.content}\n${text.trim()}`,
1814
+ ...extra
1815
+ }, previous.id);
1816
+ }
1817
+ /** Delete a user skill; a built-in one is hidden by a disabled override. */
1818
+ remove(id) {
1819
+ const wanted = skillId(id);
1820
+ const path = join(this.userDir, `${wanted}.md`);
1821
+ const builtin = this.load(this.builtinDir, "builtin").get(wanted);
1822
+ if (builtin) {
1823
+ mkdirSync(this.userDir, { recursive: true });
1824
+ writeFileSync(path, formatSkill({
1825
+ app: builtin.app,
1826
+ match: builtin.match,
1827
+ summary: builtin.summary,
1828
+ content: ""
1829
+ }, true), "utf8");
1830
+ } else if (existsSync(path)) unlinkSync(path);
1831
+ }
1832
+ /** Drop the user's override so the built-in skill applies again. */
1833
+ reset(id) {
1834
+ const path = join(this.userDir, `${skillId(id)}.md`);
1835
+ if (existsSync(path)) unlinkSync(path);
1836
+ }
1837
+ };
1838
+ //#endregion
1636
1839
  //#region lib/types/settings.js
1637
1840
  /** The Loader entry id (settings namespace); see cordis.patch.yml. */
1638
1841
  const ENTRY_ID = "copylee-computer-use";
@@ -1684,6 +1887,7 @@ const STATUS_ROUTE = "/api/dsh-computer-use/status";
1684
1887
  const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
1685
1888
  const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
1686
1889
  const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
1890
+ const SKILLS_ROUTE = "/api/dsh-computer-use/skills";
1687
1891
  function json(res, status, body) {
1688
1892
  res.writeHead(status, {
1689
1893
  "content-type": "application/json; charset=utf-8",
@@ -1792,6 +1996,54 @@ function screenshotsCleanRoute(cache) {
1792
1996
  }
1793
1997
  };
1794
1998
  }
1999
+ async function body(req) {
2000
+ const chunks = [];
2001
+ let size = 0;
2002
+ for await (const chunk of req) {
2003
+ size += chunk.length;
2004
+ if (size > 2e5) throw new Error("request too large");
2005
+ chunks.push(chunk);
2006
+ }
2007
+ const parsed = chunks.length === 0 ? {} : JSON.parse(Buffer.concat(chunks).toString("utf8"));
2008
+ return parsed !== null && typeof parsed === "object" ? parsed : {};
2009
+ }
2010
+ /** App skills for the settings page: GET lists them; POST { op: 'save' | 'delete' | 'reset', ... } changes one. */
2011
+ function skillsRoute(skills) {
2012
+ return async (req, res) => {
2013
+ if (req.method === "POST") {
2014
+ const input = await body(req);
2015
+ const id = typeof input.id === "string" ? input.id : "";
2016
+ try {
2017
+ if (input.op === "delete") skills.remove(id);
2018
+ else if (input.op === "reset") skills.reset(id);
2019
+ else if (input.op === "save") skills.save({
2020
+ app: String(input.app ?? ""),
2021
+ match: String(input.match ?? "").split(/[,,]/).map((item) => item.trim()).filter(Boolean),
2022
+ summary: String(input.summary ?? ""),
2023
+ content: String(input.content ?? "")
2024
+ }, id || void 0);
2025
+ else {
2026
+ json(res, 400, {
2027
+ ok: false,
2028
+ error: "unknown op"
2029
+ });
2030
+ return;
2031
+ }
2032
+ } catch (error) {
2033
+ json(res, 200, {
2034
+ ok: false,
2035
+ error: error instanceof Error ? error.message : String(error)
2036
+ });
2037
+ return;
2038
+ }
2039
+ }
2040
+ json(res, 200, {
2041
+ ok: true,
2042
+ dir: skills.userDir,
2043
+ skills: skills.list()
2044
+ });
2045
+ };
2046
+ }
1795
2047
  //#endregion
1796
2048
  //#region lib/types/screenshots.js
1797
2049
  /**
@@ -7909,16 +8161,35 @@ function createTools(host) {
7909
8161
  await setTimeout$1(250, void 0, { signal: call.signal });
7910
8162
  const now = await computer.foreground();
7911
8163
  if (now && now.hwnd !== before?.hwnd && !isHostWindow(now) && !isTransientShell(now) && (now.exe.toLowerCase() !== "explorer.exe" || now.className === "CabinetWClass")) break;
8164
+ if (i >= 4 && i % 4 === 0 && !isUri) {
8165
+ const opened = (await computer.windows()).find((win) => !isHostWindow(win) && appMatches(name, win));
8166
+ if (opened) {
8167
+ await computer.focus(opened).catch(() => void 0);
8168
+ break;
8169
+ }
8170
+ }
7912
8171
  }
7913
8172
  }
7914
8173
  const fg = await computer.foreground();
7915
8174
  if (fg && !isHostWindow(fg) && settings.accessMode === "per-app" && (computer.access.missing(call.session, [appName]).length === 0 || isUrl)) computer.access.grant(call.session, [fg.exe]);
7916
8175
  await computer.settle(call.signal);
7917
8176
  const shot = call.vision ? await computer.screenshot() : void 0;
7918
- return withShot(host, `${how} ${await computer.describeForeground()}`, shot, call);
8177
+ return withShot(host, `${how} ${await computer.describeForeground()}${skillNote(call.session, name, fg)}`, shot, call);
7919
8178
  },
7920
8179
  presentCall: (args) => card(`打开应用 · ${args.name ?? ""}`)
7921
8180
  }));
8181
+ /** Skills already handed to a session, so each is attached once. */
8182
+ const told = /* @__PURE__ */ new Map();
8183
+ /** The app's skill, appended to open_application's result the first time in a session. */
8184
+ function skillNote(session, name, win) {
8185
+ const skill = host.skills?.find(name, win && !isHostWindow(win) ? win : void 0);
8186
+ if (!skill) return host.skills ? "\n(No app skill for this app yet: if you have to work out how it behaves, record the reusable part with app_skill append when you are done.)" : "";
8187
+ let seen = told.get(session);
8188
+ if (!seen) told.set(session, seen = /* @__PURE__ */ new Set());
8189
+ if (seen.has(skill.id)) return "";
8190
+ seen.add(skill.id);
8191
+ return `\n\nYour skill notes for ${skill.app} (app_skill; correct them if they turn out wrong):\n${skill.content}`;
8192
+ }
7922
8193
  /** Put back what the task changed: re-minimize restored windows, report the ones it opened. */
7923
8194
  async function tidy(call) {
7924
8195
  await computer.overlay.begin(call.agent, "整理窗口");
@@ -8118,6 +8389,71 @@ function createTools(host) {
8118
8389
  },
8119
8390
  presentCall: (args) => card(`请求操控 · ${(args.apps ?? []).join("、")}`)
8120
8391
  }));
8392
+ if (host.skills) {
8393
+ const skills = host.skills;
8394
+ tools.push(defineTool({
8395
+ name: "app_skill",
8396
+ description: `Your notes on how to operate specific apps (one skill per app, kept across sessions; the user can edit them). open_application already returns the skill of the app it opens. Use "list" to see which apps have one, "read" for an app you reach another way, and "append" / "write" to record what you worked out about an unfamiliar app: reusable operating knowledge only (where things are, shortcuts, quirks, what failed and what works), never task content, personal data or pixel coordinates (they change with the window). Keep each skill under ${SKILL_MAX_CHARS} characters; rewrite it with "write" when it gets long or wrong.`,
8397
+ parameters: {
8398
+ action: {
8399
+ type: "string",
8400
+ enum: [
8401
+ "list",
8402
+ "read",
8403
+ "append",
8404
+ "write"
8405
+ ],
8406
+ required: true
8407
+ },
8408
+ app: {
8409
+ type: "string",
8410
+ description: "App name, e.g. \"Obsidian\" (read / append / write)."
8411
+ },
8412
+ content: {
8413
+ type: "string",
8414
+ description: "Markdown bullet points: the lines to add (append) or the whole skill (write)."
8415
+ },
8416
+ summary: {
8417
+ type: "string",
8418
+ description: "A few words on what the skill covers, shown in the list (write, or the first append)."
8419
+ }
8420
+ },
8421
+ output,
8422
+ isConcurrencySafe: () => false,
8423
+ async execute(args) {
8424
+ const { action, app, content, summary } = args;
8425
+ if (action === "list") {
8426
+ const rows = skills.list();
8427
+ return { text: rows.length === 0 ? "No app skills yet." : rows.map((skill) => `${skill.app}${skill.summary ? ` — ${skill.summary}` : ""} (${skill.content.length} chars)`).join("\n") };
8428
+ }
8429
+ const name = String(app ?? "").trim();
8430
+ if (name === "") throw new Error("app is required.");
8431
+ if (action === "read") {
8432
+ const skill = skills.find(name, await computer.foreground().catch(() => void 0));
8433
+ return { text: skill ? `Skill for ${skill.app}:\n${skill.content}` : `No skill for "${name}" yet. If you work out how this app behaves, record it with app_skill append.` };
8434
+ }
8435
+ const text = String(content ?? "").trim();
8436
+ if (text === "") throw new Error("content is required.");
8437
+ const fg = await computer.foreground().catch(() => void 0);
8438
+ const extra = {
8439
+ match: fg && !isHostWindow(fg) && appMatches(name, fg) && !/^applicationframehost/i.test(fg.exe) ? [fg.exe] : [],
8440
+ ...summary ? { summary } : {}
8441
+ };
8442
+ const saved = action === "write" ? skills.save({
8443
+ app: name,
8444
+ content: text,
8445
+ ...extra
8446
+ }, skills.find(name)?.id) : skills.append(name, text, extra);
8447
+ return { text: `Skill for ${saved.app} saved (${saved.content.length} of ${SKILL_MAX_CHARS} characters).` };
8448
+ },
8449
+ presentCall: (args) => card(`应用技能 · ${{
8450
+ list: "列表",
8451
+ read: "读取",
8452
+ append: "记录",
8453
+ write: "重写"
8454
+ }[args.action ?? ""] ?? ""}${args.app ? ` · ${args.app}` : ""}`)
8455
+ }));
8456
+ }
8121
8457
  tools.push(defineTool({
8122
8458
  name: "list_granted_applications",
8123
8459
  description: "List the apps you may control in this session.",
@@ -8286,8 +8622,10 @@ function apply(ctx, config = {}) {
8286
8622
  clearInterval(every);
8287
8623
  };
8288
8624
  }, "computer-use: screenshot cleanup");
8625
+ const skills = new SkillStore(helperAssetPath("skills"));
8289
8626
  const tools = createTools({
8290
8627
  computer,
8628
+ skills,
8291
8629
  async saveImage(shot, fileName) {
8292
8630
  const ref = await attachments().saveImage({
8293
8631
  data: shot.data,
@@ -8403,6 +8741,7 @@ function apply(ctx, config = {}) {
8403
8741
  route(PREVIEW_ROUTE, previewRoute(helper, settings, overlay, iconPath));
8404
8742
  route(SCREENSHOTS_ROUTE, screenshotsRoute(screenshots));
8405
8743
  route(SCREENSHOTS_CLEAN_ROUTE, screenshotsCleanRoute(screenshots));
8744
+ route(SKILLS_ROUTE, skillsRoute(skills));
8406
8745
  });
8407
8746
  ctx.inject(["systemPrompt"], (promptCtx) => {
8408
8747
  let registered;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * "应用技能" card: the per-app notes the agent keeps (see ../skills.ts). The
3
+ * user can read, edit, add and delete them here; built-in skills can be
4
+ * overridden and restored.
5
+ */
6
+ import * as React from 'react';
7
+ export declare function SkillsCard({ S }: {
8
+ S: Record<string, React.CSSProperties>;
9
+ }): React.ReactElement;
@@ -8,10 +8,12 @@ import type { Settings } from './computer.js';
8
8
  import type { HelperLike } from './helper-client.js';
9
9
  import type { OverlayController } from './overlay.js';
10
10
  import type { ScreenshotCache } from './screenshots.js';
11
+ import type { SkillStore } from './skills.js';
11
12
  export declare const STATUS_ROUTE = "/api/dsh-computer-use/status";
12
13
  export declare const PREVIEW_ROUTE = "/api/dsh-computer-use/preview";
13
14
  export declare const SCREENSHOTS_ROUTE = "/api/dsh-computer-use/screenshots";
14
15
  export declare const SCREENSHOTS_CLEAN_ROUTE = "/api/dsh-computer-use/screenshots/clean";
16
+ export declare const SKILLS_ROUTE = "/api/dsh-computer-use/skills";
15
17
  type Handler = (req: IncomingMessage, res: ServerResponse) => Promise<void>;
16
18
  export interface StatusBody {
17
19
  ok: true;
@@ -33,4 +35,6 @@ export declare function previewRoute(helper: HelperLike, settings: () => Setting
33
35
  export declare function screenshotsRoute(cache: ScreenshotCache): Handler;
34
36
  /** Delete orphaned screenshots now. */
35
37
  export declare function screenshotsCleanRoute(cache: ScreenshotCache): Handler;
38
+ /** App skills for the settings page: GET lists them; POST { op: 'save' | 'delete' | 'reset', ... } changes one. */
39
+ export declare function skillsRoute(skills: SkillStore): Handler;
36
40
  export {};
@@ -0,0 +1,60 @@
1
+ import { type WindowLike } from './access.js';
2
+ /** Notes longer than this must be condensed before more is added. */
3
+ export declare const SKILL_MAX_CHARS = 4000;
4
+ export interface Skill {
5
+ id: string;
6
+ app: string;
7
+ /** Names / exe names this skill applies to. */
8
+ match: string[];
9
+ summary: string;
10
+ content: string;
11
+ source: 'builtin' | 'user';
12
+ /** A user file replaces a built-in skill of the same id. */
13
+ overrides: boolean;
14
+ updatedAt: number;
15
+ }
16
+ export interface SkillInput {
17
+ app: string;
18
+ match?: string[];
19
+ summary?: string;
20
+ content: string;
21
+ }
22
+ interface Parsed {
23
+ app: string;
24
+ match: string[];
25
+ summary: string;
26
+ content: string;
27
+ disabled: boolean;
28
+ extend: boolean;
29
+ }
30
+ export declare function skillId(app: string): string;
31
+ export declare function parseSkill(text: string, fallbackApp: string): Parsed;
32
+ export declare function formatSkill(skill: {
33
+ app: string;
34
+ match: string[];
35
+ summary: string;
36
+ content: string;
37
+ }, disabled?: boolean, extend?: boolean): string;
38
+ export declare class SkillStore {
39
+ private readonly builtinDir;
40
+ readonly userDir: string;
41
+ constructor(builtinDir: string, userDir?: string);
42
+ private load;
43
+ /** Every active skill, user files first in precedence, sorted by app name. */
44
+ list(): Skill[];
45
+ get(id: string): Skill | undefined;
46
+ /** The skill for an app by name, or for a window by its executable. */
47
+ find(name: string, win?: WindowLike): Skill | undefined;
48
+ /** One line per skill for the system prompt. */
49
+ catalog(): string;
50
+ save(input: SkillInput, id?: string, extend?: boolean): Skill;
51
+ append(app: string, text: string, extra?: {
52
+ match?: string[];
53
+ summary?: string;
54
+ }): Skill;
55
+ /** Delete a user skill; a built-in one is hidden by a disabled override. */
56
+ remove(id: string): void;
57
+ /** Drop the user's override so the built-in skill applies again. */
58
+ reset(id: string): void;
59
+ }
60
+ export {};
@@ -1,5 +1,6 @@
1
1
  import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
2
2
  import { defineTool } from '@deepseek-ai/dsh-tools';
3
+ import { type SkillStore } from './skills.js';
3
4
  import { Computer, type CallContext, type Shot } from './computer.js';
4
5
  type ToolDefinition = ReturnType<typeof defineTool>;
5
6
  export interface ToolHost {
@@ -8,6 +9,8 @@ export interface ToolHost {
8
9
  saveImage(shot: Shot, name: string): Promise<ImageAttachmentRef>;
9
10
  /** Build the per-call context (session, agent, vision support). */
10
11
  context(exec: unknown): Promise<CallContext>;
12
+ /** Per-app notes the agent keeps (optional: tests run without). */
13
+ skills?: SkillStore;
11
14
  }
12
15
  export declare function createTools(host: ToolHost): ToolDefinition[];
13
16
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "type": "module",
6
6
  "author": "copylee",
@@ -32,6 +32,7 @@
32
32
  "helper/CuHelper.cs",
33
33
  "helper/deepseek-white.png",
34
34
  "helper/deepseek-black.png",
35
+ "helper/skills/*.md",
35
36
  "cordis.patch.yml",
36
37
  "README.md",
37
38
  "LICENSE"