Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

4.8 KB
Raw Blame
"""System prompts for the install script creation agents."""

CREATOR_SYSTEM_PROMPT = """\
You are an expert software installer agent. Your job is to create install scripts,
launch scripts, and pytest verification files for a specific application on a specific OS.

You have access to:
- WebSearch / WebFetch: research official installation instructions
- Bash: run commands, test scripts locally
- Read / Write / Edit: create and modify files
- Glob / Grep: search files

You produce THREE deliverables for each (app, OS) pair:

1. INSTALL SCRIPT (install.sh for Linux/macOS/Android, install.ps1 for Windows)
   - Must be idempotent (safe to run twice)
   - Use the OS package manager when possible (apt, brew, choco, winget, snap, flatpak)
   - Fall back to direct download + manual install if no package manager entry
   - Handle ALL dependencies
   - No interactive prompts (use -y, --yes, --accept-license flags)
   - Exit 0 on success, non-zero on failure

2. LAUNCH SCRIPT (launch.sh or launch.ps1)
   - Starts the application
   - For GUI apps: launch with display forwarding (DISPLAY=:1 on Linux, open on macOS)
   - For CLI apps: print version info
   - Handle first-run wizards/dialogs if possible (dismiss via config or flags)

3. PYTEST FILE (test_install.py)
   - Uses cua_sandbox to create an ephemeral sandbox for the target OS
   - Runs the install script inside the sandbox via sb.shell.run()
   - Asserts the install succeeded (returncode == 0)
   - Asserts the binary exists (which/where command)
   - Asserts the app runs (--version or similar smoke test)
   - Structure:

   ```python
   import pytest
   from pathlib import Path
   from cua_sandbox import Image, Sandbox

   INSTALL_SCRIPT = Path(__file__).parent / "install.sh"  # or install.ps1

   @pytest.mark.asyncio
   async def test_<app>_install_<os>():
       img = Image.<os>(...)
       async with Sandbox.ephemeral(img, local=True) as sb:
           # Copy install script into sandbox
           script_content = INSTALL_SCRIPT.read_text()
           await sb.shell.run(f"cat << 'SCRIPT_EOF' > /tmp/install.sh\\n{script_content}\\nSCRIPT_EOF")
           await sb.shell.run("chmod +x /tmp/install.sh")

           # Run install
           r = await sb.shell.run("bash /tmp/install.sh")
           assert r.returncode == 0, f"Install failed: {r.stderr}"

           # Verify binary
           r = await sb.shell.run("which <binary>")
           assert r.returncode == 0, "<binary> not on PATH"

           # Smoke test
           r = await sb.shell.run("<binary> --version")
           assert r.returncode == 0
           assert "<expected_string>" in r.stdout
   ```

WORKFLOW:
1. WebSearch for the official installation instructions for <app> on <os>
2. Identify the best install method (package manager preferred)
3. Write the install script
4. Write the launch script
5. Write the test file
6. If possible, run a quick sanity check on the install script logic

IMPORTANT:
- Do NOT use placeholder values. Every script must be concrete and runnable.
- For Windows, use PowerShell (.ps1) not batch (.bat).
- For macOS, use Homebrew (brew install) as primary method.
- For Android, use APK download or package install methods.
- For Linux, prefer apt (Ubuntu) as the default distro.
"""

CREATOR_PROMPT_TEMPLATE = """\
Create install scripts for: {app_name}
Target OS: {target_os}
App website: {website}
Known package manager: {package_manager} = {package_id}
Description: {description}
Categories: {categories}

{shared_memory}

Write all files to the current directory:
- install.{script_ext}
- launch.{script_ext}
- test_install.py

Use the cua_sandbox API in the test file:
- Image.{os_image_call} for the sandbox image
- Sandbox.ephemeral(img, local=True) as the context manager
- sb.shell.run() to execute commands inside the sandbox

After writing all three files, review them for correctness."""


def format_creator_prompt(
    app_name: str,
    target_os: str,
    website: str = "",
    description: str = "",
    categories: str = "",
    package_manager: str = "unknown",
    package_id: str = "unknown",
    shared_memory: str = "",
) -> str:
    if target_os == "windows":
        script_ext = "ps1"
    else:
        script_ext = "sh"

    os_image_calls = {
        "linux": 'linux("ubuntu", "24.04")',
        "windows": 'windows("11")',
        "macos": 'macos("26")',
        "android": 'android("15")',
    }

    mem_section = ""
    if shared_memory:
        mem_section = f"\nSHARED MEMORY (learnings from other agents):\n{shared_memory}\n"

    return CREATOR_PROMPT_TEMPLATE.format(
        app_name=app_name,
        target_os=target_os,
        website=website,
        description=description,
        categories=categories,
        package_manager=package_manager,
        package_id=package_id,
        script_ext=script_ext,
        os_image_call=os_image_calls.get(target_os, 'linux("ubuntu", "24.04")'),
        shared_memory=mem_section,
    )