Ariver
2026-08-28 c5bdc7f1eb3ff4287beeeebb17d4f02f376a8d38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/usr/bin/env bash
set -euo pipefail
 
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
L10N_SWIFT="$ROOT_DIR/Apptag/L10n.swift"
DATA_LAYER_SWIFT="$ROOT_DIR/Apptag/DataLayer.swift"
BUILD_SCRIPT="$ROOT_DIR/build.sh"
APPLE_DIR="$ROOT_DIR/Research/AppleDefaultApps"
APPLE_BASE="$APPLE_DIR/AppleDefaultApps.base.json"
APPLE_TRANSLATIONS="$APPLE_DIR/AppleDefaultApps.translations.json"
 
fail() {
  printf 'FAIL: %s\n' "$*" >&2
  exit 1
}
 
[[ -f "$L10N_SWIFT" ]] || fail "missing L10n.swift at $L10N_SWIFT"
[[ -f "$DATA_LAYER_SWIFT" ]] || fail "missing DataLayer.swift at $DATA_LAYER_SWIFT"
[[ -f "$BUILD_SCRIPT" ]] || fail "missing build.sh at $BUILD_SCRIPT"
[[ -f "$APPLE_BASE" ]] || fail "missing Apple default app base at $APPLE_BASE"
[[ -f "$APPLE_TRANSLATIONS" ]] || fail "missing Apple translations at $APPLE_TRANSLATIONS"
 
python3 - "$ROOT_DIR" <<'PY'
import json
import pathlib
import plistlib
import re
import sys
 
root = pathlib.Path(sys.argv[1])
l10n_swift = root / "Apptag" / "L10n.swift"
data_layer = root / "Apptag" / "DataLayer.swift"
apple_dir = root / "Research" / "AppleDefaultApps"
base_path = apple_dir / "AppleDefaultApps.base.json"
translations_path = apple_dir / "AppleDefaultApps.translations.json"
 
def fail(message: str) -> None:
    print(f"FAIL: {message}", file=sys.stderr)
    sys.exit(1)
 
def load_json(path: pathlib.Path):
    try:
        return json.loads(path.read_text(encoding="utf-8"))
    except Exception as error:
        fail(f"{path} is not valid JSON: {error}")
 
text = l10n_swift.read_text(encoding="utf-8")
supported_block_match = re.search(
    r"static\s+let\s+supported\s*:\s*\[\(code:\s*String,\s*name:\s*String\)\]\s*=\s*\[(.*?)\n\s*\]",
    text,
    re.S,
)
if not supported_block_match:
    fail("could not find L10n.supported language list")
l10n_codes = re.findall(r'\("([^"]+)",\s*"[^"]+"\)', supported_block_match.group(1))
if len(l10n_codes) != 29:
    fail(f"L10n.supported has {len(l10n_codes)} languages, expected 29")
 
max_note_match = re.search(r"static\s+let\s+maxAppNoteLength\s*=\s*(\d+)", data_layer.read_text(encoding="utf-8"))
if not max_note_match:
    fail("could not find TagDatabase.maxAppNoteLength")
max_note_length = int(max_note_match.group(1))
soft_note_length = max_note_length - 2
 
base = load_json(base_path)
translations = load_json(translations_path)
if base.get("resourceFormatVersion") != 1:
    fail("Apple base resourceFormatVersion must be 1")
if translations.get("resourceFormatVersion") != 1:
    fail("Apple translations resourceFormatVersion must be 1")
if translations.get("translationsVersion", 0) < 2:
    fail("Apple translationsVersion must be at least 2")
if base.get("noteLimit") != max_note_length:
    fail(f"Apple base noteLimit {base.get('noteLimit')} does not match TagDatabase.maxAppNoteLength {max_note_length}")
if set(base.get("supportedLanguages", [])) != set(l10n_codes):
    fail("Apple base supportedLanguages does not match L10n.supported")
if set(translations.get("supportedLanguages", [])) != set(l10n_codes):
    fail("Apple translations supportedLanguages does not match L10n.supported")
 
entries = base.get("entries")
if not isinstance(entries, list) or not entries:
    fail("Apple base entries is empty or not a list")
 
bundle_ids = set()
normalized_names = set()
for entry in entries:
    bundle = entry.get("bundleIdentifier")
    normalized = entry.get("normalizedName")
    canonical = entry.get("canonicalName")
    tags = entry.get("defaultTag")
    if not isinstance(bundle, str) or not bundle.strip():
        fail("Apple base entry has empty bundleIdentifier")
    if not bundle.lower().startswith("com.apple."):
        fail(f"Apple base contains non-Apple bundleIdentifier: {bundle}")
    if bundle.lower() in bundle_ids:
        fail(f"Apple base duplicate bundleIdentifier: {bundle}")
    bundle_ids.add(bundle.lower())
    if not isinstance(normalized, str) or not normalized.strip():
        fail(f"Apple base entry {bundle} has empty normalizedName")
    if normalized.lower() in normalized_names:
        fail(f"Apple base duplicate normalizedName: {normalized}")
    normalized_names.add(normalized.lower())
    if not isinstance(canonical, str) or not canonical.strip():
        fail(f"Apple base entry {bundle} has empty canonicalName")
    if not isinstance(tags, list) or not tags or not all(isinstance(tag, str) and tag.strip() for tag in tags):
        fail(f"Apple base entry {bundle} has empty defaultTag")
    if not isinstance(entry.get("familiar"), bool):
        fail(f"Apple base entry {bundle} familiar must be boolean")
 
def is_nested_inside_app_bundle(path: pathlib.Path) -> bool:
    return any(part.lower().endswith(".app") for part in path.parts[:-1])
 
def system_scanned_apple_apps() -> list[tuple[pathlib.Path, str]]:
    search_roots = [
        pathlib.Path("/System/Applications"),
        pathlib.Path("/System/Library/CoreServices/Applications"),
        pathlib.Path("/System/Cryptexes/App/System/Applications"),
        pathlib.Path("/System/Volumes/Preboot/Cryptexes/App/System/Applications"),
    ]
    seen: set[str] = set()
    result: list[tuple[pathlib.Path, str]] = []
    for search_root in search_roots:
        if not search_root.is_dir():
            continue
        for app_path in search_root.rglob("*.app"):
            if is_nested_inside_app_bundle(app_path):
                continue
            resolved = str(app_path.resolve())
            if resolved in seen:
                continue
            seen.add(resolved)
            info_path = app_path / "Contents" / "Info.plist"
            if not info_path.is_file():
                continue
            try:
                info = plistlib.loads(info_path.read_bytes())
            except Exception:
                continue
            bundle = info.get("CFBundleIdentifier")
            if isinstance(bundle, str) and bundle.lower().startswith("com.apple."):
                result.append((app_path, bundle.lower()))
    return result
 
missing_scanned_apps = [
    f"{bundle} at {app_path}"
    for app_path, bundle in system_scanned_apple_apps()
    if bundle not in bundle_ids
]
if missing_scanned_apps:
    fail(
        "Apple catalog is missing system apps scanned by AppIndexer: "
        + "; ".join(missing_scanned_apps[:12])
    )
 
display_names_by_language = translations.get("displayNamesByLanguage")
notes_by_language = translations.get("notesByLanguage")
if not isinstance(display_names_by_language, dict):
    fail("Apple translations displayNamesByLanguage must be an object")
if not isinstance(notes_by_language, dict):
    fail("Apple translations notesByLanguage must be an object")
 
script_patterns = {
    "cjk": re.compile(r"[\u4e00-\u9fff]"),
    "kana": re.compile(r"[\u3040-\u30ff]"),
    "hangul": re.compile(r"[\uac00-\ud7af]"),
    "cyrillic": re.compile(r"[\u0400-\u04ff]"),
    "arabic": re.compile(r"[\u0600-\u06ff]"),
    "thai": re.compile(r"[\u0e00-\u0e7f]"),
}
 
expected_script_requirements = {
    "zh-Hans": ("cjk",),
    "zh-Hant": ("cjk",),
    "ja": ("kana",),
    "ko": ("hangul",),
    "ar": ("arabic",),
    "ar-Najdi": ("arabic",),
    "ru": ("cyrillic",),
    "uk": ("cyrillic",),
    "sr-Cyrl": ("cyrillic",),
    "th": ("thai",),
}
 
forbidden_scripts_by_language = {
    "zh-Hans": ("kana", "hangul", "cyrillic", "arabic", "thai"),
    "zh-Hant": ("kana", "hangul", "cyrillic", "arabic", "thai"),
    "ja": ("hangul", "cyrillic", "arabic", "thai"),
    "ko": ("cjk", "kana", "cyrillic", "arabic", "thai"),
    "ar": ("cjk", "kana", "hangul", "cyrillic", "thai"),
    "ar-Najdi": ("cjk", "kana", "hangul", "cyrillic", "thai"),
    "ru": ("cjk", "kana", "hangul", "arabic", "thai"),
    "uk": ("cjk", "kana", "hangul", "arabic", "thai"),
    "sr-Cyrl": ("cjk", "kana", "hangul", "arabic", "thai"),
    "th": ("cjk", "kana", "hangul", "cyrillic", "arabic"),
}
 
for code in l10n_codes:
    forbidden_scripts_by_language.setdefault(
        code,
        ("cjk", "kana", "hangul", "cyrillic", "arabic", "thai"),
    )
 
def assert_note_language_clean(code: str, note: str, context: str) -> None:
    for script_name in expected_script_requirements.get(code, ()):
        if not script_patterns[script_name].search(note):
            fail(f"{context} does not contain expected {script_name} script for {code}")
    for script_name in forbidden_scripts_by_language.get(code, ()):
        if script_patterns[script_name].search(note):
            fail(f"{context} contains unexpected {script_name} script for {code}: {note!r}")
 
for code in l10n_codes:
    display_names = display_names_by_language.get(code)
    notes = notes_by_language.get(code)
    zh_hans_notes = notes_by_language.get("zh-Hans", {})
    if not isinstance(display_names, dict):
        fail(f"Apple translations missing displayNamesByLanguage.{code}")
    if not isinstance(notes, dict):
        fail(f"Apple translations missing notesByLanguage.{code}")
    for entry in entries:
        normalized = entry["normalizedName"]
        display = display_names.get(normalized)
        note = notes.get(normalized)
        if not isinstance(display, str) or not display.strip():
            fail(f"Apple translations has empty displayName for {code}/{normalized}")
        if not isinstance(note, str) or not note.strip():
            fail(f"Apple translations has empty note for {code}/{normalized}")
        note_len = len(note)
        if note_len > max_note_length:
            fail(f"Apple translations note for {code}/{normalized} is {note_len} chars, limit is {max_note_length}")
        if note_len >= soft_note_length:
            fail(
                f"Apple translations note for {code}/{normalized} is {note_len} chars, "
                f"too close to {max_note_length}; shorten it to avoid clipped notes"
            )
        if code not in {"zh-Hans", "zh-Hant"} and note == zh_hans_notes.get(normalized):
            fail(f"Apple translations note for {code}/{normalized} is identical to zh-Hans")
        if code not in {"zh-Hans", "zh-Hant", "ja"} and re.search(r"[\u4e00-\u9fff]", note):
            fail(f"Apple translations note for {code}/{normalized} contains Chinese characters")
        assert_note_language_clean(code, note, f"Apple translations note for {code}/{normalized}")
 
bad_fragments = [
    "Apple 內建 App",
    "Apple app for",
    "Apple-App für",
    "app Apple pour",
    "app Apple per",
    "app de Apple",
    "app da Apple",
    "Apple純正アプリ",
    "приложение Apple",
    "програма Apple",
    "Apple апликација",
    "แอป Apple",
    "ứng dụng Apple",
    "تطبيق Apple",
    "Apple uygulaması",
    "aplikace Apple",
    "Apple-app",
    "app Apple untuk",
    "aplicație Apple",
    "aplikacja Apple",
    "FamilyMart",
    "fishing",
    "pêche",
    "pesca",
    "Angeln",
    "medicine",
    "médicament",
    "medicamento",
    "remédio",
    "obat penyesalan",
    "ubat",
    "rybaření",
    "fiskeri",
    "vissen",
    "łowienie",
    "pescuit",
    "ماكينات القمار",
    "corresponding system",
    "File Management",
    "Pictures & Photos",
    "System Maintenance",
    "undefined",
    "null",
]
 
for code in l10n_codes:
    path = apple_dir / f"AppleDefaultApps.localizations.{code}.json"
    if not path.is_file():
        fail(f"missing Apple localization file: {path.name}")
    catalog = load_json(path)
    if catalog.get("resourceFormatVersion") != 1:
        fail(f"{path.name} resourceFormatVersion must be 1")
    if catalog.get("catalogContentVersion") != base.get("catalogContentVersion"):
        fail(f"{path.name} catalogContentVersion does not match base")
    if catalog.get("language") != code:
        fail(f"{path.name} language field is {catalog.get('language')!r}, expected {code!r}")
    entries_by_bundle = {}
    for item in catalog.get("entries", []):
        bundle = item.get("bundleIdentifier")
        display = item.get("displayName")
        note = item.get("note")
        if not isinstance(bundle, str) or bundle.lower() not in bundle_ids:
            fail(f"{path.name} contains unknown bundleIdentifier: {bundle!r}")
        if bundle.lower() in entries_by_bundle:
            fail(f"{path.name} duplicate bundleIdentifier: {bundle}")
        entries_by_bundle[bundle.lower()] = item
        if not isinstance(display, str) or not display.strip():
            fail(f"{path.name} has empty displayName for {bundle}")
        if not isinstance(note, str) or not note.strip():
            fail(f"{path.name} has empty note for {bundle}")
        note_len = len(note)
        if note_len > max_note_length:
            fail(f"{path.name} note for {bundle} is {note_len} chars, limit is {max_note_length}")
        if note_len >= soft_note_length:
            fail(
                f"{path.name} note for {bundle} is {note_len} chars, "
                f"too close to {max_note_length}; shorten it to avoid clipped notes"
            )
        for fragment in bad_fragments:
            if fragment in note:
                fail(f"{path.name} note for {bundle} contains blocked fragment: {fragment!r}")
        assert_note_language_clean(code, note, f"{path.name} note for {bundle}")
    missing = bundle_ids - set(entries_by_bundle)
    if missing:
        fail(f"{path.name} is missing {len(missing)} Apple entries; first missing: {sorted(missing)[:5]}")
 
print(
    "PASS Apple default app resources: "
    f"{len(entries)} apps, {len(l10n_codes)} languages, notes <= {max_note_length}"
)
PY
 
rg -Fq 'AppleDefaultApps.base.json' "$BUILD_SCRIPT" \
  || fail "build.sh must copy AppleDefaultApps.base.json"
rg -Fq 'AppleDefaultApps.localizations.*.json' "$BUILD_SCRIPT" \
  || fail "build.sh must copy AppleDefaultApps.localizations.<lang>.json"
rg -Fq 'AppleDefaultApps.localizations.\(languageCode)' "$ROOT_DIR/Apptag/AppleDefaultAppCatalog.swift" \
  || fail "AppleDefaultAppCatalog must load AppleDefaultApps.localizations.<language>"
rg -Fq 'withExtension: "json.deflate"' "$ROOT_DIR/Apptag/AppleDefaultAppCatalog.swift" \
  || fail "AppleDefaultAppCatalog must prefer deflated localization resources"
 
printf 'PASS Apple default app runtime resource boundary\n'