Skip to content

Commit d969aad

Browse files
author
Shubham Agarwal
committed
fix(mobile-app): make Metro debugging cross-host
1 parent c8455ac commit d969aad

12 files changed

Lines changed: 2379 additions & 119 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Functional tests for cross-host mobile-app scripts. The OS matrix catches
2+
# process, path, signal, and filesystem differences in wrapper behavior.
3+
name: mobile-apps-script-tests
4+
5+
on:
6+
pull_request:
7+
branches:
8+
- main
9+
paths:
10+
- "plugins/mobile-apps/scripts/**"
11+
- "plugins/mobile-apps/skills/create-mobile-app/SKILL.md"
12+
- "plugins/mobile-apps/skills/debug-app/SKILL.md"
13+
- ".github/workflows/mobile-apps-script-tests.yml"
14+
15+
jobs:
16+
test-mobile-app-scripts:
17+
name: test-mobile-app-scripts (${{ matrix.os }})
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os:
23+
- ubuntu-latest
24+
- windows-latest
25+
- macos-latest
26+
steps:
27+
- name: checkout
28+
uses: actions/checkout@v4
29+
30+
- name: setup-node
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: 22
34+
35+
- name: syntax-check-mobile-scripts
36+
shell: bash
37+
run: node --check plugins/mobile-apps/scripts/metro-session.js
38+
39+
- name: run-mobile-script-tests
40+
shell: bash
41+
run: node --test plugins/mobile-apps/scripts/tests/*.test.js

plugins/mobile-apps/AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ README.md ← Plugin overview
2626
agents/ ← native-app-planner, data-model-architect, screen-planner, screen-builder
2727
shared/ ← shared-instructions, references, samples, memory-bank template
2828
skills/ ← /create-mobile-app, /add-dataverse, /add-connector, /add-native, ...
29-
scripts/ ← shared helpers, including validate-mobile-files.js for skill-owned changed-file validation
29+
scripts/ ← shared helpers: validate-mobile-files.js for skill-owned changed-file validation, metro-session.js for cross-host Metro session ownership/logging
3030
hooks/ ← Validator implementations invoked explicitly by mobile workflows
3131
```
3232

@@ -73,6 +73,7 @@ Do not add preparation rewrites for `scheme`, `package`, `bundleIdentifier`, `sr
7373
- `DONE_WITH_CONCERNS` requires at least one concern. If none, use `DONE`.
7474
- Special early-return signals (`INDUSTRY_CONFIRM_REQUESTED:`, `DESIGN_VIBE_REQUESTED:`) pre-date this protocol and remain in effect — they are special-cased "ask the user one question and re-spawn me" handoffs, not terminal returns.
7575
- The canonical orchestrator handler lives in [`skills/create-mobile-app/SKILL.md`](./skills/create-mobile-app/SKILL.md) Step 3.0. Future skills that spawn agents should reference it rather than duplicating the switch.
76+
11. **Metro lifecycle is project-local**`/create-mobile-app` starts Metro through `scripts/metro-session.js`; `/debug-app` reads `.expo/metro-session/state.json` and the sanitized `metro.log` with a persisted byte cursor. Do not restore required `BashOutput`/terminal-ID behavior. Host terminal APIs may be optional conveniences only. Never write unsanitized Metro output to disk, and never signal a recorded PID unless the wrapper heartbeat proves ownership.
7677

7778
## Decisions made
7879

@@ -83,6 +84,7 @@ Do not add preparation rewrites for `scheme`, `package`, `bundleIdentifier`, `sr
8384
- ✅ Connection model: per-environment connections, with platform-specific auth (`expo-msal-intune` on native, `expo-auth-session` on web)
8485
- ✅ Auth: `/create-mobile-app` resolves the tenant from the selected Power Platform environment (`scripts/resolve-environment.js`), writes that tenant to `auth.config.json`, then lets the user paste an app registration client ID, create one from the Power Apps Wrap page and paste it, or skip auth for later. `/set-app-registration-native` is a manual helper for the same Wrap-page + pasted-client-ID flow.
8586
-`/add-native` v0 scope: camera, location, push, biometrics, secure-store (already in template)
87+
- ✅ Cross-host Metro session management: detached project-local process, heartbeat-based stale-PID protection, sanitized persisted logs, durable debug cursor, and explicit start/status/tail/stop/clean commands
8688
- ✅ Template is supplied as a fresh `pa-wrap-tools/templates/expo-app-standalone` folder before `/create-mobile-app` runs; users materialize it with `degit`, run `npm install`, then invoke the skill from that folder. The skill validates/prepares the folder and runs `npx power-apps init`.
8789
-`brand/` directory convention: `/design-system` (Step 6.75) writes `brand/design-system.md` (spec), `brand/tokens.ts` (importable Tamagui tokens), and `brand/design-system.html` (visual gallery). Screen-builders MUST read `brand/design-system.md` if present; `## Negatives` = HARD RULES. `/create-mobile-app` Step 9b imports `brand/tokens.ts` via `skills/design-system/references/tamagui-integration.md`. Projects without `brand/` fall back to `## Design Direction` only — no breakage.
8890
- ✅ Offline profile creation is **author-only in v0.1**`/setup-offline-profile` and `/enable-tables-offline` POST `mobileofflineprofile` / `mobileofflineprofileitem` / `mobileofflineprofileitemassociation` to Dataverse and write `offline-profile.json` to the project, but do NOT scaffold offline runtime code (SQLite store, sync engine, write queue) into the generated app. Runtime support is gated on upstream `@microsoft/power-apps-native-host` confirmation.

plugins/mobile-apps/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,24 @@ connector wiring.
8080

8181
5. Start mobile app:
8282

83-
Run the below command in a new terminal from the app directory.
83+
`/create-mobile-app` starts Metro automatically through the plugin's
84+
project-local session manager. It stores sanitized logs and process state in
85+
`.expo/metro-session/`, so `/debug-app` works after switching between VS Code,
86+
Copilot CLI, and Claude Code without asking for a terminal ID.
87+
88+
To start Metro manually instead, run the command below from the app directory.
89+
Manual sessions support normal Expo development, but `/debug-app` continuous
90+
monitoring requires a wrapper-owned session. If one is not running,
91+
`/debug-app` offers to start it.
8492
8593
```bash
8694
npm run dev
8795
```
8896
97+
The wrapper removes common credentials, tokens, keys, and signed-query
98+
values before writing `metro.log`. The complete `.expo/` folder is ignored
99+
by the template's `.gitignore`.
100+
89101
6. Preview the app by scanning the QR code with the Power Apps Developer app
90102

91103
- App store: https://apps.apple.com/us/app/power-apps-developer/id6753083462
@@ -106,7 +118,7 @@ After the prereq sanity check passes:
106118
> /create-mobile-app build me a small notes app
107119
```
108120

109-
Expected: ~6 prompts (wizard + gates), then ~5 minutes of scaffolding, table creation, and parallel screen builds. End state: a working Notes app with `npm run dev` ready to go. If anything fails, the [memory bank](#glossary) remembers where you left off — re-run the same command and it resumes.
121+
Expected: ~6 prompts (wizard + gates), then ~5 minutes of scaffolding, table creation, and parallel screen builds. End state: a working Notes app with a project-local Metro session ready to scan and debug. If anything fails, the [memory bank](#glossary) remembers where you left off — re-run the same command and it resumes.
110122

111123
## Quick examples
112124

@@ -125,7 +137,7 @@ What happens:
125137
4. **4 approval gates** — data model → native capabilities → connectors → screens (with a visual `_plan_preview.html` of every screen before any code is written)
126138
5. **Design system** — brand inputs (logo, brand doc, website, or free-text) → cost picker → style picker → component reference sheet → branded screen previews
127139
6. **Scaffold + build** — validates the prepared template folder, runs `npx power-apps init`, verifies installed dependencies, generates schemas, builds Dataverse tables, wires connectors, spawns N parallel screen-builders for the TSX
128-
7. **Dev server**`npm run dev` starts Metro; scan the QR with your native dev client on a device
140+
7. **Dev server**the plugin starts a portable Metro session; scan the QR with your native dev client and use `/debug-app` against its persisted sanitized log
129141

130142
End state: a working app you can iterate on with hot reload. ~5–12 minutes for the planning gates, then scaffolding runs.
131143

@@ -213,6 +225,7 @@ Example edit flows:
213225
| `/add-native` | ✅ v0 | Add a supported native capability/control (camera, image-picker, barcode/QR scanner, document-picker, PDF viewer/report, pen/signature, secure-store, file-system, sharing, etc.) — verifies the module already ships in the template and writes typed wrappers under `src/native/` without installing native packages or editing `app.config.js` |
214226
| `/list-connections` | ✅ v0 | Finds or creates a Power Platform connection ID, or resolves a solution connection reference, for `npx power-apps add-data-source`. Use when adding non-Dataverse connectors or re-binding after a 401. |
215227
| `/edit-app` | ✅ v0 | Post-generation app editor — updates affected sections of `native-app-plan.md`, applies Dataverse/native/design/connector changes, rebuilds affected screens, runs verification, updates `memory-bank.md`, and regenerates `preview.html` when UI changed. `--plan-only` preserves the old docs-only behavior. |
228+
| `/debug-app` | ✅ v0 | Monitors the wrapper-owned `.expo/metro-session/metro.log` with a durable byte cursor, diagnoses runtime and silent data-path failures, applies bounded fixes, and verifies against newly appended output without depending on host terminal IDs. |
216229
| `/deploy` | ✅ v0 | Build + push — `npm run build` then `npx power-apps push` to the env in `power.config.json`. **Does not** drive `expo run:ios` or `expo run:android` (out of scope for v0). |
217230
| `/open-wrap-url` | ✅ v0 | Opens the Wrap URL in browser for an app ID using `https://make.powerapps.com/environments/<envID>/wrap?appID=<appID>`. Requires both `--app-id` and `--env-id`. |
218231
| `/report-issue` | ✅ v0 | Read-only diagnostic — collects env / Expo / Node versions, project context, recent errors, and renders a copy-paste-ready GitHub issue body. Sanitizes secrets. |

0 commit comments

Comments
 (0)