## Executive Summary

While modern AI coding models excel at generating XAML and C# code, mobile application development has historically presented a major barrier: **AI coding agents were fundamentally "blind" and "clumsy"**. Agents relied on lossy visual screenshots and OCR, could not inspect the live visual tree, and frequently hijacked the developer's mouse cursor to click hardcoded pixel coordinates inside emulators.

In this session, Gerald Versluis unveiled a comprehensive toolchain to give AI coding agents **"Eyes"** (live structured visual tree inspection, property inspection, streaming logs) and **"Hands"** (programmatic taps, text input, navigation, and storage inspection) without cursor hijacking. 

Built under the **Maui Labs** incubator initiative (`github.com/dotnet/maui-labs`), the architecture comprises:
1. **Dev Flow**: An in-app debug agent (`Microsoft.Maui.DevFlow.Agent`) exposed via an **MCP (Model Context Protocol) Server Broker**, enabling agents to interact with running mobile apps like "Playwright for Mobile".
2. **Maui CLI (`maui`)**: A cross-platform CLI tool for environment diagnostics (`maui doctor`), device orchestration, and autonomous agent onboarding (`maui ai init`).
3. **Maui Labs Marketplace & AI Skills**: Domain-grounded skills teaching LLMs mobile and .NET MAUI best practices (e.g., avoiding CollectionView inside ScrollView).
4. **Maui Inspector & Mobile Canvas**: In-editor visual tree debugging, live two-way property editing, and an embedded simulator canvas inside the GitHub Copilot App.

---

## 1. The Problem: Blind AI Code Generation in Mobile

![Title: Beyond Code Generation: Give AI Eyes and Hands for .NET MAUI](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/01_title_ai_eyes_hands_maui.webp)

### Why Mobile Development Broke the AI Inner Loop

In web development, tools like Playwright and Chrome DevTools give agents structured DOM trees, accessibility trees, and programmable click targets. In mobile development:
- **Screenshot Inefficiency:** Developers took screenshots of emulators, burning thousands of LLM tokens on image encoding while still hiding off-screen elements, zero-width bounds, or collapsed visibility states.
- **Cursor Hijacking:** Crude automation tools grabbed the developer's physical mouse cursor to click emulator coordinates, breaking when windows shifted and preventing developers from doing other work.
- **Verification Gaps:** Code that compiled successfully often broke at runtime due to mobile safe-area insets, keyboard overlap, or platform rendering nuances.

![The Problem: Blind AI Code Gen in Mobile](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/02_the_problem_blind_ai_code_gen.webp)

![Exploratory Testing Demo](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/03_exploratory_testing_demo.webp)

---

## 2. Architectural Pillars: Dev Flow, Maui CLI, Skills & Inspector

![Architecture Pillars Overview](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/04_architecture_pillars_overview.webp)

```mermaid
flowchart TD
    subgraph AgentHarness["AI Agent / Editor Loop"]
        Copilot["GitHub Copilot / CLI / Claude Code"]
        Canvas["Mobile Canvas / Maui Inspector"]
    end

    subgraph ToolingLayer["Developer & Agent Toolchain"]
        MauiCLI["Maui CLI ('maui' global tool)"]
        MCPServer["Dev Flow MCP Server Broker"]
        Skills["Maui Labs AI Skills Marketplace"]
    end

    subgraph AppRuntime["Mobile Runtime (Debug Only)"]
        MauiApp[".NET MAUI / Blazor Hybrid App"]
        InAppAgent["In-App Dev Flow Debug Agent"]
        VisualTree["Live Visual Tree & Properties"]
        Controls["Control Taps, Text Input, Logs"]
    end

    Copilot -->|"MCP Protocol"| MCPServer
    Copilot -->|"Queries Best Practices"| Skills
    MCPServer <-->|"JSON-RPC (Sockets/ADB)"| InAppAgent
    InAppAgent <--> VisualTree
    InAppAgent <--> Controls
    MauiCLI -->|"Scaffolds & Inspects"| AppRuntime
    Canvas <--> InAppAgent
```

