Skip to content

Commit ccf62e9

Browse files
authored
fix(computer-use): share This PC with the person on Windows (#6598)
* fix(computer-use): share This PC with the person on Windows On Windows the agent kept the front and the pointer after it acted. When the person was using another app, Windows' foreground lock refused the helper and the step failed with "Ask the person to bring the window to the front". A mouse movement between the agent placing the pointer and clicking could move the click. The helper now takes the front only for the agent's moment. It joins the foreground app's input queue for one SetForegroundWindow call, the usual way past the lock. It defers at most half a second to a gap in typing or a released button. 0.4 s after the last focus or input it gives the front back to the window that had it, and the pointer to where the person left it, unless they clicked, typed or moved the mouse since. Low-level mouse and keyboard hooks tell the person's input from the agent's injected events and keep only timestamps. A click or key press of the person's during the moment stops the step with person_interrupted. Before a button or wheel acts, the pointer goes back to the exact point if the person moved it. Between steps, a window that came to the front is put back behind the target at most twice per request. focus_refused now asks the agent to observe again instead of asking the person. Signed-off-by: Jalil <reachjalil@gmail.com> * fix(computer-use): stop on Windows when the person types while the window comes forward The interruption baseline was set after the agent's window reached the front, so a key the person pressed while it came forward could land in it unnoticed. The baseline is now taken just before the raise. A click or key since then stops focus with person_interrupted before any input follows, and the front stays with the agent's window. Signed-off-by: Jalil <reachjalil@gmail.com> * fix(computer-use): never raise over a person who typed since the Windows step began Between steps, Rejoin waited for a gap in the person's typing and then raised the target, though typing during that wait already stopped the step. The step now stops before the raise, so the front stays with the person. Signed-off-by: Jalil <reachjalil@gmail.com> * fix(computer-use): never bring a Windows target forward under a held mouse button TakeGap gave up after half a second, so a drag the person began in another app and still held could end as a drop into the agent's window. Taking the front now stops with person_interrupted while any physical mouse button is down, however long it is held. Signed-off-by: Jalil <reachjalil@gmail.com> --------- Signed-off-by: Jalil <reachjalil@gmail.com>
1 parent 62fe665 commit ccf62e9

3 files changed

Lines changed: 281 additions & 9 deletions

File tree

‎packages/computer-use/README.md‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ a Windows chat starts on it.
153153
and that Windows is not locked or showing a secure prompt; otherwise it stops
154154
and releases held keys and buttons. A click must land on the selected window
155155
or its own popup, never on a window covering it.
156+
- The PC is shared with the person. The agent takes the front only for the
157+
moment it acts: it joins the foreground app's input queue for one
158+
`SetForegroundWindow` call, the usual way past Windows' foreground lock. 0.4 s
159+
after its last focus or input, it gives the front back to the window that had
160+
it and puts the pointer back where the person left it. It does neither if the
161+
person has clicked, typed or (for the pointer) moved the mouse since.
162+
- Low-level mouse and keyboard hooks tell the person's own input from the
163+
agent's injected events and keep only when it happened, never which key or
164+
where. A click or key press of the person's during the agent's moment stops
165+
that step (`person_interrupted`). Moving the mouse never stops or delays the
166+
agent; if it moves the pointer between the agent placing it and clicking, the
167+
pointer goes back to the exact point first. The agent defers at most half a
168+
second to a gap in typing or a released button before taking the front, and
169+
between steps puts its window back in front at most twice per request.
156170
- `command` is sent as Ctrl and `option` as Alt. Clipboard, close/quit and
157171
app-switch chords (Ctrl+C/X/V, Alt+F4, Ctrl+W, Alt+Tab and similar) are refused
158172
before anything is sent.
@@ -161,9 +175,8 @@ a Windows chat starts on it.
161175
Not yet on Windows: accessible controls through UI Automation (so no `assist`
162176
mode, `press` or `set_value`; the agent acts on screenshot coordinates), the
163177
on-desktop presence overlay, and app scripting (`computer_script` is not
164-
offered). Windows may refuse to bring a window to the front while the person
165-
is using another app; the call then fails with nothing sent and asks the
166-
person to bring it forward.
178+
offered). If Windows still refuses to bring the window to the front, the call
179+
fails with nothing sent and the agent observes again.
167180

168181
Build it on Windows with
169182
`node apps/desktop/scripts/prepare-computer-use-helper.mjs --force`; desktop dev

‎packages/computer-use/computer-windows-driver.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// helpers/openwork-computer-use.exe) and talks to it over stdin/stdout, one JSON
44
// object per line. The helper resolves each window by handle, process id and
55
// start time, captures only the selected window, and stops input as soon as the
6-
// window loses focus, moves or closes, Windows locks, or the host cancels.
6+
// window loses focus, moves or closes, Windows locks, the host cancels, or the
7+
// person clicks or types. It takes the front only for the agent's moment and
8+
// then gives the front and the pointer back.
79
// Sessions, receipts, Take over, Continue, Stop and watch frames come from the
810
// shared runtime in computer-remote.mjs.
911
import { spawn } from "node:child_process";

0 commit comments

Comments
 (0)