forked from cflmy/deepseek-harness
docs(cua): clarify what the macOS activity listener records
This commit is contained in:
1 parent
69863f91fd
commit
c10a5008ff
12 files changed
+19
-12
No files matched your search
@@ -15,8 +15,8 @@
|
||||
en: 1777e7bf6785f986
|
||||
zh: e3daac1074ebb74d
|
||||
/deepseek-ai-dsh-cua-macos/use-this-package:
|
||||
en: 9ddf794c9bd4d350
|
||||
zh: f235de9e6b68481a
|
||||
en: c529fedb203d7449
|
||||
zh: 3c3536b007fe626a
|
||||
/deepseek-ai-dsh-cua-macos/use-this-package/connect-an-external-execution-environment:
|
||||
en: 6097d7d03bc8dfad
|
||||
zh: 0978077447118d64
|
||||
|
||||
@@ -80,7 +80,9 @@ Source builds default to `sourceSigning: ad-hoc`, without creating certificates
|
||||
| `dragDurationMs` / `dragSteps` | `400` / `20` | Duration and movement segments for a drag. |
|
||||
| `textEventIntervalMs` | `0.25` | Delay after each Unicode down/up event, from 0 to 999 ms. Keystroke timing is independent. |
|
||||
|
||||
After a window accessibility read or screenshot, the next scheduled model step checks for input on that window since the start of the last successfully delivered read and within the configured lookback, including input during capture. The notice gives the window ID and time of the latest activity from each source: another Agent or external input. Each window can produce one notice until the Agent uses it again. Watches end with the turn or connection. The notice is recorded in the Session.
|
||||
After a window accessibility read or screenshot, the plugin warns the Agent when other input may have changed the window. Before the next scheduled model step, it checks for activity since the start of the last successfully delivered read, within the configured lookback. Each window can produce one notice until the Agent uses it again. Watches end with the turn or connection.
|
||||
|
||||
The external input listener subscribes only to mouse button presses and scrolling. For a watched window, the helper keeps the latest timestamp per source (another Agent or external input) in memory. The activity notice sent to the model and recorded in the Session contains only the window ID, source and elapsed time. The listener does not record keystrokes, typed text, pointer coordinates or scroll distances.
|
||||
|
||||
The [configuration catalog](../../../docs/config-catalog.md#deepseek-aidsh-cua-macos) lists all fields. Native tool calls use `{method, params}`; the complete method-specific schema is exposed to the model. `getApp` returns the `appHandle` used by every app-targeted operation, and `app.getWindow(windowId)` returns the object that owns screenshots and pointer input.
|
||||
|
||||
|
||||
@@ -80,7 +80,9 @@ pnpm dsh headless --patch packages/experimental/cua-macos/examples/macos.cordis.
|
||||
| `dragDurationMs` / `dragSteps` | `400` / `20` | 拖动时长和移动分段数。 |
|
||||
| `textEventIntervalMs` | `0.25` | 每个 Unicode 按下或抬起事件后的间隔,范围为 0 至 1000 毫秒。击键节奏独立。 |
|
||||
|
||||
模型读取窗口辅助功能树或截图后,插件在下一次模型请求前检查该窗口。回看从最近一次成功读取开始采样时算起,因此也能提示读取期间发生的输入。超过回看时限的活动会被排除。提醒给出窗口 ID,并分别说明其他 Agent 和外部输入最近出现的时间。每个窗口最多提醒一次,直到 Agent 再次使用该窗口。本轮结束或连接断开时停止关注,已发送的提醒保存在 Session 中。
|
||||
模型读取窗口辅助功能树或截图后,其他输入可能已改变窗口。插件在下一次模型请求前提醒 Agent。检查范围从最近一次成功读取开始采样时算起,且限于配置的回看时长。每个窗口最多提醒一次,直到 Agent 再次使用该窗口。本轮结束或连接断开时停止关注。
|
||||
|
||||
外部输入监听器只订阅鼠标按下和滚动事件。对于关注的窗口,helper 在内存中分别保留其他 Agent 和外部输入最近一次活动的时间。发给模型并写入 Session 日志的活动提醒只包含窗口 ID、来源和距今时间。监听器不记录按键、输入文本、鼠标坐标或滚动距离。
|
||||
|
||||
[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-cua-macos)列出全部字段。原生工具调用使用 `{method, params}`,模型可以看到每个方法的完整参数定义。`getApp` 返回每个面向应用的操作所需的 `appHandle`,`app.getWindow(windowId)` 返回负责截图和指针输入的对象。
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
en: f29d74be684f5840
|
||||
zh: 67233850329d1db1
|
||||
/dsh-cua-native-helper/request-protocol:
|
||||
en: 5459399e8b4bfa26
|
||||
zh: 3ae85c20de5b0a61
|
||||
en: da316afc1edbe50e
|
||||
zh: a150c1dacc689f4b
|
||||
/dsh-cua-native-helper/observation-and-input:
|
||||
en: 4821c4e278a5c0bf
|
||||
zh: 53105c1d7e175a89
|
||||
|
||||
@@ -61,7 +61,7 @@ AppKit runs on the main event loop. Blocking socket accepts and handshakes use b
|
||||
<a id="request-protocol"></a>
|
||||
## Request protocol
|
||||
|
||||
The shared service accepts an integer `recentActivityWindowMs` (default 60000) or `"off"` per connection through the handshake or `--recent-activity-window-ms`. Enabled connections track the latest timestamps for other Agent input and window-attributed external clicks or scrolling. The Host calls `takeWindowActivity` for the windows observed under each authorized app handle and `clearWindowActivity` at turn end. The shared listener stops when no window has an outstanding interest.
|
||||
The shared service accepts an integer `recentActivityWindowMs` (default 60000) or `"off"` per connection through the handshake or `--recent-activity-window-ms`. To flag potentially stale window observations, enabled connections keep one timestamp per source and window in memory. The external input tap uses process and window IDs to attribute clicks and scrolling, then discards the event. The Host calls `takeWindowActivity` for the windows observed under each authorized app handle and `clearWindowActivity` at turn end. The shared listener stops when no window has an outstanding interest.
|
||||
|
||||
Operation frames remain `{ "id": "opaque request id", "method": "method name", "params": {} }`. The matching reply contains exactly one of `result` or `error: {code, message}`; malformed envelopes return `INVALID_REQUEST` with a null ID. A connection sends at most one operation at a time. `{ "type": "cancel", "id": "request id" }` cancels that request; a late cancel produces no extra reply. `protocol.schema.json` defines operation fields.
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ AppKit 在主事件循环上运行。阻塞式 socket 接收与握手使用后
|
||||
<a id="request-protocol"></a>
|
||||
## 请求协议
|
||||
|
||||
每条连接通过握手字段 `recentActivityWindowMs` 或参数 `--recent-activity-window-ms` 设置回看时长,默认 60000 毫秒,填 `"off"` 可关闭。启用的连接分别记录其他 Agent 和可定位到窗口的外部点击、滚动的最近时间。Host 在每个已授权的应用句柄下调用 `takeWindowActivity` 查询观察过的窗口,并在本轮结束时调用 `clearWindowActivity`。所有窗口都停止等待提醒时,helper 卸载共享监听器。
|
||||
每条连接通过握手字段 `recentActivityWindowMs` 或参数 `--recent-activity-window-ms` 设置回看时长,默认 60000 毫秒,填 `"off"` 可关闭。为判断先前观察到的窗口是否可能发生变化,启用的连接在内存中按窗口和来源保留最近一次活动的时间。外部输入监听器通过进程和窗口 ID 判断点击或滚动属于哪个窗口,处理后即丢弃事件。Host 在每个已授权的应用句柄下调用 `takeWindowActivity` 查询观察过的窗口,并在本轮结束时调用 `clearWindowActivity`。所有窗口都停止等待提醒时,helper 卸载共享监听器。
|
||||
|
||||
操作帧为 `{ "id": "opaque request id", "method": "method name", "params": {} }`。对应回复只包含 `result` 或 `error: {code, message}` 中的一项;无效信封返回 `INVALID_REQUEST`,ID 为 null。每条连接同时最多发送一个操作。`{ "type": "cancel", "id": "request id" }` 取消该请求,迟到的取消不会产生额外回复。`protocol.schema.json` 定义操作字段。
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ import Foundation
|
||||
if !CGEvent.tapIsEnabled(tap: tap) { CGEvent.tapEnable(tap: tap, enable: true) }
|
||||
return
|
||||
}
|
||||
// A click or scroll may make an observed window stale. The tap forwards only the target and time.
|
||||
// It does not subscribe to keyboard input or retain pointer coordinates or scroll deltas.
|
||||
let types: [CGEventType] = [.leftMouseDown, .rightMouseDown, .otherMouseDown, .scrollWheel]
|
||||
let mask = types.reduce(CGEventMask(0)) { $0 | (CGEventMask(1) << $1.rawValue) }
|
||||
guard let created = CGEvent.tapCreate(tap: .cgAnnotatedSessionEventTap, place: .tailAppendEventTap,
|
||||
|
||||
@@ -14,6 +14,7 @@ struct ActivityTarget: Hashable, Sendable {
|
||||
var lastReport: UInt64?
|
||||
var lastOwnUse: UInt64?
|
||||
var armed = true
|
||||
// Keep only the latest timestamp per source for the window activity notice.
|
||||
var events: [String: UInt64] = [:]
|
||||
}
|
||||
private struct Client {
|
||||
|
||||
@@ -56,7 +56,7 @@ export function watchWindowActivity(ctx: Context): NonNullable<CuaBackend['windo
|
||||
for (const { windowId, ageSeconds, source } of rows) {
|
||||
const actor = source === 'agent' ? 'another agent' : 'a user or an automated program'
|
||||
const elapsed = ageSeconds === 0 ? 'less than a second' : `${ageSeconds} ${ageSeconds === 1 ? 'second' : 'seconds'}`
|
||||
lines.push(`Activity from ${actor} was last detected on window ${windowId} ${elapsed} ago.`)
|
||||
lines.push(`Activity from ${actor} was last detected on window ${windowId}, ${elapsed} ago.`)
|
||||
}
|
||||
} catch (error) {
|
||||
if (signal.aborted) return decision
|
||||
|
||||
@@ -232,7 +232,7 @@ it('delivers window activity at the next accepted step and clears it at turn end
|
||||
{ windowId: '7', source: 'external-input', ageSeconds: 0 },
|
||||
])
|
||||
expect(await step()).toMatchObject({ messages: [{ source: { kind: 'cua-activity' }, content: [{ type: 'text',
|
||||
text: '<system-reminder>\nActivity from another agent was last detected on window 7 1 second ago.\nActivity from a user or an automated program was last detected on window 7 less than a second ago.\nYour actions may have been influenced.\n</system-reminder>',
|
||||
text: '<system-reminder>\nActivity from another agent was last detected on window 7, 1 second ago.\nActivity from a user or an automated program was last detected on window 7, less than a second ago.\nYour actions may have been influenced.\n</system-reminder>',
|
||||
}] }] })
|
||||
expect(native.request).toHaveBeenLastCalledWith('takeWindowActivity', { appHandle: 'app-one', observations: { '7': '101' } }, expect.any(AbortSignal))
|
||||
expect(await step()).toMatchObject({ messages: [] })
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
{"type":"tool/result","data":{"turn":1,"step":6,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-native-3"},"toolCallId":"cua-native-3","content":[{"type":"text","text":"{\"appHandle\":\"fixture-app\",\"windowId\":\"7\",\"focusedWindowId\":\"7\",\"snapshotId\":\"fixture-snapshot-1\",\"tree\":\"AX scope=window offsets=UTF-16 bounds=global-points\\n- [0] AXButton \\\"Increment\\\" id=\\\"increment\\\" actions=[\\\"AXPress\\\"] bounds=[60,80,100,20]\\n- [1] AXTextField valueWritable=true selectionWritable=true value=\\\"\\\" placeholder=\\\"Fixture text\\\"\\n- AXStaticText \\\"Count: 0\\\"\\n- [2] AXMenuBarItem \\\"File\\\"\\n - [3] AXMenuItem \\\"Fixture command\\\"\",\"windows\":[{\"windowId\":\"7\",\"appName\":\"Fixture\",\"title\":\"CUA fixture\",\"bounds\":{\"x\":40,\"y\":60,\"width\":320,\"height\":200},\"isOnScreen\":true,\"onCurrentSpace\":true},{\"windowId\":\"8\",\"appName\":\"Fixture\",\"title\":\"AXless canvas\",\"bounds\":{\"x\":40,\"y\":60,\"width\":320,\"height\":200},\"isOnScreen\":true,\"onCurrentSpace\":true},{\"windowId\":\"9\",\"appName\":\"Fixture\",\"title\":\"Transformed window\",\"bounds\":{\"x\":16,\"y\":512,\"width\":131,\"height\":145},\"isOnScreen\":true,\"onCurrentSpace\":true}],\"truncated\":false}"}],"isError":false,"id":"{{message:15}}"}},"sourceEventSeqs":[39],"surfaceOp":"append"}
|
||||
{"type":"step/end","data":{"turn":1,"step":6}}
|
||||
{"type":"step/start","data":{"turn":1,"step":7}}
|
||||
{"type":"user/message","data":{"source":{"kind":"cua-activity","form":"notice","summary":"Computer use activity update"},"content":[{"type":"text","text":"<system-reminder>\nActivity from another agent was last detected on window 7 8 seconds ago.\nActivity from a user or an automated program was last detected on window 7 4 seconds ago.\nYour actions may have been influenced.\n</system-reminder>"}],"role":"user","id":"{{message:16}}"},"surfaceOp":"append"}
|
||||
{"type":"user/message","data":{"source":{"kind":"cua-activity","form":"notice","summary":"Computer use activity update"},"content":[{"type":"text","text":"<system-reminder>\nActivity from another agent was last detected on window 7, 8 seconds ago.\nActivity from a user or an automated program was last detected on window 7, 4 seconds ago.\nYour actions may have been influenced.\n</system-reminder>"}],"role":"user","id":"{{message:16}}"},"surfaceOp":"append"}
|
||||
{"type":"assistant/message","data":{"turn":1,"step":7,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-native-4","name":"cua","arguments":"{\"method\":\"click\",\"params\":{\"appHandle\":\"fixture-app\",\"snapshotId\":\"fixture-snapshot-1\",\"elementId\":\"0\",\"holdMs\":800}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:17}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1795164691092,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1795164691092,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-native-4","name":"cua","arguments":"{\"method\":\"click\",\"params\":{\"appHandle\":\"fixture-app\",\"snapshotId\":\"fixture-snapshot-1\",\"elementId\":\"0\",\"holdMs\":800}}"}}},{"type":"chunk","time":1795164691092,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1795164691092,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
|
||||
{"type":"tool/call","data":{"turn":1,"step":7,"callId":"cua-native-4","name":"cua","arguments":"{\"method\":\"click\",\"params\":{\"appHandle\":\"fixture-app\",\"snapshotId\":\"fixture-snapshot-1\",\"elementId\":\"0\",\"holdMs\":800}}"}}
|
||||
{"type":"tool/result","data":{"turn":1,"step":7,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-native-4"},"toolCallId":"cua-native-4","content":[{"type":"text","text":"{\"dispatched\":true}"}],"isError":false,"id":"{{message:18}}"}},"sourceEventSeqs":[45],"surfaceOp":"append"}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
{"type":"tool/result","data":{"turn":1,"step":1,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-ptc-activity-without-inspect"},"toolCallId":"cua-ptc-activity-without-inspect","content":[{"type":"text","text":"(run_code completed with no output)"}],"isError":false,"id":"{{message:5}}"}},"sourceEventSeqs":[14],"surfaceOp":"append"}
|
||||
{"type":"step/end","data":{"turn":1,"step":1}}
|
||||
{"type":"step/start","data":{"turn":1,"step":2}}
|
||||
{"type":"user/message","data":{"source":{"kind":"cua-activity","form":"notice","summary":"Computer use activity update"},"content":[{"type":"text","text":"<system-reminder>\nActivity from another agent was last detected on window 7 8 seconds ago.\nActivity from a user or an automated program was last detected on window 7 4 seconds ago.\nYour actions may have been influenced.\n</system-reminder>"}],"role":"user","id":"{{message:6}}"},"surfaceOp":"append"}
|
||||
{"type":"user/message","data":{"source":{"kind":"cua-activity","form":"notice","summary":"Computer use activity update"},"content":[{"type":"text","text":"<system-reminder>\nActivity from another agent was last detected on window 7, 8 seconds ago.\nActivity from a user or an automated program was last detected on window 7, 4 seconds ago.\nYour actions may have been influenced.\n</system-reminder>"}],"role":"user","id":"{{message:6}}"},"surfaceOp":"append"}
|
||||
{"type":"assistant/message","data":{"turn":1,"step":2,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-ptc-native-result","name":"run_code","arguments":"{\"code\":\"const { readFile } = await import('node:fs/promises');\\nconst app = await tools.cua({ method: 'getApp', params: { selector: 'test.fixture' } });\\nconst target = { appHandle: app.appHandle, windowId: '7' };\\nconst first = await tools.cua({ method: 'getState', params: { ...target, maxElements: 1 } });\\nconst state = first.truncated ? await tools.cua({ method: 'getState', params: { ...target, maxElements: 16 } }) : first;\\nconst shot = await tools.cua({ method: 'screenshot', params: { appHandle: app.appHandle, windowId: '7' } });\\nconst bytes = await readFile(shot.path);\\ninspect({ appHandle: app.appHandle, initiallyTruncated: first.truncated, recoveredTextField: !first.tree.includes('AXTextField') && state.tree.includes('AXTextField'), hasIncrement: state.tree.includes('Increment'), pngBytes: bytes.length, signature: bytes.subarray(0, 8).toString('hex'), imageWidth: shot.width, imageHeight: shot.height }, shot); return;\",\"description\":\"Read native CUA values and receive one screenshot\"}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:7}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1795164698501,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1795164698501,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-ptc-native-result","name":"run_code","arguments":"{\"code\":\"const { readFile } = await import('node:fs/promises');\\nconst app = await tools.cua({ method: 'getApp', params: { selector: 'test.fixture' } });\\nconst target = { appHandle: app.appHandle, windowId: '7' };\\nconst first = await tools.cua({ method: 'getState', params: { ...target, maxElements: 1 } });\\nconst state = first.truncated ? await tools.cua({ method: 'getState', params: { ...target, maxElements: 16 } }) : first;\\nconst shot = await tools.cua({ method: 'screenshot', params: { appHandle: app.appHandle, windowId: '7' } });\\nconst bytes = await readFile(shot.path);\\ninspect({ appHandle: app.appHandle, initiallyTruncated: first.truncated, recoveredTextField: !first.tree.includes('AXTextField') && state.tree.includes('AXTextField'), hasIncrement: state.tree.includes('Increment'), pngBytes: bytes.length, signature: bytes.subarray(0, 8).toString('hex'), imageWidth: shot.width, imageHeight: shot.height }, shot); return;\",\"description\":\"Read native CUA values and receive one screenshot\"}"}}},{"type":"chunk","time":1795164698501,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1795164698501,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
|
||||
{"type":"tool/call","data":{"turn":1,"step":2,"callId":"cua-ptc-native-result","name":"run_code","arguments":"{\"code\":\"const { readFile } = await import('node:fs/promises');\\nconst app = await tools.cua({ method: 'getApp', params: { selector: 'test.fixture' } });\\nconst target = { appHandle: app.appHandle, windowId: '7' };\\nconst first = await tools.cua({ method: 'getState', params: { ...target, maxElements: 1 } });\\nconst state = first.truncated ? await tools.cua({ method: 'getState', params: { ...target, maxElements: 16 } }) : first;\\nconst shot = await tools.cua({ method: 'screenshot', params: { appHandle: app.appHandle, windowId: '7' } });\\nconst bytes = await readFile(shot.path);\\ninspect({ appHandle: app.appHandle, initiallyTruncated: first.truncated, recoveredTextField: !first.tree.includes('AXTextField') && state.tree.includes('AXTextField'), hasIncrement: state.tree.includes('Increment'), pngBytes: bytes.length, signature: bytes.subarray(0, 8).toString('hex'), imageWidth: shot.width, imageHeight: shot.height }, shot); return;\",\"description\":\"Read native CUA values and receive one screenshot\"}"}}
|
||||
{"type":"tool/ptc-dispatch-start","data":{"rootCallId":"cua-ptc-native-result","parentCallId":"cua-ptc-native-result","subCallId":"cua-ptc-native-result:ptc:1","name":"cua","arguments":{"method":"getApp","params":{"selector":"test.fixture"}}}}
|
||||
|
||||
Reference in new issue
Block a user