Skip to content

cli: honor --tab flag + retry-on-stale for shortcut commands#12

Merged
koltyakov merged 2 commits into
koltyakov:mainfrom
Eridanus117:shortcut-honor-tab-flag
Jun 9, 2026
Merged

cli: honor --tab flag + retry-on-stale for shortcut commands#12
koltyakov merged 2 commits into
koltyakov:mainfrom
Eridanus117:shortcut-honor-tab-flag

Conversation

@Eridanus117

@Eridanus117 Eridanus117 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Two related CLI improvements for shortcut commands (bbx click, focus, type, hover, etc.):

1. Honor --tab flag (commit 1)

Shortcut commands silently dropped --tab <id> — the flag fell through as a positional argument. The request always hit the default routed tab instead of the explicit target.

Fix: Route shortcut commands through extractTabFlag (same as bbx call and bbx cdp-press-key), and pass tabId to both resolveRef and requestBridge.

2. Retry on ELEMENT_STALE (commit 2)

When a shortcut is given a CSS selector (not an el_xxx ref) and the action returns ELEMENT_STALE, the CLI now automatically re-resolves the selector against the current DOM and retries once.

This handles the common agent pattern where a page re-renders (React reconciliation, SPA navigation) between element resolution and action dispatch. Without this, agents must manually detect the stale error, re-query, and retry.

Safety:

  • Only retries for selector-based inputs (raw el_xxx refs skip retry — no selector to re-resolve from)
  • At most 1 retry
  • Logs bbx: ELEMENT_STALE on "<selector>", re-resolving and retrying... to stderr on retry

Why one PR

Commit 2 depends on commit 1's extractTabFlag integration in the shortcut path. They can't be split into independent PRs without duplicating the refactor.

Test plan

  • npm test passes
  • Manual: bbx click --tab <id> 'selector' targets the explicit tab
  • Manual: bbx click 'selector' without --tab uses the default (no behavior change)
  • Manual: when page re-renders between resolve and click, selector-based click auto-retries instead of returning ELEMENT_STALE

bbx click / focus / type / hover / patch-style / patch-text / html
silently dropped --tab when called as shortcuts. The flag fell through
as a positional argument, the shortcut sent its request without tabId,
and the bridge routed the work to whatever tab the access route happened
to point at (typically the user's active tab).

Symptom: agents calling `bbx click --tab 124461098 'el_xxx' ` after the
user switched browser focus saw ELEMENT_STALE or "No element found",
because the click landed on the user's now-focused tab — not the one the
agent had been driving and resolved the elementRef against.

Fix: route shortcut commands through extractTabFlag the same way
`bbx call` and `bbx cdp-press-key` already do, and pass the resolved
tabId to both resolveRef (so the selector is resolved against the
target tab) and requestBridge (so the action runs on that tab).

Verified live against a running daemon: with the bridge routed to a
different tab, `bbx click --tab <other-tabId> 'selector'` now clicks the
element in the explicit tab regardless of which tab is focused.
@Eridanus117 Eridanus117 force-pushed the shortcut-honor-tab-flag branch from 5c1377c to 1a38d21 Compare May 29, 2026 07:30
@Eridanus117 Eridanus117 changed the title cli: honor --tab flag in shortcut commands cli: honor --tab flag + retry-on-stale for shortcut commands May 29, 2026
@Eridanus117 Eridanus117 force-pushed the shortcut-honor-tab-flag branch from 1a38d21 to 5375187 Compare May 29, 2026 08:24
When a shortcut command (click, type, focus, hover, etc.) is given a
CSS selector (not an el_xxx ref), and the action returns ELEMENT_STALE,
automatically re-resolve the selector and retry once.

This handles the common agent workflow:
1. Agent queries a selector → gets elementRef el_abc
2. Page re-renders (React reconciliation, user interaction, SPA nav)
3. Agent calls `bbx click el_abc` → ELEMENT_STALE
4. Agent must manually re-query → retry

With this change, `bbx click 'button[data-x=save]'` (selector form)
will auto-retry: re-resolve the selector against the current DOM, get
a fresh elementRef, and dispatch the action. The retry is at most once
and only fires for selector-based inputs (el_xxx refs skip retry since
there is no selector to re-resolve from).
@Eridanus117 Eridanus117 force-pushed the shortcut-honor-tab-flag branch from 5375187 to 06c0d7d Compare May 29, 2026 08:28
@koltyakov

Copy link
Copy Markdown
Owner

Sorry, I only now see all your @Eridanus117 PRs. Thank you!!! I will check and merge the remaining.

@koltyakov koltyakov merged commit c7fa382 into koltyakov:main Jun 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants