Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(push): desktop granted fallback + presence-aware alert deferral

enes912a4e5d5c8f
diff --git a/src/core/agent-status-mirror.test.ts b/src/core/agent-status-mirror.test.ts
index 90e53e566..6d4599973 100644
--- a/src/core/agent-status-mirror.test.ts
+++ b/src/core/agent-status-mirror.test.ts
@@ -29,6 +29,7 @@ import {
onNodeStateChange,
onNodeNowChange,
onInboxActionable,
+ isEventUnresolved,
_resetForTest,
_snapshot,
_inboxSnapshot,
@@ -1461,3 +1462,35 @@ describe('filterMirrorForNodes (usage + inbox)', () => {
expect('inbox' in d).toBe(false)
})
})
+
+describe('isEventUnresolved (presence-hold flush lookup)', () => {
+ beforeEach(() => _resetForTest())
+ afterEach(() => _resetForTest())
+
+ it('true for a live unresolved approval, false once the node leaves blocked', () => {
+ recordAgentEvent(ev({ nodeId: 'n1', state: 'working', newTurn: true }))
+ recordAgentEvent(ev({ nodeId: 'n1', state: 'blocked', lastMessage: 'Approve write' }))
+ const id = _inboxSnapshot().events.find((e) => e.kind === 'approval')!.id
+ expect(isEventUnresolved('n1', id)).toBe(true)
+ // Leaving blocked resolves the card (resolveUnresolvedFor).
+ recordAgentEvent(ev({ nodeId: 'n1', state: 'working' }))
+ expect(isEventUnresolved('n1', id)).toBe(false)
+ })
+
+ it('true for an unread done, false after ackDone', () => {
+ recordAgentEvent(ev({ nodeId: 'n2', state: 'working', newTurn: true }))
+ recordAgentEvent(ev({ nodeId: 'n2', state: 'done', lastMessage: 'All set.' }))
+ const id = _inboxSnapshot().events.find((e) => e.kind === 'done')!.id
+ expect(isEventUnresolved('n2', id)).toBe(true)
+ ackDone('n2')
+ expect(isEventUnresolved('n2', id)).toBe(false)
+ })
+
+ it('false for an unknown event id or the wrong node', () => {
+ recordAgentEvent(ev({ nodeId: 'n3', state: 'working', newTurn: true }))
+ recordAgentEvent(ev({ nodeId: 'n3', state: 'blocked', lastMessage: 'Approve' }))
+ const id = _inboxSnapshot().events.find((e) => e.kind === 'approval')!.id
+ expect(isEventUnresolved('n3', 'no-such-id')).toBe(false)
+ expect(isEventUnresolved('other-node', id)).toBe(false)
+ })
+})
diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.ts
index a8e63f880..61d146bdf 100644
--- a/src/core/agent-status-mirror.ts
+++ b/src/core/agent-status-mirror.ts
@@ -782,6 +782,21 @@ function pushInboxEvent(e: Omit<InboxEvent, 'id'>): void {
}
}
+/**
+ * Is the inbox event `eventId` on `nodeId` STILL unresolved? The desktop push-notify service's
+ * presence-aware hold uses this on the present→away flush to drop an event that got resolved while
+ * it was held: an approval/question the node has since left blocked/waiting for (`resolved:true` via
+ * `resolveUnresolvedFor`), or a `done` the desktop/browser user already read (`ackDone`). A missing
+ * event — never seen, or aged off the capped feed — is NOT relevant either (returns false), so a
+ * held push whose event the mirror no longer tracks is dropped rather than sent late. Pure read.
+ */
+export function isEventUnresolved(nodeId: string, eventId: string): boolean {
+ for (const e of inboxEvents) {
+ if (e.id === eventId && e.nodeId === nodeId) return !e.resolved
+ }
+ return false
+}
+
/** Mark a node's unresolved approval/question events resolved (it left blocked/waiting). */
function resolveUnresolvedFor(nodeId: string): void {
for (const e of inboxEvents) {
diff --git a/src/core/push-notify.test.ts b/src/core/push-notify.test.ts
index 112a64363..ba753120c 100644
--- a/src/core/push-notify.test.ts
+++ b/src/core/push-notify.test.ts
@@ -563,6 +563,144 @@ describe('createPushNotify', () => {
})
})
+ describe('single-sender matrix (granted vs host)', () => {
+ // paired → host only, and neither → inert, are covered in the granted-mode block above. This
+ // pins the third leg: an UNPAIRED host identity (identity present, no phone pinned) must fall
+ // THROUGH to granted mode — the desktop granted-mode fallback (spec: 2026-07-21-push-grants).
+ it('unpaired host identity + grants → GRANTED mode only (host fields absent)', async () => {
+ const em = makeEmitter()
+ const getGrants = vi.fn(() => [{ deviceId: 'd', grant: 'tok-X' }])
+ const h = createPushNotify(
+ baseDeps({
+ subscribe: em.subscribe,
+ getHostIdentity: () => ({ ...IDENTITY, hasPairedPhone: false }),
+ getGrants,
+ hostLabel: () => 'niova'
+ })
+ )
+ em.emit(iev({ nodeId: 'a', title: 'A' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ const body = JSON.parse(fetchMock.mock.calls[0][1].body)
+ expect(body).not.toHaveProperty('hostDeviceId')
+ expect(body).not.toHaveProperty('hostPublicKeyB64')
+ expect(body.hostLabel).toBe('niova')
+ expect(fetchMock.mock.calls[0][1].headers.authorization).toBe('Bearer tok-X')
+ expect(getGrants).toHaveBeenCalled()
+ h.stop()
+ })
+ })
+
+ describe('presence-aware alert deferral', () => {
+ /** A manual present→away poke standing in for the desktop's powerMonitor edge detector. */
+ function presenceEmitter(): { subscribe: (cb: () => void) => () => void; away: () => void } {
+ let cb: (() => void) | null = null
+ return {
+ subscribe: (fn) => {
+ cb = fn
+ return () => {
+ cb = null
+ }
+ },
+ away: () => cb?.()
+ }
+ }
+
+ it('HOLDS alerts while the user is present, releasing them on the away edge', async () => {
+ const em = makeEmitter()
+ const pres = presenceEmitter()
+ const h = createPushNotify(
+ baseDeps({ subscribe: em.subscribe, isUserPresent: () => true, subscribePresence: pres.subscribe })
+ )
+ em.emit(iev({ nodeId: 'a', id: 'e1', title: 'A' }))
+ em.emit(iev({ nodeId: 'b', id: 'e2', title: 'B' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).not.toHaveBeenCalled() // held while present
+ pres.away()
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expect(bodyOf().events.map((e) => e.title)).toEqual(['A', 'B'])
+ h.stop()
+ })
+
+ it('on the away flush, DROPS held events resolved in the mirror and sends the rest', async () => {
+ const em = makeEmitter()
+ const pres = presenceEmitter()
+ const h = createPushNotify(
+ baseDeps({
+ subscribe: em.subscribe,
+ isUserPresent: () => true,
+ subscribePresence: pres.subscribe,
+ // e2 got resolved (answered / read) while held → dropped; e1 still unresolved → sent.
+ isEventUnresolved: (_nodeId, eventId) => eventId !== 'e2'
+ })
+ )
+ em.emit(iev({ nodeId: 'a', id: 'e1', kind: 'approval', title: 'A' }))
+ em.emit(iev({ nodeId: 'b', id: 'e2', kind: 'done', title: 'B' }))
+ pres.away()
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expect(bodyOf().events.map((e) => e.title)).toEqual(['A'])
+ h.stop()
+ })
+
+ it('presence OFF (isUserPresent false) sends immediately — no hold', async () => {
+ const em = makeEmitter()
+ const pres = presenceEmitter()
+ const h = createPushNotify(
+ baseDeps({ subscribe: em.subscribe, isUserPresent: () => false, subscribePresence: pres.subscribe })
+ )
+ em.emit(iev({ nodeId: 'a', title: 'A' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expect(bodyOf().events[0].title).toBe('A')
+ h.stop()
+ })
+
+ it('no presence deps at all = exact legacy behavior (immediate send)', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(baseDeps({ subscribe: em.subscribe }))
+ em.emit(iev({ nodeId: 'a', title: 'A' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ h.stop()
+ })
+
+ it('bounds the hold queue, dropping the OLDEST past the cap of 50', async () => {
+ const em = makeEmitter()
+ const pres = presenceEmitter()
+ const h = createPushNotify(
+ baseDeps({ subscribe: em.subscribe, isUserPresent: () => true, subscribePresence: pres.subscribe })
+ )
+ // 60 events on distinct nodes (so the per-node throttle never interferes). Cap 50 → oldest 10
+ // (t0..t9) drop.
+ for (let i = 0; i < 60; i++) em.emit(iev({ nodeId: `n${i}`, id: `e${i}`, title: `t${i}` }))
+ pres.away()
+ // 50 survivors flush 10/POST across sequential batch windows.
+ for (let i = 0; i < 5; i++) await vi.advanceTimersByTimeAsync(2000)
+ const titles = fetchMock.mock.calls.flatMap((c) =>
+ JSON.parse(c[1].body).events.map((e: { title: string }) => e.title)
+ )
+ expect(titles).toHaveLength(50)
+ expect(titles).toContain('t59') // newest kept
+ expect(titles).not.toContain('t0') // oldest dropped
+ h.stop()
+ })
+
+ it('stop() clears the hold queue (a later away edge sends nothing)', async () => {
+ const em = makeEmitter()
+ const pres = presenceEmitter()
+ const h = createPushNotify(
+ baseDeps({ subscribe: em.subscribe, isUserPresent: () => true, subscribePresence: pres.subscribe })
+ )
+ em.emit(iev({ nodeId: 'a', title: 'A' }))
+ h.stop()
+ pres.away()
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).not.toHaveBeenCalled()
+ })
+ })
+
it('stop() unsubscribes so later events are ignored', async () => {
const em = makeEmitter()
const h = createPushNotify(baseDeps({ subscribe: em.subscribe }))
diff --git a/src/core/push-notify.ts b/src/core/push-notify.ts
index a8090bad4..ee3090e25 100644
--- a/src/core/push-notify.ts
+++ b/src/core/push-notify.ts
@@ -27,6 +27,10 @@ const FETCH_TIMEOUT_MS = 8000
// Backend contract cap for the optional per-event `nodeTitle` (the node's canvas/sidebar name,
// rendered into the alert title as "<Needs you|Completed> — <nodeTitle>").
const NODE_TITLE_MAX = 80
+// Bound on the presence-aware hold queue: while the user is present at the desktop, alerts pile up
+// here until they go idle/lock. Oldest-dropped past this cap; the queue is in-memory, so a restart
+// loses it (the mirror still carries the events — acceptable, documented).
+const HELD_QUEUE_MAX = 50
/** The standing relay host's identity, needed for the backend's (hostDeviceId, hostId-from-pubkey)
* auth. `hasPairedPhone` is what makes the service live at all — no paired phone ⇒ nowhere to fan
@@ -123,6 +127,22 @@ export interface PushNotifyDeps {
* production this is `workspaceStore.getNodeTitle`. Optional / may return undefined — the field
* is then simply omitted from the payload. */
getNodeTitle?: (nodeId: string) => string | undefined
+ /** Presence-aware alert deferral (owner UX call): pushing an ALERT to the phone while the user is
+ * actively at the desktop is noise; when they go idle/lock it's exactly right. When this returns
+ * true at send time, the batched event goes to an in-memory HOLD queue instead of POSTing. Absent
+ * (or always-false, the Server Edition's headless case) ⇒ every event sends immediately, i.e.
+ * exact legacy behavior. Alerts only — the live-update stream (createLiveUpdatePush) is ambient
+ * and never deferred. */
+ isUserPresent?: () => boolean
+ /** Poke on the present→away transition to flush the hold queue. In production the desktop shell
+ * detects the edge (powerMonitor idle poll + lock-screen) and fires `cb`. Returns an unsubscribe.
+ * Paired with `isUserPresent`; absent ⇒ nothing is ever held so nothing needs flushing. */
+ subscribePresence?: (cb: () => void) => () => void
+ /** On the away-flush, drop a held event that got resolved in the mirror while it waited (an
+ * approval/question the node has since left, or a `done` the desktop user already read). In
+ * production this is `agent-status-mirror.isEventUnresolved`. Absent ⇒ all held events flush
+ * unfiltered. */
+ isEventUnresolved?: (nodeId: string, eventId: string) => boolean
/** Override base URL. Defaults to `env.NODETERM_API_BASE || 'https://api.nodeterm.dev'`. */
apiBase?: string
/** Injectable env (DNT guards + local-dev base). Defaults to `process.env`. */
@@ -157,6 +177,9 @@ export function createPushNotify(deps: PushNotifyDeps): PushNotifyHandle {
const throttleMs = deps.throttleMs ?? DEFAULT_THROTTLE_MS
const buffer: PushNotifyEvent[] = []
+ // Presence-aware hold queue: while the user is present, accepted alerts wait here (with the mirror
+ // event id, so the away-flush can drop any that got resolved meanwhile). Bounded, oldest-dropped.
+ const held: { event: PushNotifyEvent; nodeId: string; eventId: string }[] = []
const lastPushAt = new Map<string, number>()
let batchTimer: ReturnType<typeof setTimeout> | null = null
@@ -218,7 +241,7 @@ export function createPushNotify(deps: PushNotifyDeps): PushNotifyHandle {
} catch {
nodeTitle = undefined
}
- buffer.push({
+ const payload: PushNotifyEvent = {
kind: e.kind,
title: e.title,
...(e.detail ? { detail: e.detail } : {}),
@@ -228,10 +251,32 @@ export function createPushNotify(deps: PushNotifyDeps): PushNotifyHandle {
...(e.options && e.options.length > 0 ? { options: e.options } : {}),
...(e.multiSelect ? { multiSelect: true } : {}),
ts: e.ts
- })
+ }
+ // Presence-aware deferral: if the user is at the desktop right now, hold the alert instead of
+ // POSTing it — the present→away flush (subscribePresence) sends the survivors later. Carry the
+ // mirror event id so that flush can drop any that got resolved while held. Bounded/oldest-dropped.
+ if (deps.isUserPresent?.()) {
+ held.push({ event: payload, nodeId: e.nodeId, eventId: e.id })
+ if (held.length > HELD_QUEUE_MAX) held.splice(0, held.length - HELD_QUEUE_MAX)
+ return
+ }
+ buffer.push(payload)
scheduleFlush()
}
+ /** Present→away edge: move held alerts still RELEVANT (unresolved in the mirror) into the send
+ * buffer and flush; drop the rest (answered approval/question, read `done`). No-op when nothing
+ * is held. */
+ function flushHeldOnAway(): void {
+ if (held.length === 0) return
+ const items = held.splice(0, held.length)
+ for (const it of items) {
+ if (deps.isEventUnresolved && !deps.isEventUnresolved(it.nodeId, it.eventId)) continue
+ buffer.push(it.event)
+ }
+ if (buffer.length > 0) scheduleFlush()
+ }
+
async function flush(): Promise<void> {
if (buffer.length === 0) return
// Re-check the gate at flush: identity/grants/setting can change during the batch window.
@@ -270,15 +315,18 @@ export function createPushNotify(deps: PushNotifyDeps): PushNotifyHandle {
}
const unsubscribe = deps.subscribe(onEvent)
+ const unsubPresence = deps.subscribePresence?.(flushHeldOnAway)
return {
stop() {
unsubscribe()
+ unsubPresence?.()
if (batchTimer) {
clearTimeout(batchTimer)
batchTimer = null
}
buffer.length = 0
+ held.length = 0
},
_flushNow: flush
}
diff --git a/src/main/index.ts b/src/main/index.ts
index 5439d3479..81f85724f 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -40,9 +40,11 @@ import {
onInboxActionable,
onNodeStateChange,
onNodeNowChange,
+ isEventUnresolved,
type MirrorSettings
} from '../core/agent-status-mirror'
import { createPushNotify, createLiveUpdatePush } from '../core/push-notify'
+import { createGrantsAccessor } from '../core/push-grants'
import { createAckSweeper } from '../core/ack-sweep'
import { getDeviceId } from '../core/device-id'
import { initRemoteStatusPush } from './remote-ssh/remote-status-push'
@@ -749,16 +751,19 @@ app.whenReady().then(async () => {
})
// Desktop → paired-phone APNs push (spec: apns-push). Feeds off the SAME actionable-event seam
// the mobile Inbox uses (`onInboxActionable`), so it fires exactly on approval/question (post-
- // dedup) + done (turn edge). It's inert unless a phone has been paired (an approved device is
- // pinned) — that's the "standing relay host configured/paired" gate. The host public key
- // (identity every paired phone pinned) + paired flag load async and refresh on a cheap interval,
- // so a mid-run pairing / keyring-unlock is picked up without re-wiring; the getter is sync.
+ // dedup) + done (turn edge). The host public key (identity every paired phone pinned) + paired
+ // flag load async and refresh on a cheap interval, so a mid-run pairing / keyring-unlock is
+ // picked up without re-wiring; the getter is sync.
//
- // Desktop stays RELAY-ONLY: it does NOT wire the SSH-possession push grants
- // (spec: nodeterm-server/docs/specs/2026-07-21-push-grants.md, which the Server Edition uses in
- // src/server/index.ts). A desktop that a phone both relay-PAIRED and dropped a grant on would
- // push the same event to the same phone twice — once identity-signed, once grant-authorized. The
- // grant path is the fallback for hosts with no relay identity; the desktop always has one.
+ // GRANTED-MODE FALLBACK (spec: 2026-07-21-push-grants; owner-approved "B"). The desktop ALSO
+ // wires the SSH-possession push grants the Server Edition uses (src/server/index.ts) — a phone
+ // that reached this Mac by plain SSH drops a signed, device-scoped grant at
+ // `~/.nodeterm/push-grants/<deviceId>.grant` on the Mac's own fs. `resolveTarget` keeps a SINGLE
+ // sender: host-mode only when a relay identity is present AND a phone is paired; else (unpaired,
+ // or no identity) it falls through to the grants. So a plain-SSH phone gets pushes for
+ // Mac-tracked sessions with NO QR pairing, and QR-pairing later flips `hasPairedPhone` true →
+ // host-mode automatically (grants suppressed — no double-push to the same phone).
+ const pushGrants = createGrantsAccessor()
let pushHostKeyB64: string | null = null
let pushHasPairedPhone = false
const refreshPushIdentity = async (): Promise<void> => {
@@ -776,6 +781,49 @@ app.whenReady().then(async () => {
void refreshPushIdentity()
const pushIdentityTimer = setInterval(() => void refreshPushIdentity(), 60_000)
pushIdentityTimer.unref?.()
+ // Presence-aware alert deferral (spec: presence-aware-push; owner UX call). Hold phone ALERTS
+ // while the user is actively at THIS Mac (noise); release them the moment they go idle or lock
+ // the screen (exactly the right time). Presence = powerMonitor: idle < 180s AND not screen-locked.
+ // A 15s poll detects the present→away idle edge; the lock event fires the flush immediately. Only
+ // createPushNotify (alerts) is deferred — the live-update stream stays ambient. When the setting
+ // is off, isUserPresent() is always false ⇒ nothing is ever held ⇒ exact legacy behavior.
+ const PRESENCE_IDLE_AWAY_SECS = 180
+ let screenLocked = false
+ const presenceAwayListeners = new Set<() => void>()
+ const isUserPresent = (): boolean => {
+ if (settingsStore.get().mobilePushPresenceAware === false) return false
+ if (screenLocked) return false
+ try {
+ return powerMonitor.getSystemIdleTime() < PRESENCE_IDLE_AWAY_SECS
+ } catch {
+ return false // powerMonitor unavailable (e.g. no session) ⇒ treat as away, send immediately
+ }
+ }
+ const firePresenceAway = (): void => {
+ for (const cb of presenceAwayListeners) {
+ try {
+ cb()
+ } catch {
+ // A held-flush subscriber must never break its siblings.
+ }
+ }
+ }
+ let wasPresent = isUserPresent()
+ powerMonitor.on('lock-screen', () => {
+ screenLocked = true
+ wasPresent = false
+ firePresenceAway()
+ })
+ powerMonitor.on('unlock-screen', () => {
+ screenLocked = false
+ wasPresent = isUserPresent()
+ })
+ const presenceTimer = setInterval(() => {
+ const present = isUserPresent()
+ if (wasPresent && !present) firePresenceAway() // present → away: flush held alerts
+ wasPresent = present
+ }, 15_000)
+ presenceTimer.unref?.()
createPushNotify({
subscribe: onInboxActionable,
getHostIdentity: () =>
@@ -787,19 +835,32 @@ app.whenReady().then(async () => {
hasPairedPhone: pushHasPairedPhone
}
: null,
+ // Granted-mode fallback (unpaired / no relay identity → push to SSH-dropped grants; see the
+ // block comment above). resolveTarget keeps a single sender: host wins when paired.
+ getGrants: () => pushGrants.get(),
+ markGrantDead: (grant) => pushGrants.markDead(grant),
+ hostLabel: () => hostname(),
mobilePushEnabled: () => settingsStore.get().mobilePushEnabled !== false,
mobilePushNeedsYou: () => settingsStore.get().mobilePushNeedsYou !== false,
mobilePushDone: () => settingsStore.get().mobilePushDone !== false,
isPackaged: () => app.isPackaged,
// The node's canvas/sidebar display title, so the phone can title the alert
// "<Needs you|Completed> — <nodeTitle>" (see workspace-store.getNodeTitle for the freshness note).
- getNodeTitle: (nodeId) => workspaceStore.getNodeTitle(nodeId)
+ getNodeTitle: (nodeId) => workspaceStore.getNodeTitle(nodeId),
+ // Presence-aware deferral wiring (alerts only).
+ isUserPresent,
+ subscribePresence: (cb) => {
+ presenceAwayListeners.add(cb)
+ return () => presenceAwayListeners.delete(cb)
+ },
+ isEventUnresolved: (nodeId, eventId) => isEventUnresolved(nodeId, eventId)
})
// Desktop → paired-phone Live Activity updates (spec: interactive-push-live-activities). Feeds off
// the mirror's state-edge + activity/context seams, throttles activity ticks (≥20s/node), and
- // POSTs to /v1/push/live-update. Same host identity + paired-phone gate as notify, plus its own
- // `mobileLiveActivities` sub-gate under the `mobilePushEnabled` master. Inert without a paired
- // phone — same documented three-surfaces degrade (Server Edition has no standing relay identity).
+ // POSTs to /v1/push/live-update. Same host identity + granted-mode fallback as notify (a
+ // plain-SSH phone's grants also drive Live Activities), plus its own `mobileLiveActivities`
+ // sub-gate under the `mobilePushEnabled` master. Presence deferral does NOT apply here — the
+ // live-update stream is ambient (activity/context ticks), so it is never held.
createLiveUpdatePush({
subscribeStateChange: onNodeStateChange,
subscribeNowChange: onNodeNowChange,
@@ -812,6 +873,9 @@ app.whenReady().then(async () => {
hasPairedPhone: pushHasPairedPhone
}
: null,
+ getGrants: () => pushGrants.get(),
+ markGrantDead: (grant) => pushGrants.markDead(grant),
+ hostLabel: () => hostname(),
mobilePushEnabled: () => settingsStore.get().mobilePushEnabled !== false,
mobileLiveActivities: () => settingsStore.get().mobileLiveActivities !== false,
isPackaged: () => app.isPackaged,
diff --git a/src/renderer/components/settings/sections/NotificationsSection.tsx b/src/renderer/components/settings/sections/NotificationsSection.tsx
index aa7396b50..6ecc50fba 100644
--- a/src/renderer/components/settings/sections/NotificationsSection.tsx
+++ b/src/renderer/components/settings/sections/NotificationsSection.tsx
@@ -13,7 +13,7 @@ const ROWS = {
},
mobilePush: {
title: 'Send push notifications to your paired phone',
- keywords: ['push', 'phone', 'mobile', 'apns', 'ios', 'notification', 'approval', 'question', 'done', 'completed', 'needs you', 'live activity', 'live activities', 'dynamic island', 'lock screen']
+ keywords: ['push', 'phone', 'mobile', 'apns', 'ios', 'notification', 'approval', 'question', 'done', 'completed', 'needs you', 'live activity', 'live activities', 'dynamic island', 'lock screen', 'presence', 'idle', 'hold', 'defer', 'at this computer']
}
}
const ENTRIES = Object.values(ROWS)
@@ -24,6 +24,7 @@ export function NotificationsSection({ isActive }: { isActive: boolean }): React
const mobilePushNeedsYou = useSettings((s) => s.settings.mobilePushNeedsYou)
const mobilePushDone = useSettings((s) => s.settings.mobilePushDone)
const mobileLiveActivities = useSettings((s) => s.settings.mobileLiveActivities)
+ const mobilePushPresenceAware = useSettings((s) => s.settings.mobilePushPresenceAware)
const update = useSettings((s) => s.update)
// The OS refused our test notification (macOS permission denied). macOS never re-prompts
// once the app's record exists, so the only way back is the System Settings pane.
@@ -122,6 +123,17 @@ export function NotificationsSection({ isActive }: { isActive: boolean }): React
/>
}
/>
+ <FieldRow
+ label="Hold phone alerts while you're at this computer"
+ description="Defer approval, question, and completed alerts while you're active here, then send them the moment you go idle or lock the screen. Live Activities are never held."
+ control={
+ <Switch
+ checked={mobilePushPresenceAware}
+ ariaLabel="Hold phone alerts while you're at this computer"
+ onChange={(on) => update({ mobilePushPresenceAware: on })}
+ />
+ }
+ />
</div>
</SearchableRow>
</SettingsSection>
diff --git a/src/server/index.ts b/src/server/index.ts
index a9f0d26fa..db501a23f 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -323,7 +323,12 @@ export async function startServer(
...grantedPushGates,
mobilePushEnabled: () => settingsStore.get().mobilePushEnabled !== false,
mobilePushNeedsYou: () => settingsStore.get().mobilePushNeedsYou !== false,
- mobilePushDone: () => settingsStore.get().mobilePushDone !== false
+ mobilePushDone: () => settingsStore.get().mobilePushDone !== false,
+ // Presence-aware deferral (spec: presence-aware-push) is desktop-only: the Server Edition is
+ // HEADLESS — nobody is sitting at it — so nothing is ever "present". Every alert sends
+ // immediately, unchanged from before this feature. (No subscribePresence/isEventUnresolved
+ // needed: with isUserPresent always false, the hold queue is never touched.)
+ isUserPresent: () => false
})
createLiveUpdatePush({
subscribeStateChange: onNodeStateChange,
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 22048b185..d49d34e70 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -677,6 +677,12 @@ export interface Settings {
* state + activity + context% change (spec: interactive-push-live-activities). Default on.
* Sub-gate under `mobilePushEnabled` (the master switch). Toggle in Settings → Notifications. */
mobileLiveActivities: boolean
+ /** Hold phone ALERTS while you're actively at this computer, releasing them when you go idle or
+ * lock the screen (spec: presence-aware-push). Default on. Desktop-only (the Server Edition is
+ * headless, so it always sends); the live-update stream is never held. Sub-gate under
+ * `mobilePushEnabled`. Off ⇒ alerts always send immediately (legacy). Toggle in Settings →
+ * Notifications. */
+ mobilePushPresenceAware: boolean
/** Deterministic hook-reply approvals (spec: docs/hook-reply-approvals.md). When on (default),
* Claude terminal sessions launch with `NODETERM_PERM_WAIT_SECS` set: the managed permission
* hook holds briefly for a phone/canvas Approve/Deny before falling through to the normal
@@ -731,6 +737,7 @@ export const DEFAULT_SETTINGS: Settings = {
mobilePushNeedsYou: true,
mobilePushDone: true,
mobileLiveActivities: true,
+ mobilePushPresenceAware: true,
// Deterministic hook-reply approvals default ON (existing users pick it up on hydrate). Only
// affects Claude terminal sessions; off reproduces the pre-feature launch bit-for-bit.
hookReplyApprovals: true,