---

## 3. Dev Flow: "Playwright for Mobile Apps"

![Dev Flow Concept: Playwright for Mobile](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/06_devflow_concept_playwright_for_mobile.webp)

### Giving AI "Eyes"
Instead of asking an LLM to hallucinate control locations from a PNG screenshot, Dev Flow exposes the **live runtime visual tree**:
- Full hierarchical element tree (Pages, Layouts, CollectionViews, Buttons, Labels).
- Live rendered values, accessibility identifiers, and element bounds.
- Visibility diagnostics: Detects elements hidden by zero opacity, zero width/height, or clipped layout constraints.
- Token efficiency: Transmitting a compact structured JSON visual tree consumes a fraction of the token cost of high-resolution multimodal screenshots.

### Giving AI "Hands"
Dev Flow enables headless, non-intrusive UI interactions:
- Programmatic control taps: `tap(controlName)` triggers native touch events directly on the UI thread without moving the developer's physical mouse cursor.
- Text input: Setting values on `Entry` or `Editor` controls.
- Scrolling & Gestures: Navigating through lists and triggering pull-to-refresh.
- Storage & Diagnostics: Inspecting `Preferences`, `SecureStorage`, application databases, and streaming console logs.
- **Blazor Hybrid Parity:** Works identically for hybrid web-view DOM components inside .NET MAUI wrappers.

![Dev Flow MCP Broker Architecture](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/10_devflow_mcp_broker_architecture.webp)

---

## 4. Setting Up Dev Flow in C# & CLI

![Setting Up Dev Flow Agent Code](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/11_setup_devflow_agent_code.webp)

### Step 1: Add NuGet Package (Debug Only)

Dev Flow is intentionally scoped exclusively to debug builds so production binaries are never exposed to remote control:

```bash
dotnet add package Microsoft.Maui.DevFlow.Agent --prerelease
```

```csharp
// MauiProgram.cs
public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .ConfigureFonts(...);

#if DEBUG
    // Register Dev Flow in-app debug agent
    builder.AddMauiDevFlowAgent();
#endif

    return builder.Build();
}
```

### Step 2: Initialize Dev Flow via Maui CLI

![Terminal Dev Flow Init Demo](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/12_terminal_devflow_init_demo.webp)

Developers can run `maui devflow init` to configure their target environment (VS Code, Copilot CLI, or Claude Code), install MCP server definitions, and generate setup prompts for the agent.

---

## 5. The Maui CLI & Maui Sherpa

![Maui CLI Tooling and Doctor](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/07_maui_cli_tooling_doctor.webp)

### Maui CLI (`maui`)

Installed globally via `dotnet tool install -g Microsoft.Maui.Cli --prerelease`:
- `maui doctor`: Comprehensive environment diagnostics checking Android SDK, Xcode, workloads, with `--fix` and machine-readable `--json` output for agents.
- `maui device list`: Discovers connected physical hardware, emulators, and simulators.
- `maui ai init`: Downloads and configures the official .NET MAUI skills into the workspace.
- `maui ai status` & `maui ai update`: Keeps local agent skills updated with upstream best practices.

![Maui AI Init Skills](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/09_maui_ai_init_skills.webp)

### Maui Sherpa: Mission Control for Mobile Developers

![Maui Sherpa Mission Control](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/08_maui_sherpa_mission_control.webp)

Created by Jonathan Peppers, **Maui Sherpa** is a native macOS application built with .NET MAUI (using the new experimental AppKit desktop backend) providing:
- Android keystore management and certificate administration.
- Apple root certificate inspection and provisioning profile management.
- Multi-version Xcode switcher and simulator configuration.
- Local push notification payload testing without third-party APNs/FCM servers.

---

## 6. Maui Labs & Official AI Skills

