High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: the docs and MCP schema claim a wrapper over a semantic form ignores its index, but the semantic engine does index in document order (PIN-044)
Luigi Agostie627e619ba00
diff --git a/docs/commands.md b/docs/commands.mdindex d819a501..ef1a4ab1 100644--- a/docs/commands.md+++ b/docs/commands.md@@ -107,7 +107,7 @@ Most element commands accept a unified selector:- label, placeholder, alt, title, or test id selectors such as `label:Email`, `placeholder:Search`, `alt:Logo`, `title:Close`, `testid:submit`- positional wrappers such as `first:button`, `last:role:button`, or `nth:2:button` (`nth` is zero-based)-Positional wrappers index the candidates in **document order** over `css:`, `xpath:`, and `text:` selectors, so `nth:0:` is the first match in the page and `nth:1:` always comes after it. A bare `text:` selector is the one form of those that does not index: it picks the most control-like match among the smallest ones, so `text:Save` prefers a `<button>` over a `<div>` carrying the same label — which means `text:X` and `first:text:X` can resolve to different elements. A wrapper over a semantic form (`role:`, `label:`, `placeholder:`, `alt:`, `title:`, `testid:`) **does not index at all**: the best-scoring match is returned whatever the index, so `nth:2:role:button` resolves the same element as `role:button`. A wrapper only ever chooses among the matches a bare selector would find; it never changes which matches exist.+Positional wrappers index the candidates in **document order** over `css:`, `xpath:`, and `text:` selectors, so `nth:0:` is the first match in the page and `nth:1:` always comes after it. A bare `text:` selector is the one form of those that does not index: it picks the most control-like match among the smallest ones, so `text:Save` prefers a `<button>` over a `<div>` carrying the same label — which means `text:X` and `first:text:X` can resolve to different elements. A wrapper only ever chooses among the matches a bare selector would find; it never changes which matches exist.Selector prefixes are case-insensitive, so `CSS:#login` and `css:#login` mean the same thing. Only the prefix is case-folded; the value after it is passed through unchanged.diff --git a/docs/reference/mcp-tools.md b/docs/reference/mcp-tools.mdindex d9be07eb..a342c161 100644--- a/docs/reference/mcp-tools.md+++ b/docs/reference/mcp-tools.md@@ -17,7 +17,7 @@ Selector forms include:- `label:Email`, `placeholder:Search`, `alt:Logo`, `title:Close`, `testid:submit`- `first:button`, `last:button`, `nth:2:button`-Positional wrappers index the candidates in **document order** over `css:`, `xpath:`, and `text:` selectors, so `nth:0:` is the first match in the page and `nth:1:` always comes after it. A bare `text:` selector is the one form of those that does not index: it picks the most control-like match among the smallest ones, so `text:Save` prefers a `<button>` over a `<div>` carrying the same label — which means `text:X` and `first:text:X` can resolve to different elements. A wrapper over a semantic form (`role:`, `label:`, `placeholder:`, `alt:`, `title:`, `testid:`) **does not index at all**: the best-scoring match is returned whatever the index, so `nth:2:role:button` resolves the same element as `role:button`. A wrapper only ever chooses among the matches a bare selector would find; it never changes which matches exist.+Positional wrappers index the candidates in **document order** over `css:`, `xpath:`, and `text:` selectors, so `nth:0:` is the first match in the page and `nth:1:` always comes after it. A bare `text:` selector is the one form of those that does not index: it picks the most control-like match among the smallest ones, so `text:Save` prefers a `<button>` over a `<div>` carrying the same label — which means `text:X` and `first:text:X` can resolve to different elements. A wrapper only ever chooses among the matches a bare selector would find; it never changes which matches exist.Structured semantic locators are matched by the semantic engine; CSS, XPath, refs, the existing `text:` action selector, and bare CSS/text wrappers stay browser-side.diff --git a/internal/mcp/argcheck_test.go b/internal/mcp/argcheck_test.goindex 5af4dfae..2da8ce35 100644--- a/internal/mcp/argcheck_test.go+++ b/internal/mcp/argcheck_test.go@@ -636,9 +636,6 @@ func TestSelectorSchemasThatOfferWrappersStateWhatAnIndexMeans(t *testing.T) {if !strings.Contains(property.Description, "text:X and first:text:X can differ") {t.Errorf("%s.%s does not warn that a bare text: selector ranks rather than indexes: %q", tool.Name, name, property.Description)}- if !strings.Contains(property.Description, "does not index at all") {- t.Errorf("%s.%s does not warn that a wrapper over a semantic form ignores its index: %q", tool.Name, name, property.Description)- }}}if checked == 0 {diff --git a/internal/mcp/tools.go b/internal/mcp/tools.goindex b0528395..257ea497 100644--- a/internal/mcp/tools.go+++ b/internal/mcp/tools.go@@ -2,7 +2,7 @@ package mcpimport "github.com/mark3labs/mcp-go/mcp"-const positionalWrapperGrammar = " first/last/nth index matches in document order over css:, xpath: and text: selectors, so nth:0 is the first match in the page. A bare text: selector instead picks the most control-like smallest match, so text:X and first:text:X can differ. A wrapper over a semantic form (role:, label:, placeholder:, alt:, title:, testid:) does not index at all: the best-scoring match is returned whatever the index, so nth:2:role:button resolves the same element as role:button."+const positionalWrapperGrammar = " first/last/nth index matches in document order over css:, xpath: and text: selectors, so nth:0 is the first match in the page. A bare text: selector instead picks the most control-like smallest match, so text:X and first:text:X can differ."// allTools returns every MCP tool exposed by the PinchTab MCP server.func allTools() []mcp.Tool {diff --git a/internal/selector/selector_test.go b/internal/selector/selector_test.goindex 85ff7005..92a22c5a 100644--- a/internal/selector/selector_test.go+++ b/internal/selector/selector_test.go@@ -389,7 +389,7 @@ func TestSelector_SemanticQuery(t *testing.T) {}}-func TestPositionalWrapperOverSemanticFormDoesNotApplyItsIndex(t *testing.T) {+func TestPositionalWrapperOverSemanticFormReachesTheMatcherWithItsIndex(t *testing.T) {semanticPrefixes := []string{}for _, pk := range prefixKinds {if rawSelectorCanUseSemantic(pk.Prefix + "Save") {@@ -405,11 +405,11 @@ func TestPositionalWrapperOverSemanticFormDoesNotApplyItsIndex(t *testing.T) {for _, wrapped := range []string{"first:" + bare, "last:" + bare, "nth:0:" + bare, "nth:2:" + bare} {query, ok := Parse(wrapped).SemanticQuery()if !ok {- t.Errorf("%s no longer routes to the semantic matcher; docs/commands.md and positionalWrapperGrammar say a wrapper over a semantic form does not index, and that sentence must change with this", wrapped)+ t.Errorf("%s no longer routes to the semantic matcher, so the wrapper it carries is never applied", wrapped)continue}if query != wrapped {- t.Errorf("SemanticQuery(%q) = %q: the index is now stripped from the query, so docs/commands.md and positionalWrapperGrammar must stop saying a wrapper over a semantic form does not index", wrapped, query)+ t.Errorf("SemanticQuery(%q) = %q: the wrapper must reach the matcher intact, since the semantic engine parses the index itself and stripping it here drops the position the caller asked for", wrapped, query)}}}@@ -418,7 +418,7 @@ func TestPositionalWrapperOverSemanticFormDoesNotApplyItsIndex(t *testing.T) {bare := prefix + "Save"for _, wrapped := range []string{bare, "first:" + bare, "last:" + bare, "nth:2:" + bare} {if _, ok := Parse(wrapped).SemanticQuery(); ok {- t.Errorf("%s routes to the semantic matcher, so it cannot index in document order as the docs promise", wrapped)+ t.Errorf("%s routes to the semantic matcher, so it no longer indexes in document order browser-side as docs/commands.md promises for this kind", wrapped)}}}