Skip to content

chore(cua-driver): add CLI-first agent helper - #1426

Closed
kamellperry wants to merge 1 commit into
trycua:mainfrom
kamellperry:chore/cua-driver-cli-agent-helper
Closed

chore(cua-driver): add CLI-first agent helper#1426
kamellperry wants to merge 1 commit into
trycua:mainfrom
kamellperry:chore/cua-driver-cli-agent-helper

Conversation

@kamellperry

@kamellperry kamellperry commented May 2, 2026

Copy link
Copy Markdown

Summary

  • add a CLI-first agent helper script for common Cua Driver workflows
  • update the bundled cua-driver skill to use the current cua-driver call <tool> syntax
  • document screenshot file output and macOS screencapture fallback for vision reliability

Test Plan

  • bash -n libs/cua-driver/scripts/agent-cli-helper.sh
  • libs/cua-driver/scripts/agent-cli-helper.sh --help
  • grep check for stale --image-out / missing SCREENSHOT.md refs

Summary by CodeRabbit

  • New Features

    • Added a CLI helper script providing convenient commands for app launching, window inspection, screenshot capture, and daemon management.
  • Documentation

    • Updated recommended CLI usage patterns and best practices.
    • Clarified capture mode recommendations with improved operational guidance.
    • Enhanced troubleshooting procedures with clearer step-by-step instructions.

@vercel

vercel Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

@kamellperry is attempting to deploy a commit to the Cua Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR updates cua-driver documentation to clarify canonical CLI workflows using cua-driver call syntax, recommend capture_mode=ax as the default, and revise screenshot and permission-check patterns. It also introduces a new Bash wrapper script cua-driver-agent that provides convenience commands for common agentic workflows.

Changes

CUA Driver CLI Guidance and Helper Script

Layer / File(s) Summary
Documentation Updates
libs/cua-driver/Skills/cua-driver/SKILL.md
Clarifies canonical workflows using cua-driver call <tool> '<JSON>' format; changes default capture mode recommendation to ax (AX tree + element-index cache); revises screenshot guidance to use screenshot_out_file and get_window_state in som mode; updates permission-check and config-lookup commands to use cua-driver call check_permissions '{}' and cua-driver call get_config '{}'; removes references to shell shims and --image-out flag.
CLI Helper Script
libs/cua-driver/scripts/agent-cli-helper.sh
New cua-driver-agent wrapper providing convenience subcommands (apps, windows, state, state-shot, screenshot, screen, calc, fast, demo, ax/vision/som) that encapsulate capture mode switching, screenshot output management, JSON escaping, 20-second timeout-based capture attempts with macOS fallback, and cross-call state restoration via trap cleanup handlers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ddupont808

Poem

