Preview screens

From microsoft/power-platform-skills · View interactive version

Preview screens is an AI agent skill from the GitHub repository microsoft/power-platform-skills. Use when the user wants to preview generated screens in a browser without starting Metro / a simulator — for example after /create-mobile-app finishes or after /edit-app regenerates a screen.

How to use this skill

Skill file

Plugin check: Run node "${PLUGIN_ROOT}/scripts/check-version.js" - if it outputs a message, show it to the user before proceeding.

Shared instructions: shared-instructions.md — read first.

Preview Screens

Generates a self-contained HTML file that renders every screen in the app as a phone-frame mockup (an iPhone 18 Pro, 402 × 874) with tab navigation and a dark/light toggle. The agent reads TSX files, understands the Tamagui component tree, and produces equivalent HTML/CSS — no programmatic TSX parsing.

When to use

When NOT to use

Workflow

  1. Locate project → 2. Discover screens → 3. Read reference mapping → 4. Read & convert each screen → 5. Assemble preview.html → 6. Write file → 7. Open in browser

Step 1 — Locate project

Determine the working directory:

Validate the project:

Glob pattern="power.config.json" path='<working_dir>'

If missing, check for package.json. If neither exists, report the error and stop.

Read memory-bank.md if present to get the project name for the page title:

Grep pattern="^# " path="<working_dir>/memory-bank.md"

Fallback: read name from package.json.

Step 2 — Discover screens

Telemetry checkpoint: discover_app_screens

Find all TSX files under the app directory:

Glob pattern="app/**/*.tsx" path='<working_dir>'

Exclude these patterns — they are not screens:

Recognize it only when its source still contains both Power Apps Standalone and

Build your first screen by connecting data sources.

Keep it when it is the only visible screen so the preview is never empty.

Derive screen names from file paths:

If native-app-plan.md exists in the working directory, read its ## Screens section for human-friendly labels.

Build an ordered list: [ { path, screenName, screenId } ].

Default tab ordering — Home first, then two details, then the rest. Step 5 marks the first entry as active, so the order below directly controls which screen the user lands on when preview.html opens.

Sort the list with this priority:

  1. Home / dashboard first. Prefer the screen that native-app-plan.md identifies as the

home or landing screen.

Otherwise, use the first remaining screen matching any of these paths (in this priority):

app/(app)/home.tsx, app/(app)/index.tsx, app/(app)/dashboard.tsx, app/index.tsx

(only if it is a real home screen, not an auth redirect or the untouched starter route filtered

out in Step 2).

  1. Then up to two detail screens. A "detail" screen is any TSX whose route segment uses a dynamic param — file path contains [ and ] (e.g. app/(app)/recipes/[id].tsx, app/(app)/orders/[orderId]/edit.tsx). Take the first two in the order they were discovered (alphabetical by path is fine).
  2. Then everything else in discovery order.

If there are fewer than two detail screens, just include whatever exists and continue with the rest — do not pad with non-detail screens to force a count of 3.

Do not drop any screens — this rule only reorders. Every discovered screen still gets a tab.

Step 3 — Read reference mapping

Load the Tamagui-to-HTML mapping reference:

Read file_path="${PLUGIN_ROOT}/shared/references/tamagui-html-mapping.md"

Internalize:

Also check if the project has custom brand tokens:

Glob pattern="tamagui.config.ts" path='<working_dir>'

If found, read it and extract any custom color tokens (look for tokens: { color: { ... } }). Add them as additional CSS custom properties in the generated HTML.

Step 4 — Read and convert each screen

Telemetry checkpoint: render_screen_preview_frames

Print before starting:

"→ Reading + converting <N> screens to HTML/CSS (one print per screen as I go)."

For each screen in the ordered list from Step 2:

  1. Read the full TSX file.
  1. Identify the component tree. Walk the JSX return statement and note every Tamagui component, its props, and its children.
  1. Generate equivalent HTML/CSS using the mapping from Step 3:
  1. Handle dynamic content:

Native PDF/pen controls need honest static approximations:

  1. Produce a <div class="screen" id="screen-{screenId}"> wrapping the converted HTML.

Use inline styles on elements. Keep each screen's HTML self-contained (no shared CSS classes between screens, except the theme variables).

Step 5 — Assemble preview.html

Use the phone frame template from the mapping reference (Section 4) as the outer shell.

Replace the placeholders:

If the project has custom brand tokens (from Step 3), add them to the :root CSS block.

Step 6 — Write the file

Telemetry checkpoint: write_screen_preview_document

Write file_path="<working_dir>/preview.html"

Print confirmation:

✅ Preview generated: <working_dir>/preview.html
   Screens: <N> (<comma-separated list of screen names>)
   Toggle: dark/light mode button in top-right

Step 7 — Open in browser

Telemetry checkpoint: open_screen_preview

Do NOT prompt. The visual_companion flag in <working_dir>/memory-bank.md already encodes the answer; asking again is redundant. /create-mobile-app writes the flag when it creates the memory bank (Step 3.4 in screens first, Step 6.7 in data model first); without it, the default is yes.

Read the flag and act:

grep -E "^visual_companion:[[:space:]]*(yes|no)" '<working_dir>/memory-bank.md' 2>/dev/null

| Flag | Action |

|---|---|

| MOBILE_APP_EMBED_PREVIEW=1 | Print the link and stop. The owning edit plan embeds the screens. |

| visual_companion: no | Print the link and stop. Do not auto-open. |

| visual_companion: yes (or missing memory-bank, or standalone invocation) | Print the link, then auto-open. |

visual_companion: no — print:

"Preview is at: file://<working_dir>/preview.html (Visual Companion off — open manually.)"

Otherwise — print the link AND auto-open in one breath, no prompt:

"Preview is at: file://<working_dir>/preview.html — opening now."

Then try OS-appropriate openers in sequence and fall back to printing the link if none work:

open '<working_dir>/preview.html' 2>/dev/null \
  || xdg-open '<working_dir>/preview.html' 2>/dev/null \
  || MOBILE_APP_PREVIEW_PATH='<working_dir>/preview.html' \
     powershell.exe -NoProfile -Command 'Start-Process -FilePath $env:MOBILE_APP_PREVIEW_PATH' 2>/dev/null \
  || printf '%s\n' 'Could not auto-open. Open this URL in your browser: file://<working_dir>/preview.html'

open is macOS-only; the chain also tries Linux (xdg-open) and Windows

(powershell.exe Start-Process). The Windows path is passed as data, not

PowerShell source. On headless or unsupported cross-host sessions, report the

failed launch and manual link instead of claiming the browser opened.


Notes

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.