feat(automation): add background native text selection #908
<!-- clawsweeper-pr-ack:opened item=908 -->
🦞👀
ClawSweeper picked this up.
Pull request received. I will update this pull request when review starts.
<!-- clawsweeper-review-progress:start -->
ClawSweeper review complete
ClawSweeper finished reviewing this revision. The review result is being finalized.
View the workflow run.
<!-- clawsweeper-review-progress:end -->
Codex review: needs maintainer review before merge. _Reviewed October 4, 2026, 4:08 AM ET / 08:08 UTC (Revision 4)._
ClawSweeper review
What this changes
Adds native text selection and caret placement across the CLI, Agent, MCP, and Bridge, with literal UTF-16 matching and verified outcomes.
Merge readiness
✅ Ready for maintainer review
The feature remains distinct from current main. The prior diagnostic defect is fixed, and current-head native qualification resolves the previous review’s blocker; no remaining actionable patch defect was found.
Priority: P2
Reviewed head: 58ebe36f8ff28d678cd055b793d1d8765a391cfd
Review scores
| Measure | Result | What it means |
|---|---|---|
| Overall readiness | 🦞 diamond lobster (5/6) | Strong current-head native qualification, focused safety regressions, and shared implementation owners support above-average confidence with no remaining actionable finding. |
| Proof confidence | 🦞 diamond lobster (5/6) ✨ media proof bonus | Sufficient (linked_artifact): Signed qualification at the pinned head exercises the shared native selection owner through CLI and real stdio MCP, covering all modes, contexts, newline selection, unfocused fields, and refusals; inspected images supplement native-range and lifecycle results. The previous qualification blocker is resolved. No stored-data contract changes require migration proof. |
| Patch quality | 🦞 diamond lobster (5/6) | No actionable review findings were identified. |
Verification
| Check | Result | Evidence |
|---|---|---|
| Real behavior | Verified | Sufficient (linked_artifact): Signed qualification at the pinned head exercises the shared native selection owner through CLI and real stdio MCP, covering all modes, contexts, newline selection, unfocused fields, and refusals; inspected images supplement native-range and lifecycle results. The previous qualification blocker is resolved. No stored-data contract changes require migration proof. |
| Evidence reviewed | 9 items | Pinned introduction and merge identity: Reviewed the introduced main-to-head delta. Raw commit records confirm the original head’s two recorded parents and the test merge’s exact main-then-head parents; both commits have the same result tree.<br>Final-effect target validation: The selection driver rechecks exact target authority after the final awaited source read and immediately before either no-op or native write. Readback requires the requested range and unchanged UTF-16 text; unconfirmed writes remain retry-unsafe.<br>Prior diagnostic finding resolved: The exact-window guard now sits outside the generic receipt-error catch. Current CLI and MCP regressions distinguish valid process/screen observations from malformed or invalidated receipts, matching the accepted discussion at https://github.com/openclaw/peekaboo/pull/908#discussion_r4176553397. |
| Findings | None | None. |
| Security | None | None. |
How this fits together
Peekaboo’s desktop automation receives element targets and literal text from CLI or agent clients. It validates an observed window, changes the native selection through Accessibility, and returns a verified outcome and target receipt.
flowchart TD
A[CLI or agent request] --> B[Observed window and element]
B --> C[Validate target and snapshot lease]
C --> D[Resolve unique literal match]
D --> E[Native selection or caret write]
E --> F[Verify range and unchanged text]
F --> G[Outcome and target receipt]
C --> H[Safe refusal]
D --> H
Before merge
None.
<details>
<summary><strong>Agent review details</strong></summary>
Security
None.
Review metrics
| Metric | Value | Why it matters |
|---|---|---|
| Production and test growth | Swift production +902 net lines; tests +1021 net lines | Production growth implements the shared selection operation and its client surfaces, with substantial matching and boundary regression coverage. |
| Native qualification | 21 CLI/MCP cases; 48 uncached observations; 310 live receipt validations | The captured current-head qualification exercises native effects and refusals beyond mocked tests. |
Technical review
Best possible solution:
Retain the shared native-only selection path with exact-window validation, unchanged-text readback, and capability-gated remote execution.
Do we have a high-confidence way to reproduce the issue?
Not applicable to a feature request; the recorded signed current-head CLI/MCP run demonstrates selection modes, context matching, and safe refusals in a native receiver.
Is this the best way to solve the issue?
Yes: the patch reuses existing mutation planning, target receipts, snapshot leases, and native range setting rather than adding a competing input mechanism.
AGENTS.md: found and applied where relevant.
Codex review notes: model internal, reasoning medium; reviewed against 4c3e11abf585.
Labels
Label changes:
rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.Label justifications:
P2: This is a bounded desktop automation capability with demonstrated native behavior and no urgent regression.rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): Signed qualification at the pinned head exercises the shared native selection owner through CLI and real stdio MCP, covering all modes, contexts, newline selection, unfocused fields, and refusals; inspected images supplement native-range and lifecycle results. The previous qualification blocker is resolved. No stored-data contract changes require migration proof.proof: sufficient: Contributor real behavior proof is sufficient. Signed qualification at the pinned head exercises the shared native selection owner through CLI and real stdio MCP, covering all modes, contexts, newline selection, unfocused fields, and refusals; inspected images supplement native-range and lifecycle results. The previous qualification blocker is resolved. No stored-data contract changes require migration proof.Evidence
What I checked:
Core/PeekabooAutomationKit/Sources/PeekabooAutomationKit/Services/UI/ActionInputDriver.swift:350, 58ebe36f8ff2)Core/PeekabooCore/Sources/PeekabooAgentRuntime/MCP/Server/MCPDesktopActionFailureHandler.swift:71, 58ebe36f8ff2)Core/PeekabooAutomationKit/Tests/PeekabooAutomationKitTests/TextSelectionRequestTests.swift:47, 58ebe36f8ff2)Core/PeekabooCore/Sources/PeekabooBridge/PeekabooBridgeModels.swift:175, 58ebe36f8ff2)Likely related people:
Rating scale
| Score | Internal tier | Crab rank | Meaning |
|---:|:---:|---|---|
| 6/6 | S | 🦀 challenger crab | Exceptional readiness |
| 5/6 | A | 🦞 diamond lobster | Very strong readiness |
| 4/6 | B | 🐚 platinum hermit | Good normal PR; ordinary maintainer review |
| 3/6 | C | 🦐 gold shrimp | Useful, but confidence is limited |
| 2/6 | D | 🦪 silver shellfish | Proof or implementation needs work |
| 1/6 | F | 🧂 unranked krab | Not merge-ready |
| N/A | NA | 🌊 off-meta tidepool | Rating does not apply |
Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.
Workflow
@clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.@clawsweeper review to request a fresh review only.@clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.@clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.History
<details>
<summary>Review history (3 earlier review cycles)</summary>
<!-- clawsweeper-review-history v=1 total=3 -->
</details>
</details>
<!-- clawsweeper-verdict:needs-human item=908 sha=58ebe36f8ff28d678cd055b793d1d8765a391cfd confidence=high updated_at=2026-10-04T08:06:19Z reviewed_at=2026-10-04T08:08:25.545Z lease_owner=github-run-37187798344-1 lease_comment_id=5977958066 source_revision=f2d269da91357a328c8c0d342576255f45e28fe4520bdb3c16ee0004bc190064 live_verification=absent -->
<!-- clawsweeper-review-state:ready item=908 sha=58ebe36f8ff28d678cd055b793d1d8765a391cfd v=1 -->
<!-- clawsweeper-review-version item=908 reviewed_at=2026-10-04T08:08:25.545Z sha=58ebe36f8ff28d678cd055b793d1d8765a391cfd source_revision=f2d269da91357a328c8c0d342576255f45e28fe4520bdb3c16ee0004bc190064 lease_owner=github-run-37187798344-1 lease_comment_id=5977958066 v=1 -->
<!-- clawsweeper-review item=908 -->
Exact 88841dcb native requalification is complete: CLI and real stdio MCP agree with the native receiver on selection modes, context matching, full trailing-newline selection, unfocused-field selection and safe refusals. The first run's cached pre-action AX evidence remains a failed freshness clause; the new fixture run has 42 uncached pre/post observations and unchanged text/style/paste state.
The inspected captures below are synthetic-only. Before: PRIMARY is selected. After: the complete PB_PRIMARY_BASELINE line, including its trailing newline, is selected. Native state and CLI/MCP metadata—not the pixels alone—prove the exact 0+20 UTF-16 range.
The new run validates 298 signed bundles against their actual live producers, preserves all 87 baseline app generations, and samples unchanged global foreground, cursor/buttons/modifiers, clipboard and existing window order through normal cleanup. Two later daemon lifecycle receipts are offline-only. This is candidate-daemon proof; no installed-GUI or universal-parity claim.
!Before: PRIMARY selected in the synthetic receiver
!After: newline-inclusive full literal selected, native range 0+20
PR Summary
<!-- CURSOR_SUMMARY -->
Medium Risk
Introduces a new process-generation-bound accessibility mutation and Bridge 1.42 negotiation surface, but reuses existing element-action receipt patterns with strict pre-dispatch refusals and no keyboard/clipboard fallback.
Overview
Adds background native text selection end-to-end: CLI select-text, Agent/MCP select_text, and Bridge protocol 1.42 with a textSelection capability and selectText operation.
Matching is literal UTF-16 with optional adjacent prefix/suffix, modes text / cursor_before / cursor_after, and pre-dispatch refusals for ambiguous or missing matches. Execution goes through AXSelectedTextRange only (action-only policy—no typing, focus, activation, or clipboard), with source-drift checks, observed mutation readback, and the same snapshot leases / process-generation receipts as other element mutations. Exact-window snapshots are required; process-only or screen observations refuse before dispatch.
ElementActionResult and command/MCP output now carry textSelection ranges; MCP metadata projection exposes only the four public selection fields for select_text. Runtime wiring includes bridge client/server handlers, remote automation, capability policy, CI test filters, changelogs, and release preflight (34 root commands).
<sup>Reviewed by Cursor Bugbot for commit 58ebe36f8ff28d678cd055b793d1d8765a391cfd. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>
<!-- /CURSOR_SUMMARY -->
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo2M2FiMDc5YS04NWExLTQ4OTMtOGZiOC1jOWUxM2M5ZTZiNDQiLCJlbmNyeXB0aW9uS2V5IjoiX2tJTnBjZV9saHZZYnhkUHk2czhyU1poRHlaWWpvUExRRGRRbjFFMUMwTSIsImJyYW5jaCI6ImNvZGV4L2JhY2tncm91bmQtdGV4dC1zZWxlY3Rpb24iLCJyZXBvT3duZXIiOiJvcGVuY2xhdyIsInJlcG9OYW1lIjoiUGVla2Fib28iLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by Cursor Bugbot for commit 88841dcb3f3aa8f77de653a84bee43a6caac9d3f. Configure here.</sup>
Exact-window refusal message is lost
Medium Severity
<!-- DESCRIPTION START -->
The new exact-window guard throws a specific invalidInput refusal, but the surrounding catch immediately replaces it with a generic process-generation receipt failure. Callers then see a stale-snapshot error and hint, so a process-only or screen snapshot is reported as an inconsistent receipt instead of a missing exact-window target.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 79ce26de-ce5c-4a2c-b2b0-813a1fdc7444 -->
<!-- LOCATIONS START
Apps/CLI/Sources/PeekabooCLI/Commands/Interaction/SetValueCommand.swift#L368-L389
Core/PeekabooCore/Sources/PeekabooAgentRuntime/MCP/Server/MCPDesktopActionFailureHandler.swift#L55-L70
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
Core/PeekabooCore/Sources/PeekabooAgentRuntime/MCP/Server/MCPDesktopActionFailureHandler.swift#L55-L70</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjdlZDA1ZjkzLTdmZTAtNGJmYS1iODdkLTc4ZDIzODhmNzVlZSIsImVuY3J5cHRpb25LZXkiOiJkWk1oZmJPSllsZGU0UDBjZjVmMDQ4YTBxNENXYUxjY0tjcF9COFRGemhZIiwiYnJhbmNoIjoiY29kZXgvYmFja2dyb3VuZC10ZXh0LXNlbGVjdGlvbiIsInJlcG9Pd25lciI6Im9wZW5jbGF3IiwicmVwb05hbWUiOiJQZWVrYWJvbyIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjdlZDA1ZjkzLTdmZTAtNGJmYS1iODdkLTc4ZDIzODhmNzVlZSIsImVuY3J5cHRpb25LZXkiOiJkWk1oZmJPSllsZGU0UDBjZjVmMDQ4YTBxNENXYUxjY0tjcF9COFRGemhZIiwiYnJhbmNoIjoiY29kZXgvYmFja2dyb3VuZC10ZXh0LXNlbGVjdGlvbiIsInJlcG9Pd25lciI6Im9wZW5jbGF3IiwicmVwb05hbWUiOiJQZWVrYWJvbyIsInByTnVtYmVyIjo5MDgsImNvbW1pdFNoYSI6Ijg4ODQxZGNiM2YzYWE4Zjc3ZGU2NTNhODRiZWU0M2E2Y2FhYzlkM2YiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by Cursor Bugbot for commit 88841dcb3f3aa8f77de653a84bee43a6caac9d3f. Configure here.</sup>
The late exact-window diagnostic finding is accepted. Both wrappers put the exact-window requirement inside a generic receipt-error catch, so callers can get stale-process-receipt guidance for the wrong kind of target. I am fixing the distinction and adding CLI/MCP regression coverage before landing.
The signed native selection proof above remains valid for its exact tested head and cases. No merge has been pushed; the focused follow-up will receive its own review and exact-head checks. No input fallback, target-authority relaxation, or blind replay is involved.
Fixed in ff1cf19f6, included in current head 58ebe36f8. The generic catch now covers receipt assembly/invalidated evidence only; valid process-only or screen observations receive an explicit retry-safe INVALID_INPUT refusal naming --window-id / window_id. Malformed and invalidated controls retain SNAPSHOT_STALE, and no mutation or focus fallback occurs. New regressions failed on the original implementation and pass after the fix: 21 CLI tests and 74 MCP tests across the focused and adjacent suites. Both the focused fix and the main-integrated PR passed isolated P0 review. New-head hosted checks and signed qualification are running before landing.
Current-head signed native qualification is complete at 58ebe36f8ff28d678cd055b793d1d8765a391cfd.
The isolated source-blind audit passes all 21 CLI/MCP cases and their freshness/lifecycle requirements: 48 actual uncached pre/post observations and full images, 310 live-validated signed bundles (291 candidate plus 19 GUI auxiliary invalidations), and two separately checked offline lifecycle bundles. The tracked observer spans input, normal exact-generation cleanup, receipt validation and daemon shutdown: 7,133 samples, maximum gap43.797ms, with unchanged global foreground, pointer/buttons/modifiers and clipboard. All88 baseline app generations are present at final inventory. This remains finite sampled evidence, not continuous isolation.
The integrated-computer-use comparison matches both context-disambiguation cases but again selects0+19 for a requested newline-inclusive0+20 literal; Peekaboo's CLI and MCP each select all20. The two inspected synthetic captures below show that difference. Native ranges—not pixels alone—establish the counts. Prior CUA three-mode matches and the unavailable guard-window binding remain separately recorded; neither is falsely promoted to a new comparison here.
Earlier failed evidence is preserved: the first58 observer hit its600-second cap during the slower comparator, and an intermediate runner caught a readiness race before any fixture launch/input. Neither is counted as a full pass. The final bounded run records the observer's exact PID/generation and completes normally within its lifetime. No input was replayed into the old receiver.
The accepted diagnostic finding is fixed and reviewed, with21 CLI and74 MCP red-before/green-after tests; current Cursor and ClawSweeper reviews have no remaining actionable findings. New-head macOS CI is green; remaining workflow finalization is still watched before landing. No installation, release or universal-parity claim.
!Peekaboo current58: native selection 0+20 including newline
!Integrated comparator: same literal request, native selection 0+19
Landed by the repository's allowed squash method as 3f70a60411f50b969221df92ec4f747f5913aebe. The landed tree is a80df0fbde95825c577d3b779291b2747d11e162, byte-identical to the reviewed/tested head58ebe36f8. Visible main is pulled and synchronized; pre-existing local submodule selections are preserved. The signed artifacts remain labeled as pre-squash58 candidates, not installed or falsely restamped.
Final focused regression commands, run through the workspace wrapper with isolated configuration and native/ambient input gates disabled:
python3 scripts/setup-swift-workspace.py run -- swift test --package-path Apps/CLI --arch arm64 --configuration debug --jobs 2 --disable-automatic-resolution --skip-update --disable-xctest --enable-swift-testing --no-parallel --filter 'SelectTextCommandTests|SnapshotReceiptPreDispatchCommandTests|ComposedInputParityValidationTests'
python3 scripts/setup-swift-workspace.py run -- swift test --package-path Core/PeekabooCore --arch arm64 --configuration debug --jobs 2 --disable-automatic-resolution --skip-update --disable-xctest --enable-swift-testing --no-parallel --filter 'MCPTextSelectionTests|MCPDesktopActionOutcomeProjectionTests|MCPToolArgumentValidationTests'
These passed21 CLI and74 MCP tests after the new assertions failed on the original helpers. Earlier metadata/inventory follow-up passed218 tests across13 suites. Formatting, strict lint, isolated review, Cursor and ClawSweeper have no remaining actionable findings.
Exact58 hosted proof passed attempt1: macOS CI, supplemental/full-safe, and CodeQL. Signed current-head native proof is recorded above:21 CLI/MCP cases,48 uncached reads/images,310 live receipts plus2 offline lifecycle checks, and observed normal cleanup preserving88/88 baseline generations. Earlier cache/observer/setup failures remain explicitly separate.
The feature uses the existing range setter and mutation/receipt boundaries; no keyboard, clipboard or foreground fallback was added. The separate installed-GUI paste failure, wider pointer/key/scroll coverage and complex Agent/CUA concurrency goal remain open. No release or universal parity is claimed.
steipete
Summary
Add
peekaboo select-textand Agent/MCPselect_textfor literal native text selection and caret placement without typing, changing the clipboard, activating the app, or falling back to foreground input.Requests use exact UTF-16 matching, adjacent prefix/suffix disambiguation, and
text,cursor_before, orcursor_after. Missing/ambiguous matches refuse before input. Success requires a confirmed native range and unchanged source text; unconfirmed writes remain retry-unsafe.Ownership and compatibility
Reuse the existing AX range setter, element mutation planning, snapshot leases, target receipts, and canonical outcome owners. Selection is action-only and does not require AXValue writability or keyboard focus. Final window validation follows the final awaited source-text read immediately before no-op/write. Existing action/value query lookup retains its first-match fast path.
Bridge protocol 1.42 advertises the capability. Older hosts refuse without synthesized input. CLI/MCP documentation, command inventories, hosted test filters, and both changelogs are updated. Native testing also found and fixed the public MCP projector dropping the four selection metadata fields; a real server/InMemoryTransport regression reproduced that defect before the fix.
Qualification
Landed as
3f70a60411f50b969221df92ec4f747f5913aebeby the repository's allowed squash method. Its tree is byte-identical to reviewed/tested head58ebe36f8ff28d678cd055b793d1d8765a391cfd, which includes the diagnostic correction and main's prior changes. All exact-head hosted checks, signed native qualification and external reviews pass. Earlier evidence below remains pinned to its actual source.ff1cf19f6: valid process-only/screen observations now receive retry-safeINVALID_INPUTguidance naming--window-id/window_id, outside the generic receipt-error catch. Malformed/invalidated receipts still report stale, with no dispatch. Red-before/green-after: 21 CLI tests and 74 MCP tests passed, plus clean format/strict lint and isolated P0 review. The four tested file hashes remain identical after the main merge.Completed candidate qualification at
88841dcb3f3aa8f77de653a84bee43a6caac9d3f:Boundaries
This is signed candidate-daemon qualification, not an installed-GUI rollout. Native fixed-baseline tests do not cover surrogate-pair/decomposed-Unicode content; that coverage remains unit/wire-level. The separate installed rich-paste preparation failure and complex Agent/CUA concurrency acceptance remain open. No release or universal parity is claimed.
The branch was integrated with main without rebase/force and landed by the allowed squash method. The final source tree matches the tested head exactly; old green runs were not substituted for current-head CI. Signed58 artifacts are pre-squash candidates and remain uninstalled.