![Maui Labs Marketplace Skills](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/05_maui_labs_marketplace_skills.webp)

Located at `github.com/dotnet/maui-labs`, the repository is configured as an agent marketplace:

```bash
# Add Maui Labs plugin marketplace in Copilot CLI
/plugin marketplace add dotnet/maui-labs
```

Skills ground AI models in specific mobile UI conventions:
- **Layout Architecture:** Preventing anti-patterns such as nesting a `CollectionView` or `ListView` inside a `ScrollView`.
- **Safe Area Insets:** Enforcing proper safe-area padding across iOS notches, dynamic islands, and Android status bars.
- **Platform Customization:** Using conditional XAML namespaces (`OnPlatform`, `OnIdiom`) and custom handlers.

---

## 7. Maui Inspector & Mobile Canvas

![Maui Inspector Live Property Editor](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/13_maui_inspector_live_property_editor.webp)

### Maui Inspector
Served as a lightweight web interface directly inside VS Code or browser:
- **Point-and-Click Context Grounding:** Click any element on the screen to pin it into Copilot Chat context (*"Change the background of this selected Button to red"*).
- **Two-Way Live Property Editor:** Modify padding, colors, fonts, or bindings live in the running app without stopping the debug session.
- **Embedded Diagnostics:** View live console logs, network payloads, and visual hierarchy.

![Mobile Canvas in GitHub Copilot App](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/14_mobile_canvas_github_copilot_app.webp)

### Mobile Canvas (GitHub Copilot App)
An embedded canvas rendering a real-time live mirror of the iOS simulator or Android emulator inside the Copilot App. Developers can watch the autonomous agent interact with the app, verify visual regressions, and inspect local app storage side-by-side without flipping windows.

---

## 8. The Autonomous Agentic Loop

![The Autonomous Agentic Loop](/dotnetconf2026/archive/28-ai-eyes-hands-maui/screenshots/15_autonomous_agentic_loop.webp)

Gerald demonstrated an end-to-end autonomous upgrade scenario (updating a community Halloween app to .NET 11 and testing safe-area changes):
1. **Prompt Intent:** *"Update to .NET 11, run exploratory regression testing on Android, and verify all safe areas."*
2. **Inspect:** Dev Flow extracts the initial visual tree.
3. **Execute:** The agent applies framework updates and compiles the app.
4. **Hands & Eyes Validation:** Dev Flow launches the app, taps through navigation tabs, verifies that controls exist in the visual tree, and captures screenshot proof.
5. **Self-Correction:** If an element is clipped or missing, the agent re-inspects properties and iterates autonomously until all checks pass.

---

## Key Session Takeaways

| Tool / Technology | Purpose | Key Value |
|---|---|---|
| **Dev Flow Agent** | In-app debug agent (`Microsoft.Maui.DevFlow.Agent`) | Programmatic "Playwright for Mobile" with zero cursor hijacking. |
| **Dev Flow MCP Server** | Model Context Protocol broker | Standardized tool bridge connecting Copilot/Claude to running apps. |
| **Visual Tree Inspection** | Structured JSON hierarchy vs screenshots | 10x token savings, exposes zero-width and invisible elements. |
| **Maui CLI (`maui`)** | Command-line tool suite (`dotnet tool install -g`) | `maui doctor`, `maui ai init`, device discovery, and Dev Flow triggers. |
| **Maui Labs** | `github.com/dotnet/maui-labs` incubator | Official marketplace for .NET MAUI Copilot plugins and skills. |
| **Maui Sherpa** | Native macOS mission control app (by Jonathan Peppers) | All-in-one Android keystores, Apple certs, Xcode, and push testing. |
| **Maui Inspector** | Web-based visual inspector | Live two-way property editor and point-and-click agent grounding. |
| **Mobile Canvas** | Copilot App companion canvas | Real-time device mirror and autonomous agent testing viewer. |