🐰 A helper script hops in with cheer,
With clever wrappers for workflows dear—
No more long calls, just agent commands,
Screenshots catching all that the vision shuns!
Capture modes dance: ax, vision, som play,
While SKILL.md lights the canonical way. 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: adding a CLI-first agent helper script for Cua Driver workflows, with supporting documentation updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@libs/cua-driver/scripts/agent-cli-helper.sh`:
- Around line 81-83: The cleanup handler unconditionally sets capture_mode to
"ax", clobbering any pre-existing mode; modify the script to read and save the
current mode into a variable before running "$CUA_DRIVER_BIN config set
capture_mode som", and have cleanup() restore that saved value (e.g.,
"$CUA_DRIVER_BIN config set capture_mode $PREV_CAPTURE_MODE" or skip restore if
empty), ensuring the trap EXIT uses this cleanup; also handle failures robustly
by defaulting to a safe value and silencing errors with "|| true" as needed.
- Around line 92-98: The script's screenshot branch uses the non-portable
`timeout` command (in the if that runs `timeout 20 "$CUA_DRIVER_BIN" call
screenshot ...`) which is missing on stock macOS; add a small detection at
script startup to set a TIMEOUT_CMD variable to the available binary (prefer
gtimeout if present, then timeout, else empty) and then replace the hardcoded
`timeout` invocation in the screenshot if-condition with
"${TIMEOUT_CMD:+$TIMEOUT_CMD 20 }" or equivalent so the script falls back
gracefully to calling "$CUA_DRIVER_BIN" without timeout when neither `gtimeout`
nor `timeout` exist; update the if-condition that invokes `"$CUA_DRIVER_BIN"
call screenshot` to use this TIMEOUT_CMD variable so the primary cua-driver path
isn't silently skipped on macOS.
- Line 84: The get_window_state invocation embeds the user-supplied `${out}`
path into a JSON string without escaping, so use the existing json_escape helper
to produce a safe JSON string; update the call that runs "$CUA_DRIVER_BIN" call
get_window_state
"{\"pid\":${pid},\"window_id\":${wid},\"screenshot_out_file\":\"${out}\"}" to
pass the escaped path (via json_escape) instead of raw ${out}—mirror how the
state command uses json_escape at the earlier invocation to ensure quotes and
backslashes are properly escaped.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 37fc0b90-ae24-415c-8681-7e560538af35

📥 Commits

Reviewing files that changed from the base of the PR and between 91724df and 0a06465.

📒 Files selected for processing (2)
  • libs/cua-driver/Skills/cua-driver/SKILL.md
  • libs/cua-driver/scripts/agent-cli-helper.sh

Comment on lines +81 to +83
"$CUA_DRIVER_BIN" config set capture_mode som >/dev/null
cleanup() { "$CUA_DRIVER_BIN" config set capture_mode ax >/dev/null 2>&1 || true; }
trap cleanup EXIT

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

state-shot cleanup unconditionally clobbers any pre-existing capture mode to ax.

If the caller was in som or vision mode before invoking state-shot, the trap cleanup EXIT silently resets their config to ax. The fix is to save the current mode before switching and restore it on cleanup.

🐛 Proposed fix: save and restore the previous capture mode
+    prev_mode=$("$CUA_DRIVER_BIN" config get capture_mode 2>/dev/null || echo "ax")
     "$CUA_DRIVER_BIN" config set capture_mode som >/dev/null
-    cleanup() { "$CUA_DRIVER_BIN" config set capture_mode ax >/dev/null 2>&1 || true; }
+    cleanup() { "$CUA_DRIVER_BIN" config set capture_mode "$prev_mode" >/dev/null 2>&1 || true; }
     trap cleanup EXIT
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"$CUA_DRIVER_BIN" config set capture_mode som >/dev/null
cleanup() { "$CUA_DRIVER_BIN" config set capture_mode ax >/dev/null 2>&1 || true; }
trap cleanup EXIT
prev_mode=$("$CUA_DRIVER_BIN" config get capture_mode 2>/dev/null || echo "ax")
"$CUA_DRIVER_BIN" config set capture_mode som >/dev/null
cleanup() { "$CUA_DRIVER_BIN" config set capture_mode "$prev_mode" >/dev/null 2>&1 || true; }
trap cleanup EXIT
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/cua-driver/scripts/agent-cli-helper.sh` around lines 81 - 83, The
cleanup handler unconditionally sets capture_mode to "ax", clobbering any
pre-existing mode; modify the script to read and save the current mode into a
variable before running "$CUA_DRIVER_BIN config set capture_mode som", and have
cleanup() restore that saved value (e.g., "$CUA_DRIVER_BIN config set
capture_mode $PREV_CAPTURE_MODE" or skip restore if empty), ensuring the trap
EXIT uses this cleanup; also handle failures robustly by defaulting to a safe
value and silencing errors with "|| true" as needed.

"$CUA_DRIVER_BIN" config set capture_mode som >/dev/null
cleanup() { "$CUA_DRIVER_BIN" config set capture_mode ax >/dev/null 2>&1 || true; }
trap cleanup EXIT
"$CUA_DRIVER_BIN" call get_window_state "{\"pid\":${pid},\"window_id\":${wid},\"screenshot_out_file\":\"${out}\"}"

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

User-supplied output path is not JSON-escaped, so paths with " or \ produce malformed JSON.

Line 84 embeds ${out} directly into the JSON string literal. The existing json_escape helper (line 36) already handles this correctly and is used for the state command's query arg on line 70.

🐛 Proposed fix: use json_escape for the path
+    out_json=$(json_escape "$out")
-    "$CUA_DRIVER_BIN" call get_window_state "{\"pid\":${pid},\"window_id\":${wid},\"screenshot_out_file\":\"${out}\"}"
+    "$CUA_DRIVER_BIN" call get_window_state "{\"pid\":${pid},\"window_id\":${wid},\"screenshot_out_file\":${out_json}}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"$CUA_DRIVER_BIN" call get_window_state "{\"pid\":${pid},\"window_id\":${wid},\"screenshot_out_file\":\"${out}\"}"
out_json=$(json_escape "$out")
"$CUA_DRIVER_BIN" call get_window_state "{\"pid\":${pid},\"window_id\":${wid},\"screenshot_out_file\":${out_json}}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/cua-driver/scripts/agent-cli-helper.sh` at line 84, The get_window_state
invocation embeds the user-supplied `${out}` path into a JSON string without
escaping, so use the existing json_escape helper to produce a safe JSON string;
update the call that runs "$CUA_DRIVER_BIN" call get_window_state
"{\"pid\":${pid},\"window_id\":${wid},\"screenshot_out_file\":\"${out}\"}" to
pass the escaped path (via json_escape) instead of raw ${out}—mirror how the
state command uses json_escape at the earlier invocation to ensure quotes and
backslashes are properly escaped.

Comment on lines +92 to +98
if timeout 20 "$CUA_DRIVER_BIN" call screenshot "{\"window_id\":${wid},\"format\":\"png\"}" --screenshot-out-file "$out" >/tmp/cua-driver-agent-screenshot.log 2>&1 && test -s "$out"; then
printf '%s\n' "$out"
else
/usr/sbin/screencapture -x -l "$wid" "$out"
test -s "$out"
printf '%s\n' "$out"
fi

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

timeout is not available on stock macOS, silently bypassing the cua-driver screenshot path entirely.

"macOS does not include the GNU Coreutils timeout command by default." Homebrew installs it prefixed as gtimeout, not timeout.

With stderr redirected to the log file (2>&1), the bash: timeout: command not found error is silently swallowed, test -s "$out" fails (nothing was written), and the else branch runs unconditionally on every stock macOS install. The entire if arm — the primary cua-driver screenshot path — is dead code for users without GNU coreutils.

🐛 Proposed fix: resolve a timeout command at the top of the script
 CUA_DRIVER_BIN="${CUA_DRIVER_BIN:-cua-driver}"
 SHOT_DIR="${CUA_SCREENSHOT_DIR:-/tmp/cua-screenshots}"
+TIMEOUT_CMD=$(command -v timeout 2>/dev/null || command -v gtimeout 2>/dev/null || echo "")

Then in the screenshot case:

-    if timeout 20 "$CUA_DRIVER_BIN" call screenshot "{\"window_id\":${wid},\"format\":\"png\"}" --screenshot-out-file "$out" >/tmp/cua-driver-agent-screenshot.log 2>&1 && test -s "$out"; then
+    if [[ -n "$TIMEOUT_CMD" ]] && "$TIMEOUT_CMD" 20 "$CUA_DRIVER_BIN" call screenshot "{\"window_id\":${wid},\"format\":\"png\"}" --screenshot-out-file "$out" >/tmp/cua-driver-agent-screenshot.log 2>&1 && test -s "$out"; then
+    # or if no timeout available, run without it:
+    # if "$CUA_DRIVER_BIN" call screenshot ... >/tmp/cua-driver-agent-screenshot.log 2>&1 && test -s "$out"; then

Or use a portable wrapper:

+_timeout() {
+  local t="$1"; shift
+  if command -v timeout >/dev/null 2>&1; then timeout "$t" "$@"
+  elif command -v gtimeout >/dev/null 2>&1; then gtimeout "$t" "$@"
+  else "$@"
+  fi
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@libs/cua-driver/scripts/agent-cli-helper.sh` around lines 92 - 98, The
script's screenshot branch uses the non-portable `timeout` command (in the if
that runs `timeout 20 "$CUA_DRIVER_BIN" call screenshot ...`) which is missing
on stock macOS; add a small detection at script startup to set a TIMEOUT_CMD
variable to the available binary (prefer gtimeout if present, then timeout, else
empty) and then replace the hardcoded `timeout` invocation in the screenshot
if-condition with "${TIMEOUT_CMD:+$TIMEOUT_CMD 20 }" or equivalent so the script
falls back gracefully to calling "$CUA_DRIVER_BIN" without timeout when neither
`gtimeout` nor `timeout` exist; update the if-condition that invokes
`"$CUA_DRIVER_BIN" call screenshot` to use this TIMEOUT_CMD variable so the
primary cua-driver path isn't silently skipped on macOS.

@kamellperry

Copy link
Copy Markdown
Author

Closing this PR because we're moving the work into Omni-World-LLC/computer-use-agents as the canonical repo.

@kamellperry kamellperry closed this May 2, 2026
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.

1 participant