agentic-mobile-kit 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +6 -1
  2. package/bin/cli.js +1 -1
  3. package/lib/doctor.js +26 -5
  4. package/lib/init.js +235 -49
  5. package/package.json +4 -2
  6. package/stacks/react-native/expo/.agents/skills/LICENSE-expo +21 -0
  7. package/stacks/react-native/expo/.agents/skills/THIRD_PARTY.md +11 -0
  8. package/stacks/react-native/expo/.agents/skills/expo-module/SKILL.md +151 -0
  9. package/stacks/react-native/expo/.agents/skills/expo-module/agents/openai.yaml +4 -0
  10. package/stacks/react-native/expo/.agents/skills/expo-module/references/config-plugin.md +90 -0
  11. package/stacks/react-native/expo/.agents/skills/expo-module/references/create-expo-module.md +206 -0
  12. package/stacks/react-native/expo/.agents/skills/expo-module/references/lifecycle.md +127 -0
  13. package/stacks/react-native/expo/.agents/skills/expo-module/references/module-config.md +48 -0
  14. package/stacks/react-native/expo/.agents/skills/expo-module/references/native-module.md +286 -0
  15. package/stacks/react-native/expo/.agents/skills/expo-module/references/native-view.md +171 -0
  16. package/stacks/react-native/expo/.agents/skills/expo-router/SKILL.md +240 -0
  17. package/stacks/react-native/expo/.agents/skills/expo-router/agents/openai.yaml +4 -0
  18. package/stacks/react-native/expo/.agents/skills/expo-router/references/form-sheet.md +253 -0
  19. package/stacks/react-native/expo/.agents/skills/expo-router/references/route-structure.md +229 -0
  20. package/stacks/react-native/expo/.agents/skills/expo-router/references/search.md +248 -0
  21. package/stacks/react-native/expo/.agents/skills/expo-router/references/tabs.md +433 -0
  22. package/stacks/react-native/expo/.agents/skills/expo-router/references/toolbar-and-headers.md +284 -0
  23. package/stacks/react-native/expo/.agents/skills/expo-router/references/zoom-transitions.md +158 -0
  24. package/stacks/react-native/expo/.agents/skills/expo-upgrade/SKILL.md +150 -0
  25. package/stacks/react-native/expo/.agents/skills/expo-upgrade/agents/openai.yaml +4 -0
  26. package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/expo-av-to-audio.md +132 -0
  27. package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/expo-av-to-video.md +160 -0
  28. package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/native-tabs.md +124 -0
  29. package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/new-architecture.md +79 -0
  30. package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/react-19.md +79 -0
  31. package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/react-compiler.md +59 -0
  32. package/stacks/react-native/expo/.agents/skills/expo-upgrade/references/react-navigation-to-expo-router.md +61 -0
  33. package/stacks/react-native/expo/.rulesync/permissions.jsonc +40 -0
  34. package/stacks/react-native/expo/AGENTS.md +52 -0
  35. package/stacks/react-native/expo/docs/ai/expo.md +35 -0
  36. package/stacks/react-native/expo/docs/ai/known-issues.md +32 -0
  37. package/stacks/react-native/template/.agents/skills/m-release/SKILL.md +5 -4
  38. package/stacks/react-native/template/.githooks/pre-commit +7 -2
  39. package/stacks/react-native/template/.github/workflows/e2e.yml +2 -0
  40. package/stacks/react-native/template/.github/workflows/ios.yml +3 -5
  41. package/stacks/react-native/template/AGENTS.md +4 -4
  42. package/stacks/react-native/template/codemagic.yaml +2 -1
  43. package/stacks/react-native/template/docs/ai/known-issues.md +12 -2
  44. package/stacks/react-native/template/docs/ai/react-native.md +5 -4
  45. package/stacks/react-native/template/scripts/ai/android-flavors.js +41 -0
  46. package/stacks/react-native/template/scripts/ai/case-check.js +35 -0
  47. package/stacks/react-native/template/scripts/ai/install-deps.sh +4 -1
  48. package/stacks/react-native/template/scripts/ai/ios-build.sh +10 -3
  49. package/stacks/react-native/template/scripts/ai/pm-run.sh +12 -0
  50. package/stacks/react-native/template/scripts/ai/pod-install.sh +12 -0
  51. package/stacks/react-native/template/scripts/ai/prebuild.sh +28 -0
  52. package/stacks/react-native/template/scripts/ai/release-build.sh +32 -8
  53. package/stacks/react-native/template/scripts/ai/release-check.js +98 -18
  54. package/stacks/react-native/template/scripts/ai/set-version.sh +19 -1
  55. package/stacks/react-native/template/scripts/ai/verify.sh +69 -16
  56. package/stacks/react-native/template/specs/_templates/flow.yaml +9 -0
@@ -6,7 +6,7 @@
6
6
  'use strict';
