From 8942d5d89fa0aa51eb0525b85bc2d230382081fa Mon Sep 17 00:00:00 2001 From: shaun0927 <70629228+shaun0927@users.noreply.github.com> Date: Tue, 12 May 2026 23:47:42 +0900 Subject: [PATCH 1/2] Guide agents toward valid element actions Add compact affordance markers to perception output without changing canonical refs. The marker sits outside ref/backendNodeId tokens so existing ref-aware tools and parsers keep their current contract while agents get a cheaper cue for whether to type, click, or treat a target as visual.\n\nConstraint: Issue #965 requires no DOM tag injection, no XPath routing, and no ref identity/schema changes.\nRejected: Embedding markers inside refs such as [#ref_1] | would risk breaking existing ref parsers and tool arguments.\nConfidence: high\nScope-risk: narrow\nDirective: Keep future affordance changes display-only unless #828/#831 explicitly change canonical ref syntax.\nTested: npx jest tests/utils/element-affordance.test.ts tests/dom/dom-serializer.test.ts tests/tools/find.test.ts --runInBand; npm run build; npm run lint -- --quiet; npm run lint:tier\nNot-tested: Manual MCP transcript against a live browser fixture. --- README.md | 8 +- src/dom/dom-serializer.ts | 10 +- src/tools/find.ts | 5 +- src/utils/element-affordance.ts | 126 ++++++++++++++++++++++++ tests/dom/dom-serializer.test.ts | 27 +++++ tests/dom/shadow-dom-serializer.test.ts | 2 +- tests/tools/find.test.ts | 37 +++++++ tests/utils/element-affordance.test.ts | 32 ++++++ 8 files changed, 239 insertions(+), 8 deletions(-) create mode 100644 src/utils/element-affordance.ts create mode 100644 tests/utils/element-affordance.test.ts diff --git a/README.md b/README.md index 3cb01c20..dcf0cf9e 100644 --- a/README.md +++ b/README.md @@ -401,13 +401,13 @@ read_page tabId="tab1" mode="dom" [page_stats] url: https://example.com | title: Example | scroll: 0,0 | viewport: 1920x1080 -[142] ★ -[156]