Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
27e89d9
feat(024): phase 1 — rename preview → devtools surface
codemonkeychris Apr 18, 2026
8828ab5
feat(024): phase 1.4 — VS Code extension devtools args + legacy fallback
codemonkeychris Apr 18, 2026
f6dc42c
feat(024): phase 2.2/2.4 — NodeIdBuilder, NodeRegistry, SelectorParser
codemonkeychris Apr 18, 2026
bf08c9d
feat(024): phase 2.1 — DevtoolsMcpServer skeleton + core tools
codemonkeychris Apr 18, 2026
2868dcd
feat(024): phase 2.15 — mur devtools supervisor
codemonkeychris Apr 18, 2026
624694c
docs(024): update task doc to reflect phase 2 foundation progress
codemonkeychris Apr 18, 2026
39d87b4
feat(024): phase 2.3 — WindowRegistry + windows tool
codemonkeychris Apr 18, 2026
9130660
feat(024): phase 2.8/2.10-2.13 — tree walker, click, type, focus, wai…
codemonkeychris Apr 18, 2026
e72d7ac
feat(024): phase 2.9 — screenshot tool + --devtools screenshot CLI
codemonkeychris Apr 18, 2026
d992189
refactor(024): extract McpDispatcher + add integration tests
codemonkeychris Apr 18, 2026
3937359
feat(024): phase 3.4-3.9 — invoke/toggle/select/scroll/fire + deferrals
codemonkeychris Apr 18, 2026
0f7a763
feat(024): phase 3.1 — tree view=full adds layout/context/visual fields
codemonkeychris Apr 18, 2026
bc132a3
feat(024): phase 3.3 — reactor.state tool with shape-not-values payload
codemonkeychris Apr 18, 2026
99e08b9
test(024): close phase 2.16/3.10 unit gaps — cross-window mismatch + …
codemonkeychris Apr 18, 2026
539b22e
feat(024): phase 4.2 — mur devtools --print-config emits MCP fragments
codemonkeychris Apr 18, 2026
fc2f93f
feat(024): phase 4.3 — rolling devtools log with per-call observability
codemonkeychris Apr 18, 2026
477bd17
docs(024): phase 4.5 — devtools security review + MCP surface README
codemonkeychris Apr 18, 2026
7cf59c7
feat(024): phase 4.1 — stdio MCP transport alongside HTTP
codemonkeychris Apr 18, 2026
0928fd0
test(024): phase 2.17/3.11 self-host MCP fixtures + dispatcher error fix
codemonkeychris Apr 18, 2026
bf7315d
fix(024): devtools field-feedback pass (B1, B3–B7, U6, U7)
codemonkeychris Apr 18, 2026
274ec54
feat(024): phase 2.7 — switchComponent invalidates stale tree ids
codemonkeychris Apr 18, 2026
e8d7015
feat(024): phase 2.14/2.16/3.11/4.1 follow-ups + coverage matrix
codemonkeychris Apr 18, 2026
a5d7134
docs(024): phase 3.8/4.7 follow-ups
codemonkeychris Apr 18, 2026
89fbc33
test(024): phase 3.13 — pin state coverage for every hook type
codemonkeychris Apr 18, 2026
6020eb2
fix(024): marshal switchComponent through UI dispatcher
codemonkeychris Apr 18, 2026
ca9c49f
fix(024): selfhost green — select-container walk, scroll no-axis, nam…
codemonkeychris Apr 18, 2026
359ebf6
fix(024): devtools feedback round 2 — windows, scroll, expand, a11y n…
codemonkeychris Apr 18, 2026
746f87c
docs(024): add devtools sub-skill teaching MCP-driven UI automation
codemonkeychris Apr 18, 2026
31af527
fix(024): address PR #32 Copilot review comments
codemonkeychris Apr 18, 2026
f6f9ca6
fix(host): match protected internal visibility on ShouldUpdate overrides
codemonkeychris Apr 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,8 @@ selfhost/
# Rust build artifacts
src/Reactor/Native/differ/target/
samples/apps/reactorfiles/Native/reactorfs/target/

