Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/mobile-ios-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ jobs:
run: node -e 'const fs = require("node:fs"); const { expo } = require("./app.json"); fs.appendFileSync(process.env.GITHUB_OUTPUT, `version=${expo.version}\nbuild_number=${expo.ios.buildNumber}\n`)'

- name: Expo prebuild
# Why the env var: app.config.js derives the expo-notifications plugin's
# `mode` from it, which is what writes `aps-environment: production` into the
# entitlements. push-token.ts reports a production APNs environment for every
# non-__DEV__ build, so a development entitlement here would leave TestFlight
# and App Store builds registered against a sandbox they never receive from.
env:
ORCA_IOS_APS_ENVIRONMENT: production
run: npx expo prebuild --platform ios --no-install

- name: Install CocoaPods
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/mobile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ jobs:

- name: Check formatting
run: pnpm format:check

native-dismissal:
runs-on: macos-15
env:
ORCA_BACKGROUND_LAUNCH: '1'
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Check native dismissal ledger
run: |
swiftc mobile/modules/orca-notification-dismissal/ios/PushDismissalLedger.swift \
mobile/modules/orca-notification-dismissal/tests/PushDismissalLedgerChecks.swift \
-o "$RUNNER_TEMP/push-dismissal-ledger-checks"
"$RUNNER_TEMP/push-dismissal-ledger-checks"
2 changes: 2 additions & 0 deletions cloud/apps/push/src/push-delivery-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type PushOrcaData = {
kind?: 'alert' | 'dismiss'
hostFingerprint: string
worktreeId?: string
paneKey?: string
notificationId?: string
notificationSeq: number
notificationEpoch: string
Expand Down Expand Up @@ -51,6 +52,7 @@ export function buildPushDelivery(input: {
orca: {
...(notification.kind ? { kind: notification.kind } : {}),
hostFingerprint,
...(notification.paneKey === undefined ? {} : { paneKey: notification.paneKey }),
...(notification.worktreeId === undefined ? {} : { worktreeId: notification.worktreeId }),
...(notification.notificationId === undefined
? {}
Expand Down
14 changes: 14 additions & 0 deletions cloud/apps/push/src/push-pane-routing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, it } from 'vitest'
import { PushNotificationSchema } from '@orca-cloud/push-contract'
import { buildPushDelivery, orcaDataStrings } from './push-delivery-message.js'

it('preserves pane identity for both APNs and FCM, and accepts older workspace-only messages', () => {
const base = { notificationSeq: 1, notificationEpoch: 'epoch', source: 'agent-task-complete', agentState: 'finished', title: 'Done', body: '', worktreeId: 'folder:/work' }
const paneKey = 'tab-b:11111111-1111-4111-8111-111111111111'
for (const extra of [{}, { paneKey }]) {
const notification = PushNotificationSchema.parse({ ...base, ...extra })
const delivery = buildPushDelivery({ notification, hostFingerprint: 'host', registrationId: 'phone', expiresAt: Date.now() + 300000 })
expect(delivery.orca.paneKey).toBe('paneKey' in extra ? paneKey : undefined)
expect(orcaDataStrings(delivery.orca).paneKey).toBe('paneKey' in extra ? paneKey : undefined)
}
})
3 changes: 2 additions & 1 deletion cloud/packages/push-contract/src/send-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const PushNotificationSchema = z
agentState: PushAgentStateSchema.nullable(),
title: z.string().min(1).max(PUSH_LIMITS.titleMaxChars),
body: z.string().max(PUSH_LIMITS.bodyMaxChars),
worktreeId: z.string().min(1).max(2048).optional()
worktreeId: z.string().min(1).max(2048).optional(),
paneKey: z.string().min(1).max(2048).optional()
})
.strict()
.refine(
Expand Down
2 changes: 1 addition & 1 deletion docs/site/content/docs/mobile.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The Orca mobile companion is an iOS/Android app that pairs with your desktop Orc
- Create a workspace from mobile with the same Smart source modes as desktop: Smart, GitHub, Linear, GitLab, Branch, and Name. With **multiple connected desktops**, **New Workspace** asks which host should create it first (one connected host skips the picker).
- Open a host card's **⋯** menu for **Edit**, **Connect**, **Remove**, and related actions (long-press still works as a shortcut).
- Edit a saved host's display name or connection address without re-pairing (for example when the desktop moves between home LAN and Tailscale).
- Get push notifications when an agent finishes, mirroring [desktop notifications](/docs/notifications).
- Get push notifications when an agent finishes or needs input, mirroring [desktop notifications](/docs/notifications). Turn on **Enable notifications** in the phone's Notifications settings to keep receiving them while Orca is closed; see [Notifications](/docs/notifications#notifications-on-your-phone) for what that sends and where.

The mobile app is intentionally not a full editor — it's a remote control for the desktop you already have running.

Expand Down
18 changes: 18 additions & 0 deletions docs/site/content/docs/notifications.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ Pick a custom desktop notification sound per category under [Settings → Notifi
Supported formats: MP3, WAV, OGG, M4A, AAC, FLAC. One file applies to all delivered desktop notifications.

When you use a custom sound, set its playback volume from the same settings pane.

## Notifications on your phone

Turn on **Enable notifications** in the mobile app to receive agent alerts, including while the app is closed. Notifications are delivered through Orca’s push service and Apple or Google.

The service receives the notification title and text, a native push token, and opaque host and device IDs. Notification text is not end-to-end encrypted. Turning notifications off or unpairing queues removal of the push registration; an offline desktop completes that removal when contact returns.

Alert types always follow each paired desktop’s notification settings. **Notification sound** and **Suppress while focused** apply only to the phone; the latter skips alerts for the workspace currently open there.

**Only when away from desktop** is on by default. Phone alerts are suppressed while the desktop has had keyboard or mouse activity within the last three minutes. Locking the desktop allows alerts immediately. This includes activity in other desktop apps. Suppressed events do not arrive later as a backlog. When desktop presence cannot be determined, alerts are allowed.

Notifications pause after seven days without a foreground mobile registration renewal. Open the mobile app and reconnect to resume. Using desktop alone does not renew this phone’s registration. The app renews while it is open and connected, including periodically during longer visits.

Phone notifications require an updated paired desktop with push support. This mobile version does not create notifications from the live connection to older desktops; update the desktop to receive phone alerts. Headless hosts cannot determine desktop presence and do not infer it from SSH activity; agent completion detection still requires the desktop app. Android background delivery requires Google Play services.

The push service temporarily stores pending notification content for delivery, for up to five minutes
plus cleanup time. Content is cleared after processing; delivery identifiers and outcomes are retained
for 24 hours for retry and duplicate protection. Alerts expire after five minutes.
28 changes: 28 additions & 0 deletions mobile/app.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Why this file exists: a bare "expo-notifications" plugin entry writes
// `aps-environment: development` into the iOS entitlements, while push-token.ts
// reports `production` for every non-__DEV__ build. A TestFlight or App Store build
// would then register a production APNs token against a sandbox entitlement, and the
// gateway's pushes would be accepted by Apple and delivered nowhere. Deriving the
// mode from an env var the release workflow sets makes the two agree by construction
// instead of relying on the export step to rewrite the entitlement.
//
// app.json stays the source for everything else: Expo reads it first and hands it to
// this function, so the fastlane version/buildNumber rewrite still flows through.
const APS_ENVIRONMENT =
process.env.ORCA_IOS_APS_ENVIRONMENT === 'production' ? 'production' : 'development'

module.exports = ({ config }) => ({
...config,
plugins: (config.plugins ?? []).map((plugin) =>
plugin === 'expo-notifications'
? [
'expo-notifications',
{
enableBackgroundRemoteNotifications: true,
mode: APS_ENVIRONMENT,
icon: './assets/notification-icon.png'
}
]
: plugin
)
})
4 changes: 3 additions & 1 deletion mobile/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@
"allowBackup": false,
"permissions": ["RECORD_AUDIO", "MODIFY_AUDIO_SETTINGS"],
"package": "com.stably.orca.mobile",
"versionCode": 16
"versionCode": 16,
"googleServicesFile": "./google-services.json"
},
"plugins": [
"expo-router",
"expo-notifications",
"./plugins/android-respect-rotation-lock.js",
[
"expo-splash-screen",
Expand Down
60 changes: 45 additions & 15 deletions mobile/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { registerPushDismissalTask } from '../src/notifications/push-background-dismissal'
import { readNativeNotificationData } from '../src/notifications/native-notification-data'
import { setNotificationViewingWorkspace } from '../src/notifications/notification-viewing-policy'
import { useCallback, useEffect, useRef } from 'react'
import { View, StyleSheet } from 'react-native'
import { Stack, useRouter } from 'expo-router'
import { Stack, useRouter, useGlobalSearchParams, usePathname } from 'expo-router'
import { StatusBar } from 'expo-status-bar'
import * as SplashScreen from 'expo-splash-screen'
import * as Notifications from 'expo-notifications'
Expand All @@ -10,6 +13,13 @@ import { OrcaLogo } from '../src/components/OrcaLogo'
import { RpcClientProvider } from '../src/transport/client-context'
import { getNotificationNavigationTarget } from '../src/notifications/notification-routing'
import { useOpenNotificationRoute } from '../src/notifications/use-open-notification-route'
import {
isRemotePushTrigger,
pushNotificationRouteData,
foregroundNotificationBehavior
} from '../src/notifications/push-receive'
import { startPushTokenSync } from '../src/notifications/push-registration'
import { ensureDesktopNotificationChannel } from '../src/notifications/desktop-notification-channel'
import { loadHostCatalog } from '../src/transport/host-store'
import { extractPairingCodeFromUrl } from '../src/transport/pairing'
import { recoverMobileRelayPairing } from '../src/transport/mobile-relay-pairing-recovery'
Expand All @@ -19,22 +29,29 @@ import { recoverMobileRelayPairing } from '../src/transport/mobile-relay-pairing
// between the native splash and the first React paint.
SplashScreen.preventAutoHideAsync()

// Why: without this, expo-notifications silently drops notifications when
// the app is in the foreground. Setting all three to true makes iOS/Android
// display the banner, play the sound, and show the badge even while the
// app is active. This runs once at module load time before any notification
// is scheduled.
// Why at boot and not only on subscribe: the gateway's FCM payload targets the
// 'orca-desktop' channel, and a background push can land before any socket has
// connected. Android drops a notification whose channel does not exist yet.
void ensureDesktopNotificationChannel().catch(() => {})
void registerPushDismissalTask().catch(() => {})

// Register before scheduling so foreground delivery uses the same suppression policy.
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowBanner: true,
shouldShowList: true,
shouldPlaySound: true,
shouldSetBadge: false
})
handleNotification: foregroundNotificationBehavior
})

export default function RootLayout() {
const router = useRouter()
const pathname = usePathname()
const { hostId, worktreeId } = useGlobalSearchParams<{ hostId?: string; worktreeId?: string }>()
useEffect(() => {
setNotificationViewingWorkspace(
pathname.includes('/session/') && typeof hostId === 'string' && typeof worktreeId === 'string'
? { hostId, worktreeId }
: null
)
return () => setNotificationViewingWorkspace(null)
}, [pathname, hostId, worktreeId])
const openNotificationRoute = useOpenNotificationRoute()
const handledNotificationIdsRef = useRef<Set<string>>(new Set())

Expand All @@ -44,6 +61,10 @@ export default function RootLayout() {
void recoverMobileRelayPairing()
}, [])

// Why: a rolled APNs/FCM token stops delivering silently, so every paired host
// has to be re-registered with the new one as soon as the provider hands it over.
useEffect(() => startPushTokenSync(), [])

// Why: route `orca://pair?...` deep links to the confirm screen so
// the same pairing flow runs whether the link arrived via QR scan,
// paste, AirDrop, Messages, or `xcrun simctl openurl`. getInitialURL
Expand Down Expand Up @@ -94,9 +115,18 @@ export default function RootLayout() {
}
}

