- Home
- Plugins
- Tools & Capabilities
- dsh-computer-control
dsh-computer-control
regularsyr7/dsh-computer-control
Give a DSH harness real control of a Mac: screenshots, mouse and keyboard through a bundled Swift HID helper, app and whitelisted shell launching, and system info — every call returns a self-check that proves what actually happened.
Install
dsh plugin --profile web add github:regularsyr7/dsh-computer-controlREADME
@rainybox/dsh-computer-control
Give a DSH harness real control of this Mac: screenshots, mouse and keyboard, app launching, shell execution, system info. Every call returns a self_check field — a real echo proving what actually happened, not a claim.
macOS only. The mouse/keyboard half is a small Swift helper compiled on first use.
Install
npm i @rainybox/dsh-computer-control
# or from source:
git clone https://github.com/RegularsYr7/dsh-computer-control.git
Then link it into your DSH profile and add it to the bundle stack:
cd ~/.dsh/profiles/desktop
pnpm add link:~/Developer/dsh-plugins/dsh-computer-control
# add "@rainybox/dsh-computer-control" to dsh.profile.bundles in package.json
Restart DSH. The tool computer_control appears with ten actions.
Permissions (grant these first)
| Capability | System Settings path | Symptom when missing |
|---|---|---|
| Screen Recording | Privacy & Security → Screen Recording → enable DSH.app | screencapture yields an empty file; the tool reports it |
| Accessibility | Privacy & Security → Accessibility → enable DSH.app | helper exits 3: accessibility permission not granted |
| Input Monitoring | Privacy & Security → Input Monitoring → enable DSH.app | synthesized events are dropped by the system |
action=status returns accessibility / post_event_access / listen_event_access; all three must be true for input to land.
中文说明
让 DSH harness 直接操作这台 Mac:截屏、键鼠、启动程序、执行命令、读系统信息。
每个工具调用都返回 self_check 字段——用真实回显证明"这次到底做了什么",不是声明。
- 插件名:
@rainybox/dsh-computer-control - 版本:
0.1.0 - 暴露给 harness 的工具:
computer_control(单一工具,action分发十个动作) - 依赖:macOS 自带
/usr/sbin/screencapture、/usr/bin/osascript、/usr/sbin/system_profiler;键鼠走插件自带的 Swift 助手(首次调用自动编译,需要本机有swiftc)
目录结构
dsh-computer-control/
├── package.json # name/version/main + dsh.bundle.patch 挂载声明
├── cordis.patch.yml # 向 profile 层栈 insert 本插件
├── lib/index.js # 宿主入口(转发 src/index.js)
├── src/index.js # Cordis 插件:defineTool(computer_control) + exec 白名单 + 审计
├── native/DshInputHelper.swift # 键鼠助手源码(CoreGraphics HID + Accessibility)
├── native/bin/dsh-input-helper # 编译产物(build-helper.mjs 生成;缺失时首次调用自动编译)
├── scripts/build-helper.mjs # swiftc -O 编译,按 mtime 跳过重复编译
└── README.md
动作一览
| action | 作用 | 关键参数 | self_check 证明什么 |
|---|---|---|---|
status | 助手与权限自检 | – | helper、accessibility、screencapture_exit |
screenshot | 全屏/区域/指定显示器截图 | save_path、region="x,y,w,h"、display | PNG 头校验的宽高与字节数 + 坐标换算比例 |
move | 移动鼠标 | x、y | 助手回显的坐标 |
click | 点击 | x、y、button、count | 回显的坐标/按钮/次数 |
type | 输入文本(支持中文,\n 回车) | text、delay_ms | 助手回显 chars=N 与请求长度对比 |
key | 组合键 | combo="cmd+shift+4" | 回显 keyCode 与修饰键 |
scroll | 滚轮 | dy、dx,可选中点 x/y | 回显的滚动量 |
launch | 启动 App/文件 | app、args | open 退出码 + 目标名 |
exec | 执行 shell 命令 | command、cwd、timeout_ms、confirm | 退出码 + echo 通道探针 |
sysinfo | 系统信息 | detail | 解析出的机型/芯片/内存/显示器/系统版本 |
坐标与焦点(踩过的坑,务必先读)
- 键鼠坐标是"屏幕点",截图是"像素"。Retina 上 1 点 = 2 像素;
screenshot的self_check会打印点 = 像素 / pixel_scale(屏幕 W×H 点)。拿像素坐标直接点会点到别处。 - 键盘事件跟随"当前前台 App"。
osascript activate报frontmost=true之后也可能在几百毫秒内被 其他窗口(通知、聊天面板、全屏 App)抢走焦点。可靠流程是:screenshot → click 目标输入区 → screenshot 确认菜单栏/窗口已切换 → type。 在写代码/写文档的场景里,宁可先click两次再type。 - 多屏/多空间:
screencapture抓的是当前主屏;display参数只在screencapture -D下生效。 - AXPress 不等于导航。对某些 App(实测 Microsoft Outlook)用
perform action "AXPress"到侧栏行 不报错也不切换视图;可靠做法是取元素position后用computer_control的click点真实坐标, 再用窗口标题回读校验。
权限(首次一定会用到)
| 能力 | 系统设置路径 | 缺失时的表现 |
|---|---|---|
| 屏幕录制 | 隐私与安全性 → 屏幕录制 → 勾选 DSH.app | screencapture 产出空图,工具明确报"截图内容异常" |
| 辅助功能 | 隐私与安全性 → 辅助功能 → 勾选 DSH.app | 键鼠助手 exit 3,报"accessibility permission not granted" |
| 输入监听 | 隐私与安全性 → 输入监听 → 勾选 DSH.app | 键鼠事件被系统丢弃 |
action=status 里 accessibility / post_event_access / listen_event_access 三个字段为 true 才算真的能模拟输入。
exec 白名单与显式确认
exec 默认只放行只读、本地无害的前缀(ls、cat、grep、ps、echo、sw_vers、open、
osascript -e、screencapture、sips、say…),并按 && || ; | 换行 逐段校验;
出现 $(...) 或反引号直接拒绝(防命令替换绕过)。
不在白名单的命令不会执行,而是报错并提示:
命令不在白名单,未执行:rm -rf /tmp/x; 白名单是只读/本地无害前缀(见 $DSH_HOME/computer-control/config.json)。
确需执行时,把 confirm 参数设成与 command 完全相同的字符串。
传 confirm="<与 command 完全相同的字符串>" 才放行,且审计日志里会标注"显式确认"。
私有配置与审计
- 配置:
$DSH_HOME/computer-control/config.json{ "allowed_prefixes": ["ls", "cat", "grep", "..."], "default_timeout_ms": 120000, "max_output_bytes": 200000 } - 审计:
$DSH_HOME/computer-control/audit.jsonl(每次 exec/type/click/key 一行,含时间、动作、参数摘要、退出码) - 截图默认落:
$DSH_HOME/computer-control/shots/<timestamp>.png
安装与注册
npm i @rainybox/dsh-computer-control
# 或者从源码链接进 profile
cd ~/.dsh/profiles/desktop
pnpm add link:~/Developer/dsh-plugins/dsh-computer-control
# 把插件放进 profile 的 bundle 层栈(package.json 的 dsh.profile.bundles 末尾追加)
# "@rainybox/dsh-computer-control"
cordis.patch.yml:
- insert:
- id: '@rainybox/dsh-computer-control'
name: '@rainybox/dsh-computer-control'
注意:entry id 必须与包名一致;而且在 dsh.profile.bundles 里没有列出来的包根本不会被 import——
只在 package.json 里装了依赖不够,apply() 一次都不会跑。
注册后 harness 启动即挂载,无需额外注册命令。
最小调用示例
// 1. 截屏
{"action": "screenshot", "save_path": "/tmp/shot.png", "region": "0,0,1280,720"}
// → 已截屏 1280×720 → /tmp/shot.png
// 自检:PNG 头校验通过:1280×720, 436093 字节 > 1024;坐标换算:点 = 像素 / 1(屏幕 2560×1440 点)
// 2. 执行命令(白名单)
{"action": "exec", "command": "echo dsh-exec-ok && uname -m"}
// → 退出码 0;stdout: dsh-exec-ok / arm64
// 自检:echo 通道 = dsh-exec-ok;命令退出码 = 0
// 3. 输入文本(先 click 再 type,最后用 system_profiler/osascript 回读校验)
{"action": "type", "text": "DSH harness 键盘输入 OK 2026-11-30"}
// → 已键入 30 个字符
// 自检:助手回显 chars=30(请求 30 字符)
已知限制
- 仓库自带 arm64 编译产物;换到其他架构(如 x86_64)时,首次调用键鼠动作会触发 Swift 编译(约 3–8 秒,需要本机装有 Xcode Command Line Tools),产物落在
native/bin/,之后毫秒级。 - 助手只做单屏 HID 注入;需要拖动/长按等复杂手势时,用多次
move+click组合,或自行扩展 Swift 命令。 type走 Unicode 字符串注入,个别只认物理键位的 App(部分游戏、密码框)可能不接收——这属于目标程序行为,不是权限问题。- 仅在 macOS 上实现;其他平台
ensureHelper()直接报错。
License
MIT © Rainy
Related plugins
archify (deepseek-harness)
tt-a1i/archify
WeKnora (dsh-weknora)
tencent/weknora
next-ai-draw-io (dsh-plugin)
dayuanjiang/next-ai-draw-io
AiToEarn (dsh-plugin-aitoearn)
yikart/aitoearn