Skip to content

Avoid common App Store and Google Play rejections. Open playbook and pre-submission guard with 117 documented rejection patterns and fixes, privacy manifest and Data safety checks, 95 tracked deadlines (EU AI Act, DSA, COPPA, age laws), and a skill for AI coding agents.

fix(guard): scan each app in a monorepo on its own, detect deep apps, read sources once (#612) (#614)

Mirza Iqbala1f879fee191
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2e4be88..73bc3cb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ All notable changes to this playbook are recorded here. The format follows Keep
### Fixed
+- The scanner pooled its findings across every app under the project root (#612). A rule asked whether the tree held the risky symbol and whether it held the mitigating one, and a clean sibling app answered for a broken one. The guard now discovers app roots (an Expo, React Native, Flutter, or Capacitor app, an Android project, an Xcode project) and when two or more exist below the project root, or the root is itself a framework app with nested framework apps, each is scanned on its own with its own `App.` section, platform line, and findings under the single `Project.` header. A platform folder named ios or android is part of the app above it. A Swift package, a Flutter package or plugin, a React Native module, a Heroku app.json, a test fixture, and anything under Pods, node_modules, build, dist, or vendor never count, and a nested demo Xcode project under a root native app stays part of that app. A single app produces byte-identical output to before. Platform detection stopped at find depth 4, so an app at packages/mobile/app/ios reported iOS=0 and the whole Apple ruleset was skipped. It now reaches depth 12, the same reach as the privacy manifest probe. The source scan ran a grep over every file for each of its 115 checks. It now concatenates every text file once and greps that blob, with a per-run end marker that proves the write completed and a per-file fallback when it did not, so a real 700-file iOS repo scans in 19 seconds instead of 28 with a byte-identical report. The two probes that read the whole tree directly (privacy manifest presence and R8 minification) honour the same app boundary, the find prune escapes glob characters in an app name, a project path that is itself a symlink is walked through its target instead of scanning empty, and the temp file pair is created once and removed on exit. 57 new test cases, 184 total, pinning every counterexample from three adversarial review rounds and three independent reviewer passes, including a no-Gradle R8 regression that the byte comparison against the previous guard caught and the tests had not.
- The guard's hook-mode payload parser was not JSON-aware (#610, reported and measured by mj-deving). The regex extraction stopped at the first escaped quote, so `cd "$CLAUDE_PROJECT_DIR/apps/app" && npx eas submit --platform ios` reduced to two characters and the guard exited 0 unscanned, and a backslash-newline continuation left the JSON newline escape literal, so `eas submit` split across two lines never matched. The command is now read from `.tool_input.command` (or a top-level `command`) with jq, then python3, then a backslash-aware fallback when neither is installed. Backslash-newline continuations fold into one space, and bare newlines stay as separators, so a trigger split across two separate commands is never invented. In hook mode a block now writes the report to stderr, the only stream Claude Code shows on exit 2, so the reason no longer arrives empty. A pass stays on stdout and standalone mode is unchanged. An adversarial review of the fix added four more guards. the trigger is matched against the raw command with quote characters stripped, so `eas "submit"`, `bash -c 'eas submit'`, and a submit inside a `python3 -c` string are all scanned, and only a single simple line led by an inert text command (`echo`, `printf`, `grep`, `cat`, `head`, `tail`, `wc`, `sort`, `uniq`, `tee`) with no substitution, pipe, or separator has its quoted spans and trailing comment blanked, so a plain echo or grep that mentions a submit never blocks while `echo "$(eas submit)"` and a `git` alias still scan. jq and python3 are each probed with a trivial run and their real exit status is checked, so a present but broken interpreter (the macOS python3 stub without Command Line Tools, a stale pyenv shim, a jq that dies on real input) falls through instead of silencing the guard, while a payload python3 genuinely rejects as invalid JSON stays silent. A leading `cd <dir> &&`, when it is the only directory change in the command and resolves inside the project, scopes the scan to that app, which is how an EAS monorepo submits. A payload whose `tool_name` is not Bash, or that carries more than one JSON document, is never scanned. A hook timeout signal flushes the buffered report to stderr, and when no temp file can be created the report stays on stdout as before with only the block reason line added on stderr. 80 new test cases, including runs with jq and python3 removed from PATH, a present but broken interpreter on PATH, and every counterexample from four adversarial review rounds.
- The guard scanned Python virtualenvs, bundled web output under dist/, and lowercase test folders (test/, tests/, integration_test/) as app source. A virtualenv's vendored API JSON alone raised five false criticals on one Flutter project. Directories are now pruned by name below the project root only, which also fixes a project sitting under a folder named build being scanned as empty (#542).
- Every `find | grep -q .` pipeline exited 141 under `set -o pipefail` once grep stopped reading and find died of SIGPIPE, so a project with more than one PrivacyInfo.xcprivacy (any CocoaPods or SPM project) was reported as missing its privacy manifest, and platform detection could miss a platform. The pipelines now drain their input, as release_string_has already did.
diff --git a/README.md b/README.md
index 760e1c5..d742476 100644
--- a/README.md
+++ b/README.md
@@ -47,7 +47,7 @@ Set up the App Store Compliance Playbook from https://github.com/mjmirza/app-sto
Steps:
1. Clone https://github.com/mjmirza/app-store-compliance into ~/repositories/app-store-compliance. If you cannot clone, read the files over the GitHub raw URLs instead.
2. Install the audit skill: copy agent-os/skill/SKILL.md plus the docs/, data/, references/, templates/, and scripts/ folders into your agent's skills directory. For Claude Code that is ~/.claude/skills/app-store-compliance/. The references/ folder is the structured tree the agent loads slices from, and scripts/ holds the guard and the metadata-audit engine.
-3. Install the pre-submission guard: copy agent-os/hooks/app-store-compliance-guard.sh into your hooks directory (for Claude Code, ~/.claude/hooks/), make it executable, and register it as a PreToolUse hook on the Bash tool in settings.json so it runs before app submission commands (fastlane, eas submit, gradle bundleRelease, xcrun altool, bundletool, xcodebuild archive) and blocks on a critical rejection risk. Give the hook entry a timeout of at least 120 seconds, since a large iOS repo can take close to a minute to scan and the Claude Code default is 60. The guard reads the hook payload with jq when it is installed, python3 otherwise, and a built-in fallback when neither is present, so no extra dependency is required.
+3. Install the pre-submission guard: copy agent-os/hooks/app-store-compliance-guard.sh into your hooks directory (for Claude Code, ~/.claude/hooks/), make it executable, and register it as a PreToolUse hook on the Bash tool in settings.json so it runs before app submission commands (fastlane, eas submit, gradle bundleRelease, xcrun altool, bundletool, xcodebuild archive) and blocks on a critical rejection risk. Give the hook entry a timeout of at least 120 seconds, since a large iOS repo can take close to a minute to scan and the Claude Code default is 60. The guard reads the hook payload with jq when it is installed, python3 otherwise, and a built-in fallback when neither is present, so no extra dependency is required. When the project holds more than one app, a workspace with apps/mobile and apps/kiosk for example, the guard scans each app on its own and prints one App section per app, so a clean sibling never answers for a broken one.
4. Add a standing instruction to your agent config: for any iOS or Android work, always adhere to the Apple App Store Review Guidelines and Google Play policies, run the audit before submission, and never say an app is clear to submit while a critical risk stands.
5. Run the guard against my current project and show me the ranked findings:
bash ~/.claude/hooks/app-store-compliance-guard.sh /path/to/my/app
diff --git a/agent-os/hooks/app-store-compliance-guard-test.sh b/agent-os/hooks/app-store-compliance-guard-test.sh
index cecb398..1435686 100755
--- a/agent-os/hooks/app-store-compliance-guard-test.sh
+++ b/agent-os/hooks/app-store-compliance-guard-test.sh
@@ -1147,6 +1147,397 @@ OUT="$(printf '%s' "$P_HD_THEN" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)";
echo "$OUT" | grep -q 'App Store Compliance Guard' && [ "$RC" -eq 2 ] && ok "610-54 submit after a heredoc terminator is scanned" || bad "610-54 submit after a heredoc terminator is scanned (rc=$RC bytes=${#OUT})"
rm -rf "$D"
+# ===== Issue #612. Sibling apps in a monorepo are scanned on their own, deep apps are detected =====
+# apps/app is broken (no usage description, Stripe without StoreKit). apps/kiosk is clean and carries the mitigations.
+mk_pooled_mono() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/apps/app/ios/App" "$d/apps/kiosk/ios/Kiosk" "$d/node_modules/x"
+ printf '{"name":"root","workspaces":["apps/*"]}' > "$d/package.json"
+ printf '{"expo":{"name":"app"}}' > "$d/apps/app/app.json"
+ printf '<plist><dict></dict></plist>' > "$d/apps/app/ios/App/Info.plist"
+ printf 'import CoreLocation\nimport Stripe\nlet m=CLLocationManager()\n' > "$d/apps/app/ios/App/A.swift"
+ printf '{"expo":{"name":"kiosk"}}' > "$d/apps/kiosk/app.json"
+ printf '<plist><dict><key>NSLocationWhenInUseUsageDescription</key><string>Show stores</string><key>ITSAppUsesNonExemptEncryption</key><false/></dict></plist>' > "$d/apps/kiosk/ios/Kiosk/Info.plist"
+ printf '%s' "$PLIST_EMPTY" > "$d/apps/kiosk/ios/Kiosk/PrivacyInfo.xcprivacy"
+ printf 'import StoreKit\nlet iap="react-native-iap"\nlet policy="https://kiosk.example.io/privacy-policy"\nfunc restorePurchases(){}\n' > "$d/apps/kiosk/ios/Kiosk/K.swift"
+ echo "$d"
+}
+# An Xcode project seven levels down. The old platform switch stopped at depth 4 and reported iOS=0.
+mk_deep_ios() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/a/b/c/d/e/ios/Acme.xcodeproj" "$d/a/b/c/d/e/ios/Acme"
+ printf 'X=1;\n' > "$d/a/b/c/d/e/ios/Acme.xcodeproj/project.pbxproj"
+ printf '<plist><dict></dict></plist>' > "$d/a/b/c/d/e/ios/Acme/Info.plist"
+ printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$d/a/b/c/d/e/ios/Acme/A.swift"
+ echo "$d"
+}
+# One app whose own ios/ and android/ folders each carry project markers. Those are parts of the app, never sibling apps.
+mk_nested_native() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/ios/App.xcworkspace" "$d/ios/App" "$d/android/app/src/main"
+ printf '{"expo":{"name":"one"}}' > "$d/app.json"
+ printf "platform :ios, '15.0'\n" > "$d/ios/Podfile"
+ printf '<plist><dict></dict></plist>' > "$d/ios/App/Info.plist"
+ printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$d/ios/App/A.swift"
+ printf "include ':app'\n" > "$d/android/settings.gradle"
+ printf '<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>' > "$d/android/app/src/main/AndroidManifest.xml"
+ echo "$d"
+}
+# Two native projects side by side, one per platform, with no marker at the root.
+mk_two_native() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/ios-app/App.xcodeproj" "$d/ios-app/App" "$d/android-app/app/src/main"
+ printf 'X=1;\n' > "$d/ios-app/App.xcodeproj/project.pbxproj"
+ printf '<plist><dict></dict></plist>' > "$d/ios-app/App/Info.plist"
+ printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$d/ios-app/App/A.swift"
+ printf "include ':app'\n" > "$d/android-app/settings.gradle"
+ printf '<manifest><uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/></manifest>' > "$d/android-app/app/src/main/AndroidManifest.xml"
+ echo "$d"
+}
+# A Swift package library next to one app. A library is not an app and never gets its own section.
+mk_app_plus_lib() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/apps/app/ios/App" "$d/packages/kit/Sources/Kit"
+ printf '{"expo":{"name":"app"}}' > "$d/apps/app/app.json"
+ printf '<plist><dict></dict></plist>' > "$d/apps/app/ios/App/Info.plist"
+ printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$d/apps/app/ios/App/A.swift"
+ printf '// swift-tools-version:5.9\nimport PackageDescription\nlet package = Package(name: "Kit")\n' > "$d/packages/kit/Package.swift"
+ printf 'public let k = 1\n' > "$d/packages/kit/Sources/Kit/K.swift"
+ echo "$d"
+}
+P_ROOT_SUBMIT='{"tool_input":{"command":"npx eas submit --platform ios"}}'
+
+# 116 a clean sibling app never vouches for a broken one. each app root is scanned on its own
+D="$(mk_pooled_mono)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+NCRIT="$(echo "$OUT" | grep -c '^ \[CRITICAL\] ')"
+[ "$RC" -eq 2 ] && [ "$NCRIT" -eq 2 ] && echo "$OUT" | grep -q 'MISSING-USAGE-DESCRIPTION' && echo "$OUT" | grep -q 'EXTERNAL-PAYMENT' && ok "612-1 sibling app cannot vouch for a broken app" || bad "612-1 sibling app cannot vouch for a broken app (rc=$RC criticals=$NCRIT)"
+echo "$OUT" | grep -q "^Project\. $D$" && [ "$(echo "$OUT" | grep -c '^App\. ')" -eq 2 ] && ok "612-2 monorepo report keeps the root Project line and adds one App section per root" || bad "612-2 monorepo report keeps the root Project line and adds one App section per root"
+# the findings sit under the app they belong to, never under the clean sibling
+APP_SECTION="$(echo "$OUT" | awk '/^App\. .*\/apps\/app$/{p=1;next} /^App\. /{p=0} p')"
+KIOSK_SECTION="$(echo "$OUT" | awk '/^App\. .*\/apps\/kiosk$/{p=1;next} /^App\. |^Summary\./{p=0} p')"
+echo "$APP_SECTION" | grep -q '\[CRITICAL\]' && ! echo "$KIOSK_SECTION" | grep -q '\[CRITICAL\]' && ok "612-3 findings sit under their own app section" || bad "612-3 findings sit under their own app section"
+rm -rf "$D"
+
+# 117 in hook mode the per-app report is buffered and a block goes to stderr in full
+D="$(mk_pooled_mono)"
+ERR="$(mktemp)"; STDOUT="$(printf '%s' "$P_ROOT_SUBMIT" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>"$ERR")"; RC=$?
+[ "$RC" -eq 2 ] && [ -z "$STDOUT" ] && [ "$(grep -c '^App\. ' "$ERR")" -eq 2 ] && grep -q 'BLOCKED' "$ERR" && ok "612-4 hook mode block carries both app sections on stderr" || bad "612-4 hook mode block carries both app sections on stderr (rc=$RC stdout=${#STDOUT})"
+rm -rf "$D" "$ERR"
+
+# 118 a leading cd into one app still scopes the scan to that app alone, no App sections
+D="$(mk_pooled_mono)"
+OUT="$(printf '%s' "$P_CD_REL" | CLAUDE_PROJECT_DIR="$D" bash "$GUARD" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. .*/apps/app$" && ! echo "$OUT" | grep -q '^App\. ' && [ "$RC" -eq 2 ] && ok "612-5 cd into an app scopes to that app with a plain report" || bad "612-5 cd into an app scopes to that app with a plain report (rc=$RC)"
+rm -rf "$D"
+
+# 119 an Xcode project six levels down is still an iOS target
+D="$(mk_deep_ios)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'Platforms\. iOS=1' && echo "$OUT" | grep -q 'MISSING-USAGE-DESCRIPTION' && [ "$RC" -eq 2 ] && ok "612-6 Xcode project seven levels down is detected as iOS" || bad "612-6 Xcode project seven levels down is detected as iOS (rc=$RC)"
+rm -rf "$D"
+
+# 120 an app's own ios/ and android/ folders are parts of that app, so a single-app project keeps the plain report
+D="$(mk_nested_native)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && echo "$OUT" | grep -q 'Platforms\. iOS=1 Android=1' && ok "612-7 nested ios and android folders never split one app" || bad "612-7 nested ios and android folders never split one app (rc=$RC)"
+rm -rf "$D"
+
+# 121 two native projects side by side each get their own section and their own platform line
+D="$(mk_two_native)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+[ "$(echo "$OUT" | grep -c '^App\. ')" -eq 2 ] && echo "$OUT" | grep -q 'GOOGLE-PERM-BACKGROUND-LOCATION' && echo "$OUT" | grep -q 'MISSING-USAGE-DESCRIPTION' && [ "$RC" -eq 2 ] && ok "612-8 side by side native projects are scanned separately" || bad "612-8 side by side native projects are scanned separately (rc=$RC)"
+IOS_SECTION="$(echo "$OUT" | awk '/^App\. .*\/ios-app$/{p=1;next} /^App\. |^Summary\./{p=0} p')"
+echo "$IOS_SECTION" | grep -q 'Platforms\. iOS=1 Android=0' && ok "612-9 each section reports its own platforms" || bad "612-9 each section reports its own platforms"
+rm -rf "$D"
+
+# 122 a Swift package library next to one app is not a second app. one root means the plain whole-tree report
+D="$(mk_app_plus_lib)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && [ "$RC" -eq 2 ] && ok "612-10 a library package never becomes an app section" || bad "612-10 a library package never becomes an app section (rc=$RC)"
+rm -rf "$D"
+
+# 123 a binary file is still skipped by the source scan
+D="$(mk_ios_clean)"
+printf 'fixed-odds\000\000betting\000' > "$D/App/blob.plist"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+! echo "$OUT" | grep -q 'GAMBLING' && [ "$RC" -eq 0 ] && ok "612-11 binary files never feed the source scan" || bad "612-11 binary files never feed the source scan (rc=$RC)"
+rm -rf "$D"
+
+# 124 a symbol in one file and its mitigation in another still pair up
+D="$(mk_ios_clean)"
+printf '<plist><dict><key>CFBundleURLSchemes</key><array><string>acme</string></array></dict></plist>' > "$D/App/Scheme.plist"
+printf 'let x = "https://acme.example.io/.well-known/apple-app-site-association"\n' > "$D/App/C.swift"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+! echo "$OUT" | grep -q 'UNSAFE-DEEPLINK' && [ "$RC" -eq 0 ] && ok "612-12 a mitigation in another file still pairs with its trigger" || bad "612-12 a mitigation in another file still pairs with its trigger (rc=$RC)"
+rm -rf "$D"
+
+# ===== Issue #612, second round. The adversarial review findings, pinned =====
+# The project root is itself an Expo app and a nested Expo app lives under it. The child must not vouch for the root.
+mk_root_app_plus_child() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/ios/App" "$d/apps/child/ios/Child"
+ printf '{"expo":{"name":"root"}}' > "$d/app.json"
+ printf '<plist><dict></dict></plist>' > "$d/ios/App/Info.plist"
+ printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$d/ios/App/A.swift"
+ printf '{"expo":{"name":"child"}}' > "$d/apps/child/app.json"
+ printf '<plist><dict><key>NSLocationWhenInUseUsageDescription</key><string>Show stores</string><key>ITSAppUsesNonExemptEncryption</key><false/></dict></plist>' > "$d/apps/child/ios/Child/Info.plist"
+ printf '%s' "$PLIST_EMPTY" > "$d/apps/child/ios/Child/PrivacyInfo.xcprivacy"
+ printf 'let policy="https://child.example.io/privacy-policy"\n' > "$d/apps/child/ios/Child/C.swift"
+ echo "$d"
+}
+# A native app at the root with a demo Xcode project nested under Examples. The demo is part of the repo, not a second app.
+mk_root_xcode_plus_demo() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/App.xcodeproj/project.xcworkspace" "$d/App" "$d/Examples/Demo.xcodeproj" "$d/Examples/Demo"
+ printf 'X=1;\n' > "$d/App.xcodeproj/project.pbxproj"
+ printf '<plist><dict></dict></plist>' > "$d/App/Info.plist"
+ printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$d/App/A.swift"
+ printf 'X=1;\n' > "$d/Examples/Demo.xcodeproj/project.pbxproj"
+ printf 'let demo = 1\n' > "$d/Examples/Demo/D.swift"
+ echo "$d"
+}
+# A stray Pods tree under a root ios folder must not make the root an app and re-pool two real apps.
+mk_pods_at_root() {
+ local d; d="$(mk_pooled_mono)"; mkdir -p "$d/ios/Pods/Foo.xcodeproj"
+ printf 'X=1;\n' > "$d/ios/Pods/Foo.xcodeproj/project.pbxproj"
+ echo "$d"
+}
+# A Heroku-style app.json in a tooling folder is not an app. One real app means the plain report.
+mk_heroku_json_sibling() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/apps/mobile/ios/App" "$d/tools/cli"
+ printf '{"expo":{"name":"mobile"}}' > "$d/apps/mobile/app.json"
+ printf '<plist><dict></dict></plist>' > "$d/apps/mobile/ios/App/Info.plist"
+ printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$d/apps/mobile/ios/App/A.swift"
+ printf '{"name":"cli","description":"a deploy manifest","stack":"heroku-22"}' > "$d/tools/cli/app.json"
+ printf 'console.log(1)\n' > "$d/tools/cli/index.js"
+ echo "$d"
+}
+# A Flutter package (pubspec, no platform folder) next to a Flutter app is a library. One app means the plain report.
+mk_flutter_pkg_sibling() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/apps/mobile/ios/Runner" "$d/apps/mobile/lib" "$d/packages/ui/lib"
+ printf 'name: mobile\ndependencies:\n permission_handler: ^11.0.0\n' > "$d/apps/mobile/pubspec.yaml"
+ printf "import 'package:permission_handler/permission_handler.dart';\nvoid main(){Permission.camera.request();}\n" > "$d/apps/mobile/lib/main.dart"
+ printf '<plist><dict></dict></plist>' > "$d/apps/mobile/ios/Runner/Info.plist"
+ printf 'name: ui\n' > "$d/packages/ui/pubspec.yaml"
+ printf 'class Ui {}\n' > "$d/packages/ui/lib/ui.dart"
+ echo "$d"
+}
+# Two bare native projects under the conventional names, nothing at the root. Each is its own app.
+mk_bare_ios_android() {
+ local d; d="$(mktemp -d)"; mkdir -p "$d/ios/App.xcodeproj" "$d/ios/App" "$d/android/app/src/main"
+ printf 'X=1;\n' > "$d/ios/App.xcodeproj/project.pbxproj"
+ printf '<plist><dict></dict></plist>' > "$d/ios/App/Info.plist"
+ printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$d/ios/App/A.swift"
+ printf "include ':app'\n" > "$d/android/settings.gradle"
+ printf '<manifest><uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/></manifest>' > "$d/android/app/src/main/AndroidManifest.xml"
+ echo "$d"
+}
+
+# 125 a nested clean app never vouches for the root app, and the root scan leaves the nested app out
+D="$(mk_root_app_plus_child)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+ROOT_SECTION="$(echo "$OUT" | awk -v r="App. $D" '$0==r{p=1;next} /^App\. /{p=0} p')"
+CHILD_SECTION="$(echo "$OUT" | awk '/^App\. .*\/apps\/child$/{p=1;next} /^App\. |^Summary\./{p=0} p')"
+[ "$RC" -eq 2 ] && [ "$(echo "$OUT" | grep -c '^App\. ')" -eq 2 ] && echo "$ROOT_SECTION" | grep -q 'MISSING-USAGE-DESCRIPTION' && ! echo "$CHILD_SECTION" | grep -q '\[CRITICAL\]' && ok "612-13 root app plus nested app are scanned apart" || bad "612-13 root app plus nested app are scanned apart (rc=$RC)"
+rm -rf "$D"
+
+# 126 a demo Xcode project nested under a root native app stays part of that app. documented, pinned
+D="$(mk_root_xcode_plus_demo)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && [ "$RC" -eq 2 ] && ok "612-14 a nested demo Xcode project never splits a root native app" || bad "612-14 a nested demo Xcode project never splits a root native app (rc=$RC)"
+rm -rf "$D"
+
+# 127 a Pods tree under a root ios folder cannot make the root an app
+D="$(mk_pods_at_root)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+[ "$(echo "$OUT" | grep -c '^App\. ')" -eq 2 ] && [ "$RC" -eq 2 ] && ok "612-15 Pods under a root ios folder never re-pool the apps" || bad "612-15 Pods under a root ios folder never re-pool the apps (rc=$RC sections=$(echo "$OUT" | grep -c '^App\. '))"
+rm -rf "$D"
+
+# 128 an app.json that is not Expo or React Native is not an app
+D="$(mk_heroku_json_sibling)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && [ "$RC" -eq 2 ] && ok "612-16 a Heroku app.json never becomes an app section" || bad "612-16 a Heroku app.json never becomes an app section (rc=$RC)"
+rm -rf "$D"
+
+# 129 a Flutter package without a platform folder is a library, not an app
+D="$(mk_flutter_pkg_sibling)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && ok "612-17 a Flutter package never becomes an app section" || bad "612-17 a Flutter package never becomes an app section (rc=$RC)"
+rm -rf "$D"
+
+# 130 two bare native projects under ios/ and android/ with nothing at the root are two apps
+D="$(mk_bare_ios_android)"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+[ "$(echo "$OUT" | grep -c '^App\. ')" -eq 2 ] && echo "$OUT" | grep -q 'GOOGLE-PERM-BACKGROUND-LOCATION' && echo "$OUT" | grep -q 'MISSING-USAGE-DESCRIPTION' && [ "$RC" -eq 2 ] && ok "612-18 bare ios and android projects side by side are two apps" || bad "612-18 bare ios and android projects side by side are two apps (rc=$RC)"
+rm -rf "$D"
+
+# 131 the deadline section cannot be skipped from the environment
+D="$(mk_ios_clean)"
+OUT="$(DEADLINE_DONE=1 bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'Regulatory Compliance Deadline Status' && ok "612-19 DEADLINE_DONE from the environment is ignored" || bad "612-19 DEADLINE_DONE from the environment is ignored (rc=$RC)"
+rm -rf "$D"
+
+# 132 a project path with a space still splits into its apps
+B="$(mktemp -d)"; D="$B/my app"; mkdir -p "$D"; SRC="$(mk_pooled_mono)"; cp -R "$SRC"/. "$D"/; rm -rf "$SRC"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+[ "$(echo "$OUT" | grep -c '^App\. ')" -eq 2 ] && [ "$RC" -eq 2 ] && ok "612-20 a path with a space still splits into apps" || bad "612-20 a path with a space still splits into apps (rc=$RC)"
+rm -rf "$B"
+
+# 133 a truncated blob falls back to the per-file scan instead of passing silently
+D="$(mk_ios_bad)"
+OUT="$( ( ulimit -f 1; bash "$GUARD" "$D" 2>&1 ) )"; RC=$?
+echo "$OUT" | grep -q 'MISSING-USAGE-DESCRIPTION' && [ "$RC" -eq 2 ] && ok "612-21 a blob that cannot be written falls back and still blocks" || bad "612-21 a blob that cannot be written falls back and still blocks (rc=$RC)"
+rm -rf "$D"
+
+# 134 a multi-app scan leaves no temp files behind
+D="$(mk_pooled_mono)"; T="$(mktemp -d)"
+TMPDIR="$T" bash "$GUARD" "$D" >/dev/null 2>&1
+[ -z "$(ls -A "$T")" ] && ok "612-22 a multi-app scan leaves no temp files" || bad "612-22 a multi-app scan leaves no temp files ($(ls -A "$T" | wc -l | tr -d ' ') left)"
+rm -rf "$D" "$T"
+
+# 135 a workspace inside an Xcode project bundle never becomes an app of its own
+D="$(mk_ios_precision_safe)"; mkdir -p "$D/App.xcodeproj/project.xcworkspace"; printf '<Workspace/>' > "$D/App.xcodeproj/project.xcworkspace/contents.xcworkspacedata"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && [ "$RC" -eq 0 ] && ok "612-23 a workspace inside the project bundle never splits the app" || bad "612-23 a workspace inside the project bundle never splits the app (rc=$RC)"
+rm -rf "$D"
+
+# ===== Issue #612, third round. Second adversarial review, pinned =====
+# 136 a trailing slash on the project path still keeps the nested app out of the root scan
+D="$(mk_root_app_plus_child)"
+OUT="$(bash "$GUARD" "$D/" 2>&1)"; RC=$?
+ROOT_SECTION="$(echo "$OUT" | awk -v r="App. $D/" '$0==r{p=1;next} /^App\. /{p=0} p')"
+[ "$RC" -eq 2 ] && echo "$ROOT_SECTION" | grep -q 'MISSING-USAGE-DESCRIPTION' && ok "612-24 a trailing slash on the project path changes nothing" || bad "612-24 a trailing slash on the project path changes nothing (rc=$RC)"
+rm -rf "$D"
+
+# 137 a nested app's privacy manifest never vouches for the root app
+D="$(mk_root_app_plus_child)"
+printf 'let d = UserDefaults.standard\n' > "$D/ios/App/B.swift"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+ROOT_SECTION="$(echo "$OUT" | awk -v r="App. $D" '$0==r{p=1;next} /^App\. /{p=0} p')"
+echo "$ROOT_SECTION" | grep -q 'APPLE-PRIVACY-MANIFEST-MISSING' && ok "612-25 a nested app's privacy manifest never vouches for the root" || bad "612-25 a nested app's privacy manifest never vouches for the root (rc=$RC)"
+rm -rf "$D"
+
+# 138 a nested app's release minification never vouches for the root Android app
+D="$(mktemp -d)"; mkdir -p "$D/android/app/src/main" "$D/apps/child/android/app/src/main"
+printf '{"expo":{"name":"root"}}' > "$D/app.json"
+printf "include ':app'\n" > "$D/android/settings.gradle"
+printf 'android { buildTypes { release { minifyEnabled false } } }\n' > "$D/android/app/build.gradle"
+printf '<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>' > "$D/android/app/src/main/AndroidManifest.xml"
+printf '{"expo":{"name":"child"}}' > "$D/apps/child/app.json"
+printf "include ':app'\n" > "$D/apps/child/android/settings.gradle"
+printf 'android { buildTypes { release { minifyEnabled true } } }\n' > "$D/apps/child/android/app/build.gradle"
+printf '<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>' > "$D/apps/child/android/app/src/main/AndroidManifest.xml"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+ROOT_SECTION="$(echo "$OUT" | awk -v r="App. $D" '$0==r{p=1;next} /^App\. /{p=0} p')"
+echo "$ROOT_SECTION" | grep -q 'ANDROID-R8-OPTIMIZATION-MISSING' && ok "612-26 a nested app's minification never vouches for the root" || bad "612-26 a nested app's minification never vouches for the root (rc=$RC)"
+rm -rf "$D"
+
+# 139 a Flutter plugin has platform folders and is still a library
+D="$(mktemp -d)"; mkdir -p "$D/apps/mobile/ios/App" "$D/packages/camera_plugin/ios/Classes"
+printf '{"expo":{"name":"mobile"}}' > "$D/apps/mobile/app.json"
+printf '<plist><dict></dict></plist>' > "$D/apps/mobile/ios/App/Info.plist"
+printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$D/apps/mobile/ios/App/A.swift"
+printf 'name: camera_plugin\nflutter:\n plugin:\n platforms:\n ios:\n pluginClass: CameraPlugin\n' > "$D/packages/camera_plugin/pubspec.yaml"
+printf 'final class CameraPlugin {}\n' > "$D/packages/camera_plugin/ios/Classes/CameraPlugin.swift"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && [ "$RC" -eq 2 ] && ok "612-27 a Flutter plugin never becomes an app section" || bad "612-27 a Flutter plugin never becomes an app section (rc=$RC)"
+rm -rf "$D"
+
+# 140 a source file that ends with the old static marker text cannot forge a complete blob
+D="$(mktemp -d)"; mkdir -p "$D/App"
+printf '<plist><dict></dict></plist>' > "$D/App/Info.plist"
+printf '%*s%s' 494 '' '~~ascg~blob~end~~' > "$D/App/a.swift"
+printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$D/App/z.swift"
+OUT="$( ( ulimit -f 1; bash "$GUARD" "$D" 2>&1 ) )"; RC=$?
+echo "$OUT" | grep -q 'MISSING-USAGE-DESCRIPTION' && [ "$RC" -eq 2 ] && ok "612-28 a forged end marker never certifies a truncated blob" || bad "612-28 a forged end marker never certifies a truncated blob (rc=$RC)"
+rm -rf "$D"
+
+# 141 an app eleven levels down is still detected, and the tree is scanned in one piece
+D="$(mktemp -d)"; P="$D/a/b/c/d/e/f/g/h/i/ios"; mkdir -p "$P/Acme.xcodeproj" "$P/Acme"
+printf 'X=1;\n' > "$P/Acme.xcodeproj/project.pbxproj"
+printf '<plist><dict></dict></plist>' > "$P/Acme/Info.plist"
+printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$P/Acme/A.swift"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'Platforms\. iOS=1' && [ "$RC" -eq 2 ] && ok "612-29 an app eleven levels down is detected" || bad "612-29 an app eleven levels down is detected (rc=$RC)"
+rm -rf "$D"
+
+# 142 an Android app with no Gradle file at all still gets the R8 finding, as it always did
+D="$(mktemp -d)"; mkdir -p "$D/android/app/src/main"
+printf '<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>' > "$D/android/app/src/main/AndroidManifest.xml"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'ANDROID-R8-OPTIMIZATION-MISSING' && ok "612-30 no Gradle file still means the R8 finding" || bad "612-30 no Gradle file still means the R8 finding (rc=$RC)"
+rm -rf "$D"
+
+# ===== Issue #612, fourth round. Third adversarial review, pinned =====
+# 143 a nested app whose name carries glob characters is still kept out of the root scan
+D="$(mktemp -d)"; mkdir -p "$D/ios/App" "$D/apps/[child]/ios/Child"
+printf '{"expo":{"name":"root"}}' > "$D/app.json"
+printf '<plist><dict></dict></plist>' > "$D/ios/App/Info.plist"
+printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$D/ios/App/A.swift"
+printf '{"expo":{"name":"child"}}' > "$D/apps/[child]/app.json"
+printf '<plist><dict><key>NSLocationWhenInUseUsageDescription</key><string>Stores</string></dict></plist>' > "$D/apps/[child]/ios/Child/Info.plist"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+ROOT_SECTION="$(echo "$OUT" | awk -v r="App. $D" '$0==r{p=1;next} /^App\. /{p=0} p')"
+echo "$ROOT_SECTION" | grep -q 'MISSING-USAGE-DESCRIPTION' && [ "$RC" -eq 2 ] && ok "612-31 a nested app named with brackets is still pruned from the root scan" || bad "612-31 a nested app named with brackets is still pruned from the root scan (rc=$RC)"
+rm -rf "$D"
+
+# 144 a Flutter plugin with an android folder under a root app is part of the repo, never a second app
+D="$(mktemp -d)"; mkdir -p "$D/ios/App" "$D/packages/plugin/android/src/main"
+printf '{"expo":{"name":"root"}}' > "$D/app.json"
+printf '<plist><dict></dict></plist>' > "$D/ios/App/Info.plist"
+printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$D/ios/App/A.swift"
+printf 'name: plugin\nflutter:\n plugin:\n platforms:\n android:\n package: com.example.plugin\n' > "$D/packages/plugin/pubspec.yaml"
+printf '<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>' > "$D/packages/plugin/android/src/main/AndroidManifest.xml"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && [ "$RC" -eq 2 ] && ok "612-32 a Flutter plugin's android folder never becomes an app" || bad "612-32 a Flutter plugin's android folder never becomes an app (rc=$RC)"
+rm -rf "$D"
+
+# 145 two Android app modules with no settings file are two apps, and the clean one never vouches
+D="$(mktemp -d)"; mkdir -p "$D/apps/a/app/src/main" "$D/apps/b/app/src/main"
+printf "plugins { id 'com.android.application' }\nandroid { buildTypes { release { minifyEnabled false } } }\n" > "$D/apps/a/app/build.gradle"
+printf "plugins { id 'com.android.application' }\nandroid { buildTypes { release { minifyEnabled true } } }\n" > "$D/apps/b/app/build.gradle"
+printf '<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>' > "$D/apps/a/app/src/main/AndroidManifest.xml"
+printf '<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>' > "$D/apps/b/app/src/main/AndroidManifest.xml"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+A_SECTION="$(echo "$OUT" | awk '/^App\. .*\/apps\/a\/app$/{p=1;next} /^App\. |^Summary\./{p=0} p')"
+[ "$(echo "$OUT" | grep -c '^App\. ')" -eq 2 ] && echo "$A_SECTION" | grep -q 'ANDROID-R8-OPTIMIZATION-MISSING' && ok "612-33 Android app modules without a settings file are two apps" || bad "612-33 Android app modules without a settings file are two apps (rc=$RC sections=$(echo "$OUT" | grep -c '^App\. '))"
+rm -rf "$D"
+
+# 146 a React Native native module (peerDependencies, an android folder, no app config) next to one app is a library
+D="$(mktemp -d)"; mkdir -p "$D/apps/mobile/ios/App" "$D/packages/rn-lib/android/src/main"
+printf '{"expo":{"name":"mobile"}}' > "$D/apps/mobile/app.json"
+printf '<plist><dict></dict></plist>' > "$D/apps/mobile/ios/App/Info.plist"
+printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$D/apps/mobile/ios/App/A.swift"
+printf '{"name":"rn-lib","peerDependencies":{"react-native":"*"}}' > "$D/packages/rn-lib/package.json"
+printf "plugins { id 'com.android.library' }\nandroid { }\n" > "$D/packages/rn-lib/android/build.gradle"
+printf '<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>' > "$D/packages/rn-lib/android/src/main/AndroidManifest.xml"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && [ "$RC" -eq 2 ] && ok "612-34 a React Native module never becomes an app section" || bad "612-34 a React Native module never becomes an app section (rc=$RC)"
+rm -rf "$D"
+
+# ===== Issue #612, fifth round. Hook-contract persona findings, pinned =====
+# 147 a manifest inside a test fixture directory never becomes an app root
+D="$(mk_ios_bad)"; mkdir -p "$D/__tests__/fixtures/android/app/src/main"
+printf '<manifest><uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/></manifest>' > "$D/__tests__/fixtures/android/app/src/main/AndroidManifest.xml"
+printf "plugins { id 'com.android.application' }\n" > "$D/__tests__/fixtures/android/app/build.gradle"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+echo "$OUT" | grep -q "^Project\. $D$" && ! echo "$OUT" | grep -q '^App\. ' && ! echo "$OUT" | grep -q 'BACKGROUND-LOCATION' && ok "612-35 a test fixture never becomes an app root" || bad "612-35 a test fixture never becomes an app root (rc=$RC)"
+rm -rf "$D"
+
+# 148 a project path that is a symlink is scanned through its target instead of passing silently
+REAL="$(mk_ios_bad)"; LINK="$(mktemp -d)/link"; ln -s "$REAL" "$LINK"
+OUT="$(bash "$GUARD" "$LINK" 2>&1)"; RC=$?
+echo "$OUT" | grep -q 'MISSING-USAGE-DESCRIPTION' && [ "$RC" -eq 2 ] && ok "612-36 a symlinked project path is scanned" || bad "612-36 a symlinked project path is scanned (rc=$RC)"
+rm -rf "$REAL" "$(dirname "$LINK")"
+
+# 149 an app whose package.json carries a peer dependency is still an app when it owns its platform projects
+D="$(mktemp -d)"; mkdir -p "$D/apps/peer/ios/App.xcodeproj" "$D/apps/peer/ios/App" "$D/apps/peer/android/app/src/main" "$D/apps/other/ios/Other"
+printf '{"dependencies":{"react-native":"0.75.0"},"peerDependencies":{"react":"18.0.0"}}' > "$D/apps/peer/package.json"
+printf 'X=1;\n' > "$D/apps/peer/ios/App.xcodeproj/project.pbxproj"
+printf '<plist><dict></dict></plist>' > "$D/apps/peer/ios/App/Info.plist"
+printf 'import CoreLocation\nlet m=CLLocationManager()\n' > "$D/apps/peer/ios/App/A.swift"
+printf "include ':app'\n" > "$D/apps/peer/android/settings.gradle"
+printf '<manifest xmlns:android="http://schemas.android.com/apk/res/android"></manifest>' > "$D/apps/peer/android/app/src/main/AndroidManifest.xml"
+printf '{"expo":{"name":"other"}}' > "$D/apps/other/app.json"
+printf '<plist><dict></dict></plist>' > "$D/apps/other/ios/Other/Info.plist"
+OUT="$(bash "$GUARD" "$D" 2>&1)"; RC=$?
+[ "$(echo "$OUT" | grep -c '^App\. ')" -eq 2 ] && [ "$RC" -eq 2 ] && ok "612-37 an app with a peer dependency and its own platform projects is an app" || bad "612-37 an app with a peer dependency and its own platform projects is an app (rc=$RC sections=$(echo "$OUT" | grep -c '^App\. '))"
+rm -rf "$D"
+
echo ""
echo "app-store-compliance-guard-test: $PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ]
diff --git a/agent-os/hooks/app-store-compliance-guard.sh b/agent-os/hooks/app-store-compliance-guard.sh
index c48e089..1facad3 100755
--- a/agent-os/hooks/app-store-compliance-guard.sh
+++ b/agent-os/hooks/app-store-compliance-guard.sh
@@ -10,10 +10,10 @@ HOOK_LOG="$HOME/.claude/hooks/hook-log.sh"
[ -f "$HOOK_LOG" ] && source "$HOOK_LOG" 2>/dev/null || true
log_err() { if type hlog_error >/dev/null 2>&1; then hlog_error "app-store-compliance-guard" "$@"; else echo "app-store-compliance-guard: $*" >&2; fi; }
-CRIT=0; HIGH=0; MED=0
+CRIT=0; HIGH=0; MED=0; DEADLINE_DONE=0
FILELIST=""
REPORT=""; REPORT_DEGRADED=0
-cleanup() { [ -n "$FILELIST" ] && rm -f "$FILELIST" 2>/dev/null; [ -n "$REPORT" ] && rm -f "$REPORT" 2>/dev/null; true; }
+cleanup() { [ -n "$FILELIST" ] && rm -f "$FILELIST" "$FILELIST.blob" "$FILELIST.manifest" 2>/dev/null; [ -n "$REPORT" ] && rm -f "$REPORT" 2>/dev/null; true; }
trap cleanup EXIT
# ----- resolve mode and project dir -----
@@ -138,30 +138,22 @@ fi
[ -z "$DIR" ] && DIR="$PWD"
[ -d "$DIR" ] || { log_err "project dir not found. $DIR"; exit 0; }
+[ -L "${DIR%/}" ] && DIR="$(cd "$DIR" 2>/dev/null && pwd -P)" # find never descends a symlinked start point (issue #612)
-# ----- build a source file list, excluding vendor dirs -----
-# Directories are pruned by name, and only below the project root (-mindepth 1). The old full-path
-# match also hit the folders ABOVE the root, so a project sitting under a folder named build was
-# scanned as empty, and it still walked every excluded tree. Test code, Python virtualenvs, and
-# bundled web output (dist) never ship in the binary, and a virtualenv's vendored JSON otherwise
-# reads as app source. .xcprivacy is scanned because NSPrivacyCollectedDataTypes lives there.
-FILELIST="$(mktemp 2>/dev/null || echo /tmp/ascg.$$)"
-find "$DIR" -mindepth 1 \
- \( -type d \( -name node_modules -o -name Pods -o -name .git -o -name build -o \( -name dist -not -path '*/src/dist' \) \
- -o -name DerivedData -o -name vendor -o -name .dart_tool -o -name Carthage \
- -o -name '*Tests' -o -name androidTest -o -name __tests__ -o -name test -o -name tests \
- -o -name integration_test -o -name .venv -o -name venv -o -name site-packages -o -name .pub-cache \) -prune \) \
- -o -type f \( \
- -name '*.swift' -o -name '*.m' -o -name '*.h' -o -name '*.kt' -o -name '*.java' \
- -o -name '*.xml' -o -name '*.plist' -o -name '*.gradle' -o -name '*.kts' \
- -o -name '*.json' -o -name '*.js' -o -name '*.jsx' -o -name '*.ts' -o -name '*.tsx' \
- -o -name '*.dart' -o -name '*.xcconfig' -o -name '*.yaml' -o -name '*.yml' \
- -o -name '*.pbxproj' -o -name '*.entitlements' -o -name '*.html' -o -name '*.xcprivacy' \
- \) -print 2>/dev/null \
- > "$FILELIST"
-
-grep_has() { # 0 if regex found in any source file
+# Every text file once, into one blob, so a hundred grep_has calls read one file instead of every file
+# each (issue #612). The empty pattern keeps every line, -I drops binaries as before, the end marker proves a complete write.
+BLOB_END="~~ascg~blob~end~$$~${RANDOM}~~"
+build_blob() {
+ BLOB_OK=0
+ : > "$FILELIST.blob" 2>/dev/null || return 0
+ [ -s "$FILELIST" ] || { BLOB_OK=1; return 0; }
+ tr '\n' '\0' < "$FILELIST" | xargs -0 grep -EIh -e '' >> "$FILELIST.blob" 2>/dev/null
+ printf '\n%s\n' "$BLOB_END" >> "$FILELIST.blob" 2>/dev/null
+ [ "$(tail -n 1 "$FILELIST.blob" 2>/dev/null)" = "$BLOB_END" ] && BLOB_OK=1
+}
+grep_has() { # 0 if regex found in any source file. Per-line regex, so the blob answers the same as a per-file grep
[ -s "$FILELIST" ] || return 1
+ if [ "${BLOB_OK:-0}" -eq 1 ]; then grep -Eqs -e "$1" "$FILELIST.blob" 2>/dev/null; return; fi
local out
out="$(tr '\n' '\0' < "$FILELIST" | xargs -0 grep -EIls -e "$1" 2>/dev/null | head -1)"
[ -n "$out" ]
@@ -222,58 +214,73 @@ find_app() { # find_app <maxdepth> <find name expression...>
local depth="$1"; shift
find "$DIR" -mindepth 1 -maxdepth "$depth" \
\( -type d \( -name node_modules -o -name Pods -o -name .git -o -name build -o \( -name dist -not -path '*/src/dist' \) \
- -o -name DerivedData -o -name vendor -o -name .dart_tool -o -name Carthage -o -name .pub-cache \) -prune \) \
+ -o -name DerivedData -o -name vendor -o -name .dart_tool -o -name Carthage -o -name .pub-cache \
+ ${NESTED_PRUNE[@]+"${NESTED_PRUNE[@]}"} \) -prune \) \
-o \( "$@" \) -print 2>/dev/null
}
+NESTED_PRUNE=()
+find_tree() { # find "$DIR" <expr>, the whole tree as before, minus the nested app roots when the root is itself an app
+ if [ "${#NESTED_PRUNE[@]}" -eq 0 ]; then find "$DIR" "$@" 2>/dev/null
+ else find "$DIR" \( -type d \( -name '' "${NESTED_PRUNE[@]}" \) -prune \) -o "$@" 2>/dev/null; fi
+}
+FILELIST="$(mktemp 2>/dev/null || echo /tmp/ascg.$$)"
+
+# ----- the scan of one tree (issue #612). Runs once per app root, or once on the project root -----
+scan_tree() {
+
+# ----- build a source file list, excluding vendor dirs -----
+# Directories are pruned by name, and only below the project root (-mindepth 1). The old full-path
+# match also hit the folders ABOVE the root, so a project sitting under a folder named build was
+# scanned as empty, and it still walked every excluded tree. Test code, Python virtualenvs, and
+# bundled web output (dist) never ship in the binary, and a virtualenv's vendored JSON otherwise
+# reads as app source. .xcprivacy is scanned because NSPrivacyCollectedDataTypes lives there.
+find "$DIR" -mindepth 1 \
+ \( -type d \( -name node_modules -o -name Pods -o -name .git -o -name build -o \( -name dist -not -path '*/src/dist' \) \
+ -o -name DerivedData -o -name vendor -o -name .dart_tool -o -name Carthage \
+ -o -name '*Tests' -o -name androidTest -o -name __tests__ -o -name test -o -name tests \
+ -o -name integration_test -o -name .venv -o -name venv -o -name site-packages -o -name .pub-cache \
+ ${NESTED_PRUNE[@]+"${NESTED_PRUNE[@]}"} \) -prune \) \
+ -o -type f \( \
+ -name '*.swift' -o -name '*.m' -o -name '*.h' -o -name '*.kt' -o -name '*.java' \
+ -o -name '*.xml' -o -name '*.plist' -o -name '*.gradle' -o -name '*.kts' \
+ -o -name '*.json' -o -name '*.js' -o -name '*.jsx' -o -name '*.ts' -o -name '*.tsx' \
+ -o -name '*.dart' -o -name '*.xcconfig' -o -name '*.yaml' -o -name '*.yml' \
+ -o -name '*.pbxproj' -o -name '*.entitlements' -o -name '*.html' -o -name '*.xcprivacy' \
+ \) -print 2>/dev/null \
+ > "$FILELIST"
+build_blob
# ----- platform detection -----
# Every find below pipes into `grep .`, never `grep -q .`, for the reason in release_string_has:
# grep -q exits on the first match, find dies of SIGPIPE, and pipefail turns "found" into "missing".
-IS_IOS=0; IS_AND=0; IS_WEB=0
-find_app 4 -name '*.xcodeproj' -o -name '*.xcworkspace' -o -name 'Package.swift' -o -name 'Podfile' | grep . >/dev/null && IS_IOS=1
-find_app 4 -name 'Info.plist' | grep . >/dev/null && IS_IOS=1
-find_app 5 -name 'AndroidManifest.xml' -o -name 'build.gradle' -o -name 'build.gradle.kts' | grep . >/dev/null && IS_AND=1
-find_app 4 -name 'package.json' -o -name 'index.html' -o -name 'webpack.config.js' -o -name 'next.config.js' | grep . >/dev/null && IS_WEB=1
+IS_IOS=0; IS_AND=0; IS_WEB=0 # depth 12, the reach of the manifest probe. depth 4 left packages/mobile/app/ios invisible (issue #612)
+find_app 12 -name '*.xcodeproj' -o -name '*.xcworkspace' -o -name 'Package.swift' -o -name 'Podfile' | grep . >/dev/null && IS_IOS=1
+find_app 12 -name 'Info.plist' | grep . >/dev/null && IS_IOS=1
+find_app 12 -name 'AndroidManifest.xml' -o -name 'build.gradle' -o -name 'build.gradle.kts' | grep . >/dev/null && IS_AND=1
+find_app 12 -name 'package.json' -o -name 'index.html' -o -name 'webpack.config.js' -o -name 'next.config.js' | grep . >/dev/null && IS_WEB=1
# ----- cross-platform framework detection -----
# IS_IOS/IS_AND above still fire on the built artifact. This adds framework-specific checks.
IS_FLUTTER=0; IS_RN=0; IS_IONIC=0
-find_app 4 -name 'pubspec.yaml' | grep . >/dev/null && IS_FLUTTER=1
+find_app 12 -name 'pubspec.yaml' | grep . >/dev/null && IS_FLUTTER=1
# Scan EVERY package.json within depth (not just the first), so a monorepo root's tooling
# package.json never shadows a real apps/mobile/package.json deeper in the tree.
while IFS= read -r pkg; do
grep -qE '"react-native"|"expo"' "$pkg" 2>/dev/null && IS_RN=1
grep -qE '"@capacitor/core"|"@capacitor/ios"|"@capacitor/android"|"@ionic/(angular|react|vue)"|"cordova-android"|"cordova-ios"' "$pkg" 2>/dev/null && IS_IONIC=1
-done < <(find "$DIR" -maxdepth 4 -name 'package.json' 2>/dev/null | grep -vE '/(node_modules|ios/Pods)/')
-find_app 4 -name 'capacitor.config.*' | grep . >/dev/null && IS_IONIC=1
+done < <(find_app 12 -name 'package.json' | grep -vE '/(node_modules|ios/Pods)/')
+find_app 12 -name 'capacitor.config.*' | grep . >/dev/null && IS_IONIC=1
# config.xml alone is ambiguous (Maven/NuGet/tooling also use that filename), so require the
# Cordova widget marker before it counts as a signal.
while IFS= read -r cfg; do
grep -qE '<widget|xmlns:cdv' "$cfg" 2>/dev/null && IS_IONIC=1
-done < <(find "$DIR" -maxdepth 4 -name 'config.xml' 2>/dev/null)
+done < <(find_app 12 -name 'config.xml')
# The actual gate the framework checks below use: a committed ios/ folder AND the
# invoking command (when known) does not explicitly target Android-only.
IOS_TARGET_ACTIVE=0
[ "$IS_IOS" -eq 1 ] && [ "$CMD_TARGET_ANDROID_ONLY" -eq 0 ] && IOS_TARGET_ACTIVE=1
-# ----- report routing (issue #610). Hook mode buffers the report. A block goes to stderr, the only
-# stream Claude Code shows on exit 2. A pass stays on stdout. Standalone mode prints straight to stdout.
-emit_report() { # $1 is the exit code about to be returned
- [ -n "$REPORT" ] || return 0
- exec 1>&3 3>&-
- if [ "$1" -eq 2 ]; then cat "$REPORT" >&2; else cat "$REPORT"; fi
- rm -f "$REPORT" 2>/dev/null; REPORT=""
-}
-# A hook timeout sends TERM. Flush what was buffered to stderr so the partial report is not lost.
-trap 'emit_report 2; exit 143' INT TERM HUP
-if [ -n "$STDIN_JSON" ]; then
- REPORT="$(mktemp 2>/dev/null)" || REPORT=""
- if [ -n "$REPORT" ] && : >"$REPORT" 2>/dev/null; then exec 3>&1; exec >"$REPORT"; else REPORT=""; REPORT_DEGRADED=1; fi
-fi
-
-echo "== App Store Compliance Guard =="
-echo "Project. $DIR"
echo "Platforms. iOS=$IS_IOS Android=$IS_AND Web=$IS_WEB"
echo "Frameworks. Flutter=$IS_FLUTTER ReactNative/Expo=$IS_RN Ionic/Capacitor/Cordova=$IS_IONIC"
[ "$CMD_TARGET_ANDROID_ONLY" -eq 1 ] && echo "Command targets Android only. Apple-only framework checks suppressed for this run."
@@ -288,10 +295,11 @@ for candidate in \
"$HOOK_DIR/../skills/app-store-compliance/scripts/deadline-checker.py"; do
if [ -f "$candidate" ]; then DEADLINE_PY="$candidate"; break; fi
done
-if [ -n "$DEADLINE_PY" ]; then
+if [ -n "$DEADLINE_PY" ] && [ "${DEADLINE_DONE:-0}" -eq 0 ]; then
python3 "$DEADLINE_PY"
echo ""
fi
+DEADLINE_DONE=1
# ===== shared checks =====
# App Store Connect API 4.3 and 4.4 removed the old age-rating declaration endpoints. a pipeline that still calls them stops the release.
@@ -325,7 +333,7 @@ fi
# iOS-only Apple requirement, gated on IS_IOS so an Android-only build is never blocked for it.
if [ "$IS_FLUTTER" -eq 1 ]; then
if [ "$IOS_TARGET_ACTIVE" -eq 1 ] && grep_has 'permission_handler|image_picker|geolocator|device_info_plus|package_info_plus|shared_preferences|sqflite|firebase_'; then
- if ! find "$DIR" -name 'PrivacyInfo.xcprivacy' 2>/dev/null | grep . >/dev/null; then
+ if ! find_tree -name 'PrivacyInfo.xcprivacy' -print | grep . >/dev/null; then
finding critical "FLUTTER-PRIVACY-MANIFEST-MISSING" "Flutter plugins that touch required-reason APIs but no PrivacyInfo.xcprivacy anywhere in the project" "Add an app-level PrivacyInfo.xcprivacy AND confirm each Flutter plugin ships its own (permission_handler, image_picker, and most first-party plugins added theirs from Flutter 3.19+). A missing plugin-level manifest is invisible to Apple's aggregator unless the app manifest also declares that plugin's reason codes. This check only runs against an iOS target."
fi
fi
@@ -343,7 +351,7 @@ if [ "$IS_RN" -eq 1 ] && [ "$IOS_TARGET_ACTIVE" -eq 1 ]; then
fi
fi
if grep_has 'Firebase|@react-native-firebase|expo-file-system|expo-application|AsyncStorage|@react-native-async-storage'; then
- if ! find "$DIR" -name 'PrivacyInfo.xcprivacy' 2>/dev/null | grep . >/dev/null; then
+ if ! find_tree -name 'PrivacyInfo.xcprivacy' -print | grep . >/dev/null; then
finding critical "RN-PRIVACY-MANIFEST-MISSING" "React Native native modules that touch required-reason APIs but no PrivacyInfo.xcprivacy anywhere" "Add an app-level PrivacyInfo.xcprivacy. Native modules bundled transitively via JS deps (analytics, storage, device-info libraries) each need their own manifest aggregated in the final IPA; this is easy to miss because the dependency is JS-side."
fi
fi
@@ -361,7 +369,7 @@ if [ "$IS_IONIC" -eq 1 ] && [ "$IOS_TARGET_ACTIVE" -eq 1 ]; then
finding critical "IONIC-UIWEBVIEW-DEPRECATED" "Deprecated UIWebView symbol referenced (directly or via a stale plugin)" "Apple auto-rejects (ITMS-90809) any binary statically linking UIWebView. Update every Capacitor/Cordova plugin to a version using WKWebView; a stale plugin can pull this in even when app code never references it."
fi
if grep_has '@capacitor/|Capacitor\.'; then
- if ! find "$DIR" -name 'PrivacyInfo.xcprivacy' 2>/dev/null | grep . >/dev/null; then
+ if ! find_tree -name 'PrivacyInfo.xcprivacy' -print | grep . >/dev/null; then
finding high "IONIC-PRIVACY-MANIFEST-MISSING" "Capacitor/Cordova plugins present but no PrivacyInfo.xcprivacy" "Capacitor plugin manifest support is less standardized than Flutter's; verify each plugin wrapping a native SDK (camera, geolocation, ads) ships PrivacyInfo.xcprivacy, and add the app-level one."
fi
fi
@@ -439,7 +447,7 @@ if [ "$IS_IOS" -eq 1 ]; then
fi
# Privacy manifest, the top modern Apple upload rejection since 2024
if grep_has 'Firebase|Alamofire|UserDefaults|systemUptime|FileManager\.default|ProcessInfo'; then
- if ! find "$DIR" -name 'PrivacyInfo.xcprivacy' 2>/dev/null | grep . >/dev/null; then
+ if ! find_tree -name 'PrivacyInfo.xcprivacy' -print | grep . >/dev/null; then
finding critical "APPLE-PRIVACY-MANIFEST-MISSING" "Required reason APIs or SDKs present but no PrivacyInfo.xcprivacy" "Add a privacy manifest with approved reason codes and tracking domains, and confirm each SDK ships its signed manifest."
fi
fi
@@ -459,7 +467,8 @@ if [ "$IS_IOS" -eq 1 ]; then
\( -type d \( -name node_modules -o -name Pods -o -name .git -o -name build -o \( -name dist -not -path '*/src/dist' \) \
-o -name DerivedData -o -name vendor -o -name .dart_tool -o -name Carthage \
-o -name '*Tests' -o -name androidTest -o -name __tests__ -o -name test -o -name tests \
- -o -name integration_test -o -name .venv -o -name venv -o -name site-packages -o -name .pub-cache \) -prune \) \
+ -o -name integration_test -o -name .venv -o -name venv -o -name site-packages -o -name .pub-cache \
+ ${NESTED_PRUNE[@]+"${NESTED_PRUNE[@]}"} \) -prune \) \
-o -name 'PrivacyInfo.xcprivacy' -print 2>/dev/null \
| while IFS= read -r manifest; do
python3 "$MANIFEST_VALIDATOR" "$manifest" 2>/dev/null
@@ -569,7 +578,11 @@ if [ "$IS_AND" -eq 1 ]; then
finding high "GOOGLE-GENAI-NCII-CONTROLS" "Generative image or video feature without moderation controls" "Add input and output moderation for intimate and deepfake content, document tested safety prompts, and give the reviewer a full-access test account."
fi
# From February 2027 release builds must be R8-optimized (25 percent minimum coverage, Play Console Help 17492799).
- if ! grep -rqE '(isMinifyEnabled|minifyEnabled)[[:space:]=]+true' "$DIR" --include='*.gradle' --include='*.kts' 2>/dev/null; then
+ R8_ON=0
+ while IFS= read -r g; do
+ grep -qE '(isMinifyEnabled|minifyEnabled)[[:space:]=]+true' "$g" 2>/dev/null && { R8_ON=1; break; }
+ done < <(find_tree -type f \( -name '*.gradle' -o -name '*.kts' \) -print)
+ if [ "$R8_ON" -eq 0 ]; then
finding high "ANDROID-R8-OPTIMIZATION-MISSING" "No release build type with minifyEnabled true" "Enable R8 (isMinifyEnabled = true, isShrinkResources = true) in the release build type before February 2027."
fi
# From April 2027 sign-in apps must restore sign-in state on a new device (Restore Credentials API).
@@ -709,6 +722,110 @@ if [ "$IS_WEB" -eq 1 ]; then
fi
fi
+}
+
+# ----- app roots (issue #612). A root is an Expo, React Native, Flutter, or Capacitor app, an Android project, or an
+# Xcode project. A platform folder is part of the app above it. A library, a Pods tree, or a Heroku app.json never counts.
+is_library() { # $1 dir. a Flutter plugin, or a React Native module (peerDependencies and no app config)
+ local f
+ [ -f "$1/pubspec.yaml" ] && grep -qE '^[[:space:]]*plugin:' "$1/pubspec.yaml" 2>/dev/null && return 0
+ if [ -f "$1/package.json" ] && grep -q '"peerDependencies"' "$1/package.json" 2>/dev/null; then
+ [ -f "$1/app.json" ] && return 1
+ for f in app.config.js app.config.ts app.config.mjs app.config.cjs; do [ -f "$1/$f" ] && return 1; done
+ for f in "$1"/android/settings.gradle "$1"/android/settings.gradle.kts "$1"/ios/Podfile "$1"/ios/*.xcodeproj "$1"/ios/*.xcworkspace; do [ -e "$f" ] && return 1; done
+ return 0
+ fi
+ return 1
+}
+has_framework_marker() { # $1 dir. Expo or React Native CLI app.json, app.config.*, Flutter pubspec, Capacitor config, RN package.json
+ local f
+ is_library "$1" && return 1
+ [ -f "$1/pubspec.yaml" ] && return 0
+ for f in "$1"/capacitor.config.*; do [ -e "$f" ] && return 0; done
+ for f in app.config.js app.config.ts app.config.mjs app.config.cjs; do [ -f "$1/$f" ] && return 0; done
+ [ -f "$1/app.json" ] && grep -qE '"(expo|displayName)"' "$1/app.json" 2>/dev/null && return 0
+ [ -f "$1/package.json" ] && grep -qE '"react-native"|"expo"' "$1/package.json" 2>/dev/null && return 0
+ return 1
+}
+app_roots() { # prints the roots, one per line, only when two or more distinct apps exist. the project root itself may be one of them
+ local m d r k keep=() atroot=0
+ {
+ find_app 12 -name 'app.json' -o -name 'app.config.js' -o -name 'app.config.ts' -o -name 'app.config.mjs' -o -name 'app.config.cjs' \
+ -o -name 'pubspec.yaml' -o -name 'capacitor.config.*' -o -name 'settings.gradle' -o -name 'settings.gradle.kts' \
+ -o -name '*.xcodeproj' -o -name '*.xcworkspace' -o -name 'build.gradle' -o -name 'build.gradle.kts' | while IFS= read -r m; do
+ case "$m" in *.xcodeproj/*|*.xcworkspace/*) continue ;; esac
+ case "/$m/" in *Tests/*|*/androidTest/*|*/__tests__/*|*/test/*|*/tests/*|*/integration_test/*) continue ;; esac
+ d="$(dirname "$m")"
+ case "$m" in
+ */app.json) grep -qE '"(expo|displayName)"' "$m" 2>/dev/null || continue ;;
+ */pubspec.yaml) { [ -d "$d/ios" ] || [ -d "$d/android" ]; } && ! is_library "$d" || continue ;;
+ */build.gradle|*/build.gradle.kts) grep -qE 'com\.android\.application|android\.application' "$m" 2>/dev/null || continue ;;
+ esac
+ printf '%s\n' "$d"
+ done
+ find_app 12 -type d \( -name ios -o -name android \) | while IFS= read -r d; do
+ case "/$d/" in *Tests/*|*/androidTest/*|*/__tests__/*|*/test/*|*/tests/*|*/integration_test/*) continue ;; esac
+ find "$d" -maxdepth 4 \( -type d \( -name Pods -o -name node_modules -o -name build \) -prune \) \
+ -o \( -name 'Info.plist' -o -name '*.xcodeproj' -o -name 'AndroidManifest.xml' -o -name 'build.gradle' -o -name 'build.gradle.kts' \) -print 2>/dev/null \
+ | grep . >/dev/null && printf '%s\n' "$d"
+ done
+ } 2>/dev/null | while IFS= read -r r; do
+ case "${r##*/}" in ios|android) is_library "$(dirname "$r")" && continue; has_framework_marker "$(dirname "$r")" && r="$(dirname "$r")" ;; esac
+ printf '%s\n' "$r"
+ done | sort -u | {
+ while IFS= read -r r; do
+ [ "${r%/}" = "${DIR%/}" ] && { atroot=1; continue; }
+ for k in ${keep[@]+"${keep[@]}"}; do case "$r/" in "$k"/*) continue 2 ;; esac; done
+ [ "$atroot" -eq 1 ] && ! has_framework_marker "$r" && continue
+ keep+=("$r")
+ done
+ if [ "$atroot" -eq 1 ]; then
+ [ "${#keep[@]}" -ge 1 ] && printf '%s\n' "$DIR" "${keep[@]}"
+ else
+ [ "${#keep[@]}" -ge 2 ] && printf '%s\n' "${keep[@]}"
+ fi
+ }
+}
+
+# ----- report routing (issue #610). Hook mode buffers the report. A block goes to stderr, the only
+# stream Claude Code shows on exit 2. A pass stays on stdout. Standalone mode prints straight to stdout.
+emit_report() { # $1 is the exit code about to be returned
+ [ -n "$REPORT" ] || return 0
+ exec 1>&3 3>&-
+ if [ "$1" -eq 2 ]; then cat "$REPORT" >&2; else cat "$REPORT"; fi
+ rm -f "$REPORT" 2>/dev/null; REPORT=""
+}
+# A hook timeout sends TERM. Flush what was buffered to stderr so the partial report is not lost.
+trap 'emit_report 2; exit 143' INT TERM HUP
+if [ -n "$STDIN_JSON" ]; then
+ REPORT="$(mktemp 2>/dev/null)" || REPORT=""
+ if [ -n "$REPORT" ] && : >"$REPORT" 2>/dev/null; then exec 3>&1; exec >"$REPORT"; else REPORT=""; REPORT_DEGRADED=1; fi
+fi
+
+echo "== App Store Compliance Guard =="
+echo "Project. $DIR"
+ROOTS="$(app_roots)"
+if [ -n "$ROOTS" ]; then
+ PROJECT_ROOT="${DIR%/}"
+ echo "Apps. $(printf '%s\n' "$ROOTS" | grep -c .) app roots, each scanned on its own"
+ echo ""
+ while IFS= read -r ROOT; do
+ NESTED_PRUNE=()
+ if [ "${ROOT%/}" = "$PROJECT_ROOT" ]; then
+ while IFS= read -r OTHER; do [ "${OTHER%/}" != "$PROJECT_ROOT" ] && NESTED_PRUNE+=(-o -path "$(printf '%s' "$OTHER" | sed 's/[][*?\\]/\\&/g')"); done <<EOF2
+$ROOTS
+EOF2
+ fi
+ DIR="$ROOT"
+ echo "App. $ROOT"
+ scan_tree
+ done <<EOF
+$ROOTS
+EOF
+else
+ scan_tree
+fi
+
# ===== summary and exit =====
echo ""
echo "Summary. critical=$CRIT high=$HIGH medium=$MED"