Skip to content

Commit 9fa43f3

Browse files
feat: add native WinUI A2UI renderer and MCP hardening (#239)
Adds the native WinUI A2UI rendering pipeline, MCP/local security hardening, navigation/media safeguards, and integration/UI coverage for tray-hosted A2UI surfaces.\n\nThanks to @codemonkeychris for the substantial implementation and follow-through on review feedback.\n\nCo-authored-by: Copilot <[email protected]>
1 parent c7630fa commit 9fa43f3

86 files changed

Lines changed: 13465 additions & 259 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ jobs:
3939
- name: Restore dependencies
4040
run: dotnet restore
4141

42+
# dotnet-coverage replaces coverlet because the integration tests spawn the
43+
# tray exe out-of-process; coverlet only instruments the in-proc test
44+
# assembly. Installing once at the job level lets every test step wrap its
45+
# `dotnet test` invocation in `dotnet-coverage collect`.
46+
- name: Install dotnet-coverage
47+
run: dotnet tool install --global dotnet-coverage
48+
4249
- name: Build Shared Library
4350
run: dotnet build src/OpenClaw.Shared -c Debug --no-restore
4451

@@ -48,29 +55,82 @@ jobs:
4855
- name: Build Tests
4956
run: |
5057
dotnet build tests/OpenClaw.Shared.Tests -c Debug --no-restore
51-
dotnet build tests/OpenClaw.Tray.Tests -c Debug --no-restore
58+
dotnet build tests/OpenClaw.Tray.Tests -c Debug -r win-x64 --no-restore
59+
dotnet build tests/OpenClaw.Tray.IntegrationTests -c Debug -r win-x64 --no-restore
60+
dotnet build tests/OpenClaw.Tray.UITests -c Debug -r win-x64 --no-restore
5261
5362
- name: Run Shared Tests
5463
env:
5564
OPENCLAW_RUN_INTEGRATION: 1
5665
run: >
57-
dotnet test tests/OpenClaw.Shared.Tests
66+
dotnet-coverage collect
67+
--output TestResults\Shared\coverage.cobertura.xml
68+
--output-format cobertura
69+
"dotnet test tests/OpenClaw.Shared.Tests
5870
--no-build
5971
-c Debug
6072
--verbosity normal
61-
--collect:"XPlat Code Coverage"
6273
--results-directory TestResults\Shared
63-
--logger "trx;LogFileName=OpenClaw.Shared.Tests.trx"
74+
--logger trx;LogFileName=OpenClaw.Shared.Tests.trx"
6475
6576
- name: Run Tray Tests
6677
run: >
67-
dotnet test tests/OpenClaw.Tray.Tests
78+
dotnet-coverage collect
79+
--output TestResults\Tray\coverage.cobertura.xml
80+
--output-format cobertura
81+
"dotnet test tests/OpenClaw.Tray.Tests
6882
--no-build
6983
-c Debug
84+
-r win-x64
7085
--verbosity normal
71-
--collect:"XPlat Code Coverage"
7286
--results-directory TestResults\Tray
73-
--logger "trx;LogFileName=OpenClaw.Tray.Tests.trx"
87+
--logger trx;LogFileName=OpenClaw.Tray.Tests.trx"
88+
89+
# Tray integration tests gate on OPENCLAW_RUN_INTEGRATION; set it so the
90+
# MCP-server / capability tests actually run. dotnet-coverage with no
91+
# filter captures coverage for both the test host AND the spawned tray
92+
# exe (coverlet could not — see tests/Directory.Build.props comment).
93+
- name: Run Tray Integration Tests
94+
env:
95+
OPENCLAW_RUN_INTEGRATION: 1
96+
run: >
97+
dotnet-coverage collect
98+
--output TestResults\TrayIntegration\coverage.cobertura.xml
99+
--output-format cobertura
100+
"dotnet test tests/OpenClaw.Tray.IntegrationTests
101+
--no-build
102+
-c Debug
103+
-r win-x64
104+
--verbosity normal
105+
--results-directory TestResults\TrayIntegration
106+
--logger trx;LogFileName=OpenClaw.Tray.IntegrationTests.trx"
107+
108+
# UI tests need a real visual tree AND a system-registered WindowsAppRuntime
109+
# framework MSIX — the test fixture calls Bootstrap.Initialize(1.8, stable),
110+
# which looks up the framework package by identity. The hosted windows-2025
111+
# runner image doesn't preinstall it, so we install it explicitly here.
112+
# Version pinned to match Microsoft.WindowsAppSDK 1.8.260101001 in the csprojs.
113+
- name: Install WindowsAppRuntime 1.8
114+
shell: pwsh
115+
run: |
116+
$url = "https://aka.ms/windowsappsdk/1.8/1.8.260101001/windowsappruntimeinstall-x64.exe"
117+
$exe = "$env:RUNNER_TEMP\WindowsAppRuntimeInstall.exe"
118+
Invoke-WebRequest -Uri $url -OutFile $exe
119+
& $exe --quiet
120+
if ($LASTEXITCODE -ne 0) { throw "WindowsAppRuntimeInstall failed with exit code $LASTEXITCODE" }
121+
122+
- name: Run Tray UI Tests
123+
run: >
124+
dotnet-coverage collect
125+
--output TestResults\TrayUI\coverage.cobertura.xml
126+
--output-format cobertura
127+
"dotnet test tests/OpenClaw.Tray.UITests
128+
--no-build
129+
-c Debug
130+
-r win-x64
131+
--verbosity normal
132+
--results-directory TestResults\TrayUI
133+
--logger trx;LogFileName=OpenClaw.Tray.UITests.trx"
74134
75135
- name: Upload Test Results
76136
if: always()

‎docs/A2UI_NATIVE_WINUI.md‎

Lines changed: 300 additions & 0 deletions
Large diffs are not rendered by default.

‎docs/MCP_MODE.md‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The implementation is structured so that **adding a new node capability automati
1818

1919
## Non-goals (for this iteration)
2020

21-
- **No authentication.** Loopback bind is the access control. The endpoint is unreachable from any other machine. We will revisit when we want remote MCP, multiple users on one box, or shared dev VMs.
21+
- **No remote authentication.** Loopback bind + Origin/Host checks keep the endpoint unreachable from any other machine. A local bearer token guards against untrusted local processes on the same box (see [Authentication](#authentication) below). We will revisit ACLs / multi-user when we want remote MCP, multiple users on one box, or shared dev VMs.
2222
- **No SSE / streaming.** Plain JSON-RPC request/response is enough for the synchronous capabilities we have today.
2323
- **No per-tool input schemas.** Capabilities don't expose schemas; MCP `inputSchema` is permissive (`{type: "object", additionalProperties: true}`). When/if `INodeCapability` grows a schema property, the MCP bridge picks it up with no other changes.
2424
- **No port configuration UI.** Default `8765` is hardcoded. Easy to lift into `SettingsManager` later.
@@ -75,6 +75,22 @@ The bridge takes a `Func<IReadOnlyList<INodeCapability>>` rather than a snapshot
7575

7676
`GET /` returns a friendly text probe. `POST /` is JSON-RPC. Anything else → `405`.
7777

78+
## Authentication
79+
80+
The HTTP transport requires a bearer token on every `POST`. Defense-in-depth on top of loopback bind + Origin/Host checks: if an attacker can run code in *any* local user context they can reach `127.0.0.1:8765`, so we don't want the listener to be open-by-construction.
81+
82+
**Where the token lives.** `%APPDATA%\OpenClawTray\mcp-token.txt`. The exact path is composed by `NodeService.McpTokenPath` from `SettingsManager.SettingsDirectoryPath`, so the test-suite override `OPENCLAW_TRAY_DATA_DIR` isolates the token file too. The file inherits the parent directory's ACL — by default only the current user (and SYSTEM/Administrators) can read it.
83+
84+
**When it's created.** Lazily, on the first `NodeService.StartMcpServer()` call — i.e. the first time the user enables Local MCP Server in Settings and saves. **Until that toggle has been on at least once, the file does not exist.** This trips up users who try to grab the token before flipping the switch.
85+
86+
**How long it is.** 32 bytes of CSPRNG output, base64url-encoded with padding stripped → **43 ASCII characters** (~256 bits of entropy). See `McpAuthToken.Generate()`.
87+
88+
**Lifetime.** The token is **persistent across tray restarts**. It's only regenerated if the file is deleted or its contents are emptied. There is no automatic rotation.
89+
90+
**On the wire.** Every `POST /` must carry `Authorization: Bearer <token>`. Missing or wrong token → `401 Unauthorized` with no body. `GET /` is unauthenticated (it's just a "yes I'm here" probe).
91+
92+
**How users find it.** Settings → Developer Mode → MCP section shows the live token (masked, with Reveal/Copy buttons) and the storage path. For agents that read from disk (Claude Code, custom scripts), pointing them at `McpTokenPath` is preferable to embedding the token in their prompt or config — the path is stable, the token is a secret. For agents that only accept literal bearer values in config (Claude Desktop, Cursor), use Copy.
93+
7894
### Settings model
7995

8096
Two independent toggles in `SettingsData`:
@@ -211,7 +227,7 @@ curl -X POST http://127.0.0.1:8765/ -H "Content-Type: application/json" -d '{"js
211227
These are reasonable next steps but explicitly out of scope for the initial implementation:
212228

213229
1. **Per-tool input schemas.** Add an `IReadOnlyDictionary<string, JsonElement> InputSchemas` (or per-command descriptor) to `INodeCapability`. The MCP bridge's `HandleToolsList` picks them up automatically. Until then, MCP clients see permissive schemas and the agent has to figure out arg shapes from descriptions and trial-and-error.
214-
2. **Authentication.** Bearer token in the `Authorization` header, copied from a Settings button. Token rotates on tray restart. Stored in `%LOCALAPPDATA%\OpenClawTray\` like the device key.
230+
2. ~~**Authentication.**~~ Implemented. See [Authentication](#authentication) below.
215231
3. **Streamable HTTP / SSE.** For long-running tools (`screen.record`, future `audio.transcribe`), MCP supports streaming progress. The bridge needs to learn about it and the HTTP server needs to optionally upgrade.
216232
4. **Resource and prompt support.** MCP has `resources/*` and `prompts/*` methods we currently no-op. Notifications, recent activity, channel state could be modeled as MCP resources.
217233
5. **Configurable port.** Move `McpDefaultPort` into `SettingsManager`. Probably also pick a free port at startup if the default is in use, and surface the actual port in the Settings UI.

‎docs/a2ui/README.md‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# A2UI v0.8 — Overview & Implementation Grading
2+
3+
This folder is the entry point for everything A2UI in this repo. It captures
4+
the v0.8 specification, the standard catalog, and a side-by-side grading of
5+
two implementations:
6+
7+
- **Lit reference** in `C:\Users\andersonch\Code\openclaw` (web components,
8+
rendered in a browser via the OpenClaw canvas host).
9+
- **Native WinUI** in this repo (`src/OpenClaw.Tray.WinUI/A2UI/`,
10+
branch `feat/a2ui-native-winui`).
11+
12+
The native WinUI design doc that predates this overview lives at
13+
[`../A2UI_NATIVE_WINUI.md`](../A2UI_NATIVE_WINUI.md); this folder
14+
supersedes the parts of that doc that describe the spec and adds the
15+
grading.
16+
17+
## Contents
18+
19+
| Doc | What's in it |
20+
| --- | --- |
21+
| [`protocol.md`](./protocol.md) | Wire protocol — envelopes, JSONL, A2A extension, capability negotiation, lifecycle |
22+
| [`components.md`](./components.md) | Standard catalog — every component, every property, type, enum, behavior |
23+
| [`data-and-actions.md`](./data-and-actions.md) | A2UIValue tagged union, data model & paths, action dispatch, security |
24+
| [`grading.md`](./grading.md) | Side-by-side scoring of Lit vs WinUI vs spec, with file:line citations |
25+
26+
## Spec source of truth
27+
28+
| Document | URL |
29+
| --- | --- |
30+
| Protocol v0.8 | https://a2ui.org/specification/v0.8-a2ui/ |
31+
| A2A extension v0.8 | https://a2ui.org/specification/v0.8-a2a-extension/ |
32+
| Standard catalog (JSON) | https://a2ui.org/specification/v0_8/standard_catalog_definition.json |
33+
| Source / schemas | https://github.com/google/A2UI |
34+
| Evolution v0.8 → v0.9 | https://a2ui.org/specification/v0.9-evolution-guide/ |
35+
36+
These pages were captured 2026-04-27. v0.8 is the **stable / public preview**
37+
release; v0.9 exists as a draft.
38+
39+
## TL;DR — how the two implementations stack up
40+
41+
| Area | Lit (OpenClaw) | WinUI (this repo) | Spec |
42+
| --- | --- | --- | --- |
43+
| Component coverage | 18/18 | 18/18 | 18 in standard catalog |
44+
| Component property completeness | ~85% (4 documented TODOs) | ~95% | — |
45+
| Streaming / JSONL parser | Per-line, lenient | Per-line, lenient + size caps | line-delimited JSON |
46+
| Data model paths | Custom JSON-pointer-ish + auto-parse | Strict RFC 6901 | Path strings, format underspecified |
47+
| Action transport | DOM `CustomEvent` bubbling | Debounced dispatcher → gateway via `agent.request` | Client-to-server A2A `userAction` |
48+
| Bi-directional binding | ✓ via `processor.setData` | ✓ via `DataModelStore.Write` | Spec is silent — both impls add it |
49+
| Markdown in `Text` | ✓ (sandboxed iframe for HTML, escaped code) | ✗ (plain text only) | Spec is silent |
50+
| Modal | `<dialog>` w/ `showModal()` | `ContentDialog` (native) | Spec leaves shape open |
51+
| List virtualization | ✗ (StackPanel-style, all-at-once) | ✓ `ItemsRepeater` + cached child template | Spec calls for it |
52+
| URL safety / SSRF | None — passes URLs through to `<img>`/`<video>` | HTTPS+allowlist for `Image`/`Video`/`AudioPlayer`; DNS-rebinding pin via `SocketsHttpHandler.ConnectCallback` on `Image` only — `Video`/`AudioPlayer` hand the URI to `MediaSource.CreateFromUri`, which re-resolves at playback | Spec is silent (deferred) |
53+
| Secret redaction | ✗ | ✓ denylist (`password`, `secret`, `token`) + registered paths | Spec is silent |
54+
| Action context scoping | Caller's responsibility | Explicit `dataBinding` + implicit walk + secret filter | Spec defines `context[]` only |
55+
| Test coverage | One model unit test; no per-component | Render matrix, scale test, security tests, integration smoke | — |
56+
57+
The detailed scorecard with deductions per category is in
58+
[`grading.md`](./grading.md).
59+
60+
## How to use this folder
61+
62+
- If you're **adding a renderer** for a component: read
63+
[`components.md`](./components.md) for the spec'd properties, then
64+
[`grading.md`](./grading.md) for known WinUI gaps.
65+
- If you're **wiring a transport** (gateway, MCP bridge, etc.): read
66+
[`protocol.md`](./protocol.md) and the `data-and-actions.md` action
67+
section.
68+
- If you're **reviewing a PR that touches A2UI**: skim
69+
[`grading.md#known-deviations-by-category`](./grading.md#known-deviations-by-category)
70+
to see which deviations are intentional (good) vs known gaps (bad).

0 commit comments

Comments
 (0)