Skip to content

Commit 94fd7bf

Browse files
author
Shubham Agarwal
committed
refactor(mobile-app): move Metro logging into .powernative
Replace the process-owning Metro wrapper design with template-owned logging. The template metro.config.js now writes sanitized Metro output to .powernative/metro-logs during normal npm run dev, so manual starts and agent starts use the same log source and there is no second-Metro-on- 8082 failure mode. The logger captures both stdout/stderr and HTTP bundle failures. A probe against a generated app confirmed the important distinction: stdout tee alone captures startup logs, but bundle failures are returned as HTTP responses and do not hit stdout. The middleware wrapper logs non-2xx responses so /debug-app can see UnableToResolveError and similar bundle failures. metro-session.js is reduced from a process manager to a small status/tail helper. It no longer starts, stops, detaches, or owns Metro; it only locates the latest .powernative log, verifies the logged PID still owns the logged port, and tails by byte cursor for /debug-app. Docs and skills now describe npm run dev as the normal path, .powernative as the authoritative debug source, and terminal IDs as optional-only UI context. The old wrapper-owned .expo/metro-session state/log story is removed. Validation: node --check for the helper and template Metro config, 29 mobile script tests pass, and all repository validators pass.
1 parent b94abf9 commit 94fd7bf

13 files changed

Lines changed: 423 additions & 1544 deletions

File tree

plugins/mobile-apps/AGENTS.md

Lines changed: 2 additions & 2 deletions
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: validate-mobile-files.js for skill-owned changed-file validation, metro-session.js for cross-host Metro session ownership/logging
29+
scripts/ ← shared helpers: validate-mobile-files.js for skill-owned changed-file validation, metro-session.js for `.powernative` log status/tail
3030
hooks/ ← Validator implementations invoked explicitly by mobile workflows
3131
```
3232

@@ -73,7 +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` installs `scripts/metro-session.js` into the generated app and wires `npm run dev` through it; `/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 port probe proves the process is still ours.
76+
11. **Metro lifecycle is project-local**template `metro.config.js` writes sanitized `.powernative/metro-logs/` files during normal `npm run dev`; `/debug-app` uses `scripts/metro-session.js` only to locate/tail the latest live 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 diagnose a log unless the port probe proves the logged PID still owns the port.
7777

7878
## Decisions made
7979

plugins/mobile-apps/README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,20 @@ connector wiring.
8080

8181
5. Start mobile app:
8282

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.
83+
`/create-mobile-app` starts Metro with the app's normal `npm run dev` command.
84+
The template's Metro config stores sanitized logs in `.powernative/metro-logs/`,
85+
so `/debug-app` works after switching between VS Code, Copilot CLI, and
86+
Claude Code without asking for a terminal ID.
8787

8888
To start Metro manually instead, run the command below from the app directory.
89-
Created apps wire this command through the same project-local wrapper, so
90-
manual starts and `/debug-app` use the same captured log.
89+
Manual starts and `/debug-app` use the same `.powernative` log source.
9190

9291
```bash
9392
npm run dev
9493
```
9594

96-
Use `npm run dev:expo` only when you explicitly want raw Expo terminal
97-
behavior and do not need `/debug-app` log capture.
98-
99-
The wrapper removes common credentials, tokens, keys, and signed-query
100-
values before writing `metro.log`. The complete `.expo/` folder is ignored
101-
by the template's `.gitignore`.
95+
The Metro config removes sensitive lines before writing logs. The complete
96+
`.powernative/` folder is ignored by the template's `.gitignore`.
10297
10398
6. Preview the app by scanning the QR code with the Power Apps Developer app
10499
@@ -227,7 +222,7 @@ Example edit flows:
227222
| `/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` |
228223
| `/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. |
229224
| `/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. |
230-
| `/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. |
225+
| `/debug-app` | ✅ v0 | Monitors the latest live `.powernative/metro-logs/` file 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. |
231226
| `/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). |
232227
| `/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`. |
233228
| `/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)