phantom-win

kupakupar/phantom-win Checked 1 day ago

Zero-focus-steal-first, high-speed Windows desktop automation MCP server & Antigravity plugin (.NET 10)

Zero-focus-steal-first, high-speed Windows desktop automation MCP server & Antigravity plugin (.NET 10) 简体中文 · Architecture · Security Model · Contributing · MIT License Traditional desktop automation agents hijack the foreground window, move the user's physical mouse cursor, and clobber the clipboard on every click or keystroke. PhantomWin flips the default:

Summary extracted from the README.


Why PhantomWin?

Traditional desktop automation agents hijack the foreground window, move the user's physical mouse cursor, and clobber the clipboard on every click or keystroke. PhantomWin flips the default:

  • Background zero-focus-steal first: Prioritizes pure background execution via UI Automation (Tier 1), safe Win32 window messaging (Tier 2), and isolated managed Chromium CDP over anonymous pipes (Tier 3), falling back to millisecond focus-and-restore input leases (Tier 4) only when explicitly permitted by policy or required by custom GPU/DirectX/game UIs.
  • Process-isolated Host / Worker architecture: The MCP Stdio Host (PhantomWin.Host) enforces all authorization policies, confirmation tokens, circuit breakers, and zero-intrusion guards, while COM UIA, WGC capture, WinRT OCR, and browser sessions execute in restartable isolated worker processes (PhantomWin.Worker).
  • Low-latency CUA workflows (run_flow + SoM + OCR): Collapse multi-screen desktop workflows into 1–2 tool calls with Set-of-Mark (mode="som") visual grounding, parallel WGC + UIA / OCR + UIA pipelines, automatic frameId chaining, optional popup handling, and single-lease micro-batching.
  • Fail-closed security boundaries: Unconditional blocks on elevated (UIPI) targets, ES_PASSWORD / UIA password controls, cross-session/secure desktops, dangerous script hosts/file associations, and unallowlisted browser origins.

Four-Tier Execution Architecture

Tier Channel Foreground / Cursor Intrusion Best For
Tier 1 Tier1-UIA (MTA COM UI Automation Patterns) Zero WPF, WinForms, WinUI 3, UWP, standard native controls
Tier 2 Tier2-Win32Msg (Safe SendMessageTimeout + cursor guard) Zero Native Win32 (EDIT/BUTTON) and background coordinate clicks/scroll/drag
Tier 3 Tier3-ChromiumCDP (--remote-debugging-pipe + site allowlist) Zero (after launch) Managed Edge / Chrome / Chromium / Brave / Vivaldi / Opera / Arc web apps
Tier 4 Tier4-DirectFallback (Millisecond focus lease + cursor restore) Minimal, bounded & restored Custom canvas, DirectX, embedded CEF/Electron, keyboard shortcuts (PressKey)
flowchart LR
    Client["MCP Client / Antigravity"] <--> Host["PhantomWin.Host\nPolicy · Guard · Ledger · Registry"]
    Host <-->|"Length-prefixed JSON IPC"| Worker["PhantomWin.Worker (uia)\nUIA · WGC · WinRT OCR · Win32Msg · DirectFallback"]
    Host <-->|"Length-prefixed JSON IPC"| BrowserHost["PhantomWin.Worker (--mode browser-host)\nManaged Chromium · CDP Pipe · SiteAllowlist"]

MCP Tools (9 Tools)

Tool Kind Purpose
list_windows ReadOnly List authorized interactive windows with optional inline framework/capability profile (includeProfile)
inspect_window_profile ReadOnly Inspect DPI, framework (Wpf, WinUi3, Uwp, Electron, Cef, WebView2, Win32Raw, ...), visual state, and admitted actions
observe ReadOnly Observe UI via tree, image (WGC), som (numbered Set-of-Mark), ocr (WinRT OCR + UIA cross-binding), or hybrid
act Destructive Execute semantic (Invoke, SetText, Toggle, Select, Scroll) or coordinate (Click, DoubleClick, RightClick, MiddleClick, Hover, ScrollWheel, Drag, PressKey) actions with optional verifyVisualDelta & returnAfterImage
run_flow Destructive Multi-step pipeline (launch_app, find_and_act, ocr_click, act, wait, wait_ms, observe, switch_window) with auto frameId chaining and coalesced focus leases
launch_app Destructive Launch desktop apps (.exe, aliases, .lnk, .url) and wait for a ready windowRef, blocking dangerous script hosts & file associations
launch_managed Destructive Launch, list, or close allowlisted managed Chromium instances connected over --remote-debugging-pipe
wait_for ReadOnly Wait on ElementExists, ElementGone, PropertyEquals, TextContains, or WindowClosed
operation_status ReadOnly Query operation ledger state, confirmation outcome, and late guard events

