|
| 1 | +Pre-Action Grounding Guard |
| 2 | +========================== |
| 3 | + |
| 4 | +``guardrail`` scans text for prompt-injection and ``loop_guard`` detects stuck loops — |
| 5 | +but neither validates a *coordinate action* before it is dispatched. An agent loop |
| 6 | +executes whatever the model returns with no bounds or target check, so a hallucinated |
| 7 | +``(9999, -5)`` click fires into nothing and a 5-pixel-off click misses the button. |
| 8 | +``validate_action`` adds the "detect misaligned actions before execution" guard: reject |
| 9 | +clicks outside the screen and snap a near-miss coordinate onto the nearest known |
| 10 | +element's centre. |
| 11 | + |
| 12 | +Pure-stdlib geometry over plain element dicts (``x`` / ``y`` / ``width`` / ``height``), |
| 13 | +so it is fully unit-testable. Imports no ``PySide6``. |
| 14 | + |
| 15 | +Headless API |
| 16 | +------------ |
| 17 | + |
| 18 | +.. code-block:: python |
| 19 | +
|
| 20 | + from je_auto_control import validate_action, snap_to_element, in_bounds |
| 21 | +
|
| 22 | + check = validate_action(model_action, screen_size=(1920, 1080), targets=elements) |
| 23 | + if not check["ok"]: |
| 24 | + print("rejected:", check["reason"]) # e.g. "out of bounds" |
| 25 | + else: |
| 26 | + x, y = check["snapped"] or (model_action["x"], model_action["y"]) |
| 27 | + click(x, y) # snapped onto the real button |
| 28 | +
|
| 29 | +``in_bounds(x, y, screen_size)`` is the screen-bounds predicate; ``snap_to_element`` |
| 30 | +returns the centre of the element at (or nearest within ``max_dist`` of) a point, or |
| 31 | +``None``; ``validate_action`` combines them, returning ``{ok, reason, snapped}`` — |
| 32 | +rejecting out-of-bounds coordinates and snapping near-misses when ``targets`` are |
| 33 | +supplied. Actions without a coordinate always pass. |
| 34 | + |
| 35 | +Executor command |
| 36 | +---------------- |
| 37 | + |
| 38 | +``AC_validate_action`` (``action`` / ``screen`` / ``targets`` → ``{ok, reason, |
| 39 | +snapped}``; ``screen`` defaults to the live screen). It is exposed as the MCP tool |
| 40 | +``ac_validate_action`` and as a Script Builder command under **Native UI**. |
0 commit comments