# Select a live element, compare layouts, keep the result

A small browser helper now supports a joint design choice on a working local UI: visible selection → two real layout variants → Accept → agent source edit → remove preview → reload.

[Use the resulting app](./app/) · [View the comparison](./index.html) · [繁體中文](./README.zh-TW.md)

## Study instruction

“I use this handoff queue every day. Let me point at the workspace and compare a list-led layout with one that gives the current handoff more writing space. Keep my records and unfinished note.”

The original study app has three editable handoffs, search, explicit Save and local drafts. The replay entered an 893-character note, saved and reloaded it, then extended it to a 1,057-character draft through the visible textarea. It searched for a different handoff and returned before opening the picker.

## Actual comparison

| State | Layout and behavior |
| --- | --- |
| Original | Three queue cards above the editor; 224px minimum note height. |
| List + editor | Queue on the left, editor on the right; one-column records and 350px note height. |
| Focus first | Editor on the left, compact queue on the right; more actual writing width, with the current draft intact. |
| Accepted source | Focus first written into `app/style.css`; no overlay, marker or preview stylesheet after reload. |
| Phone | One-column accepted layout with editor before queue. Previewing List + editor moves queue first; Cancel restores editor first. |

The replay operator selected the visible padding of `#workspace`, viewed both alternatives, returned to Original, previewed Focus first and pressed Accept. The helper returned a concrete DOM selection and accepted CSS. The agent inspected the app's HTML/CSS and issued a fixed-path edit to `app/style.css` through the existing worker.

Source mapping was performed by the agent. No general AST mapper, file-writing web server, persistent daemon or replacement framework was added.

## Package API

```js
import { selectDesign } from "/path/to/productive-ui/scripts/select-design.mjs";
await page.evaluate(selectDesign, { variants: [
  { id: "split", label: "Side by side",
    css: "$target { display:grid; grid-template-columns:1fr 1.6fr; gap:28px; }" },
  { id: "stack", label: "One column",
    css: "$target { display:grid; grid-template-columns:1fr; gap:24px; }" }
] });
```

Click the visible element, or focus an element and press Enter. The temporary `window.__puiDesign` controller exposes `getState()`, `preview(id)`, `original()`, `selectParent()`, `pickAgain()`, `accept()`, `cancel()` and `dispose()`. Escape cancels.

The selection includes the unique selector, any shadow-host path, tag/id/classes, label/name, visible text, bounds and relevant computed styles. Accepted CSS still uses `$target` so the agent can map it into the existing source architecture.

Use the picker when the user wants to make a design choice together. The agent continues to choose and implement ordinary autonomous design work directly.

## Replay

Use the existing docs server on port 5840. The fixture uses the environment's installed Node Playwright.

1. Copy this study's `baseline/style.css` to `app/style.css` to start the comparison from its recorded original.
2. Run:

   ```sh
   node docs/studies/live-selection/replay.mjs
   ```

3. The browser operates the app, selects the workspace, compares both variants and accepts Focus first. It writes `accepted.json` and `accepted.css` in the evidence directory, then pauses.
4. Review the accepted decision and the known `#workspace` → `app/style.css` mapping. Send `writeback` plus a newline to the existing process's stdin.
5. The fixture-specific editor step writes the actual CSS file, disposes the temporary picker, performs a hard reload, restores normal cache behavior, and verifies subsequent ordinary reload and task use.

The installed browser helper never writes files. The replay's fixed-path Node file edit represents the agent's normal editor step after inspecting the actual source.

## Preserved work and actual failures

All three records and every form value survived the source change and reload. The 1,057-character draft survived, then was reopened, saved as the record and reloaded again. The changed interface still searched, switched records and returned to that note.

At an actual 320×480 viewport, all seven picker controls were fully visible and hit-testable; each had 44px height. The test also compared the real queue/editor positions so a selected button could not stand in for an applied layout. Keyboard Enter selected the Owner input and Escape removed the picker.

Three observations changed the replay or helper:

- A first probe compared outer editor width. The divider padding made actual textarea width the useful measurement; the corrected probe compares the writing area and keeps the independent row/column order assertions.
- An immediate soft reload reused the old static CSS. Direct HTTP and a fresh browser served the accepted file. The replay now hard-reloads after the edit, restores normal caching, then checks ordinary reload.
- Visual inspection caught a later preview losing to the accepted source's ID selector. The helper now scopes preview CSS with the selected selector plus its temporary marker. The phone test asserts the changed row order and its restoration after Cancel.

All failed logs and screenshots remain in `evidence/v08/capabilities-17/live-selection/`.

## Evidence

- `selection.json`, `accepted.json`, `accepted.css`: actual chosen element, decision and CSS.
- `before.json`, `variants.json`, `after-reload.json`: input, saved records and actual geometry.
- `01-original.png` through `07-phone-open-picker.png`: operated states.
- `phone-controls.json`: visible dimensions and reachability inside the open picker.
- `operation-log.json`: 12 timestamped steps, all passed in the final run.
- `probe-corrections.json`, `failed-1-*`, `failed-2-*`, `phone-before-specificity-correction.png`: retained failures and corrections.

Final live replay: 2026-12-05 06:58:32 UTC; Node 24.15.0 and Chromium 159.0.8154.6. A fresh private context was closed at completion.

Implementation references: [Playwright evaluation](https://playwright.dev/docs/evaluating) and [MDN composedPath](https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath). The helper and app were written for this study.

Dedicated WebCodex task: `8a5a9998107d4a47ba81199ade7ee247`. Earlier reviews and other products were unchanged.
