|
| 1 | +# Agent-Native UI |
| 2 | + |
| 3 | +Geometra's agent-native layer makes the interface itself the protocol. A normal frontend can expose a DOM, screenshots, accessibility data, and backend APIs. Geometra exposes the computed UI frame directly: exact geometry, semantics, interaction targets, policy metadata, and replayable action history from the same declarative tree that renders pixels. |
| 4 | + |
| 5 | +## Contract |
| 6 | + |
| 7 | +Every rendered frame can produce a semantic geometry snapshot: |
| 8 | + |
| 9 | +```ts |
| 10 | +{ |
| 11 | + id: 'claims-review:frame:1', |
| 12 | + route: 'claims-review', |
| 13 | + rootBounds: { x: 0, y: 0, width: 1180, height: 760 }, |
| 14 | + nodes: [ |
| 15 | + { |
| 16 | + id: 'approve-payout', |
| 17 | + role: 'button', |
| 18 | + name: 'Approve payout', |
| 19 | + bounds: { x: 474, y: 512, width: 132, height: 62 }, |
| 20 | + hitTarget: { x: 474, y: 512, width: 132, height: 62 }, |
| 21 | + visible: true, |
| 22 | + enabled: true, |
| 23 | + focusable: true, |
| 24 | + interactive: true, |
| 25 | + actionId: 'approve-payout' |
| 26 | + } |
| 27 | + ], |
| 28 | + actions: [ |
| 29 | + { |
| 30 | + id: 'approve-payout', |
| 31 | + kind: 'approve', |
| 32 | + risk: 'write', |
| 33 | + requiresConfirmation: true, |
| 34 | + bounds: { x: 474, y: 512, width: 132, height: 62 } |
| 35 | + } |
| 36 | + ] |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +Use `semantic.id` for stable UI ids. If omitted, Geometra falls back to `agentAction.id`, then `key`, then a path id like `node:0.2`. |
| 41 | + |
| 42 | +## Core APIs |
| 43 | + |
| 44 | +`@geometra/core` exports: |
| 45 | + |
| 46 | +- `collectSemanticGeometry(tree, layout)` for flat exact geometry plus role/name/state per node. |
| 47 | +- `createAgentGeometrySnapshot(tree, layout, options)` for auditable frame snapshots. |
| 48 | +- `createAgentRuntime(app, options)` for direct app-level commands: `inspect`, `snapshot`, `click`, `focus`, `type`, `key`, `getActionLog`, and `replay`. |
| 49 | +- `agentAction(contract, semantic)` and `collectAgentActions(tree, layout)` for business-level action contracts. |
| 50 | +- `createAgentGateway()` for policy, approval, execution, trace, and replay around those contracts. |
| 51 | + |
| 52 | +## Runtime Commands |
| 53 | + |
| 54 | +The app runtime operates by semantic geometry id instead of DOM selectors or guessed coordinates: |
| 55 | + |
| 56 | +```ts |
| 57 | +const runtime = createAgentRuntime(app, { route: 'claims-review' }) |
| 58 | + |
| 59 | +const frame = runtime.inspect() |
| 60 | +runtime.click('approve-payout') |
| 61 | +runtime.type('agent-note', ' reviewed') |
| 62 | +const replay = runtime.replay(runtime.getActionLog()) |
| 63 | +``` |
| 64 | + |
| 65 | +Each command records before/after frame snapshots in the runtime action log. That answers: what did the agent see, which stable target did it use, what exact geometry was active, and what changed afterward. |
| 66 | + |
| 67 | +## Gateway And HTTP |
| 68 | + |
| 69 | +`@geometra/gateway` exposes the same frame-bound contract to external agents: |
| 70 | + |
| 71 | +- `GET /inspect` returns the latest frame, semantic geometry, current actions, and pending approvals. |
| 72 | +- `GET /actions` returns contracted business actions plus the latest frame. |
| 73 | +- `POST /actions/request` requests an action by id and frame id. |
| 74 | +- `POST /actions/approve` approves or denies a pending action. |
| 75 | +- `GET /trace` returns the append-only event trace. |
| 76 | +- `GET /replay` returns before/after frame snapshots and action outcomes. |
| 77 | + |
| 78 | +The MCP-style tool adapter mirrors this with: |
| 79 | + |
| 80 | +- `geometra_gateway_inspect_frame` |
| 81 | +- `geometra_gateway_list_actions` |
| 82 | +- `geometra_gateway_request_action` |
| 83 | +- `geometra_gateway_approve_action` |
| 84 | +- `geometra_gateway_get_trace` |
| 85 | +- `geometra_gateway_get_replay` |
| 86 | + |
| 87 | +## Demo |
| 88 | + |
| 89 | +Run the claims workflow demo: |
| 90 | + |
| 91 | +```bash |
| 92 | +bun run --filter @geometra/demo-agent-native-ops dev |
| 93 | +``` |
| 94 | + |
| 95 | +The demo shows: |
| 96 | + |
| 97 | +- a human-rendered Canvas UI |
| 98 | +- exact semantic geometry for the same UI |
| 99 | +- clicking `approve-payout` by stable id |
| 100 | +- typing into `agent-note` by stable id |
| 101 | +- policy-gated gateway actions |
| 102 | +- trace and replay panels with before/after frame geometry |
| 103 | + |
| 104 | +Run the external-agent HTTP flow: |
| 105 | + |
| 106 | +```bash |
| 107 | +bun run demo:agent-native:http |
| 108 | +``` |
| 109 | + |
| 110 | +That script builds the core/gateway packages, starts a local gateway, calls `/inspect`, requests `approve-payout`, approves it, reads `/replay`, and writes `examples/replays/claims-review.json`. |
| 111 | + |
| 112 | +## Benchmark |
| 113 | + |
| 114 | +Run the deterministic value harness: |
| 115 | + |
| 116 | +```bash |
| 117 | +bun run benchmark:agent-native:assert |
| 118 | +``` |
| 119 | + |
| 120 | +The harness compares Geometra-native operation against MCP/browser/vision-style inference on context bytes, tool calls, latency, success rate, security failures, replayability, and postcondition checks. |
| 121 | +See `benchmarks/agent-native-methodology.md` for assumptions and metric definitions. |
0 commit comments