7
7
  const fs = require('fs');
8
8
  const path = require('path');
9
- const { execFileSync } = require('child_process');
9
+ const { execFileSync, spawnSync } = require('child_process');
10
10
 
11
11
  const args = process.argv.slice(2);
12
12
  const argSince = args.includes('--since') ? args[args.indexOf('--since') + 1] : null;
@@ -30,18 +30,50 @@ const atTag = git('tag', '--points-at', 'HEAD') && git('status', '--porcelain')
30
30
  const since = argSince || git('describe', '--tags', '--abbrev=0', ...(atTag ? ['HEAD^'] : []));
31
31
 
32
32
  // ---------- files ----------
33
- const xcodeproj = (fs.readdirSync('ios', { withFileTypes: true }).find(e => e.isDirectory() && e.name.endsWith('.xcodeproj')) || {}).name;
33
+ const pkg = JSON.parse(readNow('package.json') || '{}');
34
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
35
+ // Expo apps without native folders in git: ios/ and android/ are generated (and may be stale), so the checks read
36
+ // the app config instead, as `expo prebuild` applies it, with every config plugin
37
+ const expo = deps.expo && !git('ls-files', 'ios', 'android') ? expoConfig() : null;
38
+ function expoConfig() {
39
+ let cli;
40
+ try {
41
+ const dir = path.dirname(require.resolve('expo/package.json', { paths: [process.cwd()] }));
42
+ cli = path.join(dir, require(path.join(dir, 'package.json')).bin.expo);
43
+ } catch {
44
+ fail('Expo isn\'t installed, so the app config can\'t be read', 'install dependencies first: sh scripts/ai/install-deps.sh');
45
+ return null;
46
+ }
47
+ const r = spawnSync(process.execPath, [cli, 'config', '--type', 'introspect', '--json'], { encoding: 'utf8', maxBuffer: 1 << 28 });
48
+ try { return JSON.parse(r.stdout); } catch {
49
+ fail('Couldn\'t read the Expo app config', (r.stderr || '').trim().split('\n').pop() || 'run: npx expo config');
50
+ return null;
51
+ }
52
+ }
53
+ const expoResults = ((expo || {})._internal || {}).modResults || {};
54
+ const xcodeproj = !expo && fs.existsSync('ios') ? (fs.readdirSync('ios', { withFileTypes: true }).find(e => e.isDirectory() && e.name.endsWith('.xcodeproj')) || {}).name : null;
34
55
  const pbxPath = xcodeproj ? `ios/${xcodeproj}/project.pbxproj` : null;
35
56
  const pbx = pbxPath ? readNow(pbxPath) : null;
36
57
  const plists = all(/INFOPLIST_FILE = ([^;]+);/g, pbx).map(p => `ios/${p}`).filter(p => fs.existsSync(p));
37
- const gradlePath = ['android/app/build.gradle', 'android/app/build.gradle.kts'].find(f => fs.existsSync(f));
58
+ const gradlePath = expo ? null : ['android/app/build.gradle', 'android/app/build.gradle.kts'].find(f => fs.existsSync(f));
38
59
  const gradle = stripComments(readNow(gradlePath));
39
- const manifestPath = 'android/app/src/main/AndroidManifest.xml';
40
- const pkg = JSON.parse(readNow('package.json') || '{}');
60
+ const manifestPath = expo ? null : 'android/app/src/main/AndroidManifest.xml';
41
61
  // this kit's codemagic.yaml sets build numbers and the Android upload key on the build machine
42
62
  const codemagic = readNow('codemagic.yaml') || '';
43
- const ciBuildNumber = { iOS: /agvtool new-version/.test(codemagic), Android: /versionCode[^\n]*\$code/.test(codemagic) };
44
- const deps = { ...pkg.dependencies, ...pkg.devDependencies };
63
+ // build numbers set at build time (by CI or fastlane, as this kit's codemagic.yaml does) never change in the repo
64
+ const workflows = fs.existsSync('.github/workflows') ? fs.readdirSync('.github/workflows').map(f => `.github/workflows/${f}`) : [];
65
+ const buildFiles = ['codemagic.yaml', 'bitrise.yml', '.gitlab-ci.yml', '.circleci/config.yml', 'azure-pipelines.yml', ...workflows,
66
+ ...['fastlane', 'ios/fastlane', 'android/fastlane'].map(d => `${d}/Fastfile`)];
67
+ const setsBuild = {
68
+ iOS: /agvtool new-version|increment_build_number|set-xcode-build-number|Set :CFBundleVersion/,
69
+ Android: /versionCode[^\n]*\$|increment_version_code|android_set_version_code|change-android-versioncode/,
70
+ };
71
+ const ciBuildNumber = Object.fromEntries(Object.entries(setsBuild).map(([p, re]) => [p, buildFiles.find(f => re.test(readNow(f) || ''))]));
72
+ // EAS sets them itself with autoIncrement, or keeps them on its servers (appVersionSource: remote)
73
+ const eas = (() => { try { return JSON.parse(readNow('eas.json') || '{}'); } catch { return {}; } })();
74
+ if ((eas.cli || {}).appVersionSource === 'remote' || Object.values(eas.build || {}).some(b => b && b.autoIncrement)) {
75
+ for (const p of ['iOS', 'Android']) ciBuildNumber[p] = ciBuildNumber[p] || 'eas.json';
76
+ }
45
77
 
