fix(cua): include system sleep in activity age
This commit is contained in:
1 parent
c86d8c5449
commit
b20dbfd8c3
6 files changed
+34
-9
No files matched your search
@@ -46,8 +46,7 @@ import Foundation
|
||||
|
||||
func receive(_ type: CGEventType, event: CGEvent) {
|
||||
if type == .tapDisabledByTimeout || type == .tapDisabledByUserInput {
|
||||
// A later window use retries registration.
|
||||
stop()
|
||||
if let tap { CGEvent.tapEnable(tap: tap, enable: true) }
|
||||
return
|
||||
}
|
||||
guard event.getIntegerValueField(.eventSourceUnixProcessID) != Int64(getpid()) else { return }
|
||||
@@ -57,7 +56,7 @@ import Foundation
|
||||
guard [.leftMouseDown, .rightMouseDown, .otherMouseDown, .scrollWheel].contains(type) else { return }
|
||||
let rawWindow = event.getIntegerValueField(.mouseEventWindowUnderMousePointerThatCanHandleThisEvent)
|
||||
guard let id = UInt32(exactly: rawWindow), id > 0, ownerOfWindow(id) == pid else { return }
|
||||
activity.record(ActivityTarget(process: process, windowID: id), owner: nil, at: event.timestamp)
|
||||
activity.recordExternal(ActivityTarget(process: process, windowID: id), eventUptime: event.timestamp)
|
||||
}
|
||||
|
||||
nonisolated static func windowOwner(_ id: UInt32) -> Int32? {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Window interests and input metadata belong to the observing helper connection for one turn.
|
||||
import Foundation
|
||||
import Dispatch
|
||||
import Darwin
|
||||
|
||||
struct ActivityTarget: Hashable, Sendable {
|
||||
let process: ProcessIdentity
|
||||
@@ -22,8 +22,20 @@ struct ActivityTarget: Hashable, Sendable {
|
||||
}
|
||||
private var clients: [UUID: Client] = [:]
|
||||
private let now: () -> UInt64
|
||||
private let uptime: () -> UInt64
|
||||
|
||||
init(now: @escaping () -> UInt64 = { DispatchTime.now().uptimeNanoseconds }) { self.now = now }
|
||||
init(now: @escaping () -> UInt64 = { clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW) },
|
||||
uptime: @escaping () -> UInt64 = { clock_gettime_nsec_np(CLOCK_UPTIME_RAW) }) {
|
||||
self.now = now
|
||||
self.uptime = uptime
|
||||
}
|
||||
/// Quartz timestamps exclude sleep. Preserve their delivery delay on the clock used for expiry.
|
||||
func recordExternal(_ target: ActivityTarget, eventUptime: UInt64) {
|
||||
let awake = uptime()
|
||||
let current = now()
|
||||
guard awake >= eventUptime, current >= awake - eventUptime else { return }
|
||||
record(target, owner: nil, at: current - (awake - eventUptime))
|
||||
}
|
||||
func connect(_ owner: UUID, lookbackMs: Int) { clients[owner] = Client(lookback: UInt64(lookbackMs) * 1_000_000) }
|
||||
var hasInterests: Bool { clients.values.contains { $0.windows.values.contains(where: \.armed) } }
|
||||
func disconnect(_ owner: UUID) { clients.removeValue(forKey: owner) }
|
||||
|
||||
@@ -88,7 +88,7 @@ private let second: UInt64 = 1_000_000_000
|
||||
@Test @MainActor func externalInputNeedsAWindowAndANonHelperSource() throws {
|
||||
let owner = UUID()
|
||||
var time = second
|
||||
let history = RecentActivity(now: { time })
|
||||
let history = RecentActivity(now: { time }, uptime: { time })
|
||||
let target = ActivityTarget(process: try NativePlatform.identity(getpid()), windowID: 10)
|
||||
history.connect(owner, lookbackMs: 60_000)
|
||||
let observed = history.observe(target, handle: "app", owner: owner)
|
||||
@@ -111,3 +111,17 @@ private let second: UInt64 = 1_000_000_000
|
||||
.object(["source": .string("external-input"), "windowId": .string("10"), "ageSeconds": .number(0)]),
|
||||
])
|
||||
}
|
||||
|
||||
@Test @MainActor func elapsedTimeIncludesSleepAfterExternalInput() {
|
||||
var awake = second
|
||||
var continuous = 5 * second
|
||||
let history = RecentActivity(now: { continuous }, uptime: { awake })
|
||||
let owner = UUID()
|
||||
history.connect(owner, lookbackMs: 60_000)
|
||||
let observed = history.observe(target, handle: "app", owner: owner)
|
||||
awake += second
|
||||
continuous += second
|
||||
history.recordExternal(target, eventUptime: awake)
|
||||
continuous += 3_600 * second
|
||||
#expect(history.take(owner: owner, handle: "app", observations: ["10": observed]).isEmpty)
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
{
|
||||
"local": "Sources/CuaNative/WindowPointerInput.swift",
|
||||
"upstream": "libs/cua-driver/rust/crates/platform-macos/src/input/mouse.rs",
|
||||
"changes": "Reimplement the exposed window-directed click, drag and line-scroll paths in Swift. Preserve routing fields and gesture timing, post each event once, and release this operation\u2019s held button on cooperative cancellation. Preserve fractional movement delays for short or unevenly divided drags. Support middle-button and modifier-bearing clicks and configurable-button drags. Add unpressed hover with no cursor restoration and omit off-window priming clicks so revealed controls remain interactive."
|
||||
"changes": "Reimplement the exposed window-directed click, drag and line-scroll paths in Swift. Preserve routing fields and gesture timing, post each event once, and release this operation’s held button on cooperative cancellation. Preserve fractional movement delays for short or unevenly divided drags. Support middle-button and modifier-bearing clicks and configurable-button drags. Add unpressed hover with no cursor restoration and omit off-window priming clicks so revealed controls remain interactive."
|
||||
},
|
||||
{
|
||||
"local": "Sources/CuaNative/PIDEventPoster.swift",
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
zh: 515aeb5de6ae5b33
|
||||
/deepseek-ai-dsh-cua/understand-the-implementation:
|
||||
en: fa68a353d7a94703
|
||||
zh: c8df024599f34980
|
||||
zh: 432b2e6823e5eb7d
|
||||
/deepseek-ai-dsh-cua/further-exploration:
|
||||
en: c174fb5a00ea3681
|
||||
zh: 039340042676881d
|
||||
|
||||
@@ -99,7 +99,7 @@ Computer Use 详情页的权限卡片、组件列表和来源信息使用 l3 边
|
||||
|
||||
权限 Remote 还通过 `ptcConfiguration()` 和 `enablePersistentPtc()` 支持详情页的执行方式设置。查询读取现有执行器和可编辑的 profile 条目。显式写入从 Node 提供方的 `resolvePersistentExecution` 辅助函数获取执行设置,再用 `configEditor.edit()` 保留其他字段并按正常 Loader 规则重载;已是持久化模式的执行器保持不变。CUA 将 Node 提供方声明为 peer 依赖,使这些设置与已安装的提供方版本一致。此设置独立于系统权限和应用授权。
|
||||
|
||||
提供方将准备好的 helper、连接工厂、指引回调和启动能力传给 [installCua](src/index.ts)。[NativeClient](src/native-client.ts) 负责请求关联、字节上限、取消确认和失败处理。平台连接器负责启动和连接清理。其带类型的启动失败在请求写入和连接关闭时保留错误码及诊断。共享执行器为每个 Agent 保留一个连接,并在销毁时等待进行中的图像写入。 提供方可通过 `windowRead` 获知已窗口读取所用的应用授权,并在读取成功后接收原生回复。
|
||||
提供方将准备好的 helper、连接工厂、指引回调和启动能力传给 [installCua](src/index.ts)。[NativeClient](src/native-client.ts) 负责请求关联、字节上限、取消确认和失败处理。平台连接器负责启动和连接清理。其带类型的启动失败在请求写入和连接关闭时保留错误码及诊断。共享执行器为每个 Agent 保留一个连接,并在销毁时等待进行中的图像写入。提供方可通过 `windowRead` 获取窗口读取所用的授权连接,并在读取成功后接收原生回复。
|
||||
|
||||
提供方实现 `CuaBackend.getGuidance(kind)`,其中 `kind: 'raw' | 'standalone'`,分别返回原始 `cua` 调用和 `cua_run_code` 程序的操作指引;两种形态可以返回相同文本。共享 CUA 为两份结果统一补充对应能力的权限指引、配置的 AX 读取默认值和最大点击按住时长。
|
||||
|
||||
|
||||
Reference in new issue
Block a user