9 Commits

Author SHA1 Message Date
space 9dd17cf565 fix: add react-dom and regenerate lock file without --legacy-peer-deps
CodexBar Mobile Build / build-android (push) Successful in 21m11s
CodexBar Mobile Build / release (push) Successful in 11s
expo-router's radix-ui deps require react-dom as a peer. The lock file
was previously generated with --legacy-peer-deps which omitted peer dep
entries, causing `npm ci` on CI to fail with "Missing from lock file".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 11:22:35 +02:00
space 6992e58b9c fixed version issues
CodexBar Mobile Build / build-android (push) Failing after 1m24s
CodexBar Mobile Build / release (push) Has been skipped
2026-06-25 11:13:22 +02:00
Space-Banane 050c8e5cce ci: suppress SIGPIPE from yes | sdkmanager NDK install
CodexBar Mobile Build / build-android (push) Successful in 21m17s
CodexBar Mobile Build / release (push) Successful in 11s
sdkmanager closes stdin once done; yes keeps writing and gets SIGPIPE
(exit 141), failing the step even though the NDK installed successfully.
Add || true to treat SIGPIPE as success.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 21:57:46 +02:00
Space-Banane 6bf66c0afd ci: pre-install NDK 27.1.12297006 before EAS local build
CodexBar Mobile Build / build-android (push) Failing after 52s
CodexBar Mobile Build / release (push) Has been skipped
Gradle's auto-download of the NDK was failing on the runner with
"Archive is not a ZIP archive" — the download was corrupted/unavailable.
Fix by explicitly installing the NDK via sdkmanager after setup-android
so it is present in $ANDROID_HOME before gradlew runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 21:54:18 +02:00
Space-Banane 2c63dcfd75 fix: guard expo-notifications against Expo Go crash on import
CodexBar Mobile Build / build-android (push) Failing after 3m21s
CodexBar Mobile Build / release (push) Has been skipped
SDK 53+ removed push notification support from Expo Go, causing the
module to throw at require-time. The static import in notifications.ts
propagated the error to _layout.tsx and both tab screens, making expo-
router report missing default exports and crash the app.

