Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix: route foreground pointer input through native hit testing

Rach Pradhan3221225a7c4f
diff --git a/apps/native/electron/computer.cjs b/apps/native/electron/computer.cjs
index 99720c8b..d0f755f0 100644
--- a/apps/native/electron/computer.cjs
+++ b/apps/native/electron/computer.cjs
@@ -14,7 +14,7 @@ class ComputerUse {
const { response } = await dialog.showMessageBox(this.window, {
title: 'Computer use', type: 'info', buttons: [this.enabled ? 'Disable computer use' : 'Enable computer use', 'Cancel'], cancelId: 1,
message: this.enabled ? 'Computer use is enabled for this launch.' : 'Let graff interact with macOS apps during your tasks?',
- detail: `Accessibility: ${status.accessibility ? 'allowed' : 'not allowed'}\nScreen Recording: ${status.screenRecording ? 'allowed' : 'not allowed'}\n\nGraff can inspect apps, take screenshots, click and type. Screenshots happen only when requested. You can disable access here at any time; macOS permissions are managed in System Settings.`,
+ detail: `Accessibility: ${status.accessibility ? 'allowed' : 'not allowed'}\nScreen Recording: ${status.screenRecording ? 'allowed' : 'not allowed'}\n\nGraff can inspect apps, take screenshots, click and type. Clicking and scrolling use the system pointer in the foreground app. Screenshots happen only when requested. You can disable access here at any time; macOS permissions are managed in System Settings.`,
});
if (response === 0) {
this.enabled = !this.enabled;
diff --git a/apps/native/electron/native-gui.cjs b/apps/native/electron/native-gui.cjs
index 556ec27a..dde2f7f6 100644
--- a/apps/native/electron/native-gui.cjs
+++ b/apps/native/electron/native-gui.cjs
@@ -61,13 +61,20 @@ app.whenReady().then(async () => {
try {
if (permissions.accessibility) {
testDesktop.present(win);
- await wc.executeJavaScript('document.querySelector("input").focus()');
+ const point = await wc.executeJavaScript(`(() => {
+ document.activeElement.blur();
+ const r = document.querySelector('input').getBoundingClientRect();
+ return { x: r.x + r.width / 2, y: r.y + r.height / 2 };
+ })()`);
+ const bounds = win.getContentBounds();
+ await computer.command('click', { pid: process.pid, x: bounds.x + point.x, y: bounds.y + point.y });
+ await wait(() => wc.executeJavaScript('document.activeElement === document.querySelector("input")'), 'Native OS click did not focus the test input');
const tree = await computer.command('snapshot', { pid: process.pid });
assert.ok(tree.elements.length > 0);
await computer.command('type', { pid: process.pid, text: 'native-input' });
await wait(() => wc.executeJavaScript('document.querySelector("input").value === "native-input"'), 'Native OS typing did not reach the test window');
- report.passed.push('native Accessibility snapshot and OS typing');
- } else report.skipped.push('native Accessibility snapshot and OS typing: Accessibility permission unavailable');
+ report.passed.push('native Accessibility snapshot, OS click and typing');
+ } else report.skipped.push('native Accessibility snapshot, OS click and typing: Accessibility permission unavailable');
if (permissions.screenRecording) {
const capture = await computer.command('screenshot');
assert.ok(capture.data.length > 100);
diff --git a/apps/native/electron/native/ComputerUse.swift b/apps/native/electron/native/ComputerUse.swift
index 24ec465b..a2d4ed27 100644
--- a/apps/native/electron/native/ComputerUse.swift
+++ b/apps/native/electron/native/ComputerUse.swift
@@ -103,15 +103,17 @@ private func nativeCommand(_ p: [String: Any]) -> [String: Any] {
var hitPID: pid_t = 0
AXUIElementGetPid(hit, &hitPID)
guard hitPID == pid else { return fail("Coordinates belong to a different app; inspect the target again") }
- CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: point, mouseButton: .left)?.postToPid(pid)
+ // Pointer events need WindowServer hit-testing to associate the native window.
+ // This foreground-only path moves the system pointer; it is not background input.
+ CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: point, mouseButton: .left)?.post(tap: .cghidEventTap)
if method == "click" {
let right = (p["button"] as? String) == "right"
for type in right ? [CGEventType.rightMouseDown, .rightMouseUp] : [.leftMouseDown, .leftMouseUp] {
- CGEvent(mouseEventSource: nil, mouseType: type, mouseCursorPosition: point, mouseButton: right ? .right : .left)?.postToPid(pid)
+ CGEvent(mouseEventSource: nil, mouseType: type, mouseCursorPosition: point, mouseButton: right ? .right : .left)?.post(tap: .cghidEventTap)
}
} else {
let dy = Int32(max(-2000, min(2000, p["dy"] as? Int ?? 0)))
- CGEvent(scrollWheelEvent2Source: nil, units: .pixel, wheelCount: 1, wheel1: dy, wheel2: 0, wheel3: 0)?.postToPid(pid)
+ CGEvent(scrollWheelEvent2Source: nil, units: .pixel, wheelCount: 1, wheel1: dy, wheel2: 0, wheel3: 0)?.post(tap: .cghidEventTap)
}
return ["ok": true]
}