dsh-screen-automation 0.1.2 → 0.1.9

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
@@ -6,7 +6,7 @@
6
6
 
7
7
  > 这不是重写屏幕自动化,而是**桥接**:dsh 负责 Agent 编排,小助手负责本地执行。
8
8
 
9
- > ⚠️ **前置依赖**:本插件只是一层桥接,**本机必须先独立安装「屏幕自动化小助手」桌面端**(Windows `.exe` / macOS `.app`),30 个工具才能真正工作。安装方式见下方「[前置依赖:安装屏幕自动化小助手](#前置依赖安装屏幕自动化小助手)」。
9
+ > ⚠️ **前置依赖**:本插件只是一层桥接,**本机必须先独立安装「屏幕自动化小助手」桌面端**(Windows `.exe` / macOS `.app`),46 个工具才能真正工作。安装方式见下方「[前置依赖:安装屏幕自动化小助手](#前置依赖安装屏幕自动化小助手)」。
10
10
 
11
11
  ## 设计原则
12
12
 
@@ -34,7 +34,37 @@ dsh-screen-automation (Host 插件, Node/TS)
34
34
  平台 CLI 与 Windows/macOS 共用同一套命令,且标准输出为 JSON,因此桥接层只需要:
35
35
  **定位二进制 → 调 CLI → 解析 JSON → 回传**。
36
36
 
37
- ## 暴露的工具(共 30 个)
37
+ ## 工作流开发语义
38
+
39
+ 本插件不自行解析、转换或补全 `workflow.md`,因此桌面端新增流程语言时,桥接层保持原样透传。
40
+ 需要创建或修改流程的 Agent 必须遵循“屏幕自动化工程师”的[当前工作流开发标准](https://github.com/xiaozs-com/screen-automation-engineer/blob/main/references/workflow-standard.md),并以本机
41
+ `screen_automation_capabilities` 和 `screen_automation_workflow_inspect` 的结果为准。安装前先检查、
42
+ 校验流程;校验报错时不得猜测字段或用旧语法绕过。当前标准已包括表单填写的运行期 OCR `锚定`、
43
+ 相对 `偏移`、`相对【文字】右侧` 等位置约束、越界滚动重定位、锚点虚线提示及安全停止规则。
44
+
45
+ ## 暴露的工具(共 48 个)
46
+
47
+ ### 浏览器增强(受管会话)
48
+
49
+ 插件桥接 `browser health/status/open/navigate/auth-status/probe/outcome/locate/read/click/fill/select-text/scroll/press/verify/copy/download/close`。
50
+ 同一个网页任务只调用一次 `screen_automation_browser_open`,后续工具按 `browser=chrome|edge` 跨 CLI
51
+ 进程复用同一会话;不得在每一步前重新打开,也不得在观察和操作之间关闭。插件不向 Agent 暴露
52
+ `browser open --new` 或 `browser close --stop-daemon`。仅当小助手明确返回 `browser_session_expired`
53
+ 时重新打开一次;若返回 `browser_session_not_open`,先调用 `screen_automation_browser_status`,随后停止
54
+ 无限重试并向用户报告。
55
+
56
+ 给出网址时,在首次 `screen_automation_browser_open` 中直接传 `url`。小助手会创建或复用持久化受管
57
+ Profile 并进入该网址;正常关闭或重启后会保留站点登录状态。若返回 `waiting_for_user / login_required`,
58
+ 保留当前窗口,停止工具调用并请用户登录;用户确认后调用 `screen_automation_browser_auth_status`,状态为
59
+ `ready` 才在原会话继续。用户明确提供账号、密码或验证码时可以代填;敏感文字通过标准输入传给小助手,
60
+ 不出现在进程命令行中。只禁止 Agent 将 Cookie、密码等原始凭据写入模型上下文、流程文件、运行日志或
61
+ 结果输出;技术上无法代办的扫码、安全密钥、生物识别才等待用户。
62
+
63
+ 执行 DOM 任务前调用 `screen_automation_browser_probe`,按返回的 `USE_DOM`、`ENHANCE_DOM` 或
64
+ `EXIT_DOM` 选择 DOM 路线。只有显式采用 Probe 返回的策略时,才把 `strategy_id` 传给
65
+ `screen_automation_browser_locate`;普通定位不传。任务结束后调用一次
66
+ `screen_automation_browser_outcome` 记账,只有业务结果已经验证时才把成功记录为已验证。
67
+ `EXIT_DOM` 只退出 DOM 路线,不会禁用 UIA、OCR、CV、VLM、鼠标键盘或普通屏幕自动化。
38
68
 
39
69
  ### 1. 平台自检与流程生命周期
40
70
 
@@ -75,8 +105,8 @@ dsh-screen-automation (Host 插件, Node/TS)
75
105
 
76
106
  | 工具 | 映射的 CLI | 说明 |
77
107
  |---|---|---|
78
- | `screen_automation_workflow_validate` | `cli workflow validate <id>` | 校验已安装 workflow |
79
- | `screen_automation_workflow_install` | `cli workflow install <source>` | 从本地源(目录/压缩包)安装 workflow |
108
+ | `screen_automation_workflow_validate` | `cli workflow validate <id>` | 校验已安装 workflow;修改后必须执行,报错时不得猜语法 |
109
+ | `screen_automation_workflow_install` | `cli workflow install <source>` | 从本地源(目录/压缩包)安装已按当前流程语言检查过的 workflow |
80
110
  | `screen_automation_workflow_remove` | `cli workflow remove <id>` | 移除已安装 workflow |
81
111
 
82
112
  ### 5. 任务会话(绑定窗口,后续控制/识别在该窗口内生效)
@@ -109,18 +139,30 @@ screen capture 拿图 → ctx.attachments.saveImage 登记为不可变图片引
109
139
  注册成 dsh 的一个 provider,再把 `provider` / `model` 传进工具即可——本地算力,不烧远程 VLM。
110
140
  - 依赖 dsh 运行时的 `ctx.llm`(视觉模型服务)与 `ctx.attachments`(图片登记服务);任一不可用,工具会抛出明确错误。
111
141
 
142
+ ## Agent Bridge 任务级工具策略
143
+
144
+ 插件正常安装在交互式 DSH 会话中时,仍提供完整工具集。由“屏幕自动化小助手”的 Agent Bridge
145
+ 启动受控任务时,Bridge 会同时设置策略版本和精确工具白名单;插件在每次执行工具前强制校验,
146
+ 未列入的流程安装、卸载、启动等工具即使出现在模型上下文中也会被拒绝。
147
+
148
+ 策略使用 `SCREEN_AUTOMATION_AGENT_TOOL_POLICY_VERSION=1` 和
149
+ `SCREEN_AUTOMATION_AGENT_ALLOWED_TOOLS`。这两个变量是 Bridge 与插件之间的内部契约,普通用户
150
+ 不应手工设置;只设置其中一个、使用未知策略版本或传入空白名单时,默认拒绝所有插件工具。
151
+ 此检查是执行边界,不以提示词服从作为授权依据。
152
+
112
153
  ## 二进制发现(按优先级)
113
154
 
114
155
  1. 环境变量 `SCREEN_AUTOMATION_BIN`(最高优先级,直接指向可执行文件)
115
156
  2. macOS:`SCREEN_AUTOMATION_MAC_APP` → 其下 `Contents/MacOS/screen-automation-helper`
116
157
  或 `/Applications/Screen Automation Helper.app/...`、 `$HOME/Applications/Screen Automation Helper.app/...`
117
- 3. Windows:`SCREEN_AUTOMATION_WIN_EXE` → `%ProgramFiles%\Xiaozs\ScreenAutomationHelper\...`
158
+ 3. Windows:`SCREEN_AUTOMATION_WIN_EXE` → `%LOCALAPPDATA%\Programs\Xiaozs\ScreenAutomationHelper\...` →
159
+ `%ProgramFiles%\Xiaozs\ScreenAutomationHelper\...` → `%ProgramFiles(x86)%\Xiaozs\ScreenAutomationHelper\...`
118
160
 
119
161
  都找不到时,工具会抛出带官网下载链接的明确错误。
120
162
 
121
163
  ## 前置依赖:安装屏幕自动化小助手
122
164
 
123
- 本插件**不内置**任何屏幕识别或输入执行的代码,它只是一层桥接。要让上面 30 个工具真正可用,
165
+ 本插件**不内置**任何屏幕识别或输入执行的代码,它只是一层桥接。要让上面 46 个工具真正可用,
124
166
  你本机必须先装好「屏幕自动化小助手」(Screen Automation Helper) 桌面端——Windows 上是
125
167
  `ScreenAutomationHelper.exe`,macOS 上是 `Screen Automation Helper.app`。小助手通过 `cli <subcommand>`
126
168
  暴露 JSON 接口,本插件只是去「定位二进制 → 调 CLI → 解析 JSON → 回传」。
@@ -198,12 +240,22 @@ dsh plugin --profile web add dsh-screen-automation && dsh restart web
198
240
  ## 发布到 npm(让 `dsh plugin add` 可用)
199
241
 
200
242
  仓库已加 GitHub `dsh-plugin` 话题(官方发现聚合渠道,搜该话题即可找到)。要让人能
201
- `dsh plugin --profile web add dsh-screen-automation` 一键安装,还需发到 npm:
243
+ `dsh plugin --profile web add dsh-screen-automation` 一键安装,需要发布到 npm。
202
244
 
203
- ```sh
204
- npm login # 用你的 npm 账号登录
205
- npm publish # package.json 已设 files=[lib, README.md, cordis.patch.yml],自动排除 src/node_modules
206
- ```
245
+ ### 一次性配置
246
+
247
+ 在 GitHub 仓库的 **Settings → Secrets and variables → Actions** 中创建 Secret:
248
+
249
+ - 名称:`NPM_TOKEN`
250
+ - 值:npm 网站创建的 Automation token(只用于发布 `dsh-screen-automation`)
251
+
252
+ ### 日常发布(无需建 GitHub Release)
253
+
254
+ 1. 修改 `package.json` 的 `version`,例如 `0.1.4`,并提交、推送到 `main`。
255
+ 2. 创建同名标签并推送:`git tag v0.1.4`,然后 `git push origin v0.1.4`。
256
+ 3. GitHub Actions 的 **Publish to npm** 会自动安装依赖、构建、校验发布内容,然后发布到 npm。
257
+
258
+ 标签必须与 `package.json` 的版本完全相同;不一致时工作流会停止,避免误发布。仅修改文档时不需要改版本、打标签或发布 npm。
207
259
 
208
260
  发布前确认:`peerDependencies` 已声明 harness 包(与宿主 dsh 共用同一份实例,避免拉第二份 cordis 副本);
209
261
  `dsh.bundle.patch` 指向 `cordis.patch.yml`(install 时自动插入插件行)。
@@ -220,7 +272,7 @@ npm publish # package.json 已设 files=[lib, README.md, cor
220
272
  - **依赖完整性**:原 `package.json` 缺 `typescript`,已补入 `devDependencies`;`npm install && npm run build` 现在可稳定产出 `lib/index.js` + `lib/index.d.ts`。
221
273
  - **类型层**:对照真实发布的 `@deepseek-ai/dsh-tools` / `@deepseek-ai/dsh-llm` / `@deepseek-ai/dsh-attachment` 编译通过。
222
274
  - **运行时层**:用桩二进制(写一张 PNG 到 `--output`)+ mock `ctx.llm.stream` / `ctx.attachments.saveImage` 验证全链路——
223
- 30 个工具注册成功,`screen_automation_understand` 正确执行 `cli screen capture --output`、读字节、登记 attachment、
275
+ 工具注册成功,`screen_automation_understand` 正确执行 `cli screen capture --output`、读字节、登记 attachment、
224
276
  把 image block 塞进 `llm.stream` 的消息、并累积 text-delta 成结果。
225
277
  - 真机端到端需在已安装小助手 `.app`/`.exe` 且 dsh profile 配置了视觉模型的机器上跑(本仓库不携带该二进制)。
226
278
 
package/lib/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
2
  export declare const name = "screen-automation";
3
3
  export declare const inject: string[];
4
+ /** Bridge tasks receive an exact allowlist; normal DSH sessions keep all tools. */
5
+ export declare function isToolAllowedByBridge(toolName: string, env?: NodeJS.ProcessEnv): boolean;
4
6
  export declare function apply(ctx: Context): void;
package/lib/index.js CHANGED
@@ -8,9 +8,13 @@ import { defineTool } from '@deepseek-ai/dsh-tools';
8
8
  // - ImageAttachmentRef/SaveImageAttachment/ImageMediaType 是 attachment 服务的写入契约
9
9
  import { MessageId } from '@deepseek-ai/dsh-llm';
10
10
  // 插件身份:name 是插件在配置树里的稳定 id;inject 声明本插件依赖的
11
- // Harness 服务(工具注册表 tools)。Cordis 会等 tools 就绪后再调用 apply。
11
+ // Harness 服务。除了工具注册表 tools,understand(VLM 视觉理解) 工具还需要
12
+ // llm(视觉推理)与 attachments(把截图登记为图片引用)两个服务。不把它们
13
+ // 列入 inject,Cordis 会在执行里访问 ctx.llm / ctx.attachments 时抛
14
+ // "cannot get property 'llm' without inject"。注意:被注入的服务必须在该
15
+ // profile 中存在,否则整个插件不会激活(见末尾说明)。
12
16
  export const name = 'screen-automation';
13
- export const inject = ['tools'];
17
+ export const inject = ['tools', 'llm', 'attachments'];
14
18
  /**
15
19
  * 这个插件把本地「屏幕自动化小助手」(Screen Automation Helper) 桌面端桥接进
16
20
  * DeepSeek Harness 的 Agent 工具系统。
@@ -41,6 +45,18 @@ const INSTALL_HINT = 'The local "Screen Automation Helper" desktop app is requir
41
45
  ' ZIP: https://www.xiaozs.com/sah/downloads/zip/latest\n' +
42
46
  'Or point this plugin at an existing install via one of the env vars: ' +
43
47
  'SCREEN_AUTOMATION_BIN, SCREEN_AUTOMATION_MAC_APP, SCREEN_AUTOMATION_WIN_EXE.';
48
+ const BRIDGE_POLICY_VERSION = '1';
49
+ /** Bridge tasks receive an exact allowlist; normal DSH sessions keep all tools. */
50
+ export function isToolAllowedByBridge(toolName, env = process.env) {
51
+ const policyVersion = env.SCREEN_AUTOMATION_AGENT_TOOL_POLICY_VERSION?.trim();
52
+ const rawAllowlist = env.SCREEN_AUTOMATION_AGENT_ALLOWED_TOOLS;
53
+ if (!policyVersion && rawAllowlist === undefined)
54
+ return true;
55
+ if (policyVersion !== BRIDGE_POLICY_VERSION || rawAllowlist === undefined)
56
+ return false;
57
+ const allowed = new Set(rawAllowlist.split(',').map((item) => item.trim()).filter(Boolean));
58
+ return allowed.has(toolName);
59
+ }
44
60
  /** 在多个候选路径里找到已安装的屏幕自动化小助手二进制。优先级:环境变量 > 平台默认位置。 */
45
61
  function resolveBinary() {
46
62
  const env = process.env;
@@ -63,23 +79,33 @@ function resolveBinary() {
63
79
  const win = env.SCREEN_AUTOMATION_WIN_EXE;
64
80
  if (win && fs.existsSync(win))
65
81
  return win;
66
- const pf = env.ProgramFiles;
67
- const guess = pf ? `${pf}\\Xiaozs\\ScreenAutomationHelper\\ScreenAutomationHelper.exe` : null;
68
- if (guess && fs.existsSync(guess))
69
- return guess;
82
+ const candidates = [
83
+ env.LOCALAPPDATA
84
+ ? `${env.LOCALAPPDATA}\\Programs\\Xiaozs\\ScreenAutomationHelper\\ScreenAutomationHelper.exe`
85
+ : null,
86
+ env.ProgramFiles
87
+ ? `${env.ProgramFiles}\\Xiaozs\\ScreenAutomationHelper\\ScreenAutomationHelper.exe`
88
+ : null,
89
+ env['ProgramFiles(x86)']
90
+ ? `${env['ProgramFiles(x86)']}\\Xiaozs\\ScreenAutomationHelper\\ScreenAutomationHelper.exe`
91
+ : null,
92
+ ].filter(Boolean);
93
+ for (const candidate of candidates)
94
+ if (fs.existsSync(candidate))
95
+ return candidate;
70
96
  return null;
71
97
  }
72
98
  return null;
73
99
  }
74
100
  /** 调用小助手 CLI(统一前缀 `cli`),解析 JSON 标准输出,返回结构化结果。 */
75
- async function runCli(args, timeoutMs = 30000) {
101
+ async function runCli(args, timeoutMs = 30000, stdinText) {
76
102
  const bin = resolveBinary();
77
103
  if (!bin) {
78
104
  throw new Error(INSTALL_HINT);
79
105
  }
80
106
  const command = `cli ${args.join(' ')}`;
81
107
  return new Promise((resolve, reject) => {
82
- execFile(bin, ['cli', ...args], { timeout: timeoutMs, maxBuffer: 64 * 1024 * 1024 }, (err, stdout, stderr) => {
108
+ const child = execFile(bin, ['cli', ...args], { timeout: timeoutMs, maxBuffer: 64 * 1024 * 1024 }, (err, stdout, stderr) => {
83
109
  const raw = (stdout || '').toString();
84
110
  let data = null;
85
111
  try {
@@ -95,6 +121,8 @@ async function runCli(args, timeoutMs = 30000) {
95
121
  }
96
122
  resolve({ ok: true, command, raw, data });
97
123
  });
124
+ if (stdinText !== undefined)
125
+ child.stdin?.end(stdinText);
98
126
  });
99
127
  }
100
128
  /** 把一个 CLI 子命令包装成一个 dsh 工具:注册 → 调用 CLI → 透传 JSON 结果。 */
@@ -120,8 +148,11 @@ function cliTool(opts) {
120
148
  },
121
149
  },
122
150
  async execute(args) {
151
+ if (!isToolAllowedByBridge(opts.name)) {
152
+ throw new Error(`screen_automation tool denied by Agent Bridge task policy: ${opts.name}`);
153
+ }
123
154
  try {
124
- return await runCli(opts.buildArgs(args));
155
+ return await runCli(opts.buildArgs(args), 30000, opts.stdinText?.(args));
125
156
  }
126
157
  catch (e) {
127
158
  if (opts.softFail) {
@@ -153,6 +184,233 @@ export function apply(ctx) {
153
184
  parameters: {},
154
185
  buildArgs: () => ['capabilities'],
155
186
  }));
187
+ // 浏览器增强使用小助手的跨进程受管会话。工具层不暴露 --new 或 --stop-daemon,
188
+ // 避免 Agent 在每轮观察时关闭并重建浏览器。
189
+ ctx.tools.register(cliTool({
190
+ name: 'screen_automation_browser_health',
191
+ description: 'Check browser-enhancement availability. Call before opening a managed browser when status has not been checked.',
192
+ parameters: {},
193
+ buildArgs: () => ['browser', 'health'],
194
+ }));
195
+ ctx.tools.register(cliTool({
196
+ name: 'screen_automation_browser_status',
197
+ description: 'Report browser-enhancement installation, daemon and active managed sessions. On browser_session_not_open, call this once and report the state; never loop browser_open.',
198
+ parameters: {},
199
+ buildArgs: () => ['browser', 'status'],
200
+ }));
201
+ ctx.tools.register(cliTool({
202
+ name: 'screen_automation_browser_open',
203
+ description: 'Open or reuse one persistent managed Chrome/Edge session and optionally enter a URL immediately. Call once at the start of a browser task. On waiting_for_user, use credentials only when the user explicitly supplied them; otherwise stop and ask the user to log in in the open window. Never refresh, close or reopen while waiting.',
204
+ parameters: {
205
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'], description: 'Managed browser kind.' },
206
+ region: { type: 'string', description: 'Optional screen bounds left,top,right,bottom.' },
207
+ url: { type: 'string', description: 'Optional HTTP/HTTPS URL to enter immediately.' },
208
+ timeout: { type: 'number', description: 'Navigation timeout seconds.' },
209
+ },
210
+ buildArgs: (a) => {
211
+ const args = ['browser', 'open', String(a.browser)];
212
+ if (typeof a.region === 'string' && a.region)
213
+ args.push('--region', a.region);
214
+ if (typeof a.url === 'string' && a.url)
215
+ args.push('--url', a.url);
216
+ if (typeof a.timeout === 'number')
217
+ args.push('--timeout', String(a.timeout));
218
+ return args;
219
+ },
220
+ }));
221
+ ctx.tools.register(cliTool({
222
+ name: 'screen_automation_browser_auth_status',
223
+ description: 'Recheck the existing browser after login or verification. Continue only when status is ready. Never write raw cookies or passwords into model context, workflow files, runtime logs or result output.',
224
+ parameters: {
225
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'] },
226
+ },
227
+ buildArgs: (a) => ['browser', 'auth-status', '--browser', String(a.browser)],
228
+ }));
229
+ ctx.tools.register(cliTool({
230
+ name: 'screen_automation_browser_navigate',
231
+ description: 'Navigate the existing managed browser session. On waiting_for_user, use credentials only when explicitly supplied; otherwise leave the page open and wait. After user confirmation call browser_auth_status and continue the same session. Do not call browser_open again unless browser_session_expired.',
232
+ parameters: {
233
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'] },
234
+ url: { type: 'string', required: true, description: 'HTTP/HTTPS URL.' },
235
+ timeout: { type: 'number', description: 'Navigation timeout seconds.' },
236
+ },
237
+ buildArgs: (a) => {
238
+ const args = ['browser', 'navigate', '--browser', String(a.browser), String(a.url)];
239
+ if (typeof a.timeout === 'number')
240
+ args.push('--timeout', String(a.timeout));
241
+ return args;
242
+ },
243
+ }));
244
+ ctx.tools.register(cliTool({
245
+ name: 'screen_automation_browser_probe',
246
+ description: 'Probe the current managed page before a DOM task. Use the returned USE_DOM, ENHANCE_DOM or EXIT_DOM decision only for the DOM route; EXIT_DOM does not disable UIA, OCR, CV, VLM or ordinary screen control.',
247
+ parameters: {
248
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'] },
249
+ task_kind: { type: 'string', required: true, enum: ['READ', 'LOCATE', 'ACT', 'FILL', 'SELECT', 'DOWNLOAD', 'VERIFY'] },
250
+ },
251
+ buildArgs: (a) => ['browser', 'probe', '--browser', String(a.browser), '--task-kind', String(a.task_kind)],
252
+ }));
253
+ ctx.tools.register(cliTool({
254
+ name: 'screen_automation_browser_outcome',
255
+ description: 'Record the verified result of a DOM route once. Record success only when the requested outcome was verified; otherwise report failure with a structured failure type.',
256
+ parameters: {
257
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'] },
258
+ decision: { type: 'string', required: true, enum: ['USE_DOM', 'ENHANCE_DOM', 'EXIT_DOM'] },
259
+ task_kind: { type: 'string', required: true, enum: ['READ', 'LOCATE', 'ACT', 'FILL', 'SELECT', 'DOWNLOAD', 'VERIFY'] },
260
+ result: { type: 'string', required: true, enum: ['success', 'failure'] },
261
+ verified: { type: 'boolean', description: 'Set only when the requested page outcome was explicitly verified.' },
262
+ failure_type: { type: 'string', description: 'Structured helper failure type when result is failure.' },
263
+ },
264
+ buildArgs: (a) => {
265
+ const args = [
266
+ 'browser', 'outcome', '--browser', String(a.browser),
267
+ '--decision', String(a.decision), '--task-kind', String(a.task_kind),
268
+ '--result', String(a.result),
269
+ ];
270
+ if (a.verified)
271
+ args.push('--verified');
272
+ if (typeof a.failure_type === 'string' && a.failure_type)
273
+ args.push('--failure-type', a.failure_type);
274
+ return args;
275
+ },
276
+ }));
277
+ ctx.tools.register(cliTool({
278
+ name: 'screen_automation_browser_locate',
279
+ description: 'Locate visible DOM objects in the existing managed browser session. Pass strategy_id only when explicitly adopting the current probe strategy. Page changes invalidate prior objects, so locate again after navigation or actions.',
280
+ parameters: {
281
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'] },
282
+ selector: { type: 'string', description: 'Optional CSS selector.' },
283
+ match_text: { type: 'string', description: 'Optional visible-text filter.' },
284
+ article: { type: 'boolean', description: 'Locate the main article body.' },
285
+ limit: { type: 'number', description: 'Maximum candidates, default 20.' },
286
+ strategy_id: { type: 'string', description: 'Strategy id returned by the current browser probe; omit for ordinary locate.' },
287
+ },
288
+ buildArgs: (a) => {
289
+ const args = ['browser', 'locate', '--browser', String(a.browser)];
290
+ if (typeof a.selector === 'string' && a.selector)
291
+ args.push('--selector', a.selector);
292
+ if (typeof a.match_text === 'string' && a.match_text)
293
+ args.push('--match-text', a.match_text);
294
+ if (a.article)
295
+ args.push('--article');
296
+ if (typeof a.limit === 'number')
297
+ args.push('--limit', String(a.limit));
298
+ if (typeof a.strategy_id === 'string' && a.strategy_id)
299
+ args.push('--strategy-id', a.strategy_id);
300
+ return args;
301
+ },
302
+ }));
303
+ const browserTargetParameters = (extra = {}) => ({
304
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'] },
305
+ selector: { type: 'string', description: 'CSS selector; omit only when object_json is supplied.' },
306
+ match_text: { type: 'string', description: 'Optional visible-text filter.' },
307
+ index: { type: 'number', description: 'Explicit zero-based candidate index when multiple matches are expected.' },
308
+ object_json: { type: 'string', description: 'Previously located object JSON from the same live session.' },
309
+ ...extra,
310
+ });
311
+ const browserTargetArgs = (command, a) => {
312
+ const args = ['browser', command, '--browser', String(a.browser)];
313
+ if (typeof a.selector === 'string' && a.selector)
314
+ args.push('--selector', a.selector);
315
+ if (typeof a.match_text === 'string' && a.match_text)
316
+ args.push('--match-text', a.match_text);
317
+ if (typeof a.index === 'number')
318
+ args.push('--index', String(a.index));
319
+ if (typeof a.object_json === 'string' && a.object_json)
320
+ args.push('--object-json', a.object_json);
321
+ return args;
322
+ };
323
+ ctx.tools.register(cliTool({
324
+ name: 'screen_automation_browser_read',
325
+ description: 'Read fields from one uniquely matched visible object in the existing session. Never open or close the browser around this call.',
326
+ parameters: browserTargetParameters({ fields: { type: 'string', description: 'Comma-separated fields, default text.' } }),
327
+ buildArgs: (a) => {
328
+ const args = browserTargetArgs('read', a);
329
+ if (typeof a.fields === 'string' && a.fields)
330
+ args.push('--fields', a.fields);
331
+ return args;
332
+ },
333
+ }));
334
+ for (const operation of [
335
+ ['click', 'Click one uniquely matched visible browser object.'],
336
+ ['select-text', 'Select the visible text of one uniquely matched browser object.'],
337
+ ]) {
338
+ ctx.tools.register(cliTool({
339
+ name: `screen_automation_browser_${operation[0].replace('-', '_')}`,
340
+ description: `${operation[1]} Re-locate and verify after the action; keep the same managed session open.`,
341
+ parameters: browserTargetParameters(),
342
+ buildArgs: (a) => browserTargetArgs(operation[0], a),
343
+ }));
344
+ }
345
+ ctx.tools.register(cliTool({
346
+ name: 'screen_automation_browser_fill',
347
+ description: 'Fill one uniquely matched browser field, including a credential authorized by the user. Sensitive text is sent over stdin and must not be written into model context, workflow files, runtime logs or result output.',
348
+ parameters: browserTargetParameters({ text: { type: 'string', required: true } }),
349
+ buildArgs: (a) => [...browserTargetArgs('fill', a), '--text-stdin'],
350
+ stdinText: (a) => String(a.text),
351
+ }));
352
+ ctx.tools.register(cliTool({
353
+ name: 'screen_automation_browser_scroll',
354
+ description: 'Scroll the current managed browser page, then locate/read again because page objects may have changed.',
355
+ parameters: {
356
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'] },
357
+ x: { type: 'number', description: 'Horizontal delta.' },
358
+ y: { type: 'number', description: 'Vertical delta.' },
359
+ },
360
+ buildArgs: (a) => ['browser', 'scroll', '--browser', String(a.browser), '--x', String(a.x ?? 0), '--y', String(a.y ?? 0)],
361
+ }));
362
+ ctx.tools.register(cliTool({
363
+ name: 'screen_automation_browser_press',
364
+ description: 'Press a key in the current managed browser session and verify the result without reopening the browser.',
365
+ parameters: {
366
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'] },
367
+ key: { type: 'string', required: true, description: 'Playwright key name such as Enter or Escape.' },
368
+ },
369
+ buildArgs: (a) => ['browser', 'press', '--browser', String(a.browser), String(a.key)],
370
+ }));
371
+ ctx.tools.register(cliTool({
372
+ name: 'screen_automation_browser_copy',
373
+ description: 'Copy one safe field from a uniquely matched browser object. The helper returns bounded metadata and does not log copied content.',
374
+ parameters: browserTargetParameters({ field: { type: 'string', enum: ['text', 'value', 'href'], description: 'Field to copy, default text.' } }),
375
+ buildArgs: (a) => {
376
+ const args = browserTargetArgs('copy', a);
377
+ if (typeof a.field === 'string')
378
+ args.push('--field', a.field);
379
+ return args;
380
+ },
381
+ }));
382
+ ctx.tools.register(cliTool({
383
+ name: 'screen_automation_browser_download',
384
+ description: 'Download through one uniquely matched browser object into the helper-managed download directory.',
385
+ parameters: browserTargetParameters({
386
+ filename: { type: 'string', description: 'Optional safe output filename.' },
387
+ timeout: { type: 'number', description: 'Download timeout seconds.' },
388
+ }),
389
+ buildArgs: (a) => {
390
+ const args = browserTargetArgs('download', a);
391
+ if (typeof a.filename === 'string' && a.filename)
392
+ args.push('--filename', a.filename);
393
+ if (typeof a.timeout === 'number')
394
+ args.push('--timeout', String(a.timeout));
395
+ return args;
396
+ },
397
+ }));
398
+ ctx.tools.register(cliTool({
399
+ name: 'screen_automation_browser_verify',
400
+ description: 'Verify a browser action against an explicit expectation in the existing session.',
401
+ parameters: {
402
+ browser: { type: 'string', required: true, enum: ['chrome', 'edge'] },
403
+ action_json: { type: 'string', required: true, description: 'Action result JSON.' },
404
+ expectation_json: { type: 'string', required: true, description: 'Verification expectation JSON.' },
405
+ },
406
+ buildArgs: (a) => ['browser', 'verify', '--browser', String(a.browser), '--action-json', String(a.action_json), '--expectation-json', String(a.expectation_json)],
407
+ }));
408
+ ctx.tools.register(cliTool({
409
+ name: 'screen_automation_browser_close',
410
+ description: 'Close the managed browser only after the browser task completes, fails, or the user stops it. Never close between observation and action steps.',
411
+ parameters: { browser: { type: 'string', required: true, enum: ['chrome', 'edge'] } },
412
+ buildArgs: (a) => ['browser', 'close', String(a.browser)],
413
+ }));
156
414
  // 3) 列出已安装 workflow
157
415
  ctx.tools.register(cliTool({
158
416
  name: 'screen_automation_list_workflows',
@@ -437,17 +695,18 @@ export function apply(ctx) {
437
695
  // 19) 键入文本
438
696
  ctx.tools.register(cliTool({
439
697
  name: 'screen_automation_type_text',
440
- description: 'Type text into the focused element via the local helper keyboard.',
698
+ description: 'Type user-authorized text into the focused element. Sensitive text is sent over stdin and must not be written into model context, workflow files, runtime logs or result output.',
441
699
  parameters: {
442
700
  text: { type: 'string', required: true, description: 'Text to type.' },
443
701
  interval: { type: 'number', description: 'Seconds between keystrokes (default 0.0).' },
444
702
  },
445
703
  buildArgs: (a) => {
446
- const args = ['keyboard', 'write', '--text', String(a.text)];
704
+ const args = ['keyboard', 'write', '--text-stdin'];
447
705
  if (typeof a.interval === 'number')
448
706
  args.push('--interval', String(a.interval));
449
707
  return args;
450
708
  },
709
+ stdinText: (a) => String(a.text),
451
710
  }));
452
711
  // 20) 组合热键
453
712
  ctx.tools.register(cliTool({
@@ -464,7 +723,7 @@ export function apply(ctx) {
464
723
  // 21) 校验已安装 workflow
465
724
  ctx.tools.register(cliTool({
466
725
  name: 'screen_automation_workflow_validate',
467
- description: 'Validate an installed workflow by id via the local helper CLI.',
726
+ description: 'Validate an installed workflow by id via the local helper CLI. Run this after every workflow change; if it reports an error, stop and fix the workflow instead of guessing unsupported language syntax.',
468
727
  parameters: {
469
728
  workflow_id: { type: 'string', required: true, description: 'Installed workflow id.' },
470
729
  },
@@ -473,7 +732,7 @@ export function apply(ctx) {
473
732
  // 22) 安装 workflow(从本地源路径)
474
733
  ctx.tools.register(cliTool({
475
734
  name: 'screen_automation_workflow_install',
476
- description: 'Install a workflow into the local helper from a source path (directory or archive).',
735
+ description: 'Install a workflow into the local helper from a source path (directory or archive). Inspect and validate the source against the local helper current workflow language before installing; never invent unsupported workflow fields.',
477
736
  parameters: {
478
737
  source: { type: 'string', required: true, description: 'Path to workflow source (dir/archive).' },
479
738
  },
@@ -546,7 +805,7 @@ export function apply(ctx) {
546
805
  // 29) 检查 workflow 源(未安装也能看)
547
806
  ctx.tools.register(cliTool({
548
807
  name: 'screen_automation_workflow_inspect',
549
- description: 'Inspect a workflow source (directory/archive) without installing it; returns its manifest as JSON.',
808
+ description: 'Inspect and validate a workflow source (directory/archive) without installing it; returns validated source metadata as JSON. Use before installing or upgrading a workflow.',
550
809
  parameters: {
551
810
  source: { type: 'string', required: true, description: 'Path to workflow source (dir/archive).' },
552
811
  },
@@ -555,8 +814,11 @@ export function apply(ctx) {
555
814
  // 30) 把小助手截图喂给 dsh 的视觉模型(识别阶梯的最高层:VLM 理解屏幕)
556
815
  // 流程:screen capture 拿图 → ctx.attachments 登记为不可变图片引用 →
557
816
  // 拼一个含 image block 的 user 消息 → ctx.llm.stream 多模态推理 → 收集 text-delta。
558
- // 注意:模型走的是 dsh 当前 profile 配置的 provider;若你想免费本地推理,
559
- // 把本机视觉模型注册成 dsh 的一个 provider,然后把 provider/model 传进来即可。
817
+ // 注意:模型走的是 dsh 当前 profile 配置的 provider。默认 deepseek-official 提供方的
818
+ // deepseek-v4-flash-vision-exp 就是视觉模型,可直接用于屏幕理解;若想改用
819
+ // 本机模型,用环境变量 SCREEN_AUTOMATION_VISION_PROVIDER / _MODEL 配置,或每次
820
+ // 调用传 provider/model(例如本机 Ollama 的 qwen2.5-vl)。understand 依赖
821
+ // ctx.llm 与 ctx.attachments,已在插件顶层 inject 中声明。
560
822
  ctx.tools.register(defineTool({
561
823
  name: 'screen_automation_understand',
562
824
  description: 'Capture the screen via the local helper and feed the screenshot to the dsh vision model. ' +
@@ -569,8 +831,8 @@ export function apply(ctx) {
569
831
  prompt: { type: 'string', description: 'What to ask about the screenshot. Defaults to a general description request.' },
570
832
  target: { type: 'string', description: 'Capture target: foreground | virtual-screen | work-area | task. Default foreground.' },
571
833
  region: { type: 'string', description: 'Optional capture region in helper format (e.g. "0,0,800,600").' },
572
- provider: { type: 'string', description: 'dsh LLM provider route (e.g. deepseek / a local ollama provider). Defaults to deepseek.' },
573
- model: { type: 'string', description: 'Model id registered under the provider. Defaults to deepseek-chat.' },
834
+ provider: { type: 'string', description: 'dsh LLM provider route for vision. Falls back to env SCREEN_AUTOMATION_VISION_PROVIDER, then "deepseek-official".' },
835
+ model: { type: 'string', description: 'Vision model id under the provider. Falls back to env SCREEN_AUTOMATION_VISION_MODEL, then "deepseek-v4-flash-vision-exp".' },
574
836
  system: { type: 'string', description: 'Optional system prompt for the vision call.' },
575
837
  },
576
838
  output: {
@@ -604,7 +866,17 @@ export function apply(ctx) {
604
866
  if (!ctx.attachments) {
605
867
  throw new Error('dsh attachment service (ctx.attachments) is unavailable in this profile; cannot register the screenshot.');
606
868
  }
607
- // 1) 让小助手截图,输出到我们可控的临时文件
869
+ const provider = (typeof args.provider === 'string' && args.provider.trim())
870
+ ? args.provider.trim()
871
+ : (process.env.SCREEN_AUTOMATION_VISION_PROVIDER?.trim() || 'deepseek-official');
872
+ const model = (typeof args.model === 'string' && args.model.trim())
873
+ ? args.model.trim()
874
+ : (process.env.SCREEN_AUTOMATION_VISION_MODEL?.trim() || 'deepseek-v4-flash-vision-exp');
875
+ const modelInfo = await ctx.llm.resolveModelInfo(provider, model);
876
+ if (!modelInfo.inputModalities?.includes('image')) {
877
+ throw new Error(`dsh model ${provider}/${model} does not declare image input; screenshot was not captured.`);
878
+ }
879
+ // 1) 能力确认通过后再让小助手截图,输出到我们可控的临时文件
608
880
  const target = typeof args.target === 'string' && args.target.trim() ? args.target.trim() : 'foreground';
609
881
  const region = typeof args.region === 'string' && args.region.trim() ? args.region.trim() : undefined;
610
882
  const outPath = path.join(os.tmpdir(), `dsh-sa-capture-${process.pid}-${Date.now()}.png`);
@@ -650,9 +922,10 @@ export function apply(ctx) {
650
922
  content: userContent,
651
923
  source: { kind: 'user' },
652
924
  };
653
- // 5) 走 dsh 当前 profile 的视觉模型(可传 provider/model 指向本地模型)
654
- const provider = typeof args.provider === 'string' && args.provider.trim() ? args.provider.trim() : 'deepseek';
655
- const model = typeof args.model === 'string' && args.model.trim() ? args.model.trim() : 'deepseek-chat';
925
+ // 5) 走 dsh 当前 profile 的视觉模型(可传 provider/model 指向本地模型)。
926
+ // 优先级:调用参数 > 环境变量(整 profile 统一默认) > hardcoded 兜底。
927
+ // 默认 deepseek-official 提供方的 deepseek-v4-flash-vision-exp 即视觉模型;
928
+ // 想换本机模型(如 qwen2.5-vl)就靠 provider/model 或环境变量覆盖。
656
929
  let text = '';
657
930
  for await (const chunk of ctx.llm.stream({
658
931
  provider,
@@ -674,7 +947,7 @@ export function apply(ctx) {
674
947
  };
675
948
  },
676
949
  }));
677
- console.log('[screen-automation] loaded; bridged tools: status, capabilities, list/run/stop workflows, runs, health, capture, ' +
950
+ console.log('[screen-automation] loaded; bridged tools: status, capabilities, browser enhancement, list/run/stop workflows, runs, health, capture, ' +
678
951
  'recognize_text, locate_text, color_regions, match_template, contours, wait_text, ' +
679
952
  'click, drag, scroll, long_press, type_text, hotkey, ' +
680
953
  'workflow_validate/install/remove/show/describe/inspect, task_begin/status/end, ' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-screen-automation",
3
- "version": "0.1.2",
3
+ "version": "0.1.9",
4
4
  "description": "DeepSeek Harness (dsh) plugin that bridges the local 'Screen Automation Helper' desktop platform (Windows/macOS) into the Agent tool system. Exposes status, capabilities, workflow list/run/stop, run management, screen capture, local recognition primitives, input control, workflow lifecycle, task sessions and VLM understanding as dsh tools that shell out to the helper's CLI (JSON interface).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,7 +27,8 @@
27
27
  },
28
28
  "scripts": {
29
29
  "build": "tsc -p tsconfig.json",
30
- "watch": "tsc -p tsconfig.json --watch"
30
+ "watch": "tsc -p tsconfig.json --watch",
31
+ "prepack": "npm run build"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "@deepseek-ai/cordis": "*",