Computer use for the Pi coding agent — Windows apps, browsers and desktops through native UI trees, screenshots and real input.
TypeScript accessibilityagent-toolsai-agentbrowser-automationcomputer-usecuadesktop-automationelectronpipi-coding-agentpi-extensionpi-packageplaywrighttypescriptui-automationvisionwebview2windowswindows-automationwsl
feat!: input by target goes through UI Automation only and falls back to the real pointer; points and keys are real input; the foreground parameter is gone (LPT-942)
alexshpunt-clanker[bot]da479c5a0b1c
diff --git a/src/complete-input.ts b/src/complete-input.tsindex a3800af..7e105b4 100644--- a/src/complete-input.ts+++ b/src/complete-input.ts@@ -201,7 +201,7 @@ function validateTimeline(events: unknown, point: (x: unknown, y: unknown) => vo/** Translate supported fields only. Coordinates stay in the original overview's local image domain.* captureBoundDrag enables straight-drag binding only for a separately qualified native runtime. */-export function nativeInput(command: InputCommand, target: { pid: number; window_id: number }, delivery: string, captureId?: string, captureBoundDrag = false): { name: string; args: Record<string, unknown> } {+export function nativeInput(command: InputCommand, target: { pid: number; window_id: number }, delivery: string, captureId?: string, captureBoundDrag = false, uiaOnly = false): { name: string; args: Record<string, unknown> } {if (isCoordinateScroll(command)) return { name: "scroll_at", args: {...target, capture_id: captureId, x: command.x, y: command.y,delta_x: command.delta_x ?? 0, delta_y: command.delta_y ?? 0, unit: command.unit, delivery_mode: delivery,@@ -221,6 +221,11 @@ export function nativeInput(command: InputCommand, target: { pid: number; windowif (value !== undefined) args[key === "modifiers" ? command.action === "key" ? "modifiers" : "modifier" : key] = value;}if (command.action === "select_all") args.keys = ["ctrl", "a"];+ // UI Automation only: an element click or scroll that no pattern carries is refused by the driver, never posted.+ if (uiaOnly) {+ if (args.element_token === undefined || !["click", "scroll"].includes(name)) throw new Error("uia_only takes a click or scroll on an element token.");+ args.uia_only = true;+ }if (captureId && ((command.action === "click" && command.x !== undefined) || (captureBoundDrag && command.action === "drag" && command.via === undefined))) args.capture_id = captureId;return { name, args };}diff --git a/src/computer-resources.ts b/src/computer-resources.tsindex f6925b1..df365ec 100644--- a/src/computer-resources.ts+++ b/src/computer-resources.ts@@ -61,13 +61,13 @@ export interface InputPlan {native: Record<string, unknown> | string;/** The Playwright action without its target, or why browser pages cannot run it. */web: Record<string, unknown> | string;- /** true sends native input in the foreground at once; false never leaves the background. */- foreground?: boolean;+ /** Internal: send real input, after UI Automation could not carry the action on its target. */+ real?: boolean;/** Runs after this one is delivered, such as Enter after typing. */then?: InputPlan;}-/** Native input that moves the real pointer, so it always goes in the foreground. */-const FOREGROUND_ONLY = ["hover", "move", "timeline"];+/** Native actions a target carries through UI Automation: a click runs the element's Invoke, Toggle, SelectionItem or ExpandCollapse pattern, a scroll its scroll pattern. */+const STRUCTURAL = ["click", "check", "uncheck", "scroll"];/** Native actions that only a locator target runs; a ref of the latest Read becomes the locator of its element. */const LOCATOR_ONLY = ["check", "uncheck"];/** What a target string is: a native ref of a window Read (1:a), a page ref of a DOM Read (e12, f1e3), or a Playwright locator. */@@ -284,8 +284,6 @@ export class ComputerResources {private readonly starting = new Map<string, Promise<OpenedMachine>>();/** Sandbox launches and machine starts still in progress; a cancelled one finishes its own cleanup before it settles. */private readonly opening = new Set<Promise<unknown>>();- /** Windows that refused background input once; typed input to them goes in the foreground. */- private readonly foreground = new Set<string>();/** Short aliases of this run's long addresses (computer:zinpc/w3qk). */private readonly shorts = new ShortAddresses();/** Window names the agent gave, with the window's title when it was named. */@@ -899,17 +897,19 @@ export class ComputerResources {/*** Typed input on a native window: a locator resolves in fresh UI walks, a ref of the latest Read and points use the- * window's current observation, captured first when there is none with the pixels a point needs. A background- * refusal, which sends nothing, is retried at once in the foreground, and the window keeps foreground delivery.+ * window's current observation, captured first when there is none with the pixels a point needs. A click or scroll+ * on a target goes through UI Automation; when no pattern carries it, which sends nothing, it goes again as real input.*/private async nativeStep(window: string, session: ComputerSession, plan: InputPlan, cwd: string, signal?: AbortSignal): Promise<ComputerResult> {if (typeof plan.native === "string") throw new ComputerRequestError(plan.native);const command: Record<string, unknown> = structuredClone(plan.native);const action = String(command.action);- const pointerOnly = FOREGROUND_ONLY.includes(action);- if (pointerOnly && plan.foreground === false) throw new ComputerRequestError(`${plan.label} on a native window moves the real pointer, so it needs the foreground.`);- const foreground = plan.foreground ?? (pointerOnly || this.foreground.has(window));- if (foreground && !isSemanticAction(action)) command.delivery_mode = "foreground";+ // What the agent sees structurally is pressed structurally: a click or scroll on a target goes through UI Automation+ // alone, and the driver refuses before sending anything when no pattern carries it. Points, keys, drags and timelines+ // are real input; semantic actions and menus are UI Automation calls of their own.+ const structural = !plan.real && plan.target !== undefined && plan.point === undefined && STRUCTURAL.includes(action) && command.unit === undefined && command.modifiers === undefined;+ if (structural) command.uia_only = true;+ else if (!isSemanticAction(action) && action !== "menu") command.delivery_mode = "foreground";let target = plan.target;let view = session.inputView(window);// The registry decides whether an observation still grounds input: a detail Read, a sequence or the registry's@@ -923,7 +923,7 @@ export class ComputerResources {delete command.option;}let result: ComputerResult;- // What a foreground retry sends: the input observation is spent by then, so its refs become locators or points.+ // What the real-input retry sends: the input observation is spent by then, so its refs become locators or points.let retry = (): InputPlan => plan;if (refKind(target) === "locator") {if (plan.end) throw new ComputerRequestError(`${plan.label} takes refs of the window's latest Read or points, not locators.`);@@ -967,10 +967,9 @@ export class ComputerResources {result = await this.performAt(observation, cwd, JSON.stringify(command), signal);}const capability = result.details.action_capability;- if (foreground || plan.foreground === false || result.details.status !== "refused" || capability?.background !== "unavailable") return result;- this.foreground.add(window);- const again = await this.nativeStep(window, session, { ...retry(), foreground: true }, cwd, signal);- return { ...again, content: [{ type: "text", text: `The window refused background input (${capability.code}), so this call sent it in the foreground; later input to this window goes in the foreground.` }, ...again.content] };+ if (!structural || result.details.status !== "refused" || capability?.background !== "unavailable") return result;+ const again = await this.nativeStep(window, session, { ...retry(), real: true }, cwd, signal);+ return { ...again, content: [{ type: "text", text: `No UI Automation pattern of the target carried this ${plan.label}, so this call used the real pointer.` }, ...again.content] };}/** The element of a ref in the window's current observation. */diff --git a/src/computer-tools.ts b/src/computer-tools.tsindex e2998a5..7cbf9d5 100644--- a/src/computer-tools.ts+++ b/src/computer-tools.ts@@ -255,10 +255,9 @@ export function recordCommand(params: Static<typeof recordParameters>): { comman}const inputWindow = Type.String({ description: "Window address from Search, Read or a name, such as computer:zinpc/w3qk or computer:game." });-const inputTarget = (what: string) => Type.Optional(Type.String({ description: `${what}: a ref from the window's latest Read (1:a in a window Read, e12 in a page snapshot) or a Playwright locator such as getByRole('button', { name: 'Save' }).` }));-const coordinate = (axis: string) => Type.Optional(Type.Number({ minimum: 0, description: `${axis} of a point instead of target: pixels of the window's latest image, or CSS pixels of a browser page.` }));+const inputTarget = (what: string) => Type.Optional(Type.String({ description: `${what}: a ref from the window's latest Read (1:a in a window Read, e12 in a page snapshot) or a Playwright locator such as getByRole('button', { name: 'Save' }). On native windows a target is pressed through UI Automation in the background when it supports that, otherwise with the real pointer.` }));+const coordinate = (axis: string) => Type.Optional(Type.Number({ minimum: 0, description: `${axis} of a point instead of target: pixels of the window's latest image, or CSS pixels of a browser page. A point on a native window gets the real pointer: the window comes to the front.` }));const pointSpace = Type.Optional(Type.Union([Type.Literal("page"), Type.Literal("window")], { description: "Browser windows: page (default) takes refs, locators and CSS points of the page; window takes refs and points of a window Read, such as the browser's own toolbar." }));-const foregroundField = Type.Optional(Type.Boolean({ description: "Native windows: true sends input in the foreground at once (it activates the window and moves the real pointer); false never leaves the background. By default input starts in the background and moves to the foreground when the window refuses it." }));const modifiersField = Type.Optional(Type.Array(Type.Union([Type.Literal("ctrl"), Type.Literal("shift"), Type.Literal("alt"), Type.Literal("win")]), { maxItems: 4, description: "Keys held during the action." }));const locatorTimeout = Type.Optional(Type.Integer({ minimum: 0, maximum: 60000, description: "How long a locator target may take to match one ready element, default 5000." }));const PAGE_MODIFIERS: Record<string, string> = { ctrl: "Control", shift: "Shift", alt: "Alt", win: "Meta" };@@ -273,8 +272,7 @@ function aim(params: Endpoint, label: string, required: boolean): Pick<InputPlanreturn { ...(params.target !== undefined ? { target: params.target } : {}), ...(point ? { point } : {}) };}/** Fields every input plan shares. */-const shared = (params: { space?: "page" | "window"; foreground?: boolean }) =>- ({ ...(params.space ? { space: params.space } : {}), ...(params.foreground !== undefined ? { foreground: params.foreground } : {}) });+const shared = (params: { space?: "page" | "window" }) => ({ ...(params.space ? { space: params.space } : {}) });const timeout = (params: { timeout_ms?: number }) => params.timeout_ms !== undefined ? { timeout_ms: params.timeout_ms } : {};const pageModifiers = (modifiers?: string[]) => modifiers?.length ? { modifiers: modifiers.map(key => PAGE_MODIFIERS[key]) } : {};/** A Playwright key name for a key the native tools also take, such as ctrl, return, up or f5. */@@ -297,7 +295,7 @@ const clickParameters = Type.Object({window: inputWindow, target: inputTarget("The element to click"), x: coordinate("Left"), y: coordinate("Top"), space: pointSpace,button: Type.Optional(Type.Union([Type.Literal("left"), Type.Literal("right"), Type.Literal("middle")], { description: "Mouse button, default left." })),count: Type.Optional(Type.Integer({ minimum: 1, maximum: 3, description: "Clicks: 2 is a double click, 3 a triple click (browser pages). Default 1." })),- modifiers: modifiersField, timeout_ms: locatorTimeout, foreground: foregroundField,+ modifiers: modifiersField, timeout_ms: locatorTimeout,}, { additionalProperties: false });/** What computer_click sends to a native window and to a browser page. */@@ -338,7 +336,7 @@ const dragParameters = Type.Object({{ minItems: 1, maxItems: 254, description: "Points the pointer passes through on the way, in order, for a path rather than a straight line; left button only." })),duration_ms: Type.Optional(Type.Integer({ minimum: 0, maximum: 10000, description: "How long the move takes, default 500." })),button: Type.Optional(Type.Union([Type.Literal("left"), Type.Literal("right"), Type.Literal("middle")], { description: "Button held during the drag, default left." })),- modifiers: modifiersField, foreground: foregroundField,+ modifiers: modifiersField,}, { additionalProperties: false });/** What computer_drag sends: a native drag, or a page timeline that presses, moves and releases. */@@ -359,7 +357,7 @@ const scrollParameters = Type.Object({window: inputWindow, target: inputTarget("The element to scroll; omit for the middle of the window or page"), x: coordinate("Left"), y: coordinate("Top"), space: pointSpace,delta_x: Type.Optional(Type.Integer({ minimum: -50, maximum: 50, description: "Wheel notches to the right (negative: left)." })),delta_y: Type.Optional(Type.Integer({ minimum: -50, maximum: 50, description: "Wheel notches down (negative: up). One notch scrolls about 100 CSS pixels in a browser; apps decide their own distance." })),- timeout_ms: locatorTimeout, foreground: foregroundField,+ timeout_ms: locatorTimeout,}, { additionalProperties: false });/** What computer_scroll sends: wheel notches at a point, or an accessibility scroll of a native element target. */@@ -376,12 +374,12 @@ export function scrollPlan(params: Static<typeof scrollParameters>): InputPlan {}const typeParameters = Type.Object({- window: inputWindow, text: Type.String({ maxLength: 20000, description: "Text to type, as is: newlines and quotes stay text. Native windows take up to 2000 characters." }),+ window: inputWindow, text: Type.String({ maxLength: 20000, description: "Text to type, as is: newlines and quotes stay text. Native windows take up to 2000 characters and get real key presses, so the window comes to the front; replace sets the value through UI Automation instead." }),target: inputTarget("The field to type into; omit for the focused element"), space: pointSpace,replace: Type.Optional(Type.Boolean({ description: "Replace the field's whole value instead of typing at the caret; needs target." })),submit: Type.Optional(Type.Boolean({ description: "Press Enter after the text." })),delay_ms: Type.Optional(Type.Integer({ minimum: 0, maximum: 200, description: "Native windows: pause between characters." })),- timeout_ms: locatorTimeout, foreground: foregroundField,+ timeout_ms: locatorTimeout,}, { additionalProperties: false });/** What computer_type sends, with Enter as a second step when submit is set. */@@ -396,10 +394,9 @@ export function typePlan(params: Static<typeof typeParameters>): InputPlan {}const pressParameters = Type.Object({- window: inputWindow, key: Type.String({ maxLength: 64, description: "A key with optional modifiers joined by +, such as Enter, ctrl+s, shift+Tab, F5, ArrowDown or a." }),+ window: inputWindow, key: Type.String({ maxLength: 64, description: "A key with optional modifiers joined by +, such as Enter, ctrl+s, shift+Tab, F5, ArrowDown or a. Native windows get real key presses, so the window comes to the front." }),target: inputTarget("The element to focus first; omit for the focused element"), space: pointSpace,hold_ms: Type.Optional(Type.Integer({ minimum: 1, maximum: 10000, description: "Native windows: hold the keys down this long, for apps and games that read held keys." })),- foreground: foregroundField,}, { additionalProperties: false });const PAGE_KEYS: Record<string, string> = { enter: "Enter", return: "Enter", esc: "Escape", escape: "Escape", tab: "Tab", space: "Space", backspace: "Backspace", delete: "Delete", del: "Delete",up: "ArrowUp", down: "ArrowDown", left: "ArrowLeft", right: "ArrowRight", home: "Home", end: "End", pageup: "PageUp", pagedown: "PageDown", pgup: "PageUp", pgdn: "PageDown" };diff --git a/src/session.ts b/src/session.tsindex f40ab25..55cab9b 100644--- a/src/session.ts+++ b/src/session.ts@@ -72,6 +72,8 @@ export type Action = {window_ref: string;observation_id: string;delivery_mode?: "background" | "foreground";+ /** A click or scroll on an element token goes through UI Automation only; the driver refuses when no pattern carries it. */+ uia_only?: boolean;} & (InputCommand | { action: "sequence"; sequence: InputStep[] });/** A stored Playwright snapshot of the active tab, with the tab list, any held dialog and events since the previous snapshot. */export interface WebDom extends WebPage { truncated: boolean; matches?: number }@@ -1604,11 +1606,13 @@ export class ComputerSession {const change = await this.observationChange(entry, observed, signal).catch((error: unknown) => `the window state could not be read (${error instanceof Error ? error.message : error})`);if (change) { entry.observation = undefined; return this.result("refused", `Observation expired: ${change}. Read the window again; no input was dispatched.`); }}- const { window_ref: _ref, observation_id: _id, delivery_mode, ...command } = action;+ const { window_ref: _ref, observation_id: _id, delivery_mode, uia_only, ...command } = action;const batch = command.action === "sequence";let commands: InputStep[];try {if (delivery_mode !== undefined && !["background", "foreground"].includes(delivery_mode)) throw new Error("Unsupported delivery mode.");+ if (uia_only !== undefined && (uia_only !== true || delivery_mode === "foreground" || batch || !["click", "scroll"].includes(String(command.action))))+ throw new Error("uia_only takes one background click or scroll on an element.");if (batch) {if (Object.keys(command).some(key => !["action", "sequence"].includes(key)) || !Array.isArray(command.sequence) || command.sequence.length < 1 || command.sequence.length > SEQUENCE_STEPS)throw new Error(`A sequence needs 1..${SEQUENCE_STEPS} steps and no conflicting top-level action fields.`);@@ -1682,7 +1686,7 @@ export class ComputerSession {if (!current) return finish(this.result("refused", "Window closed or its native handle was reused. Discover again."), "Window lifetime changed.");if (signal?.aborted) return finish(this.result("refused", "Cancelled."), "Cancelled before dispatch.");// The native capture is single-use: the first step that binds to it spends it, later pixel steps use the window's current mapping.- const { name, args } = nativeInput(step, entry.target, delivery_mode ?? "background", capture, this.driver.captureBoundDrag);+ const { name, args } = nativeInput(step, entry.target, delivery_mode ?? "background", capture, this.driver.captureBoundDrag, uia_only);if (args.capture_id !== undefined) capture = undefined;// AX bounds are native. Only native click receipts establish an exact pixel action mark.const mark = { kind: "action" as const, region: step.element_token ? observed.frames.get(step.element_token) : undefined };diff --git a/test/computer-resources.test.ts b/test/computer-resources.test.tsindex ba3313f..fa2fc02 100644--- a/test/computer-resources.test.ts+++ b/test/computer-resources.test.ts@@ -2,16 +2,16 @@ import { expect, test, vi } from "vitest";import sharp from "sharp";import { computerSource } from "../src/computer-address.ts";import { ComputerResources, requireComputerAddress } from "../src/computer-resources.ts";-import { clickPlan, typePlan } from "../src/computer-tools.ts";+import { clickPlan, pressPlan, scrollPlan, typePlan } from "../src/computer-tools.ts";import { ComputerSession, type ComputerMode, type Content, type Driver, type DriverResult } from "../src/session.ts";const cwd = "/synthetic-computer-fixture";const address = requireComputerAddress;-const inputNames = new Set(["type_text", "click", "press_key", "hotkey", "scroll", "drag", "semantic_action"]);+const inputNames = new Set(["type_text", "click", "press_key", "hotkey", "scroll", "scroll_at", "drag", "semantic_action"]);async function fixture() {let mode: ComputerMode = "yolo", lifetime: string | undefined = "native-life", serial = 0;- let outcome: DriverResult = { content: [], structuredContent: { effect: "confirmed" } };+ let outcome: DriverResult | ((name: string, args: Record<string, unknown>) => DriverResult) = { content: [], structuredContent: { effect: "confirmed" } };let afterInput: (() => void) | undefined;let liveBounds = { x: 80, y: 90, width: 500, height: 320 };const raw = await sharp({ create: { width: 500, height: 320, channels: 3, background: "#eef4ff" } }).png().toBuffer();@@ -33,7 +33,7 @@ async function fixture() {} };if (name === "get_window_control_state") return { content: [], structuredContent: { state: { bounds: liveBounds, minimized: false, visible: true } } };if (name === "zoom") return { content: [jpeg], structuredContent: { width: 40, height: 20, x_offset: 80, y_offset: 60 } };- if (inputNames.has(name)) { afterInput?.(); return outcome; }+ if (inputNames.has(name)) { afterInput?.(); return typeof outcome === "function" ? outcome(name, args) : outcome; }throw Error(`Unexpected native call ${name}: ${JSON.stringify(args)}`);}),};@@ -53,7 +53,7 @@ async function fixture() {};return { session, resources, driver, window, native, inputs, captures, read,setMode(value: ComputerMode) { mode = value; }, setLifetime(value: string | undefined) { lifetime = value; },- setOutcome(value: DriverResult) { outcome = value; }, afterInput(value: () => void) { afterInput = value; },+ setOutcome(value: typeof outcome) { outcome = value; }, afterInput(value: () => void) { afterInput = value; },setBounds(value: typeof liveBounds) { liveBounds = value; } };}@@ -258,16 +258,49 @@ test.each(["native-partial", "in-flight-cancel"] as const)("%s preserves the attexpect(f.inputs()).toHaveLength(1); expect(f.captures()).toHaveLength(captured);});-test("foreground delivery does not block semantic actions", async () => {+test("computer_type replace on a ref sets the value through UI Automation, without a delivery mode", async () => {const f = await fixture();(f.driver as Driver & { semanticActions: boolean }).semanticActions = true;const view = await f.read();- await f.resources.input(f.window, cwd, typePlan({ window: f.window.source, target: view.hint!, text: "13", replace: true, foreground: true }));+ await f.resources.input(f.window, cwd, typePlan({ window: f.window.source, target: view.hint!, text: "13", replace: true }));expect(f.inputs().map(([name]) => name)).toEqual(["semantic_action"]);expect(f.inputs()[0][1]).toMatchObject({ operation: "set_value", value: "13" });expect(f.inputs()[0][1]).not.toHaveProperty("delivery_mode");});+// LPT-942: what the agent sees structurally is pressed structurally; points and keys are real input.+test("a click on a ref goes through UI Automation only, and no pattern means the real pointer", async () => {+ const f = await fixture();+ let view = await f.read();+ const structural = await f.resources.input(f.window, cwd, clickPlan({ window: f.window.source, target: view.hint! }));+ expect(structural.details.status).toBe("delivered");+ expect(f.inputs()).toEqual([["click", { target: { kind: "window", pid: 42, window_id: 91 }, delivery_mode: "background", element_token: expect.any(String), uia_only: true }, undefined]]);+ // The driver finds no pattern: it refuses before sending anything, and the click goes again with the real pointer.+ f.setOutcome((_name, args) => args.uia_only ? { isError: true, content: [{ type: "text", text: "no UIA pattern" }],+ structuredContent: { code: "background_unavailable", effect: "refused", escalation: { recommended: "foreground" } } } : { content: [], structuredContent: { effect: "confirmed" } });+ view = await f.read();+ const real = await f.resources.input(f.window, cwd, clickPlan({ window: f.window.source, target: view.hint! }));+ expect(real.details.status).toBe("delivered");+ expect(real.content[0]).toEqual({ type: "text", text: "No UI Automation pattern of the target carried this click, so this call used the real pointer." });+ const [refused, sent] = f.inputs().slice(1);+ expect(refused[1]).toMatchObject({ uia_only: true, delivery_mode: "background" });+ expect(sent[0]).toBe("click");+ expect(sent[1]).toMatchObject({ delivery_mode: "foreground" });+ expect(sent[1]).not.toHaveProperty("uia_only");+});++test("points and keys are real input; nothing posts window messages", async () => {+ const f = await fixture();+ (f.driver as Driver & { coordinateScroll: boolean }).coordinateScroll = true;+ await f.read();+ await f.resources.input(f.window, cwd, clickPlan({ window: f.window.source, x: 100, y: 70 }));+ await f.resources.input(f.window, cwd, pressPlan({ window: f.window.source, key: "ctrl+s" }));+ await f.resources.input(f.window, cwd, typePlan({ window: f.window.source, text: "hi" }));+ await f.resources.input(f.window, cwd, scrollPlan({ window: f.window.source, delta_y: 2 }));+ expect(f.inputs().map(([name, args]) => [name, (args as { delivery_mode?: string }).delivery_mode, "uia_only" in (args as object)])).toEqual([+ ["click", "foreground", false], ["hotkey", "foreground", false], ["type_text", "foreground", false], ["scroll_at", "foreground", false]]);+});+test("a display overview accepts a size for that Read only", async () => {const f = await fixture(), display = address("computer:machine/local/display/primary");await f.resources.read(display, cwd, ['capture:{"maxLongEdge":320}']);diff --git a/test/computer-tools.test.ts b/test/computer-tools.test.tsindex 3354540..6d1f28d 100644--- a/test/computer-tools.test.ts+++ b/test/computer-tools.test.ts@@ -138,7 +138,6 @@ test("typed input refuses mismatched targets before anything reaches the machineawait expect(f.resources.input(window, cwd, clickPlan({ window: "x", target: "e4" }))).rejects.toThrow("e4 is a page ref from a DOM Read; this window is not a browser page");await expect(f.resources.input(window, cwd, clickPlan({ window: "x", x: 1, y: 2, space: "page" }))).rejects.toThrow("space applies to browser windows only");await expect(f.resources.input(window, cwd, clickPlan({ window: "x", target: "9:z" }))).rejects.toThrow("9:z is not a ref of this window's latest Read");- await expect(f.resources.input(window, cwd, { ...hoverPlan({ window: "x", target: "getByText('a')" }), foreground: false })).rejects.toThrow("hover on a native window moves the real pointer");});/** A Chrome window (pid 4100) attached to a fake Playwright worker that records page actions. */diff --git a/test/live/quick-fixes.live.ts b/test/live/quick-fixes.live.tsindex a2bf3aa..cd87ad4 100644--- a/test/live/quick-fixes.live.ts+++ b/test/live/quick-fixes.live.ts@@ -23,18 +23,18 @@ test("a display overview takes a per-Read size", async () => {expect(small.details.agent_image).toMatchObject({ output: { width: 320 } });});-test("computer_type replace with foreground reaches the slider through accessibility", async () => {+test("computer_type replace reaches the slider through accessibility", async () => {const opened = await live.insert(live.machine, { action: "open", app: "Paint" });const window = `computer:window/${opened.details.window_ref}`;try {const view = await live.read(window, ["ui"]);const size = view.details.ui!.elements.find(element => element.role === "Slider" && element.name === "Size")!;- const done = await live.resources.input(requireComputerAddress(window), live.cwd, typePlan({ window, target: size.hint, text: "20", replace: true, foreground: true }));+ const done = await live.resources.input(requireComputerAddress(window), live.cwd, typePlan({ window, target: size.hint, text: "20", replace: true }));// Paint's Size slider is read-only through UIA, so the driver itself answers; the adapter no longer refuses first.expect(text(done)).not.toMatch(/accessibility only/);expect(done.details.state).toMatchObject({ route: "accessibility", native_message: "semantic_element_read_only" });} finally {- await live.resources.input(requireComputerAddress(window), live.cwd, pressPlan({ window, key: "alt+F4", foreground: true }));+ await live.resources.input(requireComputerAddress(window), live.cwd, pressPlan({ window, key: "alt+F4" }));}});diff --git a/test/timeline.test.ts b/test/timeline.test.tsindex b859dca..330a7c3 100644--- a/test/timeline.test.ts+++ b/test/timeline.test.ts@@ -35,3 +35,13 @@ test.each([])("invalid timelines refuse before any input: %j", (events, message) => {expect(() => validateInput(timeline(events), observed)).toThrow(message);});++// LPT-942: uia_only reaches the driver only on an element click or scroll.+test("uia_only is passed to an element click or scroll and refused elsewhere", () => {+ const target = { pid: 4, window_id: 9 };+ expect(nativeInput({ action: "click", element_token: "s1:0" }, target, "background", undefined, false, true).args).toMatchObject({ element_token: "s1:0", uia_only: true });+ expect(nativeInput({ action: "scroll", element_token: "s1:0", direction: "down", amount: 2 } as never, target, "background", undefined, false, true).args).toMatchObject({ uia_only: true });+ expect(nativeInput({ action: "click", element_token: "s1:0" }, target, "background").args).not.toHaveProperty("uia_only");+ expect(() => nativeInput({ action: "click", x: 3, y: 4 }, target, "background", "cap", false, true)).toThrow("uia_only takes a click or scroll on an element token.");+ expect(() => nativeInput({ action: "key", key: "a" }, target, "background", undefined, false, true)).toThrow("uia_only");+});