@gfean/react-native-bundle-drop 0.5.1 → 0.7.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 (127) hide show
  1. package/BundleDrop.podspec +96 -0
  2. package/README.md +194 -5
  3. package/android/build.gradle +66 -0
  4. package/android/src/main/java/com/bundledrop/BundleDropBoundedDownloader.kt +86 -0
  5. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +206 -13
  6. package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +43 -13
  7. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +35 -0
  8. package/android/src/main/java/com/bundledrop/BundleDropRuntimeCrypto.kt +81 -0
  9. package/android/src/main/java/com/bundledrop/BundleDropStartupRecovery.kt +1117 -0
  10. package/ios/BundleDropBridge.m +45 -0
  11. package/ios/BundleDropLocator.swift +66 -4
  12. package/ios/BundleDropModule.swift +181 -3
  13. package/ios/BundleDropOtaResolver.swift +137 -29
  14. package/ios/BundleDropRuntimeCrypto.swift +45 -0
  15. package/ios/BundleDropStartupRecovery.swift +1108 -0
  16. package/ios/BundleDropStartupRecoveryAdapter.swift +301 -0
  17. package/lib/CLI/cli.d.ts +1 -0
  18. package/lib/CLI/cli.js +57 -6
  19. package/lib/CLI/scripts/aipowered/apply-setup-plan.js +7 -17
  20. package/lib/CLI/scripts/aipowered/backend-client.js +29 -4
  21. package/lib/CLI/scripts/aipowered/code-push-residue.d.ts +5 -0
  22. package/lib/CLI/scripts/aipowered/code-push-residue.js +126 -0
  23. package/lib/CLI/scripts/aipowered/credential-safety.d.ts +1 -0
  24. package/lib/CLI/scripts/aipowered/credential-safety.js +14 -0
  25. package/lib/CLI/scripts/aipowered/diff-preview.js +12 -4
  26. package/lib/CLI/scripts/aipowered/init-project-config.d.ts +4 -0
  27. package/lib/CLI/scripts/aipowered/init-project-config.js +221 -45
  28. package/lib/CLI/scripts/aipowered/scanner.d.ts +1 -0
  29. package/lib/CLI/scripts/aipowered/scanner.js +164 -32
  30. package/lib/CLI/scripts/aipowered/terminal-safety.d.ts +4 -0
  31. package/lib/CLI/scripts/aipowered/terminal-safety.js +124 -0
  32. package/lib/CLI/scripts/aipowered/validate-plan.d.ts +3 -0
  33. package/lib/CLI/scripts/aipowered/validate-plan.js +1080 -19
  34. package/lib/CLI/scripts/bare-metro-config.d.ts +1 -1
  35. package/lib/CLI/scripts/bare-metro-config.js +24 -32
  36. package/lib/CLI/scripts/doctor.js +162 -22
  37. package/lib/CLI/scripts/expo/configure-expo.js +52 -60
  38. package/lib/CLI/scripts/expo/package-manager.d.ts +2 -0
  39. package/lib/CLI/scripts/expo/package-manager.js +63 -25
  40. package/lib/CLI/scripts/init-config.d.ts +7 -7
  41. package/lib/CLI/scripts/init-config.js +198 -14
  42. package/lib/CLI/scripts/login-cli.js +31 -7
  43. package/lib/CLI/scripts/metro-config-authority.d.ts +8 -0
  44. package/lib/CLI/scripts/metro-config-authority.js +303 -0
  45. package/lib/CLI/scripts/native/write-runtime-identity.d.ts +19 -0
  46. package/lib/CLI/scripts/native/write-runtime-identity.js +92 -0
  47. package/lib/CLI/scripts/native-entrypoint-authority.d.ts +2 -0
  48. package/lib/CLI/scripts/native-entrypoint-authority.js +378 -0
  49. package/lib/CLI/scripts/native-setup-contract.d.ts +2 -2
  50. package/lib/CLI/scripts/native-setup-contract.js +63 -33
  51. package/lib/CLI/scripts/native-startup-validator.d.ts +3 -0
  52. package/lib/CLI/scripts/native-startup-validator.js +964 -0
  53. package/lib/CLI/scripts/safe-file-transaction.d.ts +12 -0
  54. package/lib/CLI/scripts/safe-file-transaction.js +159 -0
  55. package/lib/CLI/scripts/upload-cli.d.ts +12 -2
  56. package/lib/CLI/scripts/upload-cli.js +74 -11
  57. package/lib/CLI/serverUrl.d.ts +3 -0
  58. package/lib/CLI/serverUrl.js +31 -0
  59. package/lib/api/clientApi.d.ts +3 -1
  60. package/lib/api/clientApi.js +14 -0
  61. package/lib/api/types.d.ts +39 -0
  62. package/lib/bundleInfo.d.ts +2 -0
  63. package/lib/bundleInfo.js +16 -1
  64. package/lib/context.d.ts +1 -1
  65. package/lib/context.js +12 -2
  66. package/lib/fs/bundlePointer.d.ts +1 -17
  67. package/lib/fs/bundlePointer.js +5 -93
  68. package/lib/index.d.ts +2 -0
  69. package/lib/index.js +3 -1
  70. package/lib/install/bundleInstallShared.js +4 -4
  71. package/lib/install/installFromZip.d.ts +3 -0
  72. package/lib/install/installFromZip.js +10 -1
  73. package/lib/loadConfig.d.ts +17 -1
  74. package/lib/loadConfig.js +16 -0
  75. package/lib/manager/downloadAndInstall.d.ts +3 -2
  76. package/lib/manager/downloadAndInstall.js +134 -66
  77. package/lib/manager/reporting.d.ts +8 -1
  78. package/lib/manager/reporting.js +17 -22
  79. package/lib/manager/rollbackState.d.ts +18 -52
  80. package/lib/manager/rollbackState.js +115 -216
  81. package/lib/manager/updateCheck.d.ts +1 -0
  82. package/lib/manager/updateCheck.js +224 -78
  83. package/lib/manager/updateState.d.ts +2 -1
  84. package/lib/manager/updateState.js +59 -6
  85. package/lib/metro.d.ts +8 -1
  86. package/lib/metro.js +69 -19
  87. package/lib/native/bundleDropNative.d.ts +62 -0
  88. package/lib/native/bundleDropNative.js +268 -2
  89. package/lib/native/fs.d.ts +6 -0
  90. package/lib/native/fs.js +24 -0
  91. package/lib/patch-engine/installFromPatchSet.d.ts +2 -0
  92. package/lib/patch-engine/installFromPatchSet.js +16 -5
  93. package/lib/patch-engine/patchTransport.d.ts +2 -0
  94. package/lib/patch-engine/patchTransport.js +9 -0
  95. package/lib/runtime/initState.d.ts +5 -0
  96. package/lib/runtime/initState.js +4 -0
  97. package/lib/runtime/service.js +82 -67
  98. package/lib/runtime-delivery/artifactCapability.d.ts +1 -0
  99. package/lib/runtime-delivery/artifactCapability.js +32 -0
  100. package/lib/runtime-delivery/authorityLeaseVerifier.d.ts +3 -0
  101. package/lib/runtime-delivery/authorityLeaseVerifier.js +106 -0
  102. package/lib/runtime-delivery/bootstrapConfig.d.ts +68 -0
  103. package/lib/runtime-delivery/bootstrapConfig.js +278 -0
  104. package/lib/runtime-delivery/diagnostics.d.ts +17 -0
  105. package/lib/runtime-delivery/diagnostics.js +58 -0
  106. package/lib/runtime-delivery/encoding.d.ts +5 -0
  107. package/lib/runtime-delivery/encoding.js +132 -0
  108. package/lib/runtime-delivery/heartbeat.d.ts +3 -0
  109. package/lib/runtime-delivery/heartbeat.js +88 -0
  110. package/lib/runtime-delivery/localResolver.d.ts +23 -0
  111. package/lib/runtime-delivery/localResolver.js +81 -0
  112. package/lib/runtime-delivery/manifestState.d.ts +11 -0
  113. package/lib/runtime-delivery/manifestState.js +123 -0
  114. package/lib/runtime-delivery/manifestVerifier.d.ts +13 -0
  115. package/lib/runtime-delivery/manifestVerifier.js +335 -0
  116. package/lib/runtime-delivery/runtimeDelivery.d.ts +19 -0
  117. package/lib/runtime-delivery/runtimeDelivery.js +375 -0
  118. package/lib/runtime-delivery/types.d.ts +87 -0
  119. package/lib/runtime-delivery/types.js +6 -0
  120. package/lib/scripts/bundle.d.ts +9 -2
  121. package/lib/scripts/bundle.js +68 -18
  122. package/lib/scripts/download-bundle.d.ts +1 -0
  123. package/lib/scripts/download-bundle.js +2 -2
  124. package/lib/scripts/resolveModule.d.ts +2 -0
  125. package/lib/scripts/resolveModule.js +5 -0
  126. package/package.json +5 -2
  127. package/plugin/xcodeBuildPhase.js +2 -1
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isBundleDropHostedAiPlanningServer = exports.isTrustedAiPlanningServer = exports.findCredentialLikeLiteral = void 0;
6
+ exports.authoritativeDynamicExpoConfigFile = exports.isBundleDropHostedAiPlanningServer = exports.isTrustedAiPlanningServer = exports.findCredentialLikeLiteral = void 0;
7
7
  exports.findProjectRoot = findProjectRoot;