# Claude Code local harness state — per-session lock and per-user settings
# that must never land in the shared repo
.claude/scheduled_tasks.lock
.claude/settings.local.json
1 change: 1 addition & 0 deletions SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ re-renders automatically. No XAML. No data binding. No ViewModels.
| [`skills/async.md`](skills/async.md) | Fetching data, caching, pagination, optimistic writes. `UseResource`, `UseMutation`, `UseInfiniteResource`, `Pending`. |
| [`skills/design.md`](skills/design.md) | Any visual-styling work. Windows 11 design rules — theme tokens, High Contrast, typography, 4px grid, acrylic surfaces, accessibility. |
| [`skills/commanding.md`](skills/commanding.md) | Actions that appear in multiple surfaces (menu + toolbar), need keyboard shortcuts, or need `CanExecute`. `Command`, `StandardCommand`, `UseCommand`, `CommandHost`. |
| [`skills/devtools.md`](skills/devtools.md) | Drive a running app from code — screenshot, inspect visual tree, click/type/scroll, read hook state. Load when diagnosing visible bugs (layout, contrast) or verifying a change landed. |
| [`skills/dsl-reference.md`](skills/dsl-reference.md) | Look up signatures — every factory, modifier, and enum in the DSL. |

## Project Setup
Expand Down
48 changes: 48 additions & 0 deletions docs/specs/notes/024-snapshot-diff-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Snapshot / diff primitives — deferred (spec 024)