async function getNavigationTarget(data: unknown) {
async function getNavigationTarget(notification: Notifications.Notification) {
const hosts = await loadHostCatalog().catch(() => null)
return getNotificationNavigationTarget(data, {
const data = readNativeNotificationData(notification.request)
// A gateway push names its host by key fingerprint, not by this device's hostId.
// With no catalog to resolve against, such a push stays unrouted instead of
// falling back to whatever hostId its raw data carries.
const routeData = pushNotificationRouteData(
data,
hosts ?? [],
isRemotePushTrigger(notification.request.trigger)
)
return getNotificationNavigationTarget(routeData, {
knownHostIds: hosts ? new Set(hosts.map((host) => host.id)) : undefined,
credentialStatusByHostId: hosts
? new Map(hosts.map((host) => [host.id, host.credentialStatus]))
Expand Down Expand Up @@ -124,7 +154,7 @@ export default function RootLayout() {
}
}

const target = await getNavigationTarget(response.notification.request.content.data)
const target = await getNavigationTarget(response.notification)
clearLastNotificationResponse()
if (disposed) {
return
Expand Down
4 changes: 2 additions & 2 deletions mobile/app/mobile-onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
saveDefaultSessionView,
type MobileSessionView
} from '../src/storage/session-view-preferences'
import { savePushNotificationsEnabled } from '../src/storage/preferences'
import { setRemotePushEnabled } from '../src/notifications/push-registration'

const SLIDE_DURATION_MS = 280

Expand Down Expand Up @@ -127,7 +127,7 @@ function MobileOnboardingFlow({
setError(null)
try {
const enabled = choice === 'enable' ? await ensureNotificationPermissions() : false
await savePushNotificationsEnabled(enabled)
await setRemotePushEnabled(enabled)
advanceOrContinue()
} catch {
setError('Notification settings could not be updated. Try again.')
Expand Down
6 changes: 5 additions & 1 deletion mobile/app/notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NativeNotificationDeliverySettings } from '../src/settings/native-notification-delivery-settings'
import { useRouter } from 'expo-router'
import NotificationsScreen from '../src/settings/notification-settings-screen'
import { nativeNotificationSettingsOperations } from '../src/settings/native-notification-settings-operations'
Expand All @@ -7,6 +8,9 @@ export default function NativeNotificationsRoute() {
<NotificationsScreen
operations={nativeNotificationSettingsOperations}
onBack={() => router.back()}
/>
description="Get agent alerts even when the app is closed. Delivered through Orca’s push service and Apple or Google."
>
{(enabled) => <NativeNotificationDeliverySettings enabled={enabled} />}
</NotificationsScreen>
)
}
Binary file added mobile/assets/notification-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions mobile/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "120364513935",
"project_id": "onorca-cloud",
"storage_bucket": "onorca-cloud.firebasestorage.app"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:120364513935:android:1d951dc430aeb9bc664efa",
"android_client_info": {
"package_name": "com.stably.orca.mobile"
}
},
"oauth_client": [
{
"client_id": "120364513935-evfa8502bp5r9hn7afhd9i03oibs8223.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyBmT_w0OUQSiVfxblx-F0qlRvGkBBkTNQU"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "120364513935-evfa8502bp5r9hn7afhd9i03oibs8223.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"platforms": ["apple"],
"apple": {
"modules": ["OrcaNotificationDismissalModule"],
"appDelegateSubscribers": ["OrcaNotificationDismissalSubscriber"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Pod::Spec.new do |s|
s.name = 'OrcaNotificationDismissal'
s.version = '0.0.1'
s.summary = 'Native notification dismissal and sequence fencing'
s.description = s.summary
s.license = { :type => 'MIT' }
s.author = 'Orca'
s.homepage = 'https://onorca.dev'
s.source = { :git => 'https://github.com/stablyai/orca.git' }
s.platforms = { :ios => '15.1' }
s.swift_version = '5.9'
s.static_framework = true
s.dependency 'ExpoModulesCore'
s.source_files = '**/*.swift'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ExpoModulesCore

public class OrcaNotificationDismissalModule: Module {
public func definition() -> ModuleDefinition {
Name("OrcaNotificationDismissal")
AsyncFunction("remember") { (payload: [String: Any]) in
if let identity = PushDismissalIdentity(payload) { PushDismissalLedger.shared.remember(identity) }
}
AsyncFunction("wasDismissed") { (payload: [String: Any]) -> Bool in
guard let identity = PushDismissalIdentity(payload) else { return false }
return PushDismissalLedger.shared.contains(identity)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ExpoModulesCore
import UserNotifications

public class OrcaNotificationDismissalSubscriber: ExpoAppDelegateSubscriber {
public func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
guard let payload = userInfo["orca"] as? [String: Any],
payload["kind"] as? String == "dismiss", let fence = PushDismissalIdentity(payload)
else { completionHandler(.noData); return }
PushDismissalLedger.shared.remember(fence)
let center = UNUserNotificationCenter.current()
center.getDeliveredNotifications { notifications in
let ids = notifications.compactMap { notification -> String? in
guard let data = notification.request.content.userInfo["orca"] as? [String: Any],
data["hostFingerprint"] as? String == fence.hostFingerprint,
PushDismissalLedger.shared.containsNotification(data) else { return nil }
return notification.request.identifier
}
center.removeDeliveredNotifications(withIdentifiers: ids)
completionHandler(ids.isEmpty ? .noData : .newData)
}
}
}
Loading
Loading