8
8
  exports.scanProjectForAiSetup = scanProjectForAiSetup;
9
9
  const crypto_1 = __importDefault(require("crypto"));
@@ -13,9 +13,15 @@ const os_1 = __importDefault(require("os"));
13
13
  const path_1 = __importDefault(require("path"));
14
14
  const expo_1 = require("../../../expo");
15
15
  const native_setup_contract_1 = require("../native-setup-contract");
16
+ const safe_file_transaction_1 = require("../safe-file-transaction");
17
+ const native_entrypoint_authority_1 = require("../native-entrypoint-authority");
18
+ const terminal_safety_1 = require("./terminal-safety");
19
+ const credential_safety_1 = require("./credential-safety");
16
20
  const MAX_UP = 12;
17
21
  const MAX_FILE_BYTES = 80 * 1024;
18
- const MAX_TOTAL_BYTES = 350 * 1024;
22
+ const MAX_SUMMARIZED_SOURCE_BYTES = 1024 * 1024;
23
+ const MAX_TOTAL_BYTES = 128 * 1024;
24
+ const MAX_NATIVE_SCAN_ENTRIES = 5000;
19
25
  const TRUSTED_BUNDLE_DROP_AI_HOSTS = new Set(['api.bundledrop.app']);
20
26
  const LOCAL_AI_HOSTS = new Set(['localhost', '127.0.0.1', '::1', '[::1]', '10.0.2.2']);
