dsh-copilot-vision 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -111,7 +111,7 @@ DSH_HOME=<DSH_HOME> dsh plugin --profile web add file:<绝对路径>/dsh-copilot
111
111
  ```
112
112
 
113
113
  - **宿主**:web(问答卡片授权)/ headless(无 UI 答者,只能 Shift+Space,需真人在场)/ desktop(待 DSH 市场审核后内置验证)。
114
- - **授权**:按 Shift+Space 开启或撤销持续授权;模型也可调 `vp_request_auth(mode='persistent')` 请求,你在卡片上确认一次。单次授权已取消。
114
+ - **授权**:按 Shift+Space 开启或撤销持续授权;模型也可调 `vp_request_auth(mode='persistent')` 请求,你在卡片上确认一次。单次授权已取消。热键在插件加载后约 250ms 才生效——启动关键阶段不加载 robot-ts 原生模块(原生段错误是唯一无法被 try/catch 接住的故障面);这段时间内 `vp_auth_status` 会返回 `hotkeyAvailable:false` 并说明原因。
115
115
  - **平台**:本地主屏。Windows 完整验证;macOS 与 Linux/X11 已接入但未在真机回归。macOS 首次使用需在「系统设置 → 隐私与安全性」授予宿主应用的**辅助功能**与**屏幕录制**权限,改完授权必须重启宿主进程;Linux 需 X11 会话(XTest + XRandR + XRecord),Wayland 会话没有截屏、也没有全局钩子,请改用 Xorg 会话;若走 uinput 注入还需 `/dev/uinput` 读写权限(input 组或 udev 规则)。未拿到全局钩子时插件按 Fail-Closed 收回授权并在错误里给出对应授权入口。pnpm 11 拦截构建脚本时,在 profile 的 `pnpm-workspace.yaml` 中允许 `robot-ts` 构建;native 缺失时插件仍可加载,调用时返回可读错误。
116
116
  - **落盘**:截图、索引、审计日志默认在 `os.tmpdir()/vision-pilot-shots/`,`VP_SHOT_DIR` 可整体重定向。
117
117
  - **迭代**:tarball 是快照,同版本重新 `add` 会被判 "Already up to date"——改源码后标准流程是 `npm pack` → `remove` → `add`。
@@ -119,6 +119,7 @@ DSH_HOME=<DSH_HOME> dsh plugin --profile web add file:<绝对路径>/dsh-copilot
119
119
  ## 限制与边界
120
120
 
121
121
  - **输入能力边界**:支持键盘输入(`vp_type` 文本 / `vp_key` 按键与组合键);不支持拖拽、滚轮、双击。键盘只作用于**当前焦点控件**,模型无法自己「在地址栏输入」前必须先用鼠标点中输入框。
122
+ - **失败只降级、不外抛**:工具定义或注册阶段失败(dsh-tools 换了签名、工具重名、schema 被宿主驳回)只记录一行日志并跳过,其余工具照常注册;热键初始化全程 try/catch,失败时 `hotkeyAvailable:false` 并按 Fail-Closed 收回授权。插件不会把异常抛给宿主,也不会在宿主启动路径上加载原生模块。
122
123
  - **输入法干扰**:中文输入法会吞掉扫描码注入的字母键(按下不落字,要到下一次 Enter 才吐幽灵字符)。插件已对无修饰键的字符键改走 Unicode 直注绕开它,但用户在输入法里挂着的组合串仍会被 `vp_key enter` 一起提交。
123
124
  - **聊天窗口自干扰**:宿主聊天窗口的流式重绘会被当成屏幕变化(实测覆盖率约为变化门限的 14 倍)。等页面加载时,优先给 `vp_wait_change` / `vp_screenshot_diff` 传 `region` 只盯目标区域,或先把聊天窗口移出主屏、最小化。
124
125
  - **鼠标移动不可检测**:Windows 屏幕捕获不含硬件光标,挪鼠标不产生任何像素变化。
@@ -10,6 +10,8 @@
10
10
  | pixelmatch | 8.0.0 | ISC |
11
11
  | pngjs | 7.0.0 | MIT |
12
12
 
13
+ > 版本说明:上表按 `package-lock.json` 锁定的版本收录(robot-ts 2.0.3)。部署 profile 由 `dependencies` 的 `^2.0.3` 实际解析到 2.1.1;本插件使用的 API 面(`primaryMonitor` / `captureMonitor` / `typeText` / `typeChar` / `canWarpCursor` / `canTypeUnicode` / `EventTap`)在这两个版本上一致,已逐一核对。robot-ts 的原生模块以 N-API 8 预编译形式随包分发(`prebuilds/<platform>-<arch>/`),安装时不编译。
14
+
13
15
  ### robot-ts (MIT)
14
16
 
15
17
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-copilot-vision",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "description": "为 DSH(DeepSeek Harness)打造的本地桌面 Computer Use 增强插件(Windows 完整验证,macOS 与 Linux/X11 已接入):纯 JS 视觉差分、网格位置编码、键盘注入、语义级记忆压缩、长程任务闭环与人机共驾授权。",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -43,10 +43,10 @@
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@deepseek-ai/cordis": "^4.0.1",
46
- "@deepseek-ai/dsh-tools": "^0.1.5-rc.1 || ^0.2.0-rc.2"
46
+ "@deepseek-ai/dsh-tools": "^0.1.5-rc.1 || ^0.2.0-rc.2 || ^0.2.2-rc.5"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@deepseek-ai/cordis": "^4.0.1",
50
- "@deepseek-ai/dsh-tools": "^0.1.5-rc.1 || ^0.2.0-rc.2"
50
+ "@deepseek-ai/dsh-tools": "^0.1.5-rc.1 || ^0.2.0-rc.2 || ^0.2.2-rc.5"
51
51
  }
52
52
  }
package/src/index.js CHANGED
@@ -2,14 +2,14 @@
2
2
  //
3
3
  // 三层结构:
4
4
  // actions.js —— 业务逻辑(robot-ts + 授权闸门,可被回归测试直接调用)
5
- // plugin.js —— 工具定义(createPlugin(defineTool, ctx, hotkeyState))
5
+ // plugin.js —— 工具定义(createPluginSafe(defineTool, ctx, hotkeyState),失败降级为空工具集)
6
6
  // index.js —— 本文件:注入宿主 defineTool/ctx,并把热键生命周期交给 ctx.effect
7
7
  //
8
8
  // @deepseek-ai/dsh-tools 与 @deepseek-ai/cordis 由宿主以 peerDependency 提供
9
9
  // (声明见 package.json),本地 node_modules 中不存在属正常现象。
10
10
 
11
11
  import { defineTool } from '@deepseek-ai/dsh-tools'
12
- import { createPlugin } from './plugin.js'
12
+ import { createPluginSafe } from './plugin.js'
13
13
  import { startHotkey } from './hotkey.js'
14
14
  import { togglePersistent, revokeAll } from './auth.js'
15
15
  import { cleanupVisualFragments } from './paths.js'
@@ -17,40 +17,74 @@ import { cleanupVisualFragments } from './paths.js'
17
17
  export const name = 'dsh-copilot-vision'
18
18
  export const inject = ['tools', 'userQuestions']
19
19
 
20
+ // 热键延后启动:robot-ts 的原生模块只在 Session.create() 时才被加载,而热键初始化
21
+ // 会创建一个 Session。把这段挪出 apply() 的同步路径,宿主启动的关键阶段就完全不碰
22
+ // 原生代码——原生段错误是唯一能穿透 Cordis 错误隔离、直接带走进程的风险面。
23
+ // 代价:加载后约 250ms 内 Shift+Space 尚未生效(期间 vp_auth_status 会如实说明)。
24
+ const HOTKEY_START_DELAY_MS = 250
25
+
26
+ /** 把插件自己的失败写进宿主日志。这是兜底路径的一部分,它自己绝不允许再抛。 */
27
+ function reportFailure(ctx, message, error) {
28
+ const detail = error instanceof Error ? error.message : String(error)
29
+ const text = `dsh-copilot-vision: ${message}:${detail}`
30
+ try {
31
+ if (typeof ctx?.logger?.error === 'function') ctx.logger.error(text)
32
+ else console.error(text)
33
+ } catch {
34
+ // 记日志都失败时保持沉默:此处唯一的职责是别把异常抛给宿主。
35
+ }
36
+ }
37
+
20
38
  export function apply(ctx) {
21
- const hotkeyState = { available: false, error: '热键尚未初始化' }
39
+ const hotkeyState = {
40
+ available: false,
41
+ error: `热键将在插件加载后异步初始化(约 ${HOTKEY_START_DELAY_MS}ms)`,
42
+ }
22
43
 
23
44
  // 热键是长驻资源:注册在 Cordis effect 上,插件禁用/重载时自动注销。
24
- // 启动是异步的,effect 的 disposer 同时处理“启动完成前就被卸载”的竞态。
45
+ // 启动是异步且延后的,effect 的 disposer 同时负责取消定时器、以及处理
46
+ // “启动完成前就被卸载”的竞态。
25
47
  ctx.effect(() => {
26
48
  let disposed = false
27
49
  let handle
50
+ let timer
28
51
 
29
- startHotkey({
30
- onToggle: () => {
31
- togglePersistent()
32
- },
33
- // 急停通道失效 = 不能继续相信 persistent:先摘掉热键可用标记,再强制回 unauthorized。
34
- onUnavailable: (reason) => {
52
+ const begin = () => {
53
+ timer = undefined
54
+ startHotkey({
55
+ onToggle: () => {
56
+ togglePersistent()
57
+ },
58
+ // 急停通道失效 = 不能继续相信 persistent:先摘掉热键可用标记,再强制回 unauthorized。
59
+ onUnavailable: (reason) => {
60
+ hotkeyState.available = false
61
+ hotkeyState.error = reason
62
+ revokeAll('eventtap')
63
+ },
64
+ }).then((started) => {
65
+ hotkeyState.available = started.available
66
+ hotkeyState.error = started.error
67
+ if (disposed) {
68
+ void started.dispose()
69
+ } else {
70
+ handle = started
71
+ }
72
+ }).catch((error) => {
35
73
  hotkeyState.available = false
36
- hotkeyState.error = reason
37
- revokeAll('eventtap')
38
- },
39
- }).then((started) => {
40
- hotkeyState.available = started.available
41
- hotkeyState.error = started.error
42
- if (disposed) {
43
- void started.dispose()
44
- } else {
45
- handle = started
46
- }
47
- }).catch((error) => {
48
- hotkeyState.available = false
49
- hotkeyState.error = error instanceof Error ? error.message : String(error)
50
- })
74
+ hotkeyState.error = error instanceof Error ? error.message : String(error)
75
+ })
76
+ }
77
+
78
+ // unref:宿主若在热键起来之前就决定退出,这个定时器不该拖住宿主。
79
+ timer = setTimeout(begin, HOTKEY_START_DELAY_MS)
80
+ timer.unref?.()
51
81
 
52
82
  return () => {
53
83
  disposed = true
84
+ if (timer !== undefined) {
85
+ clearTimeout(timer)
86
+ timer = undefined
87
+ }
54
88
  if (handle !== undefined) {
55
89
  const current = handle
56
90
  handle = undefined
@@ -59,9 +93,20 @@ export function apply(ctx) {
59
93
  }
60
94
  }, 'dsh-copilot-vision.hotkey')
61
95
 
62
- const plugin = createPlugin(defineTool, ctx, hotkeyState)
96
+ const { plugin, error } = createPluginSafe(defineTool, ctx, hotkeyState)
97
+ if (error !== undefined) {
98
+ // 定义阶段失败(schema 非法、dsh-tools 改了签名等):本轮不注册任何工具,
99
+ // 但异常到此为止——兼容层回归的代价应该是「工具消失」,不是宿主退出。
100
+ reportFailure(ctx, '工具定义失败,本次加载未注册任何工具', error)
101
+ }
102
+
63
103
  for (const tool of plugin.tools) {
64
- ctx.tools.register(tool)
104
+ try {
105
+ ctx.tools.register(tool)
106
+ } catch (error) {
107
+ // 单条注册失败(重名、被宿主 schema 校验驳回)只损失这一个工具,其余照常。
108
+ reportFailure(ctx, `工具 ${tool.name} 注册失败,其余工具继续注册`, error)
109
+ }
65
110
  }
66
111
 
67
112
  // 启动时异步清理一次超龄的差分/网格切片。fire-and-forget:清理失败绝不阻断插件加载,
package/src/plugin.js CHANGED
@@ -334,6 +334,19 @@ const OFFSET_SCHEMA = {
334
334
  },
335
335
  }
336
336
 
337
+ /**
338
+ * 容错版工厂:定义阶段(defineTool 校验 schema、宿主换签名)失败时绝不外抛。
339
+ * 兼容层回归的代价应该是「工具消失 + 宿主日志一行」,而不是把异常交给宿主
340
+ * 去决定整个插件的生死。返回 { plugin, error },调用方负责记日志。
341
+ */
342
+ export function createPluginSafe(defineTool, ctx, hotkeyState) {
343
+ try {
344
+ return { plugin: createPlugin(defineTool, ctx, hotkeyState), error: undefined }
345
+ } catch (error) {
346
+ return { plugin: { name, inject, tools: [] }, error }
347
+ }
348
+ }
349
+
337
350
  export function createPlugin(defineTool, ctx, hotkeyState = { available: false, error: '热键尚未初始化' }) {
338
351
  const screenshotTool = defineTool({
339
352
  name: 'vp_screenshot',