feat(agent): read computed styles in project tools

LE
3d ago
+694-17

What and why

  • A read-only project tool can measure computed CSS on a listed node, such as whether an error is red, through getToolContext(options).read({ id }, { style }).
  • Only allow-listed properties of a node in the newest observation are read. Reads share the operation queue and step deadline, return secret-redacted values, and are denied to mutates: true tools.
  • ctx.read throws the same agent codes as ctx.observe and ctx.actions: a detached or unlisted node is LOCATOR_NOT_FOUND, an engine without readStyle is POLICY_DENIED.
  • Engines get an optional readStyle(ref, properties, context) member, engine/readStyle over JSON-RPC, and the computed-style capability. Web implements it; mobile does not. SPI and protocol versions stay 1.
  • e2e/engine exports COMPUTED_STYLE_PROPERTIES and validateComputedStyleProperties(properties). @e2e-dev/web calls the validator, so its e2e peer floor is 0.23.2.
const context = getToolContext(executionOptions);
await context.observe();
const { style } = await context.read({ id: nodeId }, {
  style: ['color', 'font-weight', 'visibility', 'opacity'],
});
flowchart LR
  Tool[Read-only project tool] --> ID[Node in newest observation]
  ID --> RPC[engine/readStyle]
  RPC --> CSS[getComputedStyle]
  CSS --> Redact[Redact values]
  Redact --> Tool

Issue

Fixes #1228

Verified

Ran it locally: yes

  • Testbed, built CLI, scratch config with a scripted model and two project tools: e2e run --config e2e.style-scratch.config.ts --video --reporter list,markdown. The test signs in with bad credentials on /login, styles the alert, and the read-only tool measures it.
mainthis branch
context.read is not a functionrgb(255, 0, 0), 700, and <secret:tone> for the opacity that matches a configured secret
 ✓ reads computed style through a project tool > agent.act "measure the error style and prove mutating reads are denied" 223ms · 3 model calls
 ✓ |web| tests-style-scratch/style.e2e.ts (1 test) 678ms ai 6 tokens
 Test Files  1 passed (1)

What the tools saw in that run:

{
  "measured": { "style": { "color": "rgb(255, 0, 0)", "font-weight": "700", "opacity": "<secret:tone>" } },
  "unknownNode": "LOCATOR_NOT_FOUND",
  "badProperty": "INVALID_ARGUMENT",
  "mutatingRead": "POLICY_DENIED"
}
  • grep -r for the secret value under .e2e/ finds nothing.
  • Testbed suite on the built CLI: 588 passed, 1 skipped.
  • Not run at this head: the web benchmark and the live agent suites. The video stays local, the installed gh has no --attach.