Recursive AI

The harness: driving a running app

All oneapp docs

Every Debug build of an app built on the RecursiveAI.OneApp package can listen on a local socket for MCP and be driven the way a person uses it: click, type, press keys, wait, look at the accessibility tree, capture pixels. Tests and automation tools use this instead of a window system they do not own. A Release build carries no listener: the harness ships in the package, and the app's build decides whether it is in the app (see the next section), so a shipped app has nothing to turn on.

Input goes through OnePlatform's input injector into the window's own event queue, so hover, focus, transitions and listeners run as for a device. Nothing calls a listener directly.

Building with or without the harness

The package's build targets set the MSBuild property OneAppHarness and pass it to the app as the runtime feature switch OneApp.Harness.Enabled:

OneAppHarnessWhen
truethe default when Configuration is Debug
falsethe default for every other configuration

Set it in the project file (or with -p:OneAppHarness=true) to override the default either way. With false the switch is a build-time constant: the trimmer and NativeAOT remove the listener, every verb and the RecursiveAI.OneModelContext assembly from the app, and neither ONEAPP_HARNESS nor AppOptions.Harness can start it. The same applies to ONEAPP_BACKEND. Check a shipped binary with strings for HarnessListener: there should be no hit. A framework-dependent (untrimmed) app still carries the code but never runs it while the switch is false.

Turning it on

ONEAPP_HARNESS=unix:auto (or 1)Unix socket <private folder>/<pid>.sock (see below for the folder)
ONEAPP_HARNESS=unix:PATHUnix socket at PATH; at most 103 bytes, or the app refuses to start the listener and says so
ONEAPP_HARNESS=tcp:PORTloopback TCP, 0 picks a port; needs the token below
ONEAPP_HARNESS_INFO=FILEwhere to write the discovery file (default <private folder>/<pid>.json)
ONEAPP_HARNESS_TOKEN=…the TCP token (default: random, written to the discovery file)
ONEAPP_BACKEND=headlessrun with no window system at all (any PlatformBackendKind name works)
AppOptions.Harnessthe same as ONEAPP_HARNESS, from code; the variable is read when this is null

The private folder is oneapp-harness-<user> under the temp folder (TMPDIR), when the longest path in it (<pid>.sock, ten-digit pid) is at most 103 bytes, the size of a Unix socket address on macOS (sun_path is 104 bytes there, 108 on Linux). When it is not, which is the normal case on macOS where TMPDIR is /var/folders/xx/…/T/, the folder is /tmp/oneapp-harness-<user>. The app and the oneapp tool choose with the same code, and oneapp also looks in the other candidate when it lists running apps, so a different TMPDIR in the two processes does not hide an app. An explicit unix:PATH is never rewritten.

oneapp run sets these for you. The discovery file is JSON: {"pid":…,"address":"unix:…" | "tcp:127.0.0.1:PORT","token":"…"} (the token only for TCP).

Transport and security

  • MCP over the stdio framing: one JSON-RPC message per line, UTF-8, at most 1 MiB per line.
  • Unix socket (default): in a folder created 0700 (an existing folder that is readable by others is refused), the socket and the discovery file 0600. Only the same user can connect.
  • TCP binds 127.0.0.1 only, never another interface. The first line a client sends must be the token (compared in constant time, 5 s to send it, 256 bytes at most); otherwise the connection is dropped before MCP starts. The oneapp tool and oneapp mcp do this from the discovery file.
  • Every verb runs on the app's UI thread, between loop turns. The loop sleeps in the operating system until input, a page timer or a request arrives; a request ends the sleep (PlatformApp.Wake), so there is no polling. Idle with a listener and no requests: no frames are drawn and no CPU is used.

Conventions

  • Coordinates and sizes in arguments and results are CSS pixels of the window's client area (device pixels divided by the window's scale). Captures are in device pixels.

  • Elements are picked with a CSS selector; index picks the nth match when several match (default 0).

  • Results are JSON text. A failing verb returns an MCP tool error whose text is {"error":{"code":"…","message":"…"}}. Codes: invalid_argument (the message says what was expected, including unknown argument names), no_match, not_visible, obscured, no_focus, timeout, unavailable, no_window, internal_error.

  • tools/list returns each verb's JSON Schema.

  • Windows. An app can have several windows (dialogs, overlays, menu popups). Every verb that acts on a page (query, page_text, status, a11y, click, double_click, hover, type, press, wheel, focus, capture, wait) takes an optional window: an id from windows, main (the first main window still open, the default) or focused. A menu popup is driven like any window: press ArrowDown/Enter or click one of its #mi<N> rows with window set to its id. A click that picks a menu item or closes a dialog closes the window it went to, and the result then says windowClosed: true in place of an element. resize and close_window keep their own id argument. In the CLI every such command takes --window.

Verbs

Queries