Requirements

  • OS: Windows 10 / Windows 11 (x64, build 19041+; tested on Windows 11 26100)
  • SDK: .NET 10 SDK (10.0.x, pinned in global.json)

Quick Start

1. Build & Verify

git clone https://github.com/kupakupar/phantom-win.git
cd phantom-win

# Zero-warning Release build + 15 enforceable architecture tests + core test suites
.\scripts\gate.ps1 -Milestone V4

# Full non-desktop verification suite (Unit + Win32Msg + Capture + Chromium + E2E)
.\scripts\gate.ps1 -Milestone All

2. Package & Install as an Antigravity Plugin

.\scripts\publish-plugin.ps1 -Install

This publishes PhantomWin.Host.exe and PhantomWin.Worker.exe (win-x64, Release) along with plugin.json, assets/logo.svg, rules/AGENTS.md, skills/phantom-win/SKILL.md, and mcp_config.json into ~/.gemini/config/plugins/phantom-win/.

3. Standalone MCP Client Usage

Point any MCP stdio client at the published PhantomWin.Host.exe:

{
  "mcpServers": {
    "phantom-win": {
      "command": "C:\\path\\to\\phantom-win\\dist\\plugin\\phantom-win\\bin\\PhantomWin.Host.exe",
      "args": []
    }
  }
}

Repository Layout

src/
├── PhantomWin.Contracts/          # Pure net10.0 models, IPC protocol, SSOT domain rules (0 external deps)
├── PhantomWin.Core/               # Win32 identity, geometry, trust validation, security primitives
├── PhantomWin.Policy/             # PolicyEngine, HardDenyList, single-use ConfirmTokenStore
├── PhantomWin.Guard/              # Zero-intrusion WinEvent monitor, CircuitBreaker, AdmissionTable
├── PhantomWin.Uia/                # Dedicated MTA COM UIA engine & snapshot store
├── PhantomWin.Capture/            # Windows Graphics Capture (WGC), ImageProcessor, SoM renderer
├── PhantomWin.Ocr/                # WinRT OCR engine, tiling, CJK normalization & UIA binding
├── PhantomWin.Adapters.Win32Msg/  # Safe background Win32 messaging & coordinate validation
├── PhantomWin.Adapters.Chromium/  # Managed Chromium launcher, CDP pipe client & SiteAllowlistGuard
├── PhantomWin.Host/               # MCP stdio server, 9 tools, WindowRegistry, Ledger, AuditLogger
└── PhantomWin.Worker/             # Isolated Worker (UIA/Vision/Action) & BrowserHost process
tools/
└── PhantomWin.Probe/              # Hardware/framework capability matrix probe CLI
tests/
├── PhantomWin.Tests.Unit/         # Unit + 15 enforceable ArchitectureTests
├── PhantomWin.Tests.Win32Msg/     # Background Win32 message & banned-API security tests
├── PhantomWin.Tests.Capture/      # WGC capture, staleness & geometry tests
├── PhantomWin.Tests.Ocr/          # WinRT OCR & occluded binding tests
├── PhantomWin.Tests.Chromium/     # CDP protocol & site allowlist security tests
├── PhantomWin.Tests.E2E/          # Full MCP stdio end-to-end tests across Win32/WPF/WinForms/Canvas/WebView2
└── Fixtures/                      # Deterministic multi-framework test fixture apps
plugin/                            # Antigravity plugin manifest, K logo, rules & skill
scripts/                           # gate.ps1 & publish-plugin.ps1
docs/architecture/                 # Architecture map, ADRs, governance progress & audit reports

Security & Governance

  • Untrusted UI Content: All observed window titles, control text, and OCR results are treated strictly as untrusted data.
  • Enforceable Architecture: ArchitectureTests enforces strict DAG acyclicity, Host/Worker isolation, single JsonSerializerContext, SSOT domain rules, file-size regression ceilings, and exact 9-tool MCP contract snapshots on every gate run.
  • Banned API Enforcement: BannedSymbols.txt + Microsoft.CodeAnalysis.BannedApiAnalyzers prevent accidental foreground-stealing or clipboard-clobbering API usage in zero-intrusion libraries.

See SECURITY.md for the complete security boundary specification.


License

Released under the MIT License.