Skip to content

feat(ucu): agents are told where the user is, and where each listed window is for them - #32

Merged
betoxf merged 3 commits into
mainfrom
feat/user-situation
Nov 25, 2026
Merged

betoxf merged 3 commits into
mainfrom
feat/user-situation

Conversation

@betoxf

@betoxf betoxf commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Based on main. Independent of #30 and #31.

What changes for the user

Agents can now tell what you are doing and looking at, so they can choose when and where to work. Nothing changes on screen.

What agents get

No tool text changes. The tool definitions stay at their size.

  • list_windows begins with a line on the user:
    User: in Mail, window "Inbox", typing. Spaces: 2 desktops, full screen: Safari; showing a desktop.
    It names the app and window they are in, says whether they are typing, active, or how long idle, and describes their Spaces: how many desktops, which apps are in full screen, and which they are looking at.
  • Each listed window says where it is for the user: user-screen, private-desktop or off-screen.
  • Windows on a Space the user isn't looking at follow the list, as other-space. An app's own list leaves those out, which is why a session in full screen could not be found once the user left its Space.
  • A note when the user moves: after they go to another app, or into or out of full screen, the next result ends with [ucu: The user is in Safari in full screen, idle 12 s.]. The first call of a chat says where they are.

How it works

  • ucu-window watch, the helper that runs beside the server, answers a new situation request. After every call the server asks for the app, whether it is in full screen, and what the user is doing, which no app has to answer. For list_windows it also asks for the line, the screens and the windows on other Spaces.
  • The server puts the line before the helper's list, marks each window from the screens, and adds the windows on other Spaces after it. The list command itself is unchanged.
  • Spaces come from the window server through three calls macOS doesn't document (CGSMainConnectionID, CGSCopyManagedDisplaySpaces, CGSCopySpacesForWindows). Each is looked up at run time, and where one is missing nothing is said of Spaces. An agent's desktop has Spaces of its own, which are left out.

What it costs

  • A helper built before it knew the question never answers it. A chat that starts while an update is still building the new helper has such a one for its whole life, and every call would wait a second for it. It is asked once and then left alone.

  • The helper answers in 0.3 ms after a call and 0.5 ms for a list (medians of 20). Its first answer for a list in a chat took 150 ms.

  • The list command is unchanged and takes what it took: 0.07 seconds for one app and 0.21 for every app (medians of 11). Through the server, a list of every app took 0.20 seconds.

  • A first version did the work in the list command, which is started anew each time. That made it 55 ms slower, 27 of them only to connect to the display system for the screens, so it moved to the helper.

What is told, and what is not

  • App names, the title of the window the user is in, whether they type, and their Spaces. Not what is in their windows.
  • A snapshot of this moment. No history is kept.
  • A window's title is left out for an app on the deny list, and for every app when the deny list can't be read. App names are told for those too, as list_windows already did.
  • The lines are part of the tool results, so they go to whichever model drives UCU.

How it was validated

python3 -m unittest discover -s tests in ucu/: 176 pass, 4 of them new. One was checked to fail without its code. No CI workflow runs ucu/tests, and no unit test covers ucu-window.

On this Mac, with the server and helper built from this branch:

  • The line: the right app, window title and idle time. With the front app on the deny list, and with no deny list given, the title was left out.
  • Marks: user-screen on the 8 windows of a full list, and private-desktop on a test app's two windows after move_to_desktop.
  • Full screen, with a test app's window: in its Space the line said full screen: DialogProbe; showing full screen (DialogProbe), and the note said in full screen. Back on the desktop the line said showing a desktop, the helper's list left the window out, and it followed as DialogProbe: "Dialog Probe List" fullscreen other-space.
  • The note: told on the first call, not repeated while nothing changed, told again when the user went into full screen and when they came back.

Merged locally with #30 and #31, in the scenario round of 24 November that #30 describes, with the user really working: the line named the app and window they were in and said "active", the windows of two test apps were marked private-desktop after move_to_desktop, and the note followed them from one app to the next.

Not verified

  • More than one display of the user's, and more than one desktop: this Mac had one of each.
  • A real app in full screen, such as a remote session. The test app's window stood in for it.
  • A Mac where the three calls are missing, or where Screen Recording is not granted: from the code, Spaces and the windows on other Spaces are then left out.
  • Another MCP client.

Limits

Notes for review

…indow is for them

An agent could not tell what the user was doing or looking at, so it could not choose when or where to work.
`list_windows` now begins with a line on the user: the app and window they are in, whether they type, and their
Spaces, with the apps in full screen and what is showing. Each listed window says whether it is on the user's
screen, on an agent's desktop or on no screen, and windows on a Space the user isn't looking at follow the list,
which an app's own list leaves out. When the user moves to another app, or into or out of full screen, the next
result ends with a note that names the app.

All of it comes from the helper that runs beside the server, which answers in half a millisecond. Done in the
`list` command, started anew each time, the same took 55 ms more, 27 of them for the screens alone. The title of
the user's window is left out for an app on the deny list, and for every app when the list can't be read. No
tool text changes.
…t after every call

A chat that starts while an update is still building the new helper keeps the old one for its whole life. That
one never answers the new question, so every call would have waited a second for it.
…nch adds tests

Two branches adding tests before the same line conflict for no reason.
@betoxf
betoxf marked this pull request as ready for review November 24, 2026 13:05
@betoxf
betoxf merged commit f528f4b into main Nov 25, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant