A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.
JavaScript claude-code-pluginclaude-code-skillscode-appsgithub-copilot-pluginpower-appspower-pagespower-platform
Add Mobile Apps workflow checkpoint telemetry (#520)
Nikhil agrawaled5dc0569604
diff --git a/plugins/mobile-apps/AGENTS.md b/plugins/mobile-apps/AGENTS.mdindex 28d2c93d6..9ec07a11c 100644--- a/plugins/mobile-apps/AGENTS.md+++ b/plugins/mobile-apps/AGENTS.md@@ -77,10 +77,10 @@ Do not add preparation rewrites for `scheme`, `package`, `bundleIdentifier`, `srMobile Apps bundles the canonical stdlib-only telemetry helpers from the repo-root `shared/telemetry/lib` at `scripts/lib/telemetry/lib`. Edit the shared source first, then refresh this physical copy in the same change; never copy another plugin's `ikey.json` or resolver.-- **Start-only lifecycle:** `UserPromptSubmit` records explicit slash-command starts and `PreToolUse(Skill)` records programmatic Skill-tool starts; both may fire for one visible slash command. `UserPromptSubmit` payloads differ by host — Claude Code passes the raw `/mobile-app:<skill>` text, Copilot CLI pre-expands it to a `<skill-context name="<skill>">` wrapper and emits no Skill pre-tool event — so both shapes must stay recognized or manual runs go uncaptured. Do not add `skill_completed`, duration, outcome, or persisted correlation state: Power Pages deliberately removed that flow because the hook boundary does not prove the workflow completed.+- **Lifecycle:** `UserPromptSubmit` records explicit slash-command starts and `PreToolUse(Skill)` records programmatic Skill-tool starts; both may fire for one visible slash command. `UserPromptSubmit` payloads differ by host — Claude Code passes the raw `/mobile-app:<skill>` text, Copilot CLI pre-expands it to a `<skill-context name="<skill>">` wrapper and emits no Skill pre-tool event — so both shapes must stay recognized or manual runs go uncaptured. Marked workflow boundaries emit explicit checkpoints through `scripts/emit-telemetry-checkpoint.js`; do not broaden hook matchers to observe commands. Do not infer `skill_completed`, duration, or outcome from hook boundaries.- **Coverage and attribution:** `scripts/lib/mobileapp-hook-utils.js` discovers every user- or model-invocable top-level skill, including `telemetry`. Direct-read helpers with `disable-model-invocation: true` are not independently invoked and are excluded. Bare and `mobile-app:`-qualified names are both attributed; explicitly foreign plugin namespaces are excluded.- **Session correlation:** Stable host session ids pass through unchanged. Copilot CLI reports a transient `call_*` id to nested-agent hooks, so `resolveCopilotRootSessionId` in `scripts/lib/mobile-telemetry.js` resolves it to the unique recent UUID session whose local `~/.copilot/session-state/<uuid>/events.jsonl` structurally owns that `agentId`, reading only a bounded tail. Keep host-specific quirks contained in that one function. The verified root is cached as one atomic 30-minute alias file per hashed call id so fresh hook processes reuse it; aliases hold no prompts, cwd, or tool arguments and are never transmitted. Missing, stale, malformed, or ambiguous state fails open to the original id, and Claude Code and Codex ids are not rewritten.-- **Privacy:** Mobile Apps sends no prompt, tool input, cwd, path, URL, credential, username, hostname, Dataverse org/tenant ID, or Entra object ID. The dynamic `eventInfo` contains only `invocationSource` (`prompt` or `pretool`) and a random per-project `appInstanceId` (or `null` outside a prepared project).+- **Privacy:** Mobile Apps sends no prompt, tool input, cwd, path, URL, credential, username, hostname, Dataverse org/tenant ID, or Entra object ID. The dynamic `eventInfo` contains only `invocationSource` (`prompt`, `pretool`, or `checkpoint`), a random per-project `appInstanceId` (or `null` outside a prepared project), and optional author-defined checkpoint `additionalInfo` validated as `snake_case` with a 64-character limit.- **Destination and controls:** Mobile-owned `scripts/lib/mobile-telemetry-dispatcher.js` maps shared events to the Power Apps `event` stream configured by `scripts/lib/telemetry/ikey.json`. The repository `disabled` switch is a hard-off; user and CI opt-outs suppress transmission while preserving the local diagnostic mirror.- **CI:** Every Mobile Apps test job must set `POWER_PLATFORM_SKILLS_TELEMETRY_MOBILE_APP_OPTOUT=1`. The single positive wire test clears that backstop only in its child process and routes the event to `POWER_PLATFORM_SKILLS_FAKE_HTTPS`; all other positive tests remain opted out and exercise the local mirror.diff --git a/plugins/mobile-apps/scripts/emit-telemetry-checkpoint.js b/plugins/mobile-apps/scripts/emit-telemetry-checkpoint.jsnew file mode 100644index 000000000..1d7e64fe6--- /dev/null+++ b/plugins/mobile-apps/scripts/emit-telemetry-checkpoint.js@@ -0,0 +1,62 @@+#!/usr/bin/env node+'use strict';++const { TRACKED_SKILL_NAMES } = require('./lib/mobileapp-hook-utils');+const telemetry = require('./lib/mobile-telemetry');++const CHECKPOINT_STATES = new Set(['started', 'completed', 'skipped', 'failed']);+const CHECKPOINT_NAME_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;+const CHECKPOINT_SKILLS = new Set(TRACKED_SKILL_NAMES);++function parseCheckpointPayload(payload) {+ if (typeof payload !== 'string') return null;+ const parts = payload.split('|').map((part) => part.trim());+ if (parts.length < 3 || parts.length > 4) return null;++ const [skillName, checkpointName, state, additionalInfo] = parts;+ if (parts.length === 4 && !additionalInfo) return null;+ if (+ !CHECKPOINT_SKILLS.has(skillName) ||+ checkpointName.length > 64 ||+ !CHECKPOINT_NAME_PATTERN.test(checkpointName) ||+ !CHECKPOINT_STATES.has(state)+ ) {+ return null;+ }+ if (+ additionalInfo &&+ (additionalInfo.length > 64 || !CHECKPOINT_NAME_PATTERN.test(additionalInfo))+ ) {+ return null;+ }++ return {+ skillName,+ eventName: `${checkpointName}_${state}`,+ severity: state === 'failed' ? 'Error' : 'Info',+ source: 'checkpoint',+ additionalInfo: additionalInfo || undefined,+ };+}++function emitCheckpoint(payload, opts = {}) {+ try {+ const invocation = parseCheckpointPayload(payload);+ if (!invocation) return null;++ const createContext = opts.createTelemetryContext || telemetry.createTelemetryContext;+ const context = createContext({});+ if (!context) return null;++ const emit = opts.emitCheckpoint || telemetry.emitCheckpoint;+ return emit(context, invocation, { cwd: opts.cwd || process.cwd() });+ } catch {+ return null;+ }+}++if (require.main === module) {+ emitCheckpoint(process.argv[2]);+}++module.exports = { emitCheckpoint, parseCheckpointPayload };\ No newline at end of filediff --git a/plugins/mobile-apps/scripts/lib/mobile-telemetry.js b/plugins/mobile-apps/scripts/lib/mobile-telemetry.jsindex f13070a04..09ea6caf8 100644--- a/plugins/mobile-apps/scripts/lib/mobile-telemetry.js+++ b/plugins/mobile-apps/scripts/lib/mobile-telemetry.js@@ -248,6 +248,7 @@ function commonFields(context, invocation, opts = {}) {// identity rides here rather than needing a new allowlisted column.const eventInfo = {};if (invocation.source) eventInfo.invocationSource = invocation.source;+ if (invocation.additionalInfo) eventInfo.additionalInfo = invocation.additionalInfo;const appInstanceId = findAppInstanceId(opts.cwd) || null;eventInfo.appInstanceId = appInstanceId;if (Object.keys(eventInfo).length) fields.eventInfo = eventInfo;@@ -280,7 +281,19 @@ function emitSkillStarted(context, invocation, opts = {}) {return event;}+function emitCheckpoint(context, invocation, opts = {}) {+ const event = events.buildSkillStarted(+ context.eventStreamName,+ commonFields(context, invocation, opts),+ );+ event.data.eventName = invocation.eventName;+ event.data.severity = invocation.severity;+ dispatch(context, event, opts);+ return event;+}+module.exports = {createTelemetryContext,+ emitCheckpoint,emitSkillStarted,};\ No newline at end of filediff --git a/plugins/mobile-apps/scripts/tests/mobile-telemetry.test.js b/plugins/mobile-apps/scripts/tests/mobile-telemetry.test.jsindex a9c285643..5cbc1f852 100644--- a/plugins/mobile-apps/scripts/tests/mobile-telemetry.test.js+++ b/plugins/mobile-apps/scripts/tests/mobile-telemetry.test.js@@ -9,8 +9,13 @@ const { spawnSync } = require('node:child_process');const {createTelemetryContext,+ emitCheckpoint: emitCheckpointEvent,emitSkillStarted,} = require('../lib/mobile-telemetry');+const {+ emitCheckpoint: emitCheckpointCommand,+ parseCheckpointPayload,+} = require('../emit-telemetry-checkpoint');const { ensureAppInstanceId, findAppInstanceId } = require('../lib/app-identity');const PLUGIN_ROOT = path.resolve(__dirname, '..', '..');@@ -207,6 +212,114 @@ test('started event is allowlisted and carries no user, tenant, prompt, or path}});+test('checkpoint payload accepts only tracked skills and static snake_case fields', () => {+ assert.deepEqual(+ parseCheckpointPayload('create-mobile-app|planning|completed|with_dataverse'),+ {+ skillName: 'create-mobile-app',+ eventName: 'planning_completed',+ severity: 'Info',+ source: 'checkpoint',+ additionalInfo: 'with_dataverse',+ },+ );++ for (const payload of [+ '',+ 'unknown-skill|planning|started',+ 'create-mobile-app|Planning|started',+ 'create-mobile-app|planning|finished',+ 'create-mobile-app|planning|started|',+ 'create-mobile-app|planning|failed|C:\\secret\\file.txt',+ `create-mobile-app|${'a'.repeat(65)}|started`,+ 'create-mobile-app|planning|started|safe|extra',+ ]) {+ assert.equal(parseCheckpointPayload(payload), null, payload);+ }+});++test('checkpoint command emits directly and remains fail-open', () => {+ const context = { sessionId: 'checkpoint-session' };+ let captured;+ const result = emitCheckpointCommand(+ 'create-mobile-app|template_gate|started',+ {+ cwd: 'C:\\private-project',+ createTelemetryContext: (payload) => {+ assert.deepEqual(payload, {});+ return context;+ },+ emitCheckpoint: (...args) => {+ captured = args;+ return 'emitted';+ },+ },+ );++ assert.equal(result, 'emitted');+ assert.deepEqual(captured, [+ context,+ {+ skillName: 'create-mobile-app',+ eventName: 'template_gate_started',+ severity: 'Info',+ source: 'checkpoint',+ additionalInfo: undefined,+ },+ { cwd: 'C:\\private-project' },+ ]);+ assert.equal(emitCheckpointCommand('invalid', {+ createTelemetryContext: () => { throw new Error('must not run'); },+ }), null);+ assert.equal(emitCheckpointCommand('create-mobile-app|planning|started', {+ createTelemetryContext: () => { throw new Error('telemetry unavailable'); },+ }), null);+});++test('checkpoint event carries only static checkpoint enrichment', (t) => {+ const context = contextFor(provisioned);+ const event = emitCheckpointEvent(context, {+ skillName: 'create-mobile-app',+ eventName: 'planning_failed',+ severity: 'Error',+ source: 'checkpoint',+ additionalInfo: 'dependency_missing',+ }, {+ emit: () => {},+ readAiAgent: () => ({}),+ correlationId: 'correlation-1',+ cwd: tempProject(t),+ });++ assert.equal(event.data.eventName, 'planning_failed');+ assert.equal(event.data.severity, 'Error');+ assert.equal(event.data.skillName, 'create-mobile-app');+ assert.deepEqual(event.data.eventInfo, {+ invocationSource: 'checkpoint',+ additionalInfo: 'dependency_missing',+ appInstanceId: null,+ });+ for (const forbidden of ['prompt', 'cwd', 'path', 'error', 'errorDescription']) {+ assert.equal(Object.prototype.hasOwnProperty.call(event.data, forbidden), false);+ }+});++test('create-mobile-app uses the single direct checkpoint command at seven boundaries', () => {+ const shared = fs.readFileSync(path.join(PLUGIN_ROOT, 'shared', 'shared-instructions.md'), 'utf8');+ const workflow = fs.readFileSync(+ path.join(PLUGIN_ROOT, 'skills', 'create-mobile-app', 'SKILL.md'),+ 'utf8',+ );++ assert.match(shared, /node "\$\{CLAUDE_SKILL_DIR\}\/\.\.\/\.\.\/scripts\/emit-telemetry-checkpoint\.js"/);+ assert.doesNotMatch(shared, /trigger-telemetry/);+ assert.deepEqual(+ [...workflow.matchAll(/\*\*Telemetry checkpoint: `([^`]+)`\*\*/g)]+ .map((match) => match[1]),+ ['template_gate', 'prerequisites', 'planning', 'scaffold', 'data_model', 'screens', 'app_ready'],+ );+});+test('app instance id is minted once and reused by later skill runs', (t) => {const project = tempProject(t);fs.writeFileSync(diff --git a/plugins/mobile-apps/shared/shared-instructions.md b/plugins/mobile-apps/shared/shared-instructions.mdindex 4f9a6ba92..f134edbf9 100644--- a/plugins/mobile-apps/shared/shared-instructions.md+++ b/plugins/mobile-apps/shared/shared-instructions.md@@ -14,6 +14,26 @@ Run at the start of every skill execution (at most once per day). Notifies the u---+## Workflow Checkpoint Telemetry++A workflow opts a step into telemetry with this marker directly below its heading:++```markdown+**Telemetry checkpoint: `<static_snake_case_name>`**+```++At a marked boundary, run this command with the current top-level skill name:++```bash+node "${CLAUDE_SKILL_DIR}/../../scripts/emit-telemetry-checkpoint.js" "<skill-name>|<checkpoint-name>|<state>|<optional-info>"+```++Use `started` immediately before the work, then `completed` after success or `failed` before stopping on failure. A valid branch that bypasses the work emits only `skipped`. Omit the final `|<optional-info>` when no extra classification is needed.++Checkpoint names and optional info must be fixed, author-written `snake_case` values of at most 64 characters. Optional info is for low-cardinality classifications such as `dependency_missing`; never interpolate prompts, errors, paths, names, identifiers, URLs, command output, or other runtime data. Do not emit checkpoints for unmarked steps. Telemetry is fail-open: ignore its output and never retry, block, or alter workflow behavior when the command fails.++---+## Memory Bank**📋 [memory-bank.md](./memory-bank.md)**diff --git a/plugins/mobile-apps/skills/create-mobile-app/SKILL.md b/plugins/mobile-apps/skills/create-mobile-app/SKILL.mdindex 7175f1e10..13cba068f 100644--- a/plugins/mobile-apps/skills/create-mobile-app/SKILL.md+++ b/plugins/mobile-apps/skills/create-mobile-app/SKILL.md@@ -68,6 +68,8 @@ This gate is intentionally simple: `/create-mobile-app` creates a new app from a### Step 0 — Resume check + fresh-template gate+**Telemetry checkpoint: `template_gate`**+If `$ARGUMENTS` includes a `--working-dir` (or the user names an existing directory), check whether `<working_dir>/memory-bank.md` exists.- **Bank present** → read it. Identify the highest-numbered completed step. Inform the user:@@ -97,6 +99,8 @@ node "${PLUGIN_ROOT}/scripts/lib/app-identity.js" "<working_dir>"### Step 1 — Prerequisites+**Telemetry checkpoint: `prerequisites`**+Run all checks first — no point gathering requirements if the toolchain isn't ready.**Important: npm auth and Power Platform app auth are separate.** The account used for `npm install` can be different from the account used by `npx power-apps`:@@ -432,6 +436,8 @@ No background scaffold pipeline is used. The template is already present in `<wo### Step 3 — Plan (planner agent + 4 approval gates)+**Telemetry checkpoint: `planning`**+First, create the working and planning-artifact directories:```bash@@ -875,6 +881,8 @@ If the resolved environment doesn't match what the planner used in Step 3, ask t### Step 5 — Prepare existing template+**Telemetry checkpoint: `scaffold`**+This step is template-only and foreground-only. Do not clone/copy templates, do not run background scaffold jobs, and do not use any legacy fallback path.**Print before starting:**@@ -1417,6 +1425,8 @@ Do NOT touch `src/playerConfig.ts` — auth identifiers live in `auth.config.jso### Step 8 — Apply data model+**Telemetry checkpoint: `data_model`**+If `<dataverse_planning_mode> = connector-only`, verify the approved`## Data Model` says zero Dataverse tables and no `.datamodel-manifest.json`exists, print `↷ Step 8 skipped — connector-only app has no Dataverse data model.`,@@ -2105,6 +2115,8 @@ If this fails, do not launch Step 11. Capture the full error list once, batch-fi### Step 11 — Build screens (parallel)+**Telemetry checkpoint: `screens`**+**Build mode is NEVER a user-facing question.** Do not ask "Build mode? parallel/inline" or any variant. The orchestrator decides automatically per the preflight below.**Quality rule — screen count/time is NOT a fallback trigger.** If `Task` can spawn `mobile-app:screen-builder`, always use screen-builder waves, even for 10+ screens. Do NOT write "given the scale/time, I'll write screens inline" or any equivalent shortcut. Screen-builder agents carry the quality checklist, domain-pattern rules, resolved-import discipline, safe-area/contrast/a11y checks, and per-screen return protocol. Inline mode exists only for host/tooling failure, not for convenience.@@ -2272,6 +2284,8 @@ After `tsc` passes, offer a static HTML preview. The dev server starts next (Ste### Step 12 — Start dev server (background)+**Telemetry checkpoint: `app_ready`**+**Print before starting:**> "→ [Step 12/13] Launching Metro dev server in the background so you can scan the QR."