46
78
  // ---------- 1. versions ----------
47
79
  const iosVersions = t => all(/MARKETING_VERSION = ([^;]+);/g, t);
@@ -50,7 +82,7 @@ const androidVersions = t => all(/versionName\s*=?\s*"([^"]+)"/g, stripComments(
50
82
  const androidBuilds = t => all(/versionCode\s*=?\s*(\d+)/g, stripComments(t));
51
83
 
52
84
  function compare(platform, now, before, kind, versionChanged) {
53
- if (kind === 'build number' && ciBuildNumber[platform]) { info(`${platform} build number: set by Codemagic at build time`); return; }
85
+ if (kind === 'build number' && ciBuildNumber[platform]) { info(`${platform} build number: set at build time (${ciBuildNumber[platform]})`); return; }
54
86
  if (!now.length) { warn(`${platform} ${kind}: couldn't read it`, 'check it by hand before you ship'); return; }
55
87
  if (!before) { info(`${platform} ${kind}: ${now.join(', ')}`); return; }
56
88
  if (!before.length || now.join() !== before.join()) {
@@ -61,7 +93,7 @@ function compare(platform, now, before, kind, versionChanged) {
61
93
  // the App Store needs a new build number only within a version, so 1 again for a new version is fine
62
94
  ok(`${platform} build number (${now.join(', ')} again, for a new version)`);
63
95
  } else if (kind === 'build number') {
64
- warn(`${platform} build number unchanged since ${since} (${now.join(', ')})`, 'bump it, unless your CI sets it (for example Codemagic); stores reject a repeated build number');
96
+ warn(`${platform} build number unchanged since ${since} (${now.join(', ')})`, 'bump it, unless CI or fastlane sets it at build time; stores reject a repeated build number');
65
97
  } else {
66
98
  warn(`${platform} version unchanged since ${since} (${now.join(', ')})`, 'fine for a re-upload of the same version; otherwise bump it');
67
99
  }
@@ -77,6 +109,17 @@ if (gradle) {
77
109
  compare('Android', androidVersions(gradle), since && androidVersions(readAt(since, gradlePath)), 'version');
78
110
  compare('Android', androidBuilds(gradle), since && androidBuilds(readAt(since, gradlePath)), 'build number');
79
111
  }
112
+ if (expo) {
113
+ // the release before, from app.json at its tag (an app.config.* can't be evaluated at an old commit)
114
+ let old = null;
115
+ try { const j = JSON.parse(readAt(since, 'app.json')); old = j.expo || j; } catch {}
116
+ const now = [expo.version].filter(Boolean);
117
+ const before = since && (old ? [old.version].filter(Boolean) : null);
118
+ compare('App', now, before, 'version');
119
+ const builds = c => c && { iOS: [String((c.ios || {}).buildNumber || 1)], Android: [String((c.android || {}).versionCode || 1)] };
120
+ compare('iOS', builds(expo).iOS, since && old && builds(old).iOS, 'build number', before && now.join() !== before.join());
121
+ compare('Android', builds(expo).Android, since && old && builds(old).Android, 'build number');
122
+ }
80
123
  if (pbx && gradle) {
81
124
  const a = iosVersions(pbx), b = androidVersions(gradle);
82
125
  if (a.length && b.length && !a.some(v => b.includes(v))) {
@@ -112,12 +155,23 @@ const NEEDS = {
112
155
  'react-native-touch-id': ['NSFaceIDUsageDescription'],
113
156
  'react-native-audio-recorder-player': ['NSMicrophoneUsageDescription'],
114
157
  '@react-native-voice/voice': ['NSMicrophoneUsageDescription', 'NSSpeechRecognitionUsageDescription'],
158
+ 'expo-camera': ['NSCameraUsageDescription'],
159
+ 'expo-image-picker': ['NSPhotoLibraryUsageDescription'],
160
+ 'expo-media-library': ['NSPhotoLibraryUsageDescription'],
161
+ 'expo-location': ['NSLocationWhenInUseUsageDescription'],
162
+ 'expo-contacts': ['NSContactsUsageDescription'],
163
+ 'expo-local-authentication': ['NSFaceIDUsageDescription'],
115
164
  };
165
+ // the texts Expo's config plugins write when app.json gives none: too vague for App Review
166
+ const EXPO_DEFAULT = /^Allow \$\(PRODUCT_NAME\) to /;
116
167
  const PLACEHOLDER = /^\s*$|\b(todo|tbd|lorem|placeholder|description here|your text)\b/i;
117
168
  const usageTexts = f => Object.fromEntries([...(readNow(f) || '').matchAll(/<key>(\w+UsageDescription)<\/key>\s*<string>([^<]*)<\/string>/g)].map(m => [m[1], m[2]]));
118
- const textsByPlist = Object.fromEntries(plists.map(f => [f, usageTexts(f)]));
169
+ const expoPlist = (expoResults.ios || {}).infoPlist || {};
170
+ const textsByPlist = expo
171
+ ? { 'app config (ios.infoPlist)': Object.fromEntries(Object.entries(expoPlist).filter(([k, v]) => /UsageDescription$/.test(k) && typeof v === 'string')) }
172
+ : Object.fromEntries(plists.map(f => [f, usageTexts(f)]));
119
173
  const needed = Object.entries(NEEDS).filter(([lib]) => deps[lib]).flatMap(([lib, keys]) => keys.map(key => ({ lib, key })));
120
- for (const plistPath of plists) {
174
+ for (const plistPath of Object.keys(textsByPlist)) {
121
175
  const texts = textsByPlist[plistPath];
122
176
  const problems = [];
123
177
  for (const { lib, key } of needed) {
@@ -133,9 +187,12 @@ for (const plistPath of plists) {
133
187
  if (neededKeys.includes(key)) fail(`${plistPath}: ${key} is ${text.trim() ? `a placeholder ("${text.trim()}")` : 'empty'}`, 'write a real reason users can understand');
134
188
  else warn(`${plistPath}: ${key} is ${text.trim() ? 'a placeholder' : 'empty'}`, 'remove the key if the app doesn\'t use this permission; otherwise write a real reason');
135
189
  }
136
- if (!problems.length && !Object.values(texts).some(t => PLACEHOLDER.test(t))) ok(`${plistPath}: permission texts`, `${Object.keys(texts).length} present`);
137
- const plist = readNow(plistPath);
138
- if (/<key>NSAllowsArbitraryLoads<\/key>\s*<true\s*\/>/.test(plist)) {
190
+ const vague = Object.entries(texts).filter(([, t]) => EXPO_DEFAULT.test(t)).map(([k]) => k);
191
+ if (vague.length) warn(`${plistPath}: Expo's default text for ${vague.join(', ')}`, 'App Review asks why the app needs each permission: set the text in the library\'s plugin options or ios.infoPlist in app.json');
192
+ if (!problems.length && !vague.length && !Object.values(texts).some(t => PLACEHOLDER.test(t))) ok(`${plistPath}: permission texts`, `${Object.keys(texts).length} present`);
193
+ const arbitrary = expo ? (expoPlist.NSAppTransportSecurity || {}).NSAllowsArbitraryLoads === true
194
+ : /<key>NSAllowsArbitraryLoads<\/key>\s*<true\s*\/>/.test(readNow(plistPath) || '');
195
+ if (arbitrary) {
139
196
  warn(`${plistPath}: NSAllowsArbitraryLoads is true (any HTTP allowed)`, 'App Review may ask why; allow only the domains that need it (NSExceptionDomains)');
140
197
  }
141
198
  }
@@ -143,8 +200,10 @@ for (const plistPath of plists) {
143
200
  // ---------- 4. Android permissions ----------
144
201
  const SENSITIVE = /\.(ACCESS_(FINE|COARSE|BACKGROUND)_LOCATION|CAMERA|RECORD_AUDIO|READ_CONTACTS|WRITE_CONTACTS|READ_EXTERNAL_STORAGE|WRITE_EXTERNAL_STORAGE|READ_MEDIA_\w+|BLUETOOTH_SCAN|BLUETOOTH_CONNECT|POST_NOTIFICATIONS|READ_PHONE_STATE|BODY_SENSORS|READ_CALENDAR|WRITE_CALENDAR|ACCESS_MEDIA_LOCATION)$/;
145
202
  const perms = t => all(/<uses-permission[^>]*android:name="([^"]+)"/g, t);
146
- const permsNow = perms(readNow(manifestPath));
147
- if (since && readAt(since, manifestPath) !== null) {
203
+ // Expo: the manifest prebuild would write, as JSON
204
+ const expoManifest = ((expoResults.android || {}).manifest || {}).manifest;
205
+ const permsNow = expo ? uniq(((expoManifest || {})['uses-permission'] || []).map(p => p.$['android:name'])) : perms(readNow(manifestPath));
206
+ if (manifestPath && since && readAt(since, manifestPath) !== null) {
148
207
  const before = perms(readAt(since, manifestPath));
149
208
  const added = permsNow.filter(p => !before.includes(p));
150
209
  const removed = before.filter(p => !permsNow.includes(p));
@@ -175,14 +234,35 @@ else if (/signingConfig\s*=?\s*signingConfigs\.debug/.test(releaseBlock)) {
175
234
  // the kit's release-build.sh (and Codemagic) sign with the upload key, and Play rejects debug-signed uploads anyway
176
235
  info('build.gradle signs release builds with the debug key', 'build store releases with sh scripts/ai/release-build.sh android, which signs with your upload key');
177
236
  }
178
- if (/android:usesCleartextTraffic="true"/.test(readNow(manifestPath) || '')) {
237
+ const cleartext = expo ? ((((expoManifest || {}).application || [])[0] || {}).$ || {})['android:usesCleartextTraffic'] === 'true'
238
+ : /android:usesCleartextTraffic="true"/.test(readNow(manifestPath) || '');
239
+ if (cleartext) {
179
240
  warn('Android allows cleartext (HTTP) traffic', 'allow only the domains that need it (network security config)');
180
241
  }
181
242
  const debuggers = (git('grep', '-n', '-E', '^[[:space:]]*debugger;?[[:space:]]*$', '--', '*.js', '*.jsx', '*.ts', '*.tsx') || '').split('\n').filter(Boolean);
182
243
  if (debuggers.length) fail(`"debugger" statements left in code: ${debuggers.slice(0, 3).join(', ')}${debuggers.length > 3 ? ' …' : ''}`, 'remove them');
183
244
  else ok('No "debugger" statements');
184
245
 
185
- // ---------- 6. store notes ----------
246
+ // ---------- 6. signing keys in git ----------
247
+ // the standard debug.keystore (password "android") is public and fine; real keys and passwords aren't
248
+ const tracked = (git('ls-files') || '').split('\n').filter(Boolean);
249
+ const gradleCode = stripComments(readNow(gradlePath));
250
+ const storeFiles = [
251
+ ...all(/storeFile\s*=?\s*file\(\s*["']([^"']+)["']\s*\)/g, gradleCode).map(f => path.posix.join('android/app', f)),
252
+ ...all(/storeFile\s*=?\s*rootProject\.file\(\s*["']([^"']+)["']\s*\)/g, gradleCode).map(f => path.posix.join('android', f)),
253
+ ];
254
+ // credentials.json: EAS's local credentials, with the keystore passwords
255
+ const keys = tracked.filter(f => (/\.(jks|keystore|p12|p8|mobileprovision)$/.test(f) || storeFiles.includes(f) || f === 'credentials.json') && path.basename(f) !== 'debug.keystore');
256
+ // React Native's docs suggest android/gradle.properties for these passwords, and that file is usually committed
257
+ const propsPasswords = tracked.includes('android/gradle.properties')
258
+ ? (readNow('android/gradle.properties') || '').split('\n').filter(l => /^[^#]*password[^=]*=\s*\S/i.test(l)).length : 0;
259
+ const passwords = [...gradleCode.matchAll(/(?:store|key)Password\s*=?\s*["']([^"']*)["']/g)].filter(m => m[1] !== 'android').length + propsPasswords;
260
+ if (keys.length || passwords) {
261
+ const what = [keys.length && `signing keys are in git: ${keys.join(', ')}`, passwords && `${passwords} signing password(s) are written in ${propsPasswords ? 'android/gradle.properties or ' : ''}${gradlePath}`].filter(Boolean).join('; ');
262
+ warn(what.charAt(0).toUpperCase() + what.slice(1), 'anyone who can read the repo can sign builds as you: keep keys in a password manager, read passwords from the environment or ~/.gradle/gradle.properties, and reset the upload key in Play Console if Play App Signing is on');
263
+ }
264
+
265
+ // ---------- 7. store notes ----------
186
266
  const LIMITS = { 'play-store': 500, 'app-store': 4000 };
187
267
  const noteFiles = fs.existsSync('release-notes') ? (git('ls-files', '--others', '--cached', '--exclude-standard', 'release-notes') || '').split('\n').filter(Boolean) : [];
188
268
  for (const f of noteFiles) {
@@ -1,10 +1,28 @@
1
1
  #!/bin/sh
2
- # Sets the version users see on both platforms: iOS MARKETING_VERSION and Android versionName.
2
+ # Sets the version users see on both platforms: iOS MARKETING_VERSION and Android versionName, or in Expo
3
+ # apps without native folders, expo.version in app.json.
3
4
  # Build numbers are left alone (codemagic.yaml sets them at build time).
4
5
  # Usage: sh scripts/ai/set-version.sh 1.4.0
5
6
  set -eu
6
7
  v=${1:-}
7
8
  echo "$v" | grep -qE '^[0-9]+\.[0-9]+(\.[0-9]+)?$' || { echo "usage: sh scripts/ai/set-version.sh <version, e.g. 1.4.0>" >&2; exit 1; }
9
+
10
+ # Expo apps without native folders in git: the version is expo.version in the app config
11
+ if [ -z "$(git ls-files -- ios android 2> /dev/null)" ] &&
12
+ node -e "const p = require('./package.json'); process.exit({ ...p.dependencies, ...p.devDependencies }.expo ? 0 : 1)" 2> /dev/null; then
13
+ config=$(ls app.config.js app.config.ts app.config.mjs app.config.cjs 2> /dev/null | head -1)
14
+ [ -z "$config" ] || { echo "This app computes its config in $config: set the version there by hand" >&2; exit 1; }
15
+ node -e '
16
+ const fs = require("fs");
17
+ const text = fs.readFileSync("app.json", "utf8");
18
+ const json = JSON.parse(text);
19
+ (json.expo || json).version = process.argv[1];
20
+ const indent = (text.match(/^[ \t]+(?=")/m) || [" "])[0];
21
+ fs.writeFileSync("app.json", `${JSON.stringify(json, null, indent)}\n`);
22
+ ' "$v"
23
+ echo "Version $v set in app.json."
24
+ exit 0
25
+ fi
8
26
  pbx=$(ls ios/*.xcodeproj/project.pbxproj | head -1)
9
27
  gradle=$(ls android/app/build.gradle android/app/build.gradle.kts 2>/dev/null | head -1)
10
28
 
@@ -3,13 +3,17 @@
3
3
  # and Android emulator, running Maestro flows and saving screenshots as evidence.
4
4
  #
5
5
  # Usage: sh scripts/ai/verify.sh [quick|ios|android|all] [--spec <id>] [--flow <file>] [--label <name>]
6
- # quick lint, typecheck, tests
7
- # ios|android release build, install, run flows, screenshots
8
- # all everything (default)
9
- # --spec <id> run .maestro/<id>*.yaml and save evidence in .ai/evidence/<id>/
10
- # --label <n> evidence folder name (default: the spec id, or a timestamp)
6
+ # [--flavor <name>] [--scheme <name>]
7
+ # quick lint, typecheck, tests
8
+ # ios|android release build, install, run flows, screenshots
9
+ # all everything (default)
10
+ # --spec <id> run .maestro/<id>*.yaml and save evidence in .ai/evidence/<id>/
11
+ # --label <n> evidence folder name (default: the spec id, or a timestamp)
12
+ # --flavor <name> Android product flavor to check (default: the first one in build.gradle)
13
+ # --scheme <name> iOS scheme to check (default: the one named like the workspace)
11
14
  # (no flows found: a smoke check that launches the app and takes a screenshot)
12
- # Env: AMK_IOS_DEVICE (simulator name or UDID), AMK_ANDROID_AVD (emulator name)
15
+ # Env: AMK_ANDROID_FLAVOR, AMK_IOS_SCHEME (defaults for the two options), AMK_IOS_DEVICE (simulator name
16
+ # or UDID), AMK_ANDROID_DEVICE (adb serial, when several are connected), AMK_ANDROID_AVD (emulator to start)
13
17
  set -eu
14
18
 
15
19
  mode=${1:-all}
@@ -17,11 +21,14 @@ mode=${1:-all}
17
21
  spec=""
18
22
  flow=""
19
23
  label=""
24
+ flavor=${AMK_ANDROID_FLAVOR:-}
20
25
  while [ $# -gt 0 ]; do
21
26
  case $1 in
22
27
  --spec) spec=$2; shift 2 ;;
23
28
  --flow) flow=$2; shift 2 ;;
24
29
  --label) label=$2; shift 2 ;;
30
+ --flavor) flavor=$2; shift 2 ;;
31
+ --scheme) AMK_IOS_SCHEME=$2; export AMK_IOS_SCHEME; shift 2 ;;
25
32
  *) echo "verify: unknown option $1"; exit 2 ;;
26
33
  esac
27
34
  done
@@ -43,7 +50,9 @@ run_flows() { # platform device app_id
43
50
  mkdir -p "$out"
44
51
  files=$(flow_files)
45
52
  if [ -z "$files" ]; then
46
- printf 'appId: %s\n---\n- launchApp\n- takeScreenshot: smoke-launch\n' "$3" > "$out/smoke.yaml"
53
+ # launchApp returns before the app has drawn, and a splash screen stays up until the JavaScript has loaded:
54
+ # a fixed wait (for text that never appears), then for the screen to settle, so the screenshot shows the app
55
+ printf 'appId: %s\n---\n- launchApp\n- extendedWaitUntil:\n visible: "agentic-mobile-kit: waiting for the app to draw"\n timeout: 5000\n optional: true\n- waitForAnimationToEnd\n- takeScreenshot: smoke-launch\n' "$3" > "$out/smoke.yaml"
47
56
  files="$out/smoke.yaml"
48
57
  fi
49
58
  passed=0
@@ -72,6 +81,8 @@ quick() {
72
81
  sh scripts/ai/pm-run.sh typecheck > "$evidence/typecheck.log" 2>&1 &&
73
82
  CI=true sh scripts/ai/pm-run.sh test > "$evidence/test.log" 2>&1; then
74
83
  echo "quick: lint, typecheck and tests passed"
84
+ # what didn't run (no such script, or an Expo app without ESLint yet)
85
+ cat "$evidence/lint.log" "$evidence/typecheck.log" "$evidence/test.log" | sed -n 's/^skip: / skipped: /p'
75
86
  else
76
87
  echo "quick: FAILED, see the logs in ${evidence#"$root"/}"
77
88
  status=1
@@ -86,12 +97,19 @@ ios() {
86
97
  return
87
98
  fi
88
99
  command -v maestro > /dev/null || { echo "ios: Maestro isn't installed (https://maestro.dev)"; status=1; return; }
89
- # pod install also generates React Native codegen files into ios/build/generated
90
- if [ ! -d ios/Pods ] || [ ! -d ios/build/generated ]; then (cd ios && pod install > "$evidence/pod-install.log" 2>&1); fi
100
+ # Expo apps without native folders in git: generate ios/ first
101
+ if ! sh scripts/ai/prebuild.sh ios > "$evidence/prebuild-ios.log" 2>&1; then
102
+ echo "ios: expo prebuild FAILED, see ${evidence#"$root"/}/prebuild-ios.log"; status=1; return
103
+ fi
104
+ # pod install also generates React Native codegen files into ios/build/generated; a newer Podfile needs it again
105
+ if [ ! -d ios/Pods ] || [ ! -d ios/build/generated ] || [ ios/Podfile -nt ios/Pods/Manifest.lock ]; then
106
+ sh scripts/ai/pod-install.sh > "$evidence/pod-install.log" 2>&1
107
+ fi
91
108
  if ! CONFIGURATION=Release sh scripts/ai/ios-build.sh > "$evidence/ios-build.log" 2>&1; then
92
109
  echo "ios: release build FAILED, see ${evidence#"$root"/}/ios-build.log"; status=1; return
93
110
  fi
94
- app=$(ls -d ios/DerivedData/Build/Products/Release-iphonesimulator/*.app | head -n 1)
111
+ # the newest app: the scheme just built (another scheme's app may still be there from an earlier build)
112
+ app=$(ls -dt ios/DerivedData/Build/Products/*-iphonesimulator/*.app | head -n 1)
95
113
  app_id=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' "$app/Info.plist")
96
114
  device=$(xcrun simctl list devices available -j | node -e '
97
115
  const all = Object.entries(JSON.parse(require("fs").readFileSync(0, "utf8")).devices)
@@ -117,20 +135,55 @@ android() {
117
135
  esac
118
136
  sdk=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$default_sdk}}
119
137
  adb="$sdk/platform-tools/adb"
120
- if ! (cd android && ./gradlew assembleRelease --no-daemon -q) > "$evidence/android-build.log" 2>&1; then
121
- echo "android: release build FAILED, see ${evidence#"$root"/}/android-build.log"; status=1; return
138
+ # Expo apps without native folders in git: generate android/ first
139
+ if ! sh scripts/ai/prebuild.sh android > "$evidence/prebuild-android.log" 2>&1; then
140
+ echo "android: expo prebuild FAILED, see ${evidence#"$root"/}/prebuild-android.log"; status=1; return
141
+ fi
142
+ # apps with product flavors: check one, the first in build.gradle unless --flavor names another
143
+ if [ -z "$flavor" ]; then
144
+ code=0
145
+ flavors=$(node scripts/ai/android-flavors.js) || code=$?
146
+ case $code in
147
+ 0) ;;
148
+ 2) echo "android: the app has several flavor dimensions; name the variant with --flavor (for example devFree)"; status=1; return ;;
149
+ *) echo "android: couldn't read the product flavors from build.gradle (see the error above)"; status=1; return ;;
150
+ esac
151
+ flavor=$(echo "$flavors" | head -n 1)
152
+ [ -z "$flavor" ] || echo "android: checking the \"$flavor\" flavor (the app has: $(echo $flavors)); --flavor <name> checks another"
122
153
  fi
123
- apk=$(ls android/app/build/outputs/apk/release/*.apk | head -n 1)
124
- app_id=$(sed -n 's/.*applicationId *=\{0,1\} *"\([^"]*\)".*/\1/p' android/app/build.gradle* | head -n 1)
125
- device=$("$adb" devices | awk 'NR > 1 && $2 == "device" { print $1; exit }')
154
+ variant=$(printf %s "$flavor" | awk '{ print toupper(substr($0, 1, 1)) substr($0, 2) }')
155
+ # the device first: the build only needs its CPU type, and an emulator boots while Gradle builds
156
+ device=${AMK_ANDROID_DEVICE:-$("$adb" devices | awk 'NR > 1 && $2 == "device" { print $1; exit }')}
126
157
  if [ -z "$device" ]; then
127
158
  avd=${AMK_ANDROID_AVD:-$("$sdk/emulator/emulator" -list-avds | head -n 1)}
128
159
  [ -n "$avd" ] || { echo "android: no emulator found (create one in Android Studio)"; status=1; return; }
129
160
  nohup "$sdk/emulator/emulator" -avd "$avd" -no-snapshot-save -no-boot-anim > /dev/null 2>&1 &
130
161
  "$adb" wait-for-device
131
- until [ "$("$adb" shell getprop sys.boot_completed 2> /dev/null | tr -d '\r')" = 1 ]; do sleep 3; done
132
162
  device=$("$adb" devices | awk 'NR > 1 && $2 == "device" { print $1; exit }')
133
163
  fi
164
+ abi=$("$adb" -s "$device" shell getprop ro.product.cpu.abi 2> /dev/null | tr -d '\r')
165
+ [ -n "$abi" ] || { echo "android: device $device isn't connected (see: adb devices)"; status=1; return; }
166
+ # native code for that CPU type only, as run-android --active-arch-only does: much faster than all four
167
+ set -- -PreactNativeArchitectures="$abi"
168
+ # signed with the project's debug key, so the check build installs whatever key its real release needs
169
+ if [ -f android/app/debug.keystore ]; then
170
+ keystore=$(cd android/app && { pwd -W 2> /dev/null || pwd; })/debug.keystore # pwd -W: a Windows path in Git Bash
171
+ set -- "$@" -Pandroid.injected.signing.store.file="$keystore" -Pandroid.injected.signing.store.password=android \
172
+ -Pandroid.injected.signing.key.alias=androiddebugkey -Pandroid.injected.signing.key.password=android
173
+ fi
174
+ if ! (cd android && ./gradlew "assemble${variant}Release" --no-daemon -q "$@") > "$evidence/android-build.log" 2>&1; then
175
+ echo "android: release build FAILED, see ${evidence#"$root"/}/android-build.log"; status=1; return
176
+ fi
177
+ # apps that split APKs by CPU type get one per type: take this device's, else the universal one
178
+ apks=$(ls android/app/build/outputs/apk/${flavor:+$flavor/}release/*.apk)
179
+ apk=$(echo "$apks" | grep -e "-$abi-" | head -n 1)
180
+ [ -n "$apk" ] || apk=$(echo "$apks" | grep universal | head -n 1)
181
+ [ -n "$apk" ] || apk=$(echo "$apks" | head -n 1)
182
+ # the app ID from the built APK, which includes flavor suffixes such as .dev
183
+ aapt2="$(ls -d "$sdk"/build-tools/*/ 2> /dev/null | sort -V | tail -n 1)aapt2"
184
+ app_id=$("$aapt2" dump badging "$apk" 2> /dev/null | sed -n "s/^package: name='\([^']*\)'.*/\1/p")
185
+ [ -n "$app_id" ] || app_id=$(sed -n 's/.*applicationId *=\{0,1\} *"\([^"]*\)".*/\1/p' android/app/build.gradle* | head -n 1)
186
+ until [ "$("$adb" -s "$device" shell getprop sys.boot_completed 2> /dev/null | tr -d '\r')" = 1 ]; do sleep 3; done
134
187
  "$adb" -s "$device" install -r "$apk" > /dev/null
135
188
  # system "isn't responding" pop-ups (common on busy emulators) cover the app and fail flows; app crashes still fail them
136
189
  "$adb" -s "$device" shell settings put global hide_error_dialogs 1
@@ -4,6 +4,13 @@ appId: ${APP_ID} # set by verify.sh
4
4
  ---
5
5
  - launchApp:
6
6
  clearState: true
7
+ # After every launchApp: a splash screen can still cover the app while assertions already pass (the app's views
8
+ # exist under it), so wait a moment (for text that never appears), then for the screen to settle.
9
+ - extendedWaitUntil:
10
+ visible: "flow: waiting for the app to draw"
11
+ timeout: 3000
12
+ optional: true
13
+ - waitForAnimationToEnd
7
14
  # Scenario 1: <scenario name from requirements.md>
8
15
  - assertVisible:
9
16
  id: "<testID of the element>"
@@ -11,4 +18,6 @@ appId: ${APP_ID} # set by verify.sh
11
18
  # Scenario 2: …
12
19
  - tapOn:
13
20
  id: "<testID>"
21
+ - assertVisible: # what THEN expects, so the screenshot shows the result and not the screen before it
22
+ id: "<testID of the result>"
14
23
  - takeScreenshot: <id>-2-<short-name>