Switch to a try/catch require() so the module initialises safely in
Expo Go (Notifications stays null, all functions become no-ops) while
still working correctly in EAS / development builds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 21:47:44 +02:00
Space-Banane 487f89699c yes
CodexBar Mobile Build / build-android (push) Successful in 22m24s
CodexBar Mobile Build / release (push) Successful in 23s
2026-06-24 21:13:43 +02:00
Space-Banane ef245d4e61 fix: bump react to 19.2.7 to satisfy react-dom peer dependency
CodexBar Mobile Build / build-android (push) Successful in 21m4s
CodexBar Mobile Build / release (push) Successful in 10s
react-dom@19.2.7 requires react@^19.2.7; the project had 19.2.3 which
caused an ERESOLVE conflict on npm install.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 20:23:50 +02:00
space 17a5ab73cb fix: sync package-lock.json with package.json
CodexBar Mobile Build / build-android (push) Failing after 1m45s
CodexBar Mobile Build / release (push) Has been skipped
2026-06-24 20:20:06 +02:00
space ba7d957155 Maximus upgradus
CodexBar Mobile Build / build-android (push) Failing after 1m38s
CodexBar Mobile Build / release (push) Has been skipped
2026-06-24 20:16:34 +02:00
20 changed files with 1176 additions and 324 deletions
+8 -2
View File
@@ -32,6 +32,9 @@ jobs:
- name: 🏗 Setup Android SDK
uses: android-actions/setup-android@v3
- name: 🏗 Install Android NDK
run: yes | sdkmanager "ndk;27.1.12297006" || true
- name: 🏗 Setup Expo and EAS
uses: expo/expo-github-action@v8
with:
@@ -53,11 +56,14 @@ jobs:
- name: 📝 Rename build to APK
run: mv app-build codexbar-release.apk
- name: 🗜 Zip APK
run: zip codexbar-release.zip codexbar-release.apk
- name: 📤 Upload build artifact
uses: actions/upload-artifact@v3
with:
name: codexbar-android-preview-build
path: codexbar-release.apk
path: codexbar-release.zip
if-no-files-found: error
release:
@@ -84,7 +90,7 @@ jobs:
with:
tag_name: ${{ env.RELEASE_TAG }}
name: ${{ env.RELEASE_TAG }}
files: codexbar-release.apk
files: codexbar-release.zip
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+4 -3
View File
@@ -1,12 +1,12 @@
{
"expo": {
"name": "codexbar.mobile",
"name": "codexbar-mobile",
"slug": "codexbar-mobile",
"scheme": "codexbar",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"userInterfaceStyle": "dark",
"ios": {
"supportsTablet": true
},
@@ -27,7 +27,8 @@
"expo-router",
"expo-status-bar",
"expo-secure-store",
"expo-document-picker"
"expo-document-picker",
"expo-notifications"
],
"extra": {
"router": {},
+6 -20
View File
@@ -1,10 +1,12 @@
import { Tabs } from "expo-router";
import { useColorScheme } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { MaterialIcons } from "@expo/vector-icons";
export default function TabLayout() {
const colorScheme = useColorScheme();
const isDark = colorScheme === "dark";
const insets = useSafeAreaInsets();
return (
<Tabs
@@ -15,8 +17,8 @@ export default function TabLayout() {
tabBarStyle: {
backgroundColor: isDark ? "#09090b" : "#ffffff",
borderTopColor: isDark ? "#27272a" : "#f4f4f5",
height: 56,
paddingBottom: 8,
height: 56 + insets.bottom,
paddingBottom: 8 + insets.bottom,
paddingTop: 6,
},
tabBarLabelStyle: {
@@ -34,24 +36,8 @@ export default function TabLayout() {
),
}}
/>
<Tabs.Screen
name="codex"
options={{
title: "Codex",
tabBarIcon: ({ color, size }) => (
<MaterialIcons name="auto-awesome" size={size} color={color} />
),
}}
/>
<Tabs.Screen
name="claude"
options={{
title: "Claude",
tabBarIcon: ({ color, size }) => (
<MaterialIcons name="psychology" size={size} color={color} />
),
}}
/>
<Tabs.Screen name="codex" options={{ href: null }} />
<Tabs.Screen name="claude" options={{ href: null }} />
<Tabs.Screen
name="settings"
options={{
+20 -9
View File
@@ -17,9 +17,11 @@ import { ErrorMessage } from "@/components/ErrorMessage";
export default function ClaudeTab() {
const {
sessionKey,
auth,
pendingKey,
setPendingKey,
pendingOrg,
setPendingOrg,
usage,
status,
error,
@@ -77,7 +79,7 @@ export default function ClaudeTab() {
<ErrorMessage
message={error && (status === "idle" || status === "error") ? error : null}
/>
{sessionKey ? (
{auth ? (
<View className="flex-row items-center justify-between">
<View className="flex-row items-center gap-x-2.5">
<View className="w-2 h-2 rounded-full bg-green-500" />
@@ -85,7 +87,7 @@ export default function ClaudeTab() {
Connected
</Text>
<Text className="text-xs text-neutral-400 dark:text-neutral-500 font-mono">
{sessionKey.slice(0, 10)}
{auth.sessionKey.slice(0, 10)}
</Text>
</View>
<TouchableOpacity
@@ -102,11 +104,20 @@ export default function ClaudeTab() {
<TextInput
value={pendingKey}
onChangeText={setPendingKey}
placeholder="sk-ant-..."
placeholder="sk-ant-… (required)"
placeholderTextColor="#a3a3a3"
autoCapitalize="none"
autoCorrect={false}
secureTextEntry
className="border border-neutral-200 dark:border-neutral-700 rounded-xl px-3 py-3 text-sm text-neutral-900 dark:text-white bg-white dark:bg-neutral-800 mb-2"
/>
<TextInput
value={pendingOrg}
onChangeText={setPendingOrg}
placeholder="lastActiveOrg UUID (optional)"
placeholderTextColor="#a3a3a3"
autoCapitalize="none"
autoCorrect={false}
className="border border-neutral-200 dark:border-neutral-700 rounded-xl px-3 py-3 text-sm text-neutral-900 dark:text-white bg-white dark:bg-neutral-800 mb-3"
/>
<TouchableOpacity
@@ -127,10 +138,10 @@ export default function ClaudeTab() {
Where to find it
</Text>
<Text className="text-xs text-neutral-500 dark:text-neutral-400 leading-relaxed">
Chrome DevTools Application Cookies claude.ai {" "}
<Text className="font-mono text-neutral-600 dark:text-neutral-300">
sessionKey
</Text>
Chrome DevTools Application Cookies claude.ai copy{" "}
<Text className="font-mono text-neutral-600 dark:text-neutral-300">sessionKey</Text>
{" "}and optionally{" "}
<Text className="font-mono text-neutral-600 dark:text-neutral-300">lastActiveOrg</Text>
</Text>
</View>
</View>
@@ -143,7 +154,7 @@ export default function ClaudeTab() {
Usage
</Text>
{status === "idle" && !sessionKey && (
{status === "idle" && !auth && (
<View className="items-center py-8">
<MaterialIcons name="insert-chart-outlined" size={32} color="#d4d4d4" />
<Text className="text-sm text-neutral-400 text-center mt-3">
+237 -70
View File
@@ -4,20 +4,81 @@ import {
Text,
TouchableOpacity,
RefreshControl,
ActivityIndicator,
} from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { router, useFocusEffect } from "expo-router";
import { useCallback } from "react";
import { useCallback, useEffect } from "react";
import { MaterialIcons } from "@expo/vector-icons";
import { useCodexUsage } from "@/hooks/useCodexUsage";
import { useClaudeUsage } from "@/hooks/useClaudeUsage";
import { ServiceStatusCard } from "@/components/ServiceStatusCard";
import { onUsageDataLoaded } from "@/lib/notifications";
import { ProgressBar } from "@/components/ProgressBar";
import { ResetCountdown } from "@/components/ResetCountdown";
import { windowLabel } from "@/lib/timeUtils";
function UsageRow({
label,
percent,
resetAtSeconds,
resetAtISO,
}: {
label: string;
percent: number;
resetAtSeconds?: number;
resetAtISO?: string;
}) {
const color =
percent >= 90 ? "#ef4444" : percent >= 70 ? "#f59e0b" : "#10a37f";
return (
<View className="mb-4">
<View className="flex-row justify-between items-baseline mb-1.5">
<Text className="text-xs font-medium text-neutral-500 dark:text-neutral-400">
{label}
</Text>
<Text className="text-sm font-bold" style={{ color }}>
{Math.round(percent)}% used
</Text>
</View>
<ProgressBar percent={percent} />
<ResetCountdown resetAtSeconds={resetAtSeconds} resetAtISO={resetAtISO} />
</View>
);
}
function SetupPrompt({ label }: { label: string }) {
return (
<View>
<Text className="text-sm text-neutral-400 dark:text-neutral-500 mb-3">
{label}
</Text>
<TouchableOpacity
onPress={() => router.navigate("/(tabs)/settings")}
className="flex-row items-center self-start gap-x-1.5 px-3 py-2 rounded-xl border border-neutral-200 dark:border-neutral-700"
>
<Text className="text-xs font-semibold text-neutral-600 dark:text-neutral-300">
Set up in Settings
</Text>
<MaterialIcons name="arrow-forward" size={12} color="#737373" />
</TouchableOpacity>
</View>
);
}
export default function DashboardTab() {
const codex = useCodexUsage();
const claude = useClaudeUsage();
// Fire daily digest reschedule + threshold check whenever fresh data arrives
useEffect(() => {
if (codex.status === "success" || claude.status === "success") {
void onUsageDataLoaded(
claude.status === "success" ? claude.usage : null,
codex.status === "success" ? codex.usage : null
);
}
}, [codex.status, claude.status]);
useFocusEffect(
useCallback(() => {
codex.reload();
@@ -33,46 +94,16 @@ export default function DashboardTab() {
claude.refresh();
};
const codexRows =
codex.usage
? [
{
label: `Primary (${windowLabel(codex.usage.rate_limit.primary_window.limit_window_seconds)})`,
percent: codex.usage.rate_limit.primary_window.used_percent,
resetAtSeconds: codex.usage.rate_limit.primary_window.reset_at,
},
{
label: `Secondary (${windowLabel(codex.usage.rate_limit.secondary_window.limit_window_seconds)})`,
percent: codex.usage.rate_limit.secondary_window.used_percent,
resetAtSeconds: codex.usage.rate_limit.secondary_window.reset_at,
},
]
: undefined;
const claudeRows =
claude.usage
? [
{
label: "5-hour window",
percent: claude.usage.five_hour.utilization,
resetAtISO: claude.usage.five_hour.resets_at,
},
{
label: "7-day window",
percent: claude.usage.seven_day.utilization,
resetAtISO: claude.usage.seven_day.resets_at,
},
]
: undefined;
const connectedCount = [codex.auth, claude.auth].filter(Boolean).length;
return (
<SafeAreaView
className="flex-1 bg-neutral-50 dark:bg-neutral-950"
edges={["top", "bottom"]}
edges={["top"]}
>
<ScrollView
className="flex-1"
contentContainerStyle={{ paddingHorizontal: 16, paddingBottom: 32 }}
contentContainerStyle={{ paddingHorizontal: 16, paddingBottom: 40 }}
refreshControl={
<RefreshControl
refreshing={isRefreshing}
@@ -82,15 +113,24 @@ export default function DashboardTab() {
}
>
{/* Header */}
<View className="flex-row items-center justify-between py-5">
<View className="flex-row items-center justify-between pt-6 pb-5">
<View className="flex-row items-center gap-x-3">
<View className="w-10 h-10 rounded-2xl bg-emerald-500 items-center justify-center">
<MaterialIcons name="bar-chart" size={20} color="white" />
</View>
<View>
<Text className="text-2xl font-bold text-neutral-900 dark:text-white tracking-tight">
<Text className="text-xl font-bold text-neutral-900 dark:text-white tracking-tight">
Codexbar
</Text>
<Text className="text-xs text-neutral-400 mt-0.5">
AI usage monitor
{connectedCount === 0
? "No services connected"
: connectedCount === 2
? "2 services connected"
: "1 of 2 services connected"}
</Text>
</View>
</View>
<TouchableOpacity
onPress={handleRefresh}
className="w-9 h-9 rounded-xl bg-neutral-100 dark:bg-neutral-800 items-center justify-center"
@@ -100,48 +140,175 @@ export default function DashboardTab() {
</View>
{/* Codex card */}
<ServiceStatusCard
title="Codex CLI"
icon="auto-awesome"
accentColor="#10a37f"
status={!codex.auth ? "idle" : codex.status}
badge={codex.usage?.plan_type}
rows={codexRows}
unconfiguredLabel="Import auth.json to see your Codex rate limits."
onConfigurePress={() => router.navigate("/(tabs)/codex")}
footer={
codex.usage && !codex.usage.credits.unlimited && codex.usage.credits.has_credits
? (
<View className="flex-row items-center gap-x-2">
<MaterialIcons name="toll" size={14} color="#a3a3a3" />
<Text className="text-xs text-neutral-500 dark:text-neutral-400">
${Number(codex.usage.credits.balance).toFixed(2)} credits remaining
<View className="rounded-2xl bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 mb-4 overflow-hidden">
<View style={{ height: 3, backgroundColor: "#10a37f" }} />
<View className="p-4">
<View className="flex-row items-center justify-between mb-4">
<View className="flex-row items-center gap-x-2.5">
<View
className="w-8 h-8 rounded-xl items-center justify-center"
style={{ backgroundColor: "#10a37f18" }}
>
<MaterialIcons name="auto-awesome" size={16} color="#10a37f" />
</View>
<Text className="text-sm font-semibold text-neutral-900 dark:text-white">
Codex CLI
</Text>
</View>
)
: codex.usage?.credits.unlimited
? (
<View className="flex-row items-center gap-x-2">
<MaterialIcons name="all-inclusive" size={14} color="#10a37f" />
{codex.usage?.plan_type && (
<View className="px-2.5 py-1 rounded-full bg-green-100 dark:bg-green-900/30">
<Text className="text-xs font-semibold text-green-700 dark:text-green-300 capitalize">
{codex.usage.plan_type}
</Text>
</View>
)}
{codex.auth && codex.status === "error" && (
<View className="w-2 h-2 rounded-full bg-red-500" />
)}
{codex.status === "success" && !codex.usage?.plan_type && (
<View className="w-2 h-2 rounded-full bg-green-500" />
)}
</View>
</View>
{!codex.auth && (
<SetupPrompt label="Import auth.json to see your Codex rate limits." />
)}
{codex.auth && codex.status === "loading" && (
<ActivityIndicator
color="#10a37f"
style={{ marginVertical: 16 }}
/>
)}
{codex.auth && codex.status === "error" && (
<View className="flex-row items-center gap-x-2 py-1">
<MaterialIcons name="error-outline" size={16} color="#ef4444" />
<Text className="text-sm text-red-500 dark:text-red-400">
Failed to fetch usage
</Text>
</View>
)}
{codex.status === "success" && codex.usage && (
<View>
<UsageRow
label={`${windowLabel(codex.usage.rate_limit.primary_window.limit_window_seconds)} window`}
percent={codex.usage.rate_limit.primary_window.used_percent}
resetAtSeconds={codex.usage.rate_limit.primary_window.reset_at}
/>
<UsageRow
label={`${windowLabel(codex.usage.rate_limit.secondary_window.limit_window_seconds)} window`}
percent={
codex.usage.rate_limit.secondary_window.used_percent
}
resetAtSeconds={
codex.usage.rate_limit.secondary_window.reset_at
}
/>
{!codex.usage.credits.unlimited &&
codex.usage.credits.has_credits && (
<View className="pt-3 border-t border-neutral-100 dark:border-neutral-800 flex-row items-center gap-x-2">
<MaterialIcons name="toll" size={14} color="#a3a3a3" />
<Text className="text-xs text-neutral-500 dark:text-neutral-400">
${Number(codex.usage.credits.balance).toFixed(2)}{" "}
credits remaining
</Text>
</View>
)}
{codex.usage.credits.unlimited && (
<View className="pt-3 border-t border-neutral-100 dark:border-neutral-800 flex-row items-center gap-x-2">
<MaterialIcons
name="all-inclusive"
size={14}
color="#10a37f"
/>
<Text className="text-xs text-green-600 dark:text-green-400">
Unlimited credits
</Text>
</View>
)
: null
}
/>
)}
</View>
)}
</View>
</View>
{/* Claude card */}
<ServiceStatusCard
title="Claude.ai"
icon="psychology"
accentColor="#d97706"
status={!claude.sessionKey ? "idle" : claude.status}
rows={claudeRows}
unconfiguredLabel="Add your session key to see Claude usage windows."
onConfigurePress={() => router.navigate("/(tabs)/claude")}
<View className="rounded-2xl bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 mb-4 overflow-hidden">
<View style={{ height: 3, backgroundColor: "#d97706" }} />
<View className="p-4">
<View className="flex-row items-center justify-between mb-4">
<View className="flex-row items-center gap-x-2.5">
<View
className="w-8 h-8 rounded-xl items-center justify-center"
style={{ backgroundColor: "#d9770618" }}
>
<MaterialIcons name="psychology" size={16} color="#d97706" />
</View>
<Text className="text-sm font-semibold text-neutral-900 dark:text-white">
Claude.ai
</Text>
</View>
{claude.auth && claude.status === "error" && (
<View className="w-2 h-2 rounded-full bg-red-500" />
)}
{claude.status === "success" && (
<View className="w-2 h-2 rounded-full bg-green-500" />
)}
</View>
{!claude.auth && (
<SetupPrompt label="Add your session key to see Claude usage windows." />
)}
{claude.auth && claude.status === "loading" && (
<ActivityIndicator
color="#d97706"
style={{ marginVertical: 16 }}
/>
)}
{claude.auth && claude.status === "error" && (
<View className="flex-row items-center gap-x-2 py-1">
<MaterialIcons name="error-outline" size={16} color="#ef4444" />
<Text className="text-sm text-red-500 dark:text-red-400">
Failed to fetch usage
</Text>
</View>
)}
{claude.status === "success" && claude.usage && (
<View>
<UsageRow
label="5-hour window"
percent={claude.usage.five_hour.utilization}
resetAtISO={claude.usage.five_hour.resets_at}
/>
<UsageRow
label="7-day window"
percent={claude.usage.seven_day.utilization}
resetAtISO={claude.usage.seven_day.resets_at}
/>
{(claude.usage.seven_day_sonnet ||
claude.usage.seven_day_opus) && (
<View className="pt-3 border-t border-neutral-100 dark:border-neutral-800">
<Text className="text-xs font-semibold uppercase tracking-widest text-neutral-400 mb-3">
By Model (7-day)
</Text>
{claude.usage.seven_day_sonnet && (
<UsageRow
label="Sonnet"
percent={claude.usage.seven_day_sonnet.utilization}
/>
)}
{claude.usage.seven_day_opus && (
<UsageRow
label="Opus"
percent={claude.usage.seven_day_opus.utilization}
/>
)}
</View>
)}
</View>
)}
</View>
</View>
</ScrollView>
</SafeAreaView>
);
+303 -13
View File
@@ -1,18 +1,47 @@
import { useEffect, useState, useCallback } from "react";
import { View, Text, TouchableOpacity, Alert, ScrollView } from "react-native";
import {
View,
Text,
TouchableOpacity,
Alert,
ScrollView,
TextInput,
Switch,
KeyboardAvoidingView,
Platform,
} from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { router, useFocusEffect } from "expo-router";
import { MaterialIcons } from "@expo/vector-icons";
import {
loadCodexAuth,
clearCodexAuth,
saveCodexAuth,
loadClaudeSessionKey,
clearClaudeSessionKey,
saveClaudeSessionKey,
saveClaudeLastActiveOrg,
clearClaudeLastActiveOrg,
} from "@/lib/storage";
import { pickAndReadCodexAuth } from "@/lib/fileReader";
import { resetOnboarding } from "@/lib/setupState";
import { useNotificationSettings } from "@/hooks/useNotificationSettings";
import type { CodexAuth } from "@/types/codex";
import Constants from "expo-constants";
function parseTimeInput(s: string): { hour: number; minute: number } | null {
const m = s.trim().match(/^(\d{1,2}):(\d{2})$/);
if (!m) return null;
const h = parseInt(m[1], 10);
const min = parseInt(m[2], 10);
if (h < 0 || h > 23 || min < 0 || min > 59) return null;
return { hour: h, minute: min };
}
function formatTime(hour: number, minute: number): string {
return `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
}
function SettingRow({
icon,
label,
@@ -88,14 +117,27 @@ function SectionCard({ children }: { children: React.ReactNode }) {
}
function Divider() {
return (
<View className="ml-16 mr-0 h-px bg-neutral-100 dark:bg-neutral-800" />
);
return <View className="ml-16 mr-0 h-px bg-neutral-100 dark:bg-neutral-800" />;
}
export default function SettingsTab() {
const [codexAuth, setCodexAuth] = useState<CodexAuth | null>(null);
const [claudeKey, setClaudeKey] = useState<string | null>(null);
const [pendingKey, setPendingKey] = useState("");
const [pendingOrg, setPendingOrg] = useState("");
const [claudeError, setClaudeError] = useState<string | null>(null);
const notif = useNotificationSettings();
const [timeInput, setTimeInput] = useState("");
const [thresholdInput, setThresholdInput] = useState("");
// Sync local text inputs when settings load
useEffect(() => {
if (notif.loaded) {
setTimeInput(formatTime(notif.settings.dailyHour, notif.settings.dailyMinute));
setThresholdInput(String(notif.settings.thresholdPct));
}
}, [notif.loaded]);
const reload = useCallback(() => {
Promise.all([loadCodexAuth(), loadClaudeSessionKey()]).then(
@@ -110,9 +152,40 @@ export default function SettingsTab() {
reload();
}, [reload]);
useFocusEffect(useCallback(() => {
useFocusEffect(
useCallback(() => {
reload();
}, [reload]));
}, [reload])
);
const handleImportCodex = async () => {
try {
const auth = await pickAndReadCodexAuth();
await saveCodexAuth(auth);
setCodexAuth(auth);
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : "UNKNOWN_ERROR";
if (msg !== "PICKER_CANCELLED") {
Alert.alert("Import failed", msg);
}
}
};
const handleSaveClaude = async () => {
const trimmed = pendingKey.trim();
if (!trimmed.startsWith("sk-ant-")) {
setClaudeError("Key must start with sk-ant-");
return;
}
const orgTrimmed = pendingOrg.trim() || undefined;
await saveClaudeSessionKey(trimmed);
if (orgTrimmed) await saveClaudeLastActiveOrg(orgTrimmed);
else await clearClaudeLastActiveOrg();
setClaudeKey(trimmed);
setPendingKey("");
setPendingOrg("");
setClaudeError(null);
};
const handleClearCodex = () => {
Alert.alert(
@@ -172,6 +245,26 @@ export default function SettingsTab() {
);
};
const handleTimeBlur = useCallback(() => {
const parsed = parseTimeInput(timeInput);
if (parsed) {
void notif.update({ dailyHour: parsed.hour, dailyMinute: parsed.minute });
} else {
// Reset to last valid value
setTimeInput(formatTime(notif.settings.dailyHour, notif.settings.dailyMinute));
}
}, [timeInput, notif]);
const handleThresholdBlur = useCallback(() => {
const n = parseInt(thresholdInput, 10);
if (!isNaN(n) && n >= 1 && n <= 99) {
void notif.update({ thresholdPct: n });
} else {
setThresholdInput(String(notif.settings.thresholdPct));
}
}, [thresholdInput, notif]);
const canSaveClaude = pendingKey.trim().startsWith("sk-ant-");
const appVersion = Constants.expoConfig?.version ?? "1.0.0";
return (
@@ -179,7 +272,15 @@ export default function SettingsTab() {
className="flex-1 bg-neutral-50 dark:bg-neutral-950"
edges={["top", "bottom"]}
>
<ScrollView className="flex-1" contentContainerStyle={{ paddingBottom: 48 }}>
<KeyboardAvoidingView
className="flex-1"
behavior={Platform.OS === "ios" ? "padding" : "height"}
>
<ScrollView
className="flex-1"
contentContainerStyle={{ paddingBottom: 48 }}
keyboardShouldPersistTaps="handled"
>
{/* Header */}
<View className="px-4 py-5">
<Text className="text-2xl font-bold text-neutral-900 dark:text-white tracking-tight">
@@ -195,7 +296,11 @@ export default function SettingsTab() {
<SettingRow
icon="check-circle"
label="Connected"
value={codexAuth.accountId ? `${codexAuth.accountId.slice(0, 16)}` : undefined}
value={
codexAuth.accountId
? `${codexAuth.accountId.slice(0, 16)}`
: undefined
}
disabled
/>
<Divider />
@@ -210,7 +315,7 @@ export default function SettingsTab() {
<SettingRow
icon="upload-file"
label="Import auth.json"
onPress={() => router.navigate("/(tabs)/codex")}
onPress={handleImportCodex}
/>
)}
</SectionCard>
@@ -235,11 +340,195 @@ export default function SettingsTab() {
/>
</>
) : (
<SettingRow
icon="vpn-key"
label="Enter session key"
onPress={() => router.navigate("/(tabs)/claude")}
<View className="p-4">
{claudeError && (
<Text className="text-xs text-red-500 mb-2">
{claudeError}
</Text>
)}
<TextInput
value={pendingKey}
onChangeText={(t) => {
setPendingKey(t);
setClaudeError(null);
}}
placeholder="sk-ant-… (required)"
placeholderTextColor="#a3a3a3"
autoCapitalize="none"
autoCorrect={false}
secureTextEntry
className="border border-neutral-200 dark:border-neutral-700 rounded-xl px-3 py-3 text-sm text-neutral-900 dark:text-white bg-neutral-50 dark:bg-neutral-800 mb-2"
/>
<TextInput
value={pendingOrg}
onChangeText={setPendingOrg}
placeholder="lastActiveOrg UUID (optional)"
placeholderTextColor="#a3a3a3"
autoCapitalize="none"
autoCorrect={false}
className="border border-neutral-200 dark:border-neutral-700 rounded-xl px-3 py-3 text-sm text-neutral-900 dark:text-white bg-neutral-50 dark:bg-neutral-800 mb-3"
/>
<TouchableOpacity
onPress={handleSaveClaude}
disabled={!canSaveClaude}
className="py-3 px-4 rounded-xl items-center"
style={{
backgroundColor: canSaveClaude ? "#d97706" : "#e5e5e5",
}}
>
<Text
className="font-semibold text-sm"
style={{ color: canSaveClaude ? "white" : "#a3a3a3" }}
>
Save Session Key
</Text>
</TouchableOpacity>
<Text className="text-xs text-neutral-400 text-center mt-3 leading-relaxed">
Chrome DevTools Application Cookies claude.ai {" "}
<Text className="font-mono text-neutral-500">sessionKey</Text>
</Text>
</View>
)}
</SectionCard>
{/* Notifications section */}
<SectionHeader title="Notifications" />
<SectionCard>
{notif.permissionStatus !== "granted" ? (
<TouchableOpacity
onPress={async () => {
const granted = await notif.askPermissions();
if (!granted && notif.permissionStatus === "denied") {
Alert.alert(
"Notifications blocked",
"Go to Settings → CodexBar → Notifications to enable them."
);
}
}}
className="flex-row items-center gap-x-3 py-3.5 px-4"
>
<View className="w-8 items-center">
<MaterialIcons name="notifications-off" size={20} color="#737373" />
</View>
<View className="flex-1">
<Text className="text-sm font-medium text-neutral-800 dark:text-neutral-100">
Enable notifications
</Text>
<Text className="text-xs text-neutral-400 mt-0.5">
{notif.permissionStatus === "denied"
? "Blocked — open system Settings to allow"
: "Required to receive alerts"}
</Text>
</View>
{notif.permissionStatus !== "denied" && (
<View className="px-2.5 py-1 rounded-full bg-amber-100 dark:bg-amber-900/30">
<Text className="text-xs font-semibold text-amber-700 dark:text-amber-300">
Allow
</Text>
</View>
)}
</TouchableOpacity>
) : (
<>
{/* Daily digest */}
<View className="flex-row items-center gap-x-3 py-3.5 px-4">
<View className="w-8 items-center">
<MaterialIcons name="alarm" size={20} color="#737373" />
</View>
<View className="flex-1">
<Text className="text-sm font-medium text-neutral-800 dark:text-neutral-100">
Daily digest
</Text>
<Text className="text-xs text-neutral-400 mt-0.5">
Daily reminder with last-known usage
</Text>
</View>
<Switch
value={notif.settings.dailyEnabled}
onValueChange={(v) => void notif.update({ dailyEnabled: v })}
trackColor={{ false: "#e5e5e5", true: "#10a37f" }}
thumbColor="white"
/>
</View>
{notif.settings.dailyEnabled && (
<>
<Divider />
<View className="flex-row items-center gap-x-3 py-3 px-4">
<View className="w-8 items-center">
<MaterialIcons name="schedule" size={20} color="#737373" />
</View>
<Text className="flex-1 text-sm font-medium text-neutral-800 dark:text-neutral-100">
Time
</Text>
<TextInput
value={timeInput}
onChangeText={setTimeInput}
onBlur={handleTimeBlur}
placeholder="09:00"
placeholderTextColor="#a3a3a3"
keyboardType="numbers-and-punctuation"
returnKeyType="done"
maxLength={5}
className="text-sm font-mono text-neutral-600 dark:text-neutral-300 text-right"
style={{ minWidth: 52 }}
/>
</View>
</>
)}
<Divider />
{/* Threshold alert */}
<View className="flex-row items-center gap-x-3 py-3.5 px-4">
<View className="w-8 items-center">
<MaterialIcons name="warning" size={20} color="#737373" />
</View>
<View className="flex-1">
<Text className="text-sm font-medium text-neutral-800 dark:text-neutral-100">
Low quota alert
</Text>
<Text className="text-xs text-neutral-400 mt-0.5">
Alert when weekly quota runs low
</Text>
</View>
<Switch
value={notif.settings.thresholdEnabled}
onValueChange={(v) => void notif.update({ thresholdEnabled: v })}
trackColor={{ false: "#e5e5e5", true: "#d97706" }}
thumbColor="white"
/>
</View>
{notif.settings.thresholdEnabled && (
<>
<Divider />
<View className="flex-row items-center gap-x-3 py-3 px-4">
<View className="w-8 items-center">
<MaterialIcons name="battery-alert" size={20} color="#737373" />
</View>
<Text className="flex-1 text-sm font-medium text-neutral-800 dark:text-neutral-100">
Alert below
</Text>
<View className="flex-row items-center gap-x-1">
<TextInput
value={thresholdInput}
onChangeText={setThresholdInput}
onBlur={handleThresholdBlur}
keyboardType="numeric"
returnKeyType="done"
maxLength={2}
className="text-sm font-mono text-neutral-600 dark:text-neutral-300 text-right"
style={{ minWidth: 28 }}
/>
<Text className="text-sm text-neutral-400 dark:text-neutral-500">
% remaining
</Text>
</View>
</View>
</>
)}
</>
)}
</SectionCard>
@@ -261,6 +550,7 @@ export default function SettingsTab() {
/>
</SectionCard>
</ScrollView>
</KeyboardAvoidingView>
</SafeAreaView>
);
}
+2 -1
View File
@@ -2,11 +2,12 @@ import "../global.css";
import { Stack } from "expo-router";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { StatusBar } from "expo-status-bar";
import "@/lib/notifications"; // registers setNotificationHandler on app start
export default function RootLayout() {
return (
<SafeAreaProvider>
<StatusBar style="auto" />
<StatusBar style="light" />
<Stack screenOptions={{ headerShown: false }} />
</SafeAreaProvider>
);
+45 -9
View File
@@ -11,17 +11,28 @@ import {
import { SafeAreaView } from "react-native-safe-area-context";
import { router } from "expo-router";
import { MaterialIcons } from "@expo/vector-icons";
import { saveClaudeSessionKey, loadClaudeSessionKey } from "@/lib/storage";
import {
saveClaudeSessionKey,
saveClaudeLastActiveOrg,
clearClaudeLastActiveOrg,
loadClaudeSessionKey,
loadClaudeLastActiveOrg,
} from "@/lib/storage";
export default function OnboardingClaudeScreen() {
const [savedKey, setSavedKey] = useState<string | null>(null);
const [savedOrg, setSavedOrg] = useState<string | null>(null);
const [pendingKey, setPendingKey] = useState("");
const [pendingOrg, setPendingOrg] = useState("");
const [error, setError] = useState<string | null>(null);
useEffect(() => {
loadClaudeSessionKey().then((k) => {
Promise.all([loadClaudeSessionKey(), loadClaudeLastActiveOrg()]).then(
([k, o]) => {
if (k) setSavedKey(k);
});
if (o) setSavedOrg(o);
}
);
}, []);
const canSave = pendingKey.trim().startsWith("sk-ant-");
@@ -32,11 +43,16 @@ export default function OnboardingClaudeScreen() {
setError("Session key must start with sk-ant-");
return;
}
const orgTrimmed = pendingOrg.trim() || undefined;
await saveClaudeSessionKey(trimmed);
if (orgTrimmed) await saveClaudeLastActiveOrg(orgTrimmed);
else await clearClaudeLastActiveOrg();
setSavedKey(trimmed);
setSavedOrg(orgTrimmed ?? null);
setPendingKey("");
setPendingOrg("");
setError(null);
}, [pendingKey]);
}, [pendingKey, pendingOrg]);
return (
<SafeAreaView className="flex-1 bg-neutral-950">
@@ -92,7 +108,8 @@ export default function OnboardingClaudeScreen() {
</Text>
{savedKey ? (
<View className="flex-row items-center gap-x-3 bg-neutral-900 rounded-2xl p-4 border border-neutral-800 mb-4">
<View className="bg-neutral-900 rounded-2xl border border-neutral-800 mb-4 overflow-hidden">
<View className="flex-row items-center gap-x-3 p-4">
<View
className="w-10 h-10 rounded-xl items-center justify-center"
style={{ backgroundColor: "#d9770622" }}
@@ -108,12 +125,22 @@ export default function OnboardingClaudeScreen() {
<TouchableOpacity
onPress={() => {
setSavedKey(null);
setSavedOrg(null);
setPendingKey("");
setPendingOrg("");
}}
>
<Text className="text-neutral-400 text-xs">Change</Text>
</TouchableOpacity>
</View>
{savedOrg && (
<View className="border-t border-neutral-800 px-4 py-3">
<Text className="text-neutral-500 text-xs font-mono">
org: {savedOrg.slice(0, 8)}
</Text>
</View>
)}
</View>
) : (
<View>
{error && (
@@ -127,13 +154,22 @@ export default function OnboardingClaudeScreen() {
setPendingKey(t);
setError(null);
}}
placeholder="sk-ant-..."
placeholder="sk-ant-… (required)"
placeholderTextColor="#525252"
autoCapitalize="none"
autoCorrect={false}
secureTextEntry
className="border border-neutral-800 rounded-xl px-4 py-3.5 text-sm text-white bg-neutral-900 mb-3"
/>
<TextInput
value={pendingOrg}
onChangeText={setPendingOrg}
placeholder="lastActiveOrg UUID (optional)"
placeholderTextColor="#525252"
autoCapitalize="none"
autoCorrect={false}
className="border border-neutral-800 rounded-xl px-4 py-3.5 text-sm text-white bg-neutral-900 mb-3"
/>
<TouchableOpacity
onPress={handleSave}
disabled={!canSave}
@@ -149,11 +185,11 @@ export default function OnboardingClaudeScreen() {
</TouchableOpacity>
<View className="bg-neutral-900 rounded-xl p-4 border border-neutral-800">
<Text className="text-neutral-400 text-xs font-semibold uppercase tracking-widest mb-2">
How to find your session key
How to find your credentials
</Text>
<Text className="text-neutral-500 text-sm leading-relaxed">
Open Claude.ai in Chrome DevTools (F12) Application Cookies claude.ai find{" "}
<Text className="text-neutral-300 font-mono">sessionKey</Text>
Open Claude.ai in Chrome DevTools (F12) Application Cookies claude.ai{"\n"}
Copy <Text className="text-neutral-300 font-mono">sessionKey</Text> and optionally <Text className="text-neutral-300 font-mono">lastActiveOrg</Text>
</Text>
</View>
</View>
+1
View File
@@ -5,5 +5,6 @@ module.exports = function (api) {
["babel-preset-expo", { jsxImportSource: "nativewind" }],
"nativewind/babel",
],
plugins: ["react-native-reanimated/plugin"],
};
};
+41 -32
View File
@@ -4,15 +4,18 @@ import {
loadClaudeSessionKey,
saveClaudeSessionKey,
clearClaudeSessionKey,
loadClaudeLastActiveOrg,
saveClaudeLastActiveOrg,
clearClaudeLastActiveOrg,
} from "@/lib/storage";
import type { ClaudeUsageResponse } from "@/types/claude";
import type { ClaudeAuth, ClaudeUsageResponse } from "@/types/claude";
type Status = "idle" | "loading" | "success" | "error";
async function doFetch(
sessionKey: string,
auth: ClaudeAuth,
set: {
sessionKey: (v: string | null) => void;
auth: (v: ClaudeAuth | null) => void;
usage: (v: ClaudeUsageResponse | null) => void;
status: (v: Status) => void;
error: (v: string | null) => void;
@@ -21,10 +24,13 @@ async function doFetch(
set.status("loading");
set.error(null);
try {
const orgs = await fetchClaudeOrgs(sessionKey);
let orgUuid = auth.lastActiveOrg;
if (!orgUuid) {
const orgs = await fetchClaudeOrgs(auth);
if (!orgs.length) throw new Error("NO_ORGS_FOUND");
const orgUuid = orgs[0].uuid;
const data = await fetchClaudeUsage(sessionKey, orgUuid);
orgUuid = orgs[0].uuid;
}
const data = await fetchClaudeUsage(auth, orgUuid);
set.usage(data);
set.status("success");
} catch (e: unknown) {
@@ -33,29 +39,32 @@ async function doFetch(
set.status("error");
if (msg === "TOKEN_EXPIRED") {
await clearClaudeSessionKey();
set.sessionKey(null);
set.auth(null);
}
}
}
export function useClaudeUsage() {
const [sessionKey, setSessionKey] = useState<string | null>(null);
const [auth, setAuth] = useState<ClaudeAuth | null>(null);
const [pendingKey, setPendingKey] = useState("");
const [pendingOrg, setPendingOrg] = useState("");
const [usage, setUsage] = useState<ClaudeUsageResponse | null>(null);
const [status, setStatus] = useState<Status>("idle");
const [error, setError] = useState<string | null>(null);
const setters = { sessionKey: setSessionKey, usage: setUsage, status: setStatus, error: setError };
const setters = { auth: setAuth, usage: setUsage, status: setStatus, error: setError };
useEffect(() => {
loadClaudeSessionKey().then((stored) => {
if (stored) setSessionKey(stored);
});
Promise.all([loadClaudeSessionKey(), loadClaudeLastActiveOrg()]).then(
([key, org]) => {
if (key) setAuth({ sessionKey: key, lastActiveOrg: org ?? undefined });
}
);
}, []);
useEffect(() => {
if (sessionKey) void doFetch(sessionKey, setters);
}, [sessionKey]);
if (auth) void doFetch(auth, setters);
}, [auth]);
const saveKey = useCallback(async () => {
const trimmed = pendingKey.trim();
@@ -63,47 +72,47 @@ export function useClaudeUsage() {
setError("Session key must start with sk-ant-");
return;
}
const orgTrimmed = pendingOrg.trim() || undefined;
await saveClaudeSessionKey(trimmed);
setSessionKey(trimmed);
if (orgTrimmed) await saveClaudeLastActiveOrg(orgTrimmed);
else await clearClaudeLastActiveOrg();
setAuth({ sessionKey: trimmed, lastActiveOrg: orgTrimmed });
setPendingKey("");
setPendingOrg("");
setError(null);
}, [pendingKey]);
}, [pendingKey, pendingOrg]);
const refresh = useCallback(async () => {
if (!sessionKey) return;
await doFetch(sessionKey, setters);
}, [sessionKey]);
if (!auth) return;
await doFetch(auth, setters);
}, [auth]);
// Re-reads the session key from storage and fetches fresh data. Call from
// useFocusEffect so the dashboard stays current when the key is saved from
// another tab. If the string value is unchanged, React bails out on setState
// so we trigger the fetch directly.
const reload = useCallback(async () => {
const stored = await loadClaudeSessionKey();
if (!stored) {
setSessionKey(null);
const [key, org] = await Promise.all([loadClaudeSessionKey(), loadClaudeLastActiveOrg()]);
if (!key) {
setAuth(null);
setUsage(null);
setStatus("idle");
return;
}
// If already set to the same string, setState bails out and [sessionKey]
// effect won't fire, so call the fetch directly.
setSessionKey(stored);
void doFetch(stored, setters);
// Creating a new object always triggers the [auth] useEffect even if values are identical
setAuth({ sessionKey: key, lastActiveOrg: org ?? undefined });
}, []);
const clearKey = useCallback(async () => {
await clearClaudeSessionKey();
setSessionKey(null);
setAuth(null);
setUsage(null);
setStatus("idle");
setError(null);
}, []);
return {
sessionKey,
auth,
pendingKey,
setPendingKey,
pendingOrg,
setPendingOrg,
usage,
status,
error,
+64
View File
@@ -0,0 +1,64 @@
import { useState, useEffect, useCallback } from "react";
import {
loadNotifSettings,
saveNotifSettings,
type NotifSettings,
} from "@/lib/storage";
import {
requestPermissions,
getPermissionStatus,
scheduleDailyDigest,
cancelDailyDigest,
} from "@/lib/notifications";
export function useNotificationSettings() {
const [settings, setSettings] = useState<NotifSettings>({
dailyEnabled: false,
dailyHour: 9,
dailyMinute: 0,
thresholdEnabled: false,
thresholdPct: 20,
});
const [permissionStatus, setPermissionStatus] = useState("undetermined");
const [loaded, setLoaded] = useState(false);
useEffect(() => {
Promise.all([loadNotifSettings(), getPermissionStatus()]).then(
([stored, status]) => {
setSettings(stored);
setPermissionStatus(status);
setLoaded(true);
}
);
}, []);
const askPermissions = useCallback(async (): Promise<boolean> => {
const granted = await requestPermissions();
setPermissionStatus(granted ? "granted" : "denied");
return granted;
}, []);
const update = useCallback(
async (patch: Partial<NotifSettings>) => {
const next = { ...settings, ...patch };
setSettings(next);
await saveNotifSettings(next);
// Keep scheduled notification in sync when toggling or changing time
const dailyChanged =
"dailyEnabled" in patch ||
"dailyHour" in patch ||
"dailyMinute" in patch;
if (dailyChanged) {
if (next.dailyEnabled) {
await scheduleDailyDigest(next.dailyHour, next.dailyMinute, null, null);
} else {
await cancelDailyDigest();
}
}
},
[settings]
);
return { settings, permissionStatus, loaded, askPermissions, update };
}
+24 -15
View File
@@ -1,24 +1,33 @@
import type { ClaudeOrg, ClaudeUsageResponse } from "@/types/claude";
import type { ClaudeAuth, ClaudeOrg, ClaudeUsageResponse } from "@/types/claude";
const BASE_URL = "https://claude.ai/api";
function cookieHeader(sessionKey: string): Record<string, string> {
const BROWSER_UA =
"Mozilla/5.0 (Linux; Android 10; Mobile) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36";
function buildHeaders(auth: ClaudeAuth): Record<string, string> {
const cookies = [`sessionKey=${auth.sessionKey}`];
if (auth.lastActiveOrg) cookies.push(`lastActiveOrg=${auth.lastActiveOrg}`);
return {
Cookie: `sessionKey=${sessionKey}`,
"Accept": "application/json",
"Origin": "https://claude.ai",
Cookie: cookies.join("; "),
Accept: "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.9",
"User-Agent": BROWSER_UA,
Referer: "https://claude.ai/",
Origin: "https://claude.ai",
"anthropic-client-platform": "web_claude_to_cc_migration",
};
}
export async function fetchClaudeOrgs(sessionKey: string): Promise<ClaudeOrg[]> {
export async function fetchClaudeOrgs(auth: ClaudeAuth): Promise<ClaudeOrg[]> {
const response = await fetch(`${BASE_URL}/organizations`, {
headers: cookieHeader(sessionKey),
headers: buildHeaders(auth),
credentials: "omit",
});
if (response.status === 401 || response.status === 403) {
throw new Error("TOKEN_EXPIRED");
}
if (!response.ok) {
await response.text().catch(() => null);
if (response.status === 401 || response.status === 403) throw new Error("TOKEN_EXPIRED");
throw new Error(`HTTP_ERROR_${response.status}`);
}
@@ -26,17 +35,17 @@ export async function fetchClaudeOrgs(sessionKey: string): Promise<ClaudeOrg[]>
}
export async function fetchClaudeUsage(
sessionKey: string,
auth: ClaudeAuth,
orgUuid: string
): Promise<ClaudeUsageResponse> {
const response = await fetch(`${BASE_URL}/organizations/${orgUuid}/usage`, {
headers: cookieHeader(sessionKey),
headers: buildHeaders(auth),
credentials: "omit",
});
if (response.status === 401 || response.status === 403) {
throw new Error("TOKEN_EXPIRED");
}
if (!response.ok) {
await response.text().catch(() => null);
if (response.status === 401 || response.status === 403) throw new Error("TOKEN_EXPIRED");
throw new Error(`HTTP_ERROR_${response.status}`);
}
+1
View File
@@ -18,6 +18,7 @@ export async function fetchCodexUsage(auth: CodexAuth): Promise<CodexUsageRespon
throw new Error("TOKEN_EXPIRED");
}
if (!response.ok) {
await response.text().catch(() => null);
throw new Error(`HTTP_ERROR_${response.status}`);
}
+6 -8
View File
@@ -1,5 +1,4 @@
import * as DocumentPicker from "expo-document-picker";
import { File } from "expo-file-system/next";
import type { CodexAuth } from "@/types/codex";
export async function pickAndReadCodexAuth(): Promise<CodexAuth> {
@@ -8,13 +7,11 @@ export async function pickAndReadCodexAuth(): Promise<CodexAuth> {
copyToCacheDirectory: true,
});
if (result.canceled) {
throw new Error("PICKER_CANCELLED");
}
if (result.canceled) throw new Error("PICKER_CANCELLED");
const { uri } = result.assets[0];
const file = new File(uri);
const text = file.text();
const response = await fetch(uri);
const text = await response.text();
let parsed: Record<string, unknown>;
try {
@@ -23,8 +20,9 @@ export async function pickAndReadCodexAuth(): Promise<CodexAuth> {
throw new Error("INVALID_JSON");
}
const accessToken = parsed["accessToken"] as string | undefined;
const accountId = parsed["accountId"] as string | undefined;
const tokens = parsed["tokens"] as Record<string, unknown> | undefined;
const accessToken = (tokens?.["access_token"] ?? parsed["accessToken"]) as string | undefined;
const accountId = (tokens?.["account_id"] ?? parsed["accountId"]) as string | undefined;
if (!accessToken || typeof accessToken !== "string") {
throw new Error("MISSING_ACCESS_TOKEN");
+160
View File
@@ -0,0 +1,160 @@
import type * as NotificationsType from "expo-notifications";
import {
loadNotifSettings,
loadNotifThresholdLastFired,
saveNotifThresholdLastFired,
} from "@/lib/storage";
import type { ClaudeUsageResponse } from "@/types/claude";
import type { CodexUsageResponse } from "@/types/codex";
// expo-notifications push notifications were removed from Expo Go in SDK 53.
// Use require() so the initialization error is caught gracefully in Expo Go.
let Notifications: typeof NotificationsType | null = null;
try {
Notifications = require("expo-notifications") as typeof NotificationsType;
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldShowBanner: true,
shouldShowList: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
} catch {
// Running in Expo Go or native module unavailable — notifications disabled.
}
export async function requestPermissions(): Promise<boolean> {
if (!Notifications) return false;
const { status } = await Notifications.requestPermissionsAsync();
return status === "granted";
}
export async function getPermissionStatus(): Promise<string> {
if (!Notifications) return "undetermined";
const { status } = await Notifications.getPermissionsAsync();
return status;
}
const DAILY_ID = "codexbar-daily-digest";
export async function scheduleDailyDigest(
hour: number,
minute: number,
claudeUsage: ClaudeUsageResponse | null,
codexUsage: CodexUsageResponse | null
): Promise<void> {
if (!Notifications) return;
try {
await Notifications.cancelScheduledNotificationAsync(DAILY_ID);
} catch {}
const parts: string[] = [];
if (claudeUsage) {
parts.push(`Claude 7d: ${Math.round(claudeUsage.seven_day.utilization)}% used`);
}
if (codexUsage) {
parts.push(
`Codex: ${Math.round(codexUsage.rate_limit.secondary_window.used_percent)}% used`
);
}
await Notifications.scheduleNotificationAsync({
identifier: DAILY_ID,
content: {
title: "Usage Digest",
body:
parts.length > 0
? parts.join(" · ")
: "Open to check your usage limits",
},
trigger: {
type: Notifications.SchedulableTriggerInputTypes.CALENDAR,
hour,
minute,
repeats: true,
},
});
}
export async function cancelDailyDigest(): Promise<void> {
if (!Notifications) return;
try {
await Notifications.cancelScheduledNotificationAsync(DAILY_ID);
} catch {}
}
interface ThresholdAlert {
service: string;
window: string;
remaining: number;
}
function buildThresholdAlerts(
thresholdPct: number,
claudeUsage: ClaudeUsageResponse | null,
codexUsage: CodexUsageResponse | null
): ThresholdAlert[] {
const alerts: ThresholdAlert[] = [];
if (claudeUsage) {
const remaining = 100 - claudeUsage.seven_day.utilization;
if (remaining <= thresholdPct) {
alerts.push({ service: "Claude", window: "7-day", remaining });
}
}
if (codexUsage) {
const remaining = 100 - codexUsage.rate_limit.secondary_window.used_percent;
if (remaining <= thresholdPct) {
alerts.push({ service: "Codex", window: "weekly", remaining });
}
}
return alerts;
}
/** Call this after every successful usage fetch. Reschedules daily digest and fires threshold alerts. */
export async function onUsageDataLoaded(
claudeUsage: ClaudeUsageResponse | null,
codexUsage: CodexUsageResponse | null
): Promise<void> {
const settings = await loadNotifSettings();
if (settings.dailyEnabled) {
await scheduleDailyDigest(
settings.dailyHour,
settings.dailyMinute,
claudeUsage,
codexUsage
);
}
if (settings.thresholdEnabled) {
const today = new Date().toISOString().slice(0, 10);
const lastFired = await loadNotifThresholdLastFired();
if (lastFired !== today) {
const alerts = buildThresholdAlerts(
settings.thresholdPct,
claudeUsage,
codexUsage
);
if (alerts.length > 0 && Notifications) {
await Notifications.scheduleNotificationAsync({
content: {
title: "Low quota warning",
body: alerts
.map(
(a) =>
`${a.service} ${a.window}: ${Math.round(a.remaining)}% remaining`
)
.join("\n"),
},
trigger: null,
});
await saveNotifThresholdLastFired(today);
}
}
}
}
+64
View File
@@ -3,8 +3,59 @@ import * as SecureStore from "expo-secure-store";
const KEYS = {
CODEX_AUTH: "codexbar_codex_auth",
CLAUDE_SESSION_KEY: "codexbar_claude_session_key",
CLAUDE_LAST_ACTIVE_ORG: "codexbar_claude_last_active_org",
NOTIF_DAILY_ENABLED: "notifDailyEnabled",
NOTIF_DAILY_HOUR: "notifDailyHour",
NOTIF_DAILY_MINUTE: "notifDailyMinute",
NOTIF_THRESHOLD_ENABLED: "notifThresholdEnabled",
NOTIF_THRESHOLD_PCT: "notifThresholdPct",
NOTIF_THRESHOLD_LAST_FIRED: "notifThresholdLastFired",
} as const;
export interface NotifSettings {
dailyEnabled: boolean;
dailyHour: number;
dailyMinute: number;
thresholdEnabled: boolean;
/** Alert when remaining quota falls below this % (e.g. 20 = fire when < 20% left) */
thresholdPct: number;
}
export async function loadNotifSettings(): Promise<NotifSettings> {
const [de, dh, dm, te, tp] = await Promise.all([
SecureStore.getItemAsync(KEYS.NOTIF_DAILY_ENABLED),
SecureStore.getItemAsync(KEYS.NOTIF_DAILY_HOUR),
SecureStore.getItemAsync(KEYS.NOTIF_DAILY_MINUTE),
SecureStore.getItemAsync(KEYS.NOTIF_THRESHOLD_ENABLED),
SecureStore.getItemAsync(KEYS.NOTIF_THRESHOLD_PCT),
]);
return {
dailyEnabled: de === "true",
dailyHour: dh !== null ? parseInt(dh, 10) : 9,
dailyMinute: dm !== null ? parseInt(dm, 10) : 0,
thresholdEnabled: te === "true",
thresholdPct: tp !== null ? parseInt(tp, 10) : 20,
};
}
export async function saveNotifSettings(s: NotifSettings): Promise<void> {
await Promise.all([
SecureStore.setItemAsync(KEYS.NOTIF_DAILY_ENABLED, String(s.dailyEnabled)),
SecureStore.setItemAsync(KEYS.NOTIF_DAILY_HOUR, String(s.dailyHour)),
SecureStore.setItemAsync(KEYS.NOTIF_DAILY_MINUTE, String(s.dailyMinute)),
SecureStore.setItemAsync(KEYS.NOTIF_THRESHOLD_ENABLED, String(s.thresholdEnabled)),
SecureStore.setItemAsync(KEYS.NOTIF_THRESHOLD_PCT, String(s.thresholdPct)),
]);
}
export async function loadNotifThresholdLastFired(): Promise<string | null> {
return SecureStore.getItemAsync(KEYS.NOTIF_THRESHOLD_LAST_FIRED);
}
export async function saveNotifThresholdLastFired(date: string): Promise<void> {
await SecureStore.setItemAsync(KEYS.NOTIF_THRESHOLD_LAST_FIRED, date);
}
export async function saveCodexAuth(auth: {
accessToken: string;
accountId?: string;
@@ -29,10 +80,23 @@ export async function loadClaudeSessionKey(): Promise<string | null> {
return SecureStore.getItemAsync(KEYS.CLAUDE_SESSION_KEY);
}
export async function saveClaudeLastActiveOrg(orgId: string): Promise<void> {
await SecureStore.setItemAsync(KEYS.CLAUDE_LAST_ACTIVE_ORG, orgId);
}
export async function loadClaudeLastActiveOrg(): Promise<string | null> {
return SecureStore.getItemAsync(KEYS.CLAUDE_LAST_ACTIVE_ORG);
}
export async function clearClaudeLastActiveOrg(): Promise<void> {
await SecureStore.deleteItemAsync(KEYS.CLAUDE_LAST_ACTIVE_ORG);
}
export async function clearCodexAuth(): Promise<void> {
await SecureStore.deleteItemAsync(KEYS.CODEX_AUTH);
}
export async function clearClaudeSessionKey(): Promise<void> {
await SecureStore.deleteItemAsync(KEYS.CLAUDE_SESSION_KEY);
await SecureStore.deleteItemAsync(KEYS.CLAUDE_LAST_ACTIVE_ORG);
}
+16 -6
View File
@@ -5,11 +5,17 @@ export function formatResetCountdown(resetAtSeconds: number): string {
if (diffSeconds <= 0) return "resetting now";
if (diffSeconds < 60) return "resets in <1m";
const hours = Math.floor(diffSeconds / 3600);
const totalHours = Math.floor(diffSeconds / 3600);
const minutes = Math.floor((diffSeconds % 3600) / 60);
if (hours > 0 && minutes > 0) return `resets in ${hours}h ${minutes}m`;
if (hours > 0) return `resets in ${hours}h`;
if (totalHours >= 24) {
const days = Math.floor(totalHours / 24);
const hours = totalHours % 24;
if (hours > 0) return `resets in ${days}d ${hours}h`;
return `resets in ${days}d`;
}
if (totalHours > 0 && minutes > 0) return `resets in ${totalHours}h ${minutes}m`;
if (totalHours > 0) return `resets in ${totalHours}h`;
return `resets in ${minutes}m`;
}
@@ -19,7 +25,11 @@ export function formatResetCountdownISO(isoString: string): string {
}
export function windowLabel(limitWindowSeconds: number): string {
if (limitWindowSeconds <= 3600) return "1h window";
if (limitWindowSeconds <= 86400) return "24h window";
return `${Math.round(limitWindowSeconds / 3600)}h window`;
const hours = limitWindowSeconds / 3600;
if (hours < 24) return `${Math.round(hours)}h`;
const days = hours / 24;
const wholeDays = Math.floor(days);
const remainderHours = Math.round(hours - wholeDays * 24);
if (remainderHours === 0) return `${wholeDays}d`;
return `${wholeDays}d ${remainderHours}h`;
}
+61 -32
View File
@@ -15,14 +15,18 @@
"expo-document-picker": "~56.0.4",
"expo-file-system": "~56.0.8",
"expo-linking": "~56.0.14",
"expo-notifications": "~56.0.18",
"expo-router": "~56.2.11",
"expo-secure-store": "~56.0.4",
"expo-status-bar": "~56.0.4",
"nativewind": "^4.2.6",
"react": "^19.2.7",
"react": "19.2.3",
"react-dom": "^19.2.3",
"react-native": "0.85.3",
"react-native-reanimated": "4.3.1",
"react-native-safe-area-context": "~5.7.0",
"react-native-screens": "4.25.2"
"react-native-screens": "4.25.2",
"react-native-worklets": "^0.8.3"
},
"devDependencies": {
"@types/react": "~19.2.2",
@@ -572,7 +576,6 @@
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.29.7.tgz",
"integrity": "sha512-N7zArUXWzAMzm+/N0uPBeVB3Fam5lMxtUwMmDK5f/IBBS7a7p1qeUoxd/6CckXoxUdgsntq1Dh8xNW06maZbDQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/helper-plugin-utils": "^7.29.7"
},
@@ -1054,7 +1057,6 @@
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.29.7.tgz",
"integrity": "sha512-I+WYbGBAiCn7nA6xBrlgPH+MB7HWb4u8pv5S0Pv7OtwNvIFvCCb24YlttKEeUFVurfBCEaOTnuhlqsb7f0Z5Dg==",
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/helper-plugin-utils": "^7.29.7"
},
@@ -1070,7 +1072,6 @@
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.29.7.tgz",
"integrity": "sha512-NCSEJ4sLFU2gqAub45HYh4fus2yQ36rr6ei6vpU7NdoJqCpxvEG8E6eJpscGyXP3VHD2Ny+fSXr04k1hoUrFqA==",
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/helper-plugin-utils": "^7.29.7"
},
@@ -2907,6 +2908,12 @@
}
}
},
"node_modules/badgin": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/badgin/-/badgin-1.2.3.tgz",
"integrity": "sha512-NQGA7LcfCpSzIbGRbkgjgdWkjy7HI+Th5VLxTJfW5EeaAf3fnS+xWQaQOCYiny+q6QSvxqoSO04vCx+4u++EJw==",
"license": "MIT"
},
"node_modules/balanced-match": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz",
@@ -3738,6 +3745,15 @@
}
}
},
"node_modules/expo-application": {
"version": "56.0.3",
"resolved": "https://registry.npmjs.org/expo-application/-/expo-application-56.0.3.tgz",
"integrity": "sha512-DdGGPlMuM6cSTeKhbvh6OeLr2O/+EI5BHKYrD+Do8sJPYgLwzGrgESELfyjJCpEhFzT+TgKIdmLmWXhNUQnHiw==",
"license": "MIT",
"peerDependencies": {
"expo": "*"
}
},
"node_modules/expo-constants": {
"version": "56.0.18",
"resolved": "https://registry.npmjs.org/expo-constants/-/expo-constants-56.0.18.tgz",
@@ -3854,6 +3870,24 @@
"react-native": "*"
}
},
"node_modules/expo-notifications": {
"version": "56.0.18",
"resolved": "https://registry.npmjs.org/expo-notifications/-/expo-notifications-56.0.18.tgz",
"integrity": "sha512-HHnrwyCLC5srFojcHYS2KskbNroy9o2fwPKdyhjrdjjrBu4sNRKm4LepcuZjDy98cZKEm89WIPW8O45vut8Rgw==",
"license": "MIT",
"dependencies": {
"@expo/image-utils": "^0.10.1",
"abort-controller": "^3.0.0",
"badgin": "^1.1.5",
"expo-application": "~56.0.3",
"expo-constants": "~56.0.18"
},
"peerDependencies": {
"expo": "*",
"react": "*",
"react-native": "*"
}
},
"node_modules/expo-router": {
"version": "56.2.11",
"resolved": "https://registry.npmjs.org/expo-router/-/expo-router-56.2.11.tgz",
@@ -6592,9 +6626,9 @@
}
},
"node_modules/react": {
"version": "19.2.7",
"resolved": "https://registry.npmjs.org/react/-/react-19.2.7.tgz",
"integrity": "sha512-HNe9WslTbXmFK8o8cmwgAeJFSBvt1bPdHCVKtaaV+WlAN36mpT4hcRpwbf3fY56ar2oIXzsBpOAiIRHAdY0OlQ==",
"version": "19.2.3",
"resolved": "https://registry.npmjs.org/react/-/react-19.2.3.tgz",
"integrity": "sha512-Ku/hhYbVjOQnXDZFv2+RibmLFGwFdeeKHFcOTlrt7xplBnya5OGn/hIRDsqDiSUcfORsDC7MPxwork8jBwsIWA==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
@@ -6611,16 +6645,15 @@
}
},
"node_modules/react-dom": {
"version": "19.2.7",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.7.tgz",
"integrity": "sha512-t0BRVXvbiE/o20Hfw669rLbMCDWtYZLvmJigy2f0MxsXF+71pxhR3xOkspmsO8h3ZlNzyibAmtCa3l4lYKk6gQ==",
"version": "19.2.3",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.3.tgz",
"integrity": "sha512-yELu4WmLPw5Mr/lmeEpox5rw3RETacE++JgHqQzd2dg+YbJuat3jH4ingc+WPZhxaoFzdv9y33G+F7Nl5O0GBg==",
"license": "MIT",
"peer": true,
"dependencies": {
"scheduler": "^0.27.0"
},
"peerDependencies": {
"react": "^19.2.7"
"react": "^19.2.3"
}
},
"node_modules/react-fast-compare": {
@@ -7013,26 +7046,24 @@
"resolved": "https://registry.npmjs.org/react-native-is-edge-to-edge/-/react-native-is-edge-to-edge-1.3.1.tgz",
"integrity": "sha512-NIXU/iT5+ORyCc7p0z2nnlkouYKX425vuU1OEm6bMMtWWR9yvb+Xg5AZmImTKoF9abxCPqrKC3rOZsKzUYgYZA==",
"license": "MIT",
"peer": true,
"peerDependencies": {
"react": "*",
"react-native": "*"
}
},
"node_modules/react-native-reanimated": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-4.5.0.tgz",
"integrity": "sha512-+iPfvK34PKKYP/p/4TaBliFkbfvjGDIvXuiiaxvISP5ip7sWegvlacwU/uAV6zNDSSmX0tDyER7PurPMKGDipA==",
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-4.3.1.tgz",
"integrity": "sha512-KhGsS0YkCA+gusgyzlf9hnqzVPIR398KTpqXyqq/+yYJJPAvyEEPKcxlB0xtOOXSMrR2A9uRKVARVQhZwrOh+Q==",
"license": "MIT",
"peer": true,
"dependencies": {
"react-native-is-edge-to-edge": "^1.3.1",
"semver": "^7.7.3"
},
"peerDependencies": {
"react": "*",
"react-native": "0.83 - 0.86",
"react-native-worklets": "0.10.x"
"react-native": "0.81 - 0.85",
"react-native-worklets": "0.8.x"
}
},
"node_modules/react-native-safe-area-context": {
@@ -7060,30 +7091,28 @@
}
},
"node_modules/react-native-worklets": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/react-native-worklets/-/react-native-worklets-0.10.0.tgz",
"integrity": "sha512-JhE6IxDf6iabC0qu3+TAKA4v9RlluXmoIngPQX7/QUByf75lfrsHZ6/dQhyjEWnp1EEQiwzz8Cpew140ZcewDw==",
"version": "0.8.3",
"resolved": "https://registry.npmjs.org/react-native-worklets/-/react-native-worklets-0.8.3.tgz",
"integrity": "sha512-oCBJROyLU7yG/1R8s0INMflygTH71bx+5XcYkH0CM938TlhSoVbiunE1WVW5FZa51vwYqfLie/IXMX2s1Kh3eg==",
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/plugin-transform-arrow-functions": "^7.27.1",
"@babel/plugin-transform-class-properties": "^7.28.6",
"@babel/plugin-transform-classes": "^7.28.6",
"@babel/plugin-transform-nullish-coalescing-operator": "^7.28.6",
"@babel/plugin-transform-optional-chaining": "^7.28.6",
"@babel/plugin-transform-class-properties": "^7.27.1",
"@babel/plugin-transform-classes": "^7.28.4",
"@babel/plugin-transform-nullish-coalescing-operator": "^7.27.1",
"@babel/plugin-transform-optional-chaining": "^7.27.1",
"@babel/plugin-transform-shorthand-properties": "^7.27.1",
"@babel/plugin-transform-template-literals": "^7.27.1",
"@babel/plugin-transform-unicode-regex": "^7.27.1",
"@babel/preset-typescript": "^7.28.5",
"@babel/types": "^7.27.1",
"@babel/preset-typescript": "^7.27.1",
"convert-source-map": "^2.0.0",
"semver": "^7.7.4"
"semver": "^7.7.3"
},
"peerDependencies": {
"@babel/core": "*",
"@react-native/metro-config": "*",
"react": "*",
"react-native": "0.83 - 0.86"
"react-native": "0.81 - 0.85"
}
},
"node_modules/react-native/node_modules/commander": {
+6 -2
View File
@@ -10,14 +10,18 @@
"expo-document-picker": "~56.0.4",
"expo-file-system": "~56.0.8",
"expo-linking": "~56.0.14",
"expo-notifications": "~56.0.18",
"expo-router": "~56.2.11",
"expo-secure-store": "~56.0.4",
"expo-status-bar": "~56.0.4",
"nativewind": "^4.2.6",
"react": "^19.2.7",
"react": "19.2.3",
"react-dom": "^19.2.3",
"react-native": "0.85.3",
"react-native-reanimated": "4.3.1",
"react-native-safe-area-context": "~5.7.0",
"react-native-screens": "4.25.2"
"react-native-screens": "4.25.2",
"react-native-worklets": "^0.8.3"
},
"devDependencies": {
"@types/react": "~19.2.2",
+5
View File
@@ -1,3 +1,8 @@
export interface ClaudeAuth {
sessionKey: string;
lastActiveOrg?: string;
}
export interface ClaudeOrg {
uuid: string;
name: string;