**Status:** deferred — no code in v1.
**Reference:** [spec 024 §10](../024-ai-agent-devtools.md), [tasks §3.9](../tasks/ai-agent-devtools-implementation.md#3.9).

## Why deferred

The spec proposes server-side `reactor.snapshot` and `reactor.diff` primitives that
would let an agent capture a tree + state bundle and ask the runtime to diff two
snapshots (structural, text, bounds, hook values). The goal is to avoid
transporting two full trees across the MCP boundary when the agent only cares
about the delta.

We deferred shipping these in v1 because:

1. **No usage signal yet.** The Phase 2 tool set gives agents `tree`, `state`,
and `screenshot` as raw materials. Until agents are actually using those on
real tasks, we don't know which diff shapes are worth supporting — naïve
text-diff? bounds-moved? hook-value-changed? All three?
2. **Agent-side diffing is usually good enough.** For a 200-node tree the
response is small. Two tree calls + a client-side comparison is within the
budget for a human-in-the-loop session.
3. **Persisting snapshots server-side has a storage question.** If a snapshot
is large (PNG + full-view tree + state), keeping more than a handful per
session adds memory pressure or forces disk spill, and we'd need to decide
whose session owns it.

## Signal we're watching for

Ship a first pass once **any** of the following is clear from v1 usage:

- Agents are repeatedly fetching two full trees and diffing locally for the
same narrow question (e.g. "did this Text node's content change?") —
suggests a targeted `diff` endpoint would cut round-trip cost.
- The same snapshot is being referenced multiple times in a session (e.g.
"compare the screenshot from 30 seconds ago against now") — suggests
server-side retention is worth the complexity.
- A concrete third-party agent framework builds its own snapshot wrapper on
top of our raw tools — we should adopt their shape rather than invent one.

If none of those signals surface after a release cycle, keep it deferred.

## Non-goals during the wait

- Don't add a `reactor.snapshot` stub that returns "not implemented." Agents
discover tools via `tools/list`; better to omit than to tease.
- Don't ship a client-side snapshot helper either — clients should remain free
to build their own over the raw `tree`/`state`/`screenshot` calls.
527 changes: 527 additions & 0 deletions docs/specs/tasks/ai-agent-devtools-implementation.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion samples/Reactor.TestApp/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

ReactorApp.Run<DemoApp>("Reactor Demo", width: 1200, height: 800
#if DEBUG
, preview: true
, devtools: true
#endif
);

Expand Down
2 changes: 1 addition & 1 deletion samples/apps/headtrax/HeadTrax/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
bool legacyPaging = Array.IndexOf(cliArgs, "--legacy-paging") >= 0;
ReactorFeatureFlags.UseHookBasedPaging = !legacyPaging;

ReactorApp.Run<App>("HeadTrax – Employee Database", width: 1400, height: 900, preview: true);
ReactorApp.Run<App>("HeadTrax – Employee Database", width: 1400, height: 900, devtools: true);
2 changes: 1 addition & 1 deletion samples/apps/validation-showcase/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

ReactorApp.Run<ShowcaseApp>("Validation Showcase", width: 720, height: 900
#if DEBUG
, preview: true
, devtools: true
#endif
);

Expand Down
154 changes: 154 additions & 0 deletions skills/devtools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
---
name: reactor-devtools
description: >
Drive a running Reactor app from code via the devtools MCP server —
inspect the visual tree, capture screenshots, click/type/scroll, read
component state, and fire named handlers. Load this when diagnosing a
visible bug (layout, contrast, wrong text), verifying a change landed,
or doing any UI automation against a live build.
---

# Reactor Devtools — MCP-driven UI automation

The Reactor devtools are a **JSON-RPC over HTTP loopback** surface that a
debug-build app exposes when launched with `--devtools run`. You use it to
look at the app the way a user does (screenshots, rendered text, layout
bounds) and drive it the way a user does (click, type, toggle, scroll).

Loopback-only, no auth — **DEBUG builds only**, never ship it.

## Launching the app with devtools

The app author enables devtools in their `Program.cs`:

```csharp
ReactorApp.Run<MyApp>("Title", width: 1200, height: 800
#if DEBUG
, devtools: true
#endif
);
```

Then launch with the `--devtools run` CLI flag:

```bash
dotnet run --project path/to/App.csproj -- --devtools run \
> /tmp/app-stdout.log 2>&1 &
```

Parse the stdout for the machine-readable ready line (one JSON object on
its own line after first render):

```
{"event":"devtools-ready","endpoint":"http://127.0.0.1:54610/mcp",...}
```

Everything after that is keyed off that `endpoint`. **Always wait for
`devtools-ready` before calling tools** — the port is chosen at random
per-run.

## Discovering the tool surface

`GET /mcp` returns a self-describing document: protocol version, selector
grammar, tree schema version, and the full tool list with input schemas.
Read this once per session instead of guessing:

```bash
curl -s http://127.0.0.1:PORT/mcp | jq '.tools[].name'
```

Every other call is JSON-RPC `tools/call`:

```bash
curl -s http://127.0.0.1:PORT/mcp -H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call",
"params":{"name":"click","arguments":{"selector":"[name=\"Save\"]"}}}'
```

## Tool catalog

| Tool | What it does |
|---|---|
| `version` | Build tag + pid + port — confirm the app is the one you expect. |
| `components` | Class names of every `Component` subclass; `current` is what's mounted. `isNested:true` marks helper components. |
| `switchComponent` | Swap the root component by class name. Invalidates all node ids. |
| `reload` | Exits with sentinel code 42 so `mur devtools` rebuilds. Old ids dead. |
| `windows` | Active window ids, titles, bounds, currently-mounted component. Use `window:"<id>"` when >1. |
| `tree` | Flat array of visual-tree nodes. `view:"full"` adds layout/automation/visual fields. Optional `selector` scopes the walk. |
| `screenshot` | Base64 PNG of the window. `selector` crops to that element's bounds; `includeChrome:true` includes the titlebar. |
| `click` | Prefers Invoke → Toggle → SelectionItem. Returns `via` so you know which pattern fired. |
| `invoke` / `toggle` / `select` | Direct UIA pattern access when you want one specifically. `select` auto-expands ComboBoxes. |
| `type` | Sets TextBox / IValueProvider text. `clear:true` replaces, else appends. |
| `focus` | Programmatic focus on a Control. |
| `scroll` | `by:{vertical:N,horizontal:N}` as **percentage deltas** 0–100 (not pixels), or `to:"<itemSelector>"` for `ScrollIntoView`. Returns both percent and pixel offsets. |
| `expand` / `collapse` | ExpandCollapse pattern (ComboBox popup, TreeViewItem, Expander). |
| `waitFor` | Polls a predicate (`selector`, `textEquals`, `textMatches`, `visible`, `count`) until satisfied or `timeoutMs`. |
| `state` | Dumps every hook value (useState/useReducer/etc.) across mounted components. Great for "why is the UI showing X?". |
| `fire` | Calls a NAMED METHOD on a live component by reflection. Escape hatch for handlers that aren't reachable via UIA. **Inline lambdas (`() => setCount(...)`) are NOT reachable** — only declared methods on the Component class. |

## Selector grammar (5 forms)

1. **Node id** — `r:main/CounterDemo.SubmitButton` — copy from `tree`. Stable within a window's lifetime; invalidated by `switchComponent` / `reload`.
2. **AutomationId** — `#btn-inc`. Matches `AutomationProperties.AutomationId` exactly.
3. **AutomationName** — `[name='Increment']` or `[name="+ 1"]`. Matches `AutomationProperties.Name` OR the visible caption of Buttons / TextBlocks / TextBoxes / ContentControls.
4. **TypePath** — `Button`, `Button[2]`, `StackPanel > Button`. Type name is `GetType().Name`. Index disambiguates.
5. **Reactor source** — `{component:'CounterDemo',line:42}`. Reserved (Phase 3).

`[name=…]` cannot be indexed — if it matches multiple, error is `ambiguous-selector` with all candidate ids listed; pick one by node id or prefix with a TypePath step.

## Typical workflows

### "Does the app look right?" — visual diagnosis

```
screenshot {} → PNG of full client area
screenshot {selector:"[name='Submit']"} → cropped to one control
tree {selector:"#login-form", view:"full"} → layout numbers for that region
```

Full-view `tree` nodes carry `bounds`, `actualSize`, `desiredSize`,
`layout.margin`, `layout.padding`, `isVisible`, `isEnabled`,
`automationControlType`. That's usually enough to spot a margin collapse
or a zero-size child without running the app in a debugger.

### Diagnosing a layout issue

1. `screenshot {}` — confirm what's actually on screen vs. what you expect.
2. `tree {selector:"<suspect container>", view:"full"}` — read `bounds` and `actualSize` down the subtree. A child with `actualSize:{width:0,height:0}` under a parent that's sized means the child isn't getting space (missing `Flex(grow:1)` on a ScrollView inside a FlexColumn is a classic).
3. Edit the Reactor code, rebuild, then `reload` (or relaunch) and re-screenshot.
4. `waitFor {predicate:{selector:"…",visible:true}}` if the state is async — don't screenshot-before-mount.

### Diagnosing a contrast / color issue

1. `screenshot {selector:"<element>"}` — pull the cropped PNG.
2. Decode the PNG client-side and sample foreground/background pixels. Compute WCAG 2.1 ratio = (L1 + 0.05) / (L2 + 0.05) where L is relative luminance. Target ≥ 4.5:1 for body text, ≥ 3:1 for large text / UI chrome.
3. If low, check whether the color came from a Theme token (correct — rebind to the right token for the surface) or a hardcoded hex (wrong — replace with a `Theme.*` token; see `skills/design.md`). Hardcoded colors are the usual culprit and also break High Contrast.
4. Edit, rebuild, screenshot, re-measure.

### Verifying a state-driven change

```
click {selector:"[name='+ 1']"}
waitFor {predicate:{selector:"[name='Current count: 1']"},timeoutMs:1000}
state {} → confirm the underlying UseState value
```

`state` is particularly useful when the UI text doesn't obviously encode
the value (e.g. a slider position or a theme toggle).

## Gotchas

1. **Both the source AND the CLI flag are required.** The MCP server only starts if the app was compiled with `devtools: true` passed to `ReactorApp.Run(...)` (usually wrapped in `#if DEBUG`) **and** launched with `--devtools run` on the command line. Miss either and the app boots normally with no MCP port, no banner, no log file. If `curl http://127.0.0.1:PORT/mcp` hangs or you never see `devtools-ready` on stdout, this is almost always why — check `Program.cs` first, then the launch args.
2. **`switchComponent` and `reload` invalidate every node id.** Re-walk the tree after them; do not cache `r:…` ids across swaps.
3. **Popups aren't in the main visual tree.** `tree` walks `window.Content` — ComboBox dropdown items, flyouts, and context menus live in separate popup roots and won't show up. `select` auto-expands the container but item resolution through the main tree will still miss them. Prefer `ISelectionItemProvider` via a node-id that `tree` emitted while the popup was open, or switch to a selector that targets the SelectorItem ancestor directly.
4. **`fire` only sees declared methods.** Inline lambdas (`Button("+1", () => setCount(...))`) are unreachable. Hoist the handler to a method on the Component class when you need `fire` access.
5. **Scroll percent read-back can lag one call.** Right after `scroll {by:{vertical:50}}`, the next tool may report `scrollPercent:0` before the engine settles. If the offset matters, call `scroll {by:{vertical:0}}` once more to read the settled value, or use `to:"<itemSelector>"` (ScrollIntoView) which is deterministic.
6. **Use `waitFor` before asserting on async UI.** Many demos render on a dispatcher hop; a `screenshot` immediately after `click` may capture the pre-state.
7. **Devtools log is authoritative.** Every call lands in `%LOCALAPPDATA%\Reactor\devtools\{pid}.log` (tab-separated: ts, tool, selector, latency, ok/err, rpc code). Tail it to reconstruct a failed run.

## Spec + source pointers

- Spec: `docs/specs/024-ai-agent-devtools.md`
- Server: `src/Reactor/Hosting/Devtools/DevtoolsMcpServer.cs`
- Tool registration: `DevtoolsTools.cs`, `DevtoolsUiaTools.cs`, `DevtoolsFireTool.cs`, `DevtoolsStateTool.cs`
- Selector grammar / parser: `SelectorParser.cs`
Loading
Loading