21
27
  const SKIP_DIRS = new Set([
@@ -55,6 +61,9 @@ const CREDENTIAL_LITERAL_PATTERNS = [
55
61
  },
56
62
  ];
57
63
  const findCredentialLikeLiteral = (content) => {
64
+ const bundleDropCredential = (0, credential_safety_1.findKnownBundleDropCredential)(content);
65
+ if (bundleDropCredential)
66
+ return bundleDropCredential;
58
67
  for (const candidate of CREDENTIAL_LITERAL_PATTERNS) {
59
68
  if (candidate.pattern.test(content))
60
69
  return candidate.name;
@@ -63,6 +72,11 @@ const findCredentialLikeLiteral = (content) => {
63
72
  };
64
73
  exports.findCredentialLikeLiteral = findCredentialLikeLiteral;
65
74
  const assertSafeAiSetupContent = (relativePath, content) => {
75
+ if ((0, terminal_safety_1.hasUnsafeTerminalControl)(content)) {
76
+ throw new Error(`Refusing AI setup because ${relativePath} contains unsafe terminal or bidirectional ` +
77
+ 'control characters. Remove them manually, then retry. The file was not shared, ' +
78
+ 'and --yes cannot bypass this safety check.');
79
+ }
66
80
  const finding = (0, exports.findCredentialLikeLiteral)(content);
67
81
  if (!finding)
68
82
  return;
@@ -99,14 +113,29 @@ const summarizeContextContent = (relativePath, rawContent, sizeBytes) => {
99
113
  const signalLines = matchedSignals.length
100
114
  ? matchedSignals.map(signal => `- ${signal}`).join('\n')
101
115
  : '- none detected';
116
+ const runtimeVersionBlock = relativePath.startsWith('bundle.drop.config.')
117
+ ? rawContent.match(/\bruntimeVersion\s*:\s*\{([\s\S]*?)\}/)?.[1] || ''
118
+ : '';
119
+ const runtimeAuthority = runtimeVersionBlock
120
+ ? /\bsource\s*:\s*['"]expo['"]/.test(runtimeVersionBlock)
121
+ ? 'expo_source'
122
+ : [
123
+ /\bios\s*:\s*['"][^'"]+['"]/.test(runtimeVersionBlock) ? 'ios_literal' : '',
124
+ /\bandroid\s*:\s*['"][^'"]+['"]/.test(runtimeVersionBlock) ? 'android_literal' : '',
125
+ ].filter(Boolean).join(',') || 'cli_validated'
126
+ : 'cli_validated';
127
+ const runtimeAuthorityLine = relativePath.startsWith('bundle.drop.config.')
128
+ ? `runtimeVersionAuthority: ${runtimeAuthority}\n`
129
+ : '';
102
130
  return [
103
131
  `BundleDrop context summary for ${relativePath}`,
104
132
  'Full content omitted to reduce setup-planning tokens; this context file is read-only.',
105
133
  `sizeBytes: ${sizeBytes}`,
134
+ runtimeAuthorityLine.trimEnd(),
106
135
  'signals:',
107
136
  signalLines,
108
137
  '',
109
- ].join('\n');
138
+ ].filter(Boolean).join('\n');
110
139
  };
111
140
  const isTrustedAiPlanningServer = (serverUrl) => {
112
141
  if (process.env.BUNDLE_DROP_ALLOW_UNTRUSTED_AI_SERVER === '1')
@@ -135,9 +164,8 @@ const isBundleDropHostedAiPlanningServer = (serverUrl) => {
135
164
  }
136
165
  };
137
166
  exports.isBundleDropHostedAiPlanningServer = isBundleDropHostedAiPlanningServer;
138
- const loadBundleDropConfig = (configPath) => {
167
+ const loadBundleDropConfig = (configPath, content) => {
139
168
  const moduleLike = { exports: {} };
140
- const content = fs_extra_1.default.readFileSync(configPath, 'utf8');
141
169
  const localRequire = (0, module_1.createRequire)(configPath);
142
170
  const load = new Function('module', 'exports', 'require', '__dirname', '__filename', content);
143
171
  load(moduleLike, moduleLike.exports, localRequire, path_1.default.dirname(configPath), configPath);
@@ -160,14 +188,23 @@ const findFilesByName = (root, names) => {
160
188
  return [];
161
189
  const matches = [];
162
190
  const stack = [root];
191
+ let visitedEntries = 0;
163
192
  while (stack.length) {
164
193
  const current = stack.pop();
194
+ visitedEntries += 1;
195
+ if (visitedEntries > MAX_NATIVE_SCAN_ENTRIES) {
196
+ throw new Error(`AI setup native source scan exceeded ${MAX_NATIVE_SCAN_ENTRIES} filesystem entries. ` +
197
+ 'Reduce generated/source files or configure native startup manually. ' +
198
+ 'No context was shared and no files were changed.');
199
+ }
165
200
  const stat = fs_extra_1.default.lstatSync(current);
166
- if (stat.isSymbolicLink())
201
+ if (SKIP_DIRS.has(path_1.default.basename(current)))
167
202
  continue;
203
+ if (stat.isSymbolicLink()) {
204
+ throw new Error(`AI setup cannot safely inspect symbolic-link source path ${toPosix(path_1.default.relative(root, current))}. ` +
205
+ 'No context was shared and no files were changed.');
206
+ }
168
207
  if (stat.isDirectory()) {
169
- if (SKIP_DIRS.has(path_1.default.basename(current)))
170
- continue;
171
208
  for (const entry of fs_extra_1.default.readdirSync(current)) {
172
209
  stack.push(path_1.default.join(current, entry));
173
210
  }
@@ -221,20 +258,67 @@ const setupFileKind = (relativePath) => {
221
258
  return 'android_entrypoint';
222
259
  return 'ios_entrypoint';
223
260
  };
261
+ const isRequiredPatchableSetupFile = (relativePath) => {
262
+ const kind = setupFileKind(relativePath);
263
+ return kind === 'android_entrypoint' ||
264
+ kind === 'ios_entrypoint' ||
265
+ relativePath.startsWith('app.config.');
266
+ };
267
+ const isSummarizedSetupFile = (relativePath) => {
268
+ const kind = setupFileKind(relativePath);
269
+ return kind === 'package_manifest' ||
270
+ kind === 'bundle_drop_config' ||
271
+ kind === 'metro_config' ||
272
+ relativePath === 'app.json';
273
+ };
274
+ const setupContextLimitError = (relativePath, reason) => new Error(`AI setup cannot safely inspect required setup file ${relativePath}: ${reason}. ` +
275
+ 'Reduce or split this file, or configure Bundle Drop manually, then retry. ' +
276
+ 'No context was shared and no files were changed.');
277
+ const authoritativeDynamicExpoConfigFile = (projectRoot, candidate) => {
278
+ if (candidate === undefined || candidate === null || candidate === '')
279
+ return null;
280
+ if (typeof candidate !== 'string' || !candidate.trim()) {
281
+ throw new Error('Expo did not identify a usable authoritative dynamic app config path. No files changed.');
282
+ }
283
+ const absolutePath = path_1.default.isAbsolute(candidate) ? candidate : path_1.default.resolve(projectRoot, candidate);
284
+ const relativePath = toPosix(path_1.default.relative(projectRoot, absolutePath));
285
+ if (relativePath.startsWith('../') ||
286
+ path_1.default.isAbsolute(relativePath) ||
287
+ !/^app\.config\.(js|ts|cjs|mjs)$/.test(relativePath)) {
288
+ throw new Error(`Expo reported an unsafe dynamic app config path: ${candidate}. No files changed.`);
289
+ }
290
+ const configFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, relativePath);
291
+ if (!configFile.exists) {
292
+ throw new Error(`Expo authoritative dynamic app config is missing: ${relativePath}. No files changed.`);
293
+ }
294
+ return relativePath;
295
+ };
296
+ exports.authoritativeDynamicExpoConfigFile = authoritativeDynamicExpoConfigFile;
224
297
  const readSetupFile = (projectRoot, relativePath) => {
225
- const filePath = path_1.default.join(projectRoot, relativePath);
226
- if (!fs_extra_1.default.existsSync(filePath))
298
+ let inspected;
299
+ try {
300
+ inspected = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, relativePath);
301
+ }
302
+ catch {
303
+ throw setupContextLimitError(relativePath, 'the path is not a regular project file');
304
+ }
305
+ if (!inspected.exists)
227
306
  return null;
228
- const stat = fs_extra_1.default.lstatSync(filePath);
229
- if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_FILE_BYTES)
307
+ const sizeBytes = Buffer.byteLength(inspected.content, 'utf8');
308
+ const summarized = isSummarizedSetupFile(relativePath);
309
+ if (sizeBytes > (summarized ? MAX_SUMMARIZED_SOURCE_BYTES : MAX_FILE_BYTES)) {
310
+ if (isRequiredPatchableSetupFile(relativePath)) {
311
+ throw setupContextLimitError(relativePath, `it exceeds the ${MAX_FILE_BYTES}-byte per-file limit`);
312
+ }
230
313
  return null;
231
- const rawContent = fs_extra_1.default.readFileSync(filePath, 'utf8');
314
+ }
315
+ const rawContent = inspected.content;
232
316
  const kind = setupFileKind(relativePath);
233
- if (kind !== 'package_manifest' && kind !== 'bundle_drop_config') {
317
+ if (!summarized) {
234
318
  assertSafeAiSetupContent(relativePath, rawContent);
235
319
  }
236
- const content = kind === 'package_manifest' || kind === 'bundle_drop_config'
237
- ? summarizeContextContent(relativePath, rawContent, stat.size)
320
+ const content = summarized
321
+ ? summarizeContextContent(relativePath, rawContent, sizeBytes)
238
322
  : rawContent;
239
323
  return {
240
324
  kind,
@@ -243,8 +327,17 @@ const readSetupFile = (projectRoot, relativePath) => {
243
327
  sha256: sha256(content),
244
328
  };
245
329
  };
246
- const collectSetupFiles = (projectRoot, projectType) => {
247
- const relativePaths = ['package.json', ...SETUP_CONFIG_FILES];
330
+ const collectSetupFiles = (projectRoot, projectType, dynamicExpoConfigFile) => {
331
+ const relativePaths = [
332
+ 'package.json',
333
+ ...SETUP_CONFIG_FILES.filter(relativePath => projectType === 'expo'
334
+ ? !relativePath.startsWith('app.config.') &&
335
+ (relativePath !== 'app.json' || !dynamicExpoConfigFile)
336
+ : relativePath !== 'app.json' && !relativePath.startsWith('app.config.')),
337
+ ];
338
+ if (projectType === 'expo' && dynamicExpoConfigFile) {
339
+ relativePaths.push(dynamicExpoConfigFile);
340
+ }
248
341
  if (projectType === 'bare') {
249
342
  for (const srcDir of ['java', 'kotlin']) {
250
343
  relativePaths.push(...findFilesByName(path_1.default.join(projectRoot, 'android', 'app', 'src', 'main', srcDir), new Set(['MainApplication.kt', 'MainApplication.java'])).map(filePath => toPosix(path_1.default.relative(projectRoot, filePath))));
@@ -253,24 +346,29 @@ const collectSetupFiles = (projectRoot, projectType) => {
253
346
  }
254
347
  const files = [];
255
348
  let totalBytes = 0;
256
- for (const relativePath of relativePaths) {
349
+ for (const relativePath of [...new Set(relativePaths)]) {
257
350
  const file = readSetupFile(projectRoot, relativePath);
258
351
  if (!file)
259
352
  continue;
260
353
  const bytes = Buffer.byteLength(file.content, 'utf8');
261
- if (totalBytes + bytes > MAX_TOTAL_BYTES)
354
+ if (totalBytes + bytes > MAX_TOTAL_BYTES) {
355
+ if (isRequiredPatchableSetupFile(relativePath)) {
356
+ throw setupContextLimitError(relativePath, `including it would exceed the ${MAX_TOTAL_BYTES}-byte total context limit`);
357
+ }
262
358
  continue;
359
+ }
263
360
  totalBytes += bytes;
264
361
  files.push(file);
265
362
  }
266
363
  return files;
267
364
  };
268
365
  const readPackageSignals = (projectRoot) => {
269
- const packagePath = path_1.default.join(projectRoot, 'package.json');
270
- const pkg = fs_extra_1.default.existsSync(packagePath) ? readJsonFile(packagePath) : {};
366
+ const packageFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, 'package.json');
367
+ const pkg = packageFile.exists ? JSON.parse(packageFile.content) : {};
271
368
  const dependencies = {
272
369
  ...(pkg.dependencies || {}),
273
370
  ...(pkg.devDependencies || {}),
371
+ ...(pkg.optionalDependencies || {}),
274
372
  ...(pkg.peerDependencies || {}),
275
373
  };
276
374
  return { pkg, dependencies };
@@ -297,9 +395,16 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
297
395
  const expoPlugins = (evaluatedExpoConfig.plugins || []).map((plugin) => typeof plugin === 'string' ? plugin : Array.isArray(plugin) ? plugin[0] : null);
298
396
  const hasBundleDropExpoPlugin = expoPlugins.includes('@gfean/react-native-bundle-drop');
299
397
  const nativeEntrypoints = files.filter(file => file.kind === 'android_entrypoint' || file.kind === 'ios_entrypoint');
300
- const hasBareNativeIntegration = nativeEntrypoints.length > 0 && nativeEntrypoints.every(file => file.kind === 'android_entrypoint'
301
- ? (0, native_setup_contract_1.hasBareAndroidStartupIntegration)(file.content)
302
- : (0, native_setup_contract_1.hasBareIosStartupIntegration)(file.path, file.content));
398
+ const androidEntrypoints = nativeEntrypoints.filter(file => file.kind === 'android_entrypoint');
399
+ const iosEntrypoints = nativeEntrypoints.filter(file => file.kind === 'ios_entrypoint');
400
+ const hasAndroidDirectory = (0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, 'android');
401
+ const hasIosDirectory = (0, safe_file_transaction_1.inspectProjectDirectory)(projectRoot, 'ios');
402
+ const hasBareNativeIntegration = (hasAndroidDirectory || hasIosDirectory) &&
403
+ (!hasAndroidDirectory || androidEntrypoints.length === 1) &&
404
+ (!hasIosDirectory || iosEntrypoints.length === 1) &&
405
+ nativeEntrypoints.every(file => file.kind === 'android_entrypoint'
406
+ ? (0, native_setup_contract_1.hasBareAndroidStartupIntegration)(file.content)
407
+ : (0, native_setup_contract_1.hasBareIosStartupIntegration)(file.path, file.content));
303
408
  const hasBundleDropIntegration = projectType === 'expo'
304
409
  ? hasBundleDropExpoPlugin
305
410
  : hasBareNativeIntegration;
@@ -311,8 +416,8 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
311
416
  : 'unknown';
312
417
  const signals = [
313
418
  projectType === 'expo' ? 'expoProject' : 'bareProject',
314
- fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'ios')) ? 'iosDirectory' : '',
315
- fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'android')) ? 'androidDirectory' : '',
419
+ hasIosDirectory ? 'iosDirectory' : '',
420
+ hasAndroidDirectory ? 'androidDirectory' : '',
316
421
  expoUpdatesOwnership.packageIsInstalled || expoUpdatesOwnership.packageIsDeclared
317
422
  ? 'expoUpdatesDependency'
318
423
  : '',
@@ -329,8 +434,7 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
329
434
  bundleDropStatus: hasBundleDropDependency && hasBundleDropConfig && hasBundleDropIntegration
330
435
  ? 'configured'
331
436
  : 'partial',
332
- hasNativeDirectories: fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'ios')) ||
333
- fs_extra_1.default.existsSync(path_1.default.join(projectRoot, 'android')),
437
+ hasNativeDirectories: hasIosDirectory || hasAndroidDirectory,
334
438
  usesExpoRouter: Boolean(pkg.main === 'expo-router/entry' || dependencies['expo-router']),
335
439
  jsEngine: configuredEngine,
336
440
  expoUpdatesStatus: expoUpdatesOwnership.state,
@@ -350,10 +454,11 @@ const detectSetupSignals = (projectRoot, projectType, files) => {
350
454
  function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualConfig) {
351
455
  const projectRoot = findProjectRoot(startDir);
352
456
  const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
353
- if (!fs_extra_1.default.existsSync(configPath) && !virtualConfig) {
457
+ const configFile = (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, 'bundle.drop.config.js');
458
+ if (!configFile.exists && !virtualConfig) {
354
459
  throw new Error('bundle.drop.config.js not found; run `bundle-drop init` first.');
355
460
  }
356
- const config = virtualConfig ? null : loadBundleDropConfig(configPath);
461
+ const config = virtualConfig ? null : loadBundleDropConfig(configPath, configFile.content);
357
462
  const serverUrl = virtualConfig
358
463
  ? normalizeServerUrl(virtualConfig.serverUrl)
359
464
  : typeof config?.serverUrl === 'string' ? normalizeServerUrl(config.serverUrl) : '';
@@ -367,7 +472,34 @@ function scanProjectForAiSetup(projectType, startDir = process.cwd(), virtualCon
367
472
  if (!(0, exports.isTrustedAiPlanningServer)(serverUrl)) {
368
473
  throw new Error(`Refusing to send project files to untrusted AI planning server: ${serverUrl}.`);
369
474
  }
370
- const files = collectSetupFiles(projectRoot, projectType);
475
+ if (projectType === 'expo') {
476
+ for (const relativePath of ['package.json', 'app.json', ...SETUP_CONFIG_FILES.filter(file => file.startsWith('app.config.'))]) {
477
+ (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, relativePath);
478
+ }
479
+ }
480
+ const expoEvaluation = projectType === 'expo' ? (0, expo_1.evaluateExpoConfig)(projectRoot) : null;
481
+ const dynamicExpoConfigFile = (0, exports.authoritativeDynamicExpoConfigFile)(projectRoot, expoEvaluation?.dynamicConfigPath);
482
+ const hasDynamicExpoConfigCandidate = projectType === 'expo' &&
483
+ SETUP_CONFIG_FILES.some(relativePath => relativePath.startsWith('app.config.') && (0, safe_file_transaction_1.inspectProjectFile)(projectRoot, relativePath).exists);
484
+ if (hasDynamicExpoConfigCandidate && !dynamicExpoConfigFile) {
485
+ throw new Error('Expo config evaluation did not identify the authoritative dynamic app.config.* file. ' +
486
+ 'No context was shared and no files were changed.');
487
+ }
488
+ const files = collectSetupFiles(projectRoot, projectType, dynamicExpoConfigFile);
489
+ if (projectType === 'bare') {
490
+ for (const platform of ['android', 'ios']) {
491
+ const kind = platform === 'android' ? 'android_entrypoint' : 'ios_entrypoint';
492
+ const entrypoints = files.filter(file => file.kind === kind).map(file => file.path);
493
+ if (entrypoints.length > 1)
494
+ continue;
495
+ const authorityIssue = (0, native_entrypoint_authority_1.findNativeEntrypointAuthorityIssue)(projectRoot, platform, entrypoints);
496
+ if (authorityIssue) {
497
+ throw new Error(`AI setup cannot prove the ${platform} application entrypoint: ${authorityIssue} ` +
498
+ 'Resolve native startup ownership manually, then retry. ' +
499
+ 'No context was shared and no files were changed.');
500
+ }
501
+ }
502
+ }
371
503
  if (virtualConfig && !files.some(file => file.kind === 'bundle_drop_config')) {
372
504
  const summarizedConfig = summarizeContextContent('bundle.drop.config.js', virtualConfig.content, Buffer.byteLength(virtualConfig.content, 'utf8'));
373
505
  files.push({
@@ -0,0 +1,4 @@
1
+ import type { AiSetupPlanResponse } from './types';
2
+ export declare const hasUnsafeTerminalControl: (value: string) => boolean;
3
+ export declare const escapeTerminalControls: (value: string) => string;
4
+ export declare function assertSafeProviderPlan(plan: unknown): asserts plan is AiSetupPlanResponse;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.escapeTerminalControls = exports.hasUnsafeTerminalControl = void 0;
4
+ exports.assertSafeProviderPlan = assertSafeProviderPlan;
5
+ const credential_safety_1 = require("./credential-safety");
6
+ const CONFIDENCE_VALUES = new Set(['high', 'medium', 'low']);
7
+ const DECISION_VALUES = new Set([
8
+ 'safe_auto_patch',
9
+ 'review_only_patch',
10
+ 'manual_fallback',
11
+ 'skip',
12
+ ]);
13
+ const ACTION_VALUES = new Set([
14
+ 'register_expo_plugin',
15
+ 'configure_bundle_drop',
16
+ 'preserve_expo_metro',
17
+ 'migrate_expo_updates',
18
+ 'configure_bare_native',
19
+ 'migrate_codepush',
20
+ 'require_native_rebuild',
21
+ 'run_doctor',
22
+ ]);
23
+ const BIDI_CONTROL = /[\u202A-\u202E\u2066-\u2069]/u;
24
+ const JAVASCRIPT_LINE_SEPARATOR = /[\u2028\u2029]/u;
25
+ const isUnsafeControlAt = (value, index) => {
26
+ const code = value.charCodeAt(index);
27
+ if (code === 0x09 || code === 0x0a)
28
+ return false;
29
+ if (code === 0x0d && value.charCodeAt(index + 1) === 0x0a)
30
+ return false;
31
+ return code < 0x20 || (code >= 0x7f && code <= 0x9f);
32
+ };
33
+ const hasUnsafeTerminalControl = (value) => {
34
+ if (BIDI_CONTROL.test(value) || JAVASCRIPT_LINE_SEPARATOR.test(value))
35
+ return true;
36
+ for (let index = 0; index < value.length; index += 1) {
37
+ if (isUnsafeControlAt(value, index))
38
+ return true;
39
+ }
40
+ return false;
41
+ };
42
+ exports.hasUnsafeTerminalControl = hasUnsafeTerminalControl;
43
+ const escapeTerminalControls = (value) => {
44
+ let escaped = '';
45
+ for (const character of value) {
46
+ const code = character.charCodeAt(0);
47
+ if (character === '\n' || character === '\t') {
48
+ escaped += character;
49
+ }
50
+ else if (character === '\r') {
51
+ escaped += '\\r';
52
+ }
53
+ else if (code < 0x20 ||
54
+ (code >= 0x7f && code <= 0x9f) ||
55
+ code === 0x2028 ||
56
+ code === 0x2029 ||
57
+ (code >= 0x202a && code <= 0x202e) ||
58
+ (code >= 0x2066 && code <= 0x2069)) {
59
+ escaped += code <= 0xff
60
+ ? `\\x${code.toString(16).padStart(2, '0')}`
61
+ : `\\u${code.toString(16).padStart(4, '0')}`;
62
+ }
63
+ else {
64
+ escaped += character;
65
+ }
66
+ }
67
+ return escaped;
68
+ };
69
+ exports.escapeTerminalControls = escapeTerminalControls;
70
+ const requireSafeProviderText = (label, value) => {
71
+ if (typeof value !== 'string') {
72
+ throw new Error(`AI setup response contains a non-text ${label}. No files changed.`);
73
+ }
74
+ if ((0, exports.hasUnsafeTerminalControl)(value)) {
75
+ throw new Error(`AI setup response contains unsafe terminal controls in ${label}. No files changed.`);
76
+ }
77
+ if ((0, credential_safety_1.findKnownBundleDropCredential)(value)) {
78
+ throw new Error(`AI setup response contains a private Bundle Drop credential in ${label}. No files changed.`);
79
+ }
80
+ };
81
+ function assertSafeProviderPlan(plan) {
82
+ if (!plan || typeof plan !== 'object') {
83
+ throw new Error('AI setup response is not an object. No files changed.');
84
+ }
85
+ const candidate = plan;
86
+ if (!CONFIDENCE_VALUES.has(String(candidate.confidence))) {
87
+ throw new Error('AI setup response contains an invalid confidence. No files changed.');
88
+ }
89
+ requireSafeProviderText('summary', candidate.summary);
90
+ if (!Array.isArray(candidate.warnings) || !Array.isArray(candidate.actions) ||
91
+ !Array.isArray(candidate.changes)) {
92
+ throw new Error('AI setup response is missing typed action, warning, or change arrays. No files changed.');
93
+ }
94
+ candidate.warnings.forEach((warning, index) => requireSafeProviderText(`warning ${index + 1}`, warning));
95
+ candidate.actions.forEach((action, index) => {
96
+ if (!action || typeof action !== 'object') {
97
+ throw new Error(`AI setup response contains an invalid action ${index + 1}. No files changed.`);
98
+ }
99
+ requireSafeProviderText(`action ${index + 1} type`, action.type);
100
+ requireSafeProviderText(`action ${index + 1} reason`, action.reason);
101
+ if (!ACTION_VALUES.has(action.type)) {
102
+ throw new Error(`AI setup response contains an unsupported action ${index + 1}. No files changed.`);
103
+ }
104
+ if (typeof action.requiresConfirmation !== 'boolean') {
105
+ throw new Error(`AI setup response contains a non-boolean confirmation flag for action ${index + 1}. ` +
106
+ 'No files changed.');
107
+ }
108
+ });
109
+ candidate.changes.forEach((change, index) => {
110
+ if (!change || typeof change !== 'object') {
111
+ throw new Error(`AI setup response contains an invalid change ${index + 1}. No files changed.`);
112
+ }
113
+ requireSafeProviderText(`change ${index + 1} file`, change.file);
114
+ requireSafeProviderText(`change ${index + 1} original hash`, change.originalSha256);
115
+ requireSafeProviderText(`change ${index + 1} reason`, change.reason);
116
+ requireSafeProviderText(`change ${index + 1} content`, change.updated);
117
+ if (!CONFIDENCE_VALUES.has(String(change.confidence))) {
118
+ throw new Error(`AI setup response contains an invalid change confidence ${index + 1}. No files changed.`);
119
+ }
120
+ if (!DECISION_VALUES.has(String(change.decisionType))) {
121
+ throw new Error(`AI setup response contains an invalid change decision ${index + 1}. No files changed.`);
122
+ }
123
+ });
124
+ }
@@ -7,9 +7,12 @@ export declare function validateSetupChangesBeforeApply(params: {
7
7
  projectType: AiSetupProjectType;
8
8
  originals: Map<string, string>;
9
9
  changes: AiPatchPlan[];
10
+ migrateExpoUpdates?: boolean;
10
11
  }): void;
11
12
  export declare function validateAppliedSetupChanges(params: {
12
13
  projectRoot: string;
13
14
  projectType: AiSetupProjectType;
14
15
  changes: AiPatchPlan[];
16
+ migrateExpoUpdates?: boolean;
17
+ originals?: Map<string, string>;
15
18
  }): void;