Skip to content

feat(cu): surface element state and tree position to the model - #1555

Merged
Astro-Han merged 1 commit into
apache:mainfrom
hqhq1025:feat/cu-element-state-fields
Jul 28, 2026
Merged

Astro-Han merged 1 commit into
apache:mainfrom
hqhq1025:feat/cu-element-state-fields

Conversation

@hqhq1025

Copy link
Copy Markdown
Contributor

Summary

get_window_state reports each element's interaction state and its parent, but normalizeCuaSnapshotElement dropped those fields. They never reached CuObservedElement and never appeared in observationText, so the model saw a flat list in which every row looked equally actionable and equally rootless.

Why it matters in a long run

Without enabled, a control that is present but not actuatable is indistinguishable from one the model simply failed to hit. The model retries the same dead element instead of looking for what actually enables it.

Without a parent link, there is no way to tell which panel, dialog, or row group an element belongs to. This becomes concrete as soon as a modal or secondary window is open and two rows share a label — the model has coordinates and a role, but no structure.

Change

Pass enabled, selected, and parent_index (as parentElementId) through the three layers that were dropping them:

cua-driver-snapshot.ts   normalizeCuaSnapshotElement  — keep the fields
cua-driver-backend.ts    observeWindow                — map into CuObservedElement
computer-use-tools.ts    observationText              — project to the model

All three are optional and omitted when absent, so the projection stays additive — no existing field changes shape.

Model-visible element before / after:

// before
{"element_id": "4", "role": "AXButton", "label": "Send", "frame": {...}}

// after
{"element_id": "4", "role": "AXButton", "label": "Send",
 "parent_element_id": "0", "frame": {...}}

Verification

Against the real driver on a live window: of 62 observed elements, 59 now carry parentElementId.

{"id":"1","role":"AXButton","label":"CUA Lab Reset","parent":"0"}
{"id":"4","role":"AXButton","label":"CUA Lab Primary Button","parent":"0"}
{"id":"5","role":"AXTextField","label":"CUA Lab Set Value Field","parent":"0"}
  • @maka/computer-use — 137/137 passed
  • @maka/runtime — 2686 passed, 8 failed; the same 8 fail on a clean origin/main build (unrelated pre-existing failures in extraction-contract / workspace-instructions / prepareStep)
  • Biome lint + format — clean

Note on enabled / selected

The pinned cua-driver v0.7.1 does not emit them yet. Its element rows are exactly:

depth · element_index · element_token · frame · label · parent_index · role

Upstream added enabled / selected by v0.12.6. This change reads them when present, so they light up on the driver upgrade with no further work here. parentElementId works on the pinned version today, which is what the verification above exercises.

`get_window_state` reports each element's interaction state and parent, but
`normalizeCuaSnapshotElement` dropped those fields, so they never reached
`CuObservedElement` and never appeared in `observationText`. The model saw a
flat list where every row looked equally actionable and equally rootless.

Two consequences in a long run:

- Without `enabled`, a disabled control is indistinguishable from one the
  model simply failed to hit, so it retries the same dead element.
- Without a parent link, there is no way to tell which panel, dialog, or row
  group an element belongs to. That matters as soon as a modal or a secondary
  window is on screen and two rows share a label.

Passes `enabled`, `selected`, and `parent_index` (as `parentElementId`)
through the normalizer, the observation mapper, and the model-visible
projection. All three are optional and omitted when absent, so the shape is
additive.

Verified against the real driver: of 62 observed elements, 59 now carry
`parentElementId`.

Note on `enabled` / `selected`: the pinned cua-driver v0.7.1 does not emit
them yet — its element rows are `depth, element_index, element_token, frame,
label, parent_index, role`. Upstream added them by v0.12.6. This change reads
them when present, so the fields light up on the driver upgrade without
further work here.
@Astro-Han
Astro-Han merged commit 32249f6 into apache:main Jul 28, 2026
3 checks passed
@Astro-Han

Copy link
Copy Markdown
Contributor

Reviewed at 4861de731067d71ceb5243806e5426d20ba42916.

No P0-P3 findings. enabled, selected, and parent_element_id survive driver normalization, backend mapping, and runtime model text, including false and parent ID 0. They are not added to the persisted observation summary. CI passed at this head.

Squash-merged as 32249f67c553c3136fb793fa9f14d93612980243.

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