Skip to content

feat(computer-use): show snapshot selected text in model observations - #5050

Merged
Astro-Han merged 2 commits into
apache:mainfrom
wutongyuonce:feat/cu-observation-selected-text
Oct 9, 2026
Merged

Astro-Han merged 2 commits into
apache:mainfrom
wutongyuonce:feat/cu-observation-selected-text

Conversation

@wutongyuonce

Copy link
Copy Markdown
Contributor

Summary

select_text already comes back with snapshot.selectedText, but the shared observation type and renderer dropped it, so the model could not confirm what was selected.

This PR:

  • adds ComputerUseSelectedText in @maka/core
  • declares CuObservation.selectedText
  • writes the selection in the observation header, truncated like value
  • withholds the string when the focused control is a secure field

Does not change protocol parsing or persist the selection into the call record.

Fixes #5047

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Verification

  • npm --workspace @maka/core run build
  • npm --workspace @maka/runtime run build
  • node --test packages/runtime/dist/__tests__/computer-use-observation-text.test.js — 17 pass, including selected-text header / truncated / secure withhold / length cap / absent field
  • Did not run root lint / format:check / full typecheck

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope:

pi-coding-agent drafted the contract type, observation header rendering, tests, and this description. Commits carry Generated-by: pi-coding-agent.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

select_text already returns a snapshot.selectedText payload, but the
shared observation type and renderer dropped it, so the model could not
confirm what was selected. Surface the field on CuObservation and write
it in the observation header, truncated like value and withheld when the
focused control is a secure field.

Generated-by: pi-coding-agent
The renderer already truncated like value. Review required a test that
fails if a 300-character selection is shown in full.

Generated-by: pi-coding-agent
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Sep 8, 2026

@me2seeks me2seeks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review notice: This comment was posted by an automated review agent operated by me2seeks make. It is not an independent human review and does not replace one.

Summary

Renders window selected text in Computer Use model observations: ComputerUseSelectedText { text, truncated } on CuObservation (maka.cu/2 §5.2), with three display rules all pinned by tests — a focused secure field (AXSecureTextField) withholds the text as selected_text=withheld(secure_field) and never leaks it, oversized selections are shortened visibly at 256 chars with an explicit (+N chars) marker, and the executor's own truncated flag is preserved. The backend comment is updated to match the new reality (selectedText now has a model-facing home). Every test path is asserted on the header line, including the no-selection case producing no mention.

Findings

  1. [P3] Only the label check ran on this head — for a change feeding application text into model context (with a security-relevant withhold rule), the test lane should run green before merge.

Verdict

merge-ready — correct, well-fenced display of selected text with the secure-field rule tested; request CI as housekeeping.

@hqhq1025 hqhq1025 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the five-file change at this exact head. It adds selected text to the Computer Use observation header, preserves the executor truncation flag, and suppresses text when a focused secure element is present in the reported tree. I found one security-relevant issue in the missing-focus case (inline). Do not merge this head until the focus/secure-field decision is made from an untruncated authoritative signal or fails closed, with a regression for a focused token absent from the reported elements.\n\nNode 24 build:test and two focused test files (37 tests) pass. A direct probe of the emitted renderer shows a truncated observation without the secure element prints selected_text="SECRET-EXAMPLE"; adding the focused AXSecureTextField with the same selection yields selected_text=withheld(secure_field). Fresh main 076cdd1fb9bd60795a43c6fb4e716bfd73901efe merge-tree and diff-check are clean; its overlapping backend change is confined to session-generation cleanup, not selection rendering. The current-head hosted test check is still queued; label is green. I did not run the full suite, a real macOS accessibility provider, or packaged Desktop. Whether native secure controls ever return selected text could not be established here; the protocol and renderer currently accept that combination.\n\n> Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

function selectedTextCaption(observation: CuObservation): string | undefined {
const selected = observation.selectedText;
if (!selected) return undefined;
const focused = observation.elements.find((element) => element.focused === true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Fail closed when the focused field is absent from the element list. selectedText and focusedElementToken are independent snapshot fields, while elements may be a truncated prefix (maka-cu-protocol.ts:530-541,846-855,925-948; maka-cu-backend.ts:1492-1496,1520-1523). If a focused AXSecureTextField falls outside that prefix, .find() returns no element and lines 502–505 send its selected text verbatim to the model. The existing secure-field test includes the focused element and misses this case. Preserve an authoritative secure/withhold signal across the snapshot boundary, or withhold when focus cannot be classified; test a valid truncated snapshot whose focused token is not in elements.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

This pull request has had no new commits for 30 days and has been marked stale. It will be closed in 7 days unless a new commit is pushed.

Comments do not reset this timer: only a new commit does. If the pull request is intentionally long-lived, a maintainer can apply the pinned label.

@github-actions github-actions Bot added the stale No qualifying activity within the lifecycle policy window label Oct 9, 2026

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at @Astro-Han's explicit request: a small, focused change with no blocking findings in our automated review of this exact head, and CI is green.

@Astro-Han
Astro-Han merged commit 6e1f1d9 into apache:main Oct 9, 2026
2 checks passed
@wutongyuonce
wutongyuonce deleted the feat/cu-observation-selected-text branch October 9, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines stale No qualifying activity within the lifecycle policy window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Computer Use cannot show the model what select_text actually selected

4 participants