VerbArgumentsResult
queryselector, limit (20, ≤200){count, matches:[element…]}; an element is {tag, id, classes[], text, attributes{}, bounds{x,y,width,height}|null, visible, hittable, focused, hovered, active, disabled, value?, checked?}. visible: a non-empty box that meets the viewport. hittable: the element is the topmost thing at its own centre. text: a text control's value, else the text with whitespace collapsed.
page_textselector?{text} of the body, or of the first match
windows{backend, windows:[{id,title,width,height,scale,focused,minimized,maximized,fullscreen,closed,keepAbove,role,parent?}]}; role is toplevel, dialog, overlay or popup
status{pid, backend, gpu, presenter, presenterReason?, presenterDetail?, gpuUnavailable?, presentedFrames, pageCreations, accessibility{state, reason?, detail?}, animating, viewport{width,height,scale}, focused}. presenter is gpu, cpu (OneRender's rasterizer draws the page and the window shows the pixels) or none (headless); presenterReason says why it is not the GPU (Requested, Environment, NoGpuDevice, GpuFailed, see docs/shell.md). Call it twice with nothing between to see whether the app draws while idle.
a11yselector?, includeIgnored (false), maxDepth (64)OneHtml's accessibility tree, nested: {role, name, description?, element, focused?, tabbable?|focusable?, states…, children[]}; text nodes are {role:"text", name}. State fields appear only when set: disabled required readOnly busy modal expanded selected checked pressed level invalid value valueText valueNow.

Input

VerbArgumentsWhat it does
click, double_clickselector+index, or x+y; button (left, middle, right)Scrolls the element into view, moves the pointer to its centre, presses and releases. obscured when something else covers that point. Result {at{x,y}, element?}.
hoveras clickMoves the pointer; :hover styles start. Follow with wait {ms} for a transition.
wheelas click, dx, dy (notches; positive dy scrolls down)Turns the wheel at the point
focusselector, indexScript focus (focus()); use click or press Tab to focus as a person does
typetext, selector?, index, clearTypes text into the focused element; with selector it is clicked first; clear presses Ctrl+A first. no_focus when nothing has focus. Result {typed, focused}.
presskeys, repeat (1)A key or chord: Tab, Enter, Escape, ArrowDown, F5, a, Shift+Tab, Ctrl+A. Modifiers Ctrl Shift Alt Meta; keys are OnePlatform.Key names (case-insensitive) with aliases Esc Return Del Up Down Left Right PgUp PgDn. Key events only, no text. Result {focused}.

Captures

VerbArgumentsResult
capturesource (auto, window, gpu, raster), selector?+index, path?, inline?PNG written to path (folders are created) and/or returned as an MCP image (inline is the default without a path). window is the frame the window shows, read from its back buffer; gpu is the same drawing offscreen; raster is OneRender's rasterizer and needs no GPU; auto tries them in that order. With selector the image is clipped to the element's box. Result {source, width, height, bytes, path?}; source says which drawing was used.

Control

VerbArgumentsWhat it does
waitselector?, index, until (present, absent, visible, hidden, focused, enabled, disabled), text, textContains, ms, timeoutMs (5000)Runs the app until the condition holds. text must equal the element's text (the page text without a selector); textContains is a substring test. ms alone just lets the app run (transitions, timers). On timeout: timeout, with what was last seen.
resizewidth, height, id?Resizes the window and runs the app until it has. The page lays out again in place.
close_windowid?Closes a window as its close button does
keep_abovevalue?, window?Reads, or with value sets, whether the window is kept above ordinary windows. Result {keepAbove, canKeepAbove, pending, failure?}; pending while a request waits for the window to be shown. unavailable when the window system cannot do it.
quitAsks the app to quit; the reply is sent first
menu_barpath? (titles joined by >)macOS and Windows. No path: every menu and item as JSON (title, enabled, key, checked, items), and tray (visible, window frame, items) when the app has a tray item. With path (Shell Demo > Quit Shell Demo, tray > Open dialog): chooses that item as a click would. An item that quits the app ends the connection before it replies (the CLI prints {"closed":true})
native_dialogaction (status, cancel, accept)macOS. Whether a native file dialog is open, and presses its Cancel or Open/Save button
press_hotkeyidmacOS and Windows. Sends the system's own "hotkey pressed" event for a hotkey the app bound, so the registration and handler run without a keyboard

| component | path?, window? | A window that shows OneUI components (see components.md): the mounted tree with each component's state, or one state value by path (TodoApp/Items). |

The oneapp tool

oneapp run <project|dir> [--headless] [--detach] [--tcp] [--timeout SECONDS] [-- app args]
oneapp apps | tools
oneapp call <verb> [json]
oneapp query <selector> [--limit N]           (all of these take --window <id|main|focused>)
oneapp click <selector> [--index N] [--button b]      oneapp click --at X,Y      oneapp hover …
oneapp type <text> [--into <selector>] [--clear]
oneapp press <keys>
oneapp capture [--selector S] [--source auto|window|gpu|raster] [--out FILE]
oneapp wait <selector> [--until U] [--text T] [--contains T] [--timeout MS]     oneapp wait --ms N
oneapp mcp                                    stdio MCP bridge for tools that speak MCP

run starts dotnet run -c Debug with the listener on and prints {"pid","launcherPid","address","info"} once it listens, then relays the app's output to stderr until it exits (--detach prints and returns; the app's output goes to the log file named in the result; stop it with quit). Other commands take --app <info file | unix:PATH | tcp:127.0.0.1:PORT>; without it they use ONEAPP_HARNESS_INFO, then the only running app. Output is the verb's JSON. Exit codes: 0 done, 1 the app reported an error (or the launched app failed), 2 bad usage, 3 no app or no connection. capture writes ./capture.png unless --out is given. Tools that speak MCP over stdio run oneapp mcp.

Run apps under a headless backend (--headless) or a session of your own; the tool does nothing to keep an app off the desktop it is started from.

Known limits

  • Resizing lays the page out again in place: typed values, focus, listeners and scroll positions stay.
  • The page keeps text set by a listener (SetTextContent) beside its document. query and page_text read the current text; a11y patches names and text of elements that hold a single text node and text controls' values, and nothing else yet.
  • Selectors are OneHtml's: no :hover or :focus matching; use the hovered and focused fields.