The best way to control Claude Code, Codex and more from any computer or phone

main
ts 502 lines 18.3 KB
Raw
1 import type { ExpoConfig } from "expo/config";
2
3 import { BRAND_ASSET_PATHS } from "../../scripts/lib/brand-assets.ts";
4 import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
5
6 type AppVariant = "development" | "preview" | "production";
7
8 const repoEnv = loadRepoEnv();
9 Object.assign(process.env, repoEnv);
10 // Expo's TypeScript setup otherwise installs `typescript` on every start; we typecheck with tsrs.
11 process.env.EXPO_NO_TYPESCRIPT_SETUP = "1";
12
13 const APP_VARIANT = resolveAppVariant(repoEnv.APP_VARIANT);
14 const isIosPersonalTeamBuild = repoEnv.T3CODE_IOS_PERSONAL_TEAM === "1";
15 const runtimeVersionPolicy =
16 process.env.MOBILE_VERSION_POLICY ??
17 (APP_VARIANT === "development" ? "appVersion" : "fingerprint");
18
19 const personalTeamBundleIdentifier = repoEnv.T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID?.trim();
20 const IOS_BUNDLE_IDENTIFIER_PATTERN = /^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/;
21
22 // Compiled into the native project. Without a relay, Observe's native side could dispatch to
23 // Expo's own ingest before observe.ts turns it off; `.invalid` never resolves (RFC 6761).
24 const observeEndpointUrl = repoEnv.T3CODE_RELAY_URL?.trim()
25 ? new URL("/v1/mobile/observe", repoEnv.T3CODE_RELAY_URL.trim()).toString()
26 : "https://observe.invalid";
27
28 const fromRepoRoot = (relativePath: string) => `../../${relativePath}`;
29 const androidAdaptiveForeground = "./assets/android-icon-foreground.png";
30
31 if (
32 isIosPersonalTeamBuild &&
33 (!personalTeamBundleIdentifier ||
34 !IOS_BUNDLE_IDENTIFIER_PATTERN.test(personalTeamBundleIdentifier))
35 ) {
36 throw new Error(
37 "T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID must be a reverse-DNS identifier such as com.example.t3code when T3CODE_IOS_PERSONAL_TEAM=1.",
38 );
39 }
40
41 const DEVELOPMENT_ASSETS = {
42 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
43 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIconComposerProject),
44 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
45 androidAdaptiveForeground,
46 androidAdaptiveBackgroundColor: "#347FF8",
47 androidAdaptiveBackgroundImage: "./assets/android-icon-background-dev.png",
48 androidSplashIcon: "./assets/android-splash-icon-dev.png",
49 androidMonochromeIcon: "./assets/android-icon-mark.png",
50 androidNotificationIcon: "./assets/android-notification-icon.png",
51 androidNotificationColor: "#00639B",
52 } as const;
53
54 const PREVIEW_ASSETS = {
55 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
56 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIconComposerProject),
57 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
58 androidAdaptiveForeground,
59 androidAdaptiveBackgroundColor: "#111533",
60 androidAdaptiveBackgroundImage: "./assets/android-icon-background-nightly.png",
61 androidSplashIcon: "./assets/android-splash-icon-nightly.png",
62 androidMonochromeIcon: "./assets/android-icon-mark.png",
63 androidNotificationIcon: "./assets/android-notification-icon.png",
64 androidNotificationColor: "#7565C7",
65 } as const;
66
67 const RELEASE_ASSETS = {
68 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
69 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIconComposerProject),
70 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
71 androidAdaptiveForeground,
72 androidAdaptiveBackgroundColor: "#000000",
73 androidAdaptiveBackgroundImage: undefined,
74 androidSplashIcon: "./assets/android-splash-icon-prod.png",
75 androidMonochromeIcon: "./assets/android-icon-mark.png",
76 androidNotificationIcon: "./assets/android-notification-icon.png",
77 androidNotificationColor: "#FFFFFF",
78 } as const;
79
80 const VARIANT_CONFIG = {
81 development: {
82 appName: "T3 Code Dev",
83 scheme: "t3code-dev",
84 iosBundleIdentifier: "com.t3tools.t3code.dev",
85 androidPackage: "com.t3tools.t3code.dev",
86 relyingParty: "clerk.t3.codes",
87 assets: DEVELOPMENT_ASSETS,
88 },
89 preview: {
90 appName: "T3 Code Preview",
91 scheme: "t3code-preview",
92 iosBundleIdentifier: "com.t3tools.t3code.preview",
93 androidPackage: "com.t3tools.t3code.preview",
94 relyingParty: "clerk.t3.codes",
95 assets: PREVIEW_ASSETS,
96 },
97 production: {
98 appName: "T3 Code",
99 scheme: "t3code",
100 iosBundleIdentifier: "com.t3tools.t3code",
101 androidPackage: "com.t3tools.t3code",
102 relyingParty: "clerk.t3.codes",
103 assets: RELEASE_ASSETS,
104 },
105 } as const;
106
107 function resolveAppVariant(value: string | undefined): AppVariant {
108 switch (value) {
109 case "development":
110 case "preview":
111 case "production":
112 return value;
113 case undefined:
114 return "production";
115 default:
116 throw new Error("APP_VARIANT must be development, preview, or production.");
117 }
118 }
119
120 const variant = VARIANT_CONFIG[APP_VARIANT];
121 // Copied thread links open the app. app.t3.codes/.well-known lists every variant's identifiers.
122 const HOSTED_APP_HOST = "app.t3.codes";
123 const iosBundleIdentifier = isIosPersonalTeamBuild
124 ? personalTeamBundleIdentifier!
125 : variant.iosBundleIdentifier;
126
127 const dmSansFonts = {
128 regular: "@expo-google-fonts/dm-sans/400Regular/DMSans_400Regular.ttf",
129 medium: "@expo-google-fonts/dm-sans/500Medium/DMSans_500Medium.ttf",
130 bold: "@expo-google-fonts/dm-sans/700Bold/DMSans_700Bold.ttf",
131 } as const;
132
133 const widgetsPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
134 "expo-widgets",
135 {
136 bundleIdentifier: `${iosBundleIdentifier}.widgets`,
137 groupIdentifier: `group.${iosBundleIdentifier}`,
138 enablePushNotifications: true,
139 // Frequent updates need the iOS entitlement to avoid early throttling.
140 frequentUpdates: true,
141 enableAndroid: true,
142 widgets: [
143 {
144 name: "SubscriptionUsage",
145 displayName: "Subscription usage",
146 description: "Subscription quotas from your connected T3 Code environments.",
147 ios: {
148 configuration: {
149 title: "Subscription usage",
150 description:
151 "Both shows Session and Weekly when available. The Lock Screen shows the tightest selected limit.",
152 parameters: {
153 codexPeriod: {
154 title: "Codex limits",
155 type: "enum",
156 default: "auto",
157 values: [
158 { name: "Both", value: "auto" },
159 { name: "Session", value: "session" },
160 { name: "Weekly", value: "weekly" },
161 ],
162 },
163 claudePeriod: {
164 title: "Claude limits",
165 type: "enum",
166 default: "auto",
167 values: [
168 { name: "Both", value: "auto" },
169 { name: "Session", value: "session" },
170 { name: "Weekly", value: "weekly" },
171 ],
172 },
173 },
174 },
175 supportedFamilies: [
176 "systemSmall",
177 "systemMedium",
178 "systemLarge",
179 "systemExtraLarge",
180 "accessoryRectangular",
181 ],
182 },
183 android: {
184 minWidth: 250,
185 minHeight: 180,
186 targetCellWidth: 4,
187 targetCellHeight: 3,
188 resizeMode: "both",
189 // The embedded layout renders before first launch; publishing replaces it with stored props.
190 initialLayout: "./src/widgets/SubscriptionUsage.android.tsx",
191 },
192 },
193 {
194 name: "AgentActivity",
195 displayName: "Agent Activity",
196 description: "Shows the current state of active T3 Code agents.",
197 android: null,
198 ios: {
199 supportedFamilies: ["systemSmall", "systemMedium", "accessoryRectangular"],
200 // Embeds the layout so the gallery preview and a new widget render
201 // before the app has run once; the app replaces it on publish.
202 initialLayout: "./src/widgets/AgentActivityWidget.tsx",
203 },
204 },
205 ],
206 },
207 ];
208
209 const sharingPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
210 "expo-sharing",
211 {
212 ios: {
213 // Personal Teams cannot sign App Groups or extension targets; keep local builds usable.
214 enabled: !isIosPersonalTeamBuild,
215 extensionBundleIdentifier: `${iosBundleIdentifier}.sharing`,
216 appGroupId: `group.${iosBundleIdentifier}`,
217 activationRule: {
218 supportsText: true,
219 supportsWebUrlWithMaxCount: 1,
220 supportsImageWithMaxCount: 8,
221 supportsMovieWithMaxCount: 8,
222 supportsFileWithMaxCount: 8,
223 },
224 },
225 android: {
226 enabled: true,
227 singleShareMimeTypes: ["*/*"],
228 multipleShareMimeTypes: ["*/*"],
229 },
230 },
231 ];
232
233 // Match iOS PostScript names on Android so RN and the native composer share fonts before runtime loading.
234
235 const config: ExpoConfig = {
236 name: variant.appName,
237 slug: "t3-code",
238 platforms: ["ios", "android"],
239 scheme: variant.scheme,
240 version: repoEnv.T3CODE_MOBILE_VERSION ?? "2.3.0",
241 runtimeVersion: {
242 // Skip costly fingerprinting on dev launches; preview and production OTAs require matching native projects.
243 policy: runtimeVersionPolicy,
244 },
245 orientation: "portrait",
246 icon: variant.assets.appIcon,
247 userInterfaceStyle: "automatic",
248 updates: {
249 enabled: repoEnv.T3CODE_MOBILE_UPDATES_ENABLED !== "0",
250 url: "https://u.expo.dev/d763fcb8-d37c-41ea-a773-b54a0ab4a454",
251 checkAutomatically: "ON_LOAD",
252 fallbackToCacheTimeout: 0,
253 },
254 ios: {
255 icon: variant.assets.iosIcon,
256 supportsTablet: true,
257 requireFullScreen: process.env.T3_SHOWCASE_CAPTURE_BUILD === "1",
258 bundleIdentifier: iosBundleIdentifier,
259 // Avoid Personal Team fallback: it cannot sign App Groups, Apple sign-in or push entitlements.
260 appleTeamId: "ARK85ZXQ4Z",
261 associatedDomains: [
262 `applinks:${variant.relyingParty}`,
263 `webcredentials:${variant.relyingParty}`,
264 `applinks:${HOSTED_APP_HOST}`,
265 ],
266 entitlements: {
267 "keychain-access-groups": [`$(AppIdentifierPrefix)${variant.iosBundleIdentifier}`],
268 },
269 infoPlist: {
270 UISupportedInterfaceOrientations: [
271 "UIInterfaceOrientationPortrait",
272 "UIInterfaceOrientationLandscapeLeft",
273 "UIInterfaceOrientationLandscapeRight",
274 ],
275 NSAppTransportSecurity: {
276 NSAllowsArbitraryLoads: true,
277 },
278 NSLocalNetworkUsageDescription:
279 "Allow T3 Code to connect to T3 Code servers on your local network or tailnet.",
280 // Built with the iOS 27 SDK, only view controllers can hide or style the status bar.
281 UIViewControllerBasedStatusBarAppearance: true,
282 NSPhotoLibraryAddUsageDescription: "Allow T3 Code to save images to your photo library.",
283 // System picture in picture needs background audio to start and survive outside the app.
284 UIBackgroundModes: ["audio"],
285 ITSAppUsesNonExemptEncryption: false,
286 // Capture builds disable multitasking because iPadOS otherwise ignores orientation requests.
287 ...(process.env.T3_SHOWCASE_CAPTURE_BUILD === "1"
288 ? {
289 "UISupportedInterfaceOrientations~ipad": [
290 "UIInterfaceOrientationPortrait",
291 "UIInterfaceOrientationPortraitUpsideDown",
292 "UIInterfaceOrientationLandscapeLeft",
293 "UIInterfaceOrientationLandscapeRight",
294 ],
295 }
296 : {}),
297 },
298 },
299 android: {
300 icon: variant.assets.appIcon,
301 package: variant.androidPackage,
302 ...(repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE
303 ? { googleServicesFile: repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE }
304 : {}),
305 adaptiveIcon: {
306 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
307 ...(variant.assets.androidAdaptiveBackgroundImage
308 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
309 : {}),
310 foregroundImage: variant.assets.androidAdaptiveForeground,
311 monochromeImage: variant.assets.androidMonochromeIcon,
312 },
313 // JS back dispatch needs RN's Android 16 shim and withAndroidPredictiveBackCompat on Android 13-15.
314 predictiveBackGestureEnabled: true,
315 // expo-sensors declares this for its pedometer, which the app does not use.
316 blockedPermissions: ["android.permission.ACTIVITY_RECOGNITION"],
317 intentFilters: [
318 {
319 action: "VIEW",
320 autoVerify: true,
321 data: [{ scheme: "https", host: HOSTED_APP_HOST, pathPrefix: "/threads/" }],
322 category: ["BROWSABLE", "DEFAULT"],
323 },
324 ],
325 },
326 web: {
327 favicon: variant.assets.appIcon,
328 },
329 plugins: [
330 "expo-asset",
331 [
332 "expo-font",
333 {
334 ios: {
335 fonts: [dmSansFonts.regular, dmSansFonts.medium, dmSansFonts.bold],
336 },
337 android: {
338 fonts: [
339 {
340 fontFamily: "DMSans-Regular",
341 fontDefinitions: [{ path: dmSansFonts.regular, weight: 400 }],
342 },
343 {
344 fontFamily: "DMSans-Medium",
345 fontDefinitions: [{ path: dmSansFonts.medium, weight: 500 }],
346 },
347 {
348 fontFamily: "DMSans-Bold",
349 fontDefinitions: [{ path: dmSansFonts.bold, weight: 700 }],
350 },
351 ],
352 },
353 },
354 ],
355 "expo-secure-store",
356 "expo-sqlite",
357 ...(isIosPersonalTeamBuild
358 ? [sharingPlugin]
359 : ["./plugins/withShareExtensionDisplayName.cjs", sharingPlugin]),
360 [
361 "expo-notifications",
362 {
363 icon: variant.assets.androidNotificationIcon,
364 color: variant.assets.androidNotificationColor,
365 mode: APP_VARIANT === "development" ? "development" : "production",
366 },
367 ],
368 // Gate Clerk here: withoutIosPersonalTeamCapabilities runs too early to strip its entitlement.
369 ["@clerk/expo", { theme: "./clerk-theme.json", appleSignIn: !isIosPersonalTeamBuild }],
370 "expo-web-browser",
371 [
372 "expo-quick-actions",
373 {
374 androidIcons: {
375 shortcut_icon: {
376 foregroundImage: variant.assets.androidAdaptiveForeground,
377 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
378 ...(variant.assets.androidAdaptiveBackgroundImage
379 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
380 : {}),
381 },
382 },
383 },
384 ],
385 [
386 "expo-audio",
387 {
388 microphonePermission: "Allow T3 Code to use your microphone for voice input.",
389 recordAudioAndroid: true,
390 enableBackgroundPlayback: false,
391 enableBackgroundRecording: false,
392 },
393 ],
394 [
395 "expo-camera",
396 {
397 cameraPermission: "Allow T3 Code to access your camera so you can scan pairing QR codes.",
398 microphonePermission: false,
399 barcodeScannerEnabled: true,
400 recordAudioAndroid: false,
401 },
402 ],
403 [
404 "expo-image-picker",
405 {
406 photosPermission: false,
407 // `false` makes this plugin add RECORD_AUDIO to blockedPermissions, breaking Android dictation.
408 microphonePermission: "Allow T3 Code to use your microphone for voice input.",
409 },
410 ],
411 [
412 "expo-splash-screen",
413 {
414 image: variant.assets.splashIcon,
415 resizeMode: "contain",
416 backgroundColor: "#ffffff",
417 imageWidth: 220,
418 dark: {
419 image: variant.assets.splashIcon,
420 backgroundColor: "#0a0a0a",
421 },
422 android: {
423 // Android 12+ masks the central two thirds of the 288dp canvas; adaptive layers avoid clipped corners.
424 image: variant.assets.androidSplashIcon,
425 imageWidth: 288,
426 dark: { image: variant.assets.androidSplashIcon },
427 },
428 },
429 ],
430 [
431 "expo-build-properties",
432 {
433 android: {
434 minSdkVersion: 24,
435 // SDK 58 lacks Kotlin 2.3's runtime-inert annotation. R8 needs explicit InputMerger constructors for widgets.
436 extraProguardRules: [
437 "-dontwarn kotlin.MustUseReturnValues",
438 "-keep class * extends androidx.work.InputMerger { <init>(); }",
439 ].join("\n"),
440 },
441 ios: {
442 deploymentTarget: "18.0",
443 // AppCheckCore 11.3+ includes Swift and needs module maps for these Objective-C dependencies.
444 extraPods: [
445 { name: "GoogleUtilities", modular_headers: true },
446 { name: "RecaptchaInterop", modular_headers: true },
447 ],
448 },
449 },
450 ],
451 "./plugins/withIosCocoaPodsUuidCache.cjs",
452 // Compile out the unused pedometer to avoid an iOS motion purpose string.
453 ["expo-sensors", { motionPermission: false }],
454 // Mods run in reverse order; expo-widgets must create and wipe the target before assets are added.
455 ...(!isIosPersonalTeamBuild ? ["./plugins/withWidgetLogoAsset.cjs", widgetsPlugin] : []),
456 "./plugins/withAndroidNetworkSecurityConfig.cjs",
457 "./plugins/withAndroidGradleHeap.cjs",
458 "./plugins/withAndroidInputBackground.cjs",
459 "./plugins/withAndroidModernPopupMenu.cjs",
460 "./plugins/withAndroidModernAlertDialog.cjs",
461 "./plugins/withAndroidPredictiveBackCompat.cjs",
462 // MainActivity mods run in reverse order; extend the tablet-orientation override.
463 "./plugins/withAndroidWindowDisplayMetrics.cjs",
464 "./plugins/withAndroidTabletOrientation.cjs",
465 ...(isIosPersonalTeamBuild ? ["./plugins/withoutIosPersonalTeamCapabilities.cjs"] : []),
466 ],
467 extra: {
468 appVariant: APP_VARIANT,
469 secretsFeatureEnabled: ["1", "true"].includes(
470 process.env.T3CODE_FEATURE_SECRETS?.trim().toLowerCase() ?? "",
471 ),
472 iosPersonalTeamBuild: isIosPersonalTeamBuild,
473 relay: {
474 url: repoEnv.T3CODE_RELAY_URL ?? null,
475 },
476 clerk: {
477 publishableKey: repoEnv.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY ?? null,
478 jwtTemplate: repoEnv.EXPO_PUBLIC_CLERK_JWT_TEMPLATE ?? null,
479 },
480 // Clerk reads these exact names at prebuild. Omit unset values: manifest null becomes truthy {}.
481 EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID,
482 EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID,
483 EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID,
484 EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME,
485 observability: {
486 tracesUrl: repoEnv.EXPO_PUBLIC_OTLP_TRACES_URL ?? "https://api.axiom.co/v1/traces",
487 tracesDataset: repoEnv.EXPO_PUBLIC_OTLP_TRACES_DATASET ?? null,
488 tracesToken: repoEnv.EXPO_PUBLIC_OTLP_TRACES_TOKEN ?? null,
489 },
490 eas: {
491 projectId: "d763fcb8-d37c-41ea-a773-b54a0ab4a454",
492 observe: { endpointUrl: observeEndpointUrl },
493 },
494 },
495 owner: "pingdotgg",
496 experiments: {
497 // Metro only runs babel-plugin-react-compiler when this is set; see src/reactCompilerCoverage.test.ts.
498 reactCompiler: true,
499 },
500 };
501
502 export default config;