@octavus/agent 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -132,7 +132,9 @@ def _overlaps_screen(x, y, w, h, screen_w, screen_h):
132
132
  return x < screen_w and y < screen_h and x + w > 0 and y + h > 0
133
133
 
134
134
 
135
- def _walk_atspi(node, elements, Atspi, screen_w, screen_h, depth=0, max_depth=20):
135
+ def _walk_atspi(
136
+ node, elements, Atspi, screen_w, screen_h, depth=0, max_depth=20, trust_geometry=False
137
+ ):
136
138
  if depth > max_depth:
137
139
  return
138
140
 
@@ -161,13 +163,17 @@ def _walk_atspi(node, elements, Atspi, screen_w, screen_h, depth=0, max_depth=20
161
163
  and _overlaps_screen(rect[0], rect[1], rect[2], rect[3], screen_w, screen_h)
162
164
  )
163
165
 
164
- # Include this node as an actionable element when it is a visible, on-screen
165
- # clickable widget. Inclusion keys on real screen geometry, not the AT-SPI
166
- # SHOWING flag: some toolkits (notably GTK4, e.g. gnome-text-editor) leave
167
- # SHOWING unset on every on-screen descendant below the top frame, so gating
168
- # on SHOWING would drop the entire app's controls. Off-screen and zero-area
169
- # nodes fail the on_screen test instead.
170
- if rect is not None and on_screen and visible:
166
+ # Include this node as an actionable element when it is an on-screen clickable
167
+ # widget. Inclusion keys on real screen geometry, not the AT-SPI SHOWING flag:
168
+ # some toolkits (notably GTK4, e.g. gnome-text-editor) leave SHOWING unset on
169
+ # every on-screen descendant below the top frame, so gating on SHOWING would
170
+ # drop the entire app's controls. `trust_geometry` extends this to the VISIBLE
171
+ # flag, which GTK4 likewise leaves unset on those descendants: for a native
172
+ # foreground app, geometry + role decide inclusion; for Chromium (whose web
173
+ # a11y flags are reliable) VISIBLE stays required, so web labeling never
174
+ # surfaces hidden-but-positioned elements. Off-screen and zero-area nodes fail
175
+ # the on_screen test regardless.
176
+ if rect is not None and on_screen and (trust_geometry or visible):
171
177
  try:
172
178
  role_name = node.get_role_name().lower()
173
179
  except Exception:
@@ -225,7 +231,9 @@ def _walk_atspi(node, elements, Atspi, screen_w, screen_h, depth=0, max_depth=20
225
231
  for i in range(n_children):
226
232
  child = node.get_child_at_index(i)
227
233
  if child is not None:
228
- _walk_atspi(child, elements, Atspi, screen_w, screen_h, depth + 1, max_depth)
234
+ _walk_atspi(
235
+ child, elements, Atspi, screen_w, screen_h, depth + 1, max_depth, trust_geometry
236
+ )
229
237
  except Exception:
230
238
  pass
231
239
 
@@ -353,13 +361,15 @@ def _active_window_is_chromium(pid):
353
361
  return False
354
362
 
355
363
 
356
- def _collect_elements(desktop, target_pid, Atspi, screen_w, screen_h):
364
+ def _collect_elements(desktop, target_pid, Atspi, screen_w, screen_h, trust_geometry=False):
357
365
  """Collect actionable elements from the AT-SPI app(s) matching target_pid.
358
366
 
359
367
  Strictly PID-scoped: a None target_pid (foreground PID unavailable) matches no
360
368
  app and returns empty, so labeling never falls back to walking the whole
361
369
  desktop, which would overlay the always-open browser's labels onto whatever
362
- native app is in front.
370
+ native app is in front. `trust_geometry` is forwarded to the walk so a native
371
+ foreground app's on-screen controls are included from geometry even when its
372
+ toolkit leaves the AT-SPI VISIBLE/SHOWING flags unset (GTK4).
363
373
  """
364
374
  elements = []
365
375
  n_apps = desktop.get_child_count()
@@ -372,7 +382,7 @@ def _collect_elements(desktop, target_pid, Atspi, screen_w, screen_h):
372
382
  continue
373
383
  except Exception:
374
384
  continue
375
- _walk_atspi(app, elements, Atspi, screen_w, screen_h)
385
+ _walk_atspi(app, elements, Atspi, screen_w, screen_h, trust_geometry=trust_geometry)
376
386
  return elements
377
387
 
378
388
 
@@ -429,13 +439,19 @@ def enumerate_elements(pid=None):
429
439
 
430
440
  screen_w, screen_h = get_screen_size()
431
441
  target_pid = pid or _get_active_window_pid()
442
+ # A native foreground app (GTK4 etc.) leaves the AT-SPI VISIBLE/SHOWING flags
443
+ # unset on its on-screen descendants, so trust geometry for it; Chromium's web
444
+ # a11y flags are reliable, so keep requiring VISIBLE there.
445
+ foreground_is_chromium = _active_window_is_chromium(target_pid)
432
446
 
433
447
  desktop = Atspi.get_desktop(0)
434
- elements = _collect_elements(desktop, target_pid, Atspi, screen_w, screen_h)
448
+ elements = _collect_elements(
449
+ desktop, target_pid, Atspi, screen_w, screen_h, trust_geometry=not foreground_is_chromium
450
+ )
435
451
 
436
452
  # The foreground app exported its own actionable tree - use it verbatim. It is
437
453
  # already scoped to the single window the agent sees (one desktop, WYSIWYG).
438
- if not elements and _active_window_is_chromium(target_pid):
454
+ if not elements and foreground_is_chromium:
439
455
  # Chromium publishes its accessibility tree lazily, and its active-window
440
456
  # PID can disagree with the AT-SPI app PID, so the PID-scoped walk above
441
457
  # can miss it. Recover by walking only the Chrome app node(s), retrying