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): per-kind selection for mobile push events

enes618d62e8468d
diff --git a/src/core/push-notify.test.ts b/src/core/push-notify.test.ts
index 2494aefe0..bedbf1c47 100644
--- a/src/core/push-notify.test.ts
+++ b/src/core/push-notify.test.ts
@@ -50,6 +50,8 @@ function baseDeps(over: Partial<PushNotifyDeps> = {}): PushNotifyDeps {
subscribe: () => () => {},
getHostIdentity: () => IDENTITY,
mobilePushEnabled: () => true,
+ mobilePushNeedsYou: () => true,
+ mobilePushDone: () => true,
isPackaged: () => true,
env: {},
fetchImpl: fetchMock as unknown as typeof fetch,
@@ -269,6 +271,76 @@ describe('createPushNotify', () => {
})
})
+ describe('per-kind selection', () => {
+ it('defaults send all kinds (needsYou + done both on)', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(baseDeps({ subscribe: em.subscribe }))
+ em.emit(iev({ nodeId: 'a', kind: 'approval', title: 'A' }))
+ em.emit(iev({ nodeId: 'b', kind: 'question', title: 'B' }))
+ em.emit(iev({ nodeId: 'c', kind: 'done', title: 'C' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(bodyOf().events.map((e) => e.kind)).toEqual(['approval', 'question', 'done'])
+ h.stop()
+ })
+
+ it('needsYou off drops approval + question but done still sends', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(
+ baseDeps({ subscribe: em.subscribe, mobilePushNeedsYou: () => false })
+ )
+ em.emit(iev({ nodeId: 'a', kind: 'approval', title: 'A' }))
+ em.emit(iev({ nodeId: 'b', kind: 'question', title: 'B' }))
+ em.emit(iev({ nodeId: 'c', kind: 'done', title: 'C' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expect(bodyOf().events.map((e) => e.kind)).toEqual(['done'])
+ h.stop()
+ })
+
+ it('done off drops done but needs-you kinds still send', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(baseDeps({ subscribe: em.subscribe, mobilePushDone: () => false }))
+ em.emit(iev({ nodeId: 'a', kind: 'approval', title: 'A' }))
+ em.emit(iev({ nodeId: 'b', kind: 'question', title: 'B' }))
+ em.emit(iev({ nodeId: 'c', kind: 'done', title: 'C' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expect(bodyOf().events.map((e) => e.kind)).toEqual(['approval', 'question'])
+ h.stop()
+ })
+
+ it('both sub-gates off sends nothing (master stays honest)', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(
+ baseDeps({
+ subscribe: em.subscribe,
+ mobilePushNeedsYou: () => false,
+ mobilePushDone: () => false
+ })
+ )
+ em.emit(iev({ nodeId: 'a', kind: 'approval', title: 'A' }))
+ em.emit(iev({ nodeId: 'b', kind: 'question', title: 'B' }))
+ em.emit(iev({ nodeId: 'c', kind: 'done', title: 'C' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).not.toHaveBeenCalled()
+ h.stop()
+ })
+
+ it('a dropped kind does not consume the node throttle window', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(
+ baseDeps({ subscribe: em.subscribe, mobilePushNeedsYou: () => false })
+ )
+ // A dropped approval on node 'a' must not throttle a following done on 'a'.
+ em.emit(iev({ nodeId: 'a', kind: 'approval', title: 'dropped' }))
+ em.emit(iev({ nodeId: 'a', kind: 'done', title: 'kept' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(bodyOf().events).toHaveLength(1)
+ expect(bodyOf().events[0].title).toBe('kept')
+ h.stop()
+ })
+ })
+
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 7b6edc823..215dda6ed 100644
--- a/src/core/push-notify.ts
+++ b/src/core/push-notify.ts
@@ -50,8 +50,12 @@ export interface PushNotifyDeps {
subscribe: (cb: (e: InboxEvent) => void) => () => void
/** The standing relay host identity, or null when none is configured/available. */
getHostIdentity: () => PushHostIdentity | null
- /** The `settings.mobilePushEnabled` gate (default on). */
+ /** The `settings.mobilePushEnabled` gate (default on) — the master switch. */
mobilePushEnabled: () => boolean
+ /** The `settings.mobilePushNeedsYou` sub-gate (default on): approval + question kinds. */
+ mobilePushNeedsYou: () => boolean
+ /** The `settings.mobilePushDone` sub-gate (default on): the done kind. */
+ mobilePushDone: () => boolean
/** `app.isPackaged` — dev never hits the prod API unless a local base is targeted. */
isPackaged: () => boolean
/** Override base URL. Defaults to `env.NODETERM_API_BASE || 'https://api.nodeterm.dev'`. */
@@ -117,9 +121,21 @@ export function createPushNotify(deps: PushNotifyDeps): PushNotifyHandle {
batchTimer.unref?.()
}
+ /** Per-kind sub-gate: "Needs you" covers approval + question, "Completed" covers done. Both
+ * default on; the master `mobilePushEnabled` still wins (checked via liveIdentity). When both
+ * sub-gates are off the service sends nothing — the master toggle stays honest. */
+ function kindAllowed(kind: InboxEvent['kind']): boolean {
+ if (kind === 'done') return deps.mobilePushDone()
+ // approval | question
+ return deps.mobilePushNeedsYou()
+ }
+
function onEvent(e: InboxEvent): void {
// Cheap gate first: if the service is inert, don't buffer anything.
if (!liveIdentity()) return
+ // Per-kind selection: drop before the throttle window is consumed, so a declined kind
+ // never blocks a later accepted one on the same node.
+ if (!kindAllowed(e.kind)) return
const t = now()
// Per-node throttle: at most one push per node per `throttleMs` (mirrors the local notify
// throttle). Recorded at accept time — a declined event costs no throttle window.
diff --git a/src/main/index.ts b/src/main/index.ts
index 8ea79d0c5..c5c260d6a 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -769,6 +769,8 @@ app.whenReady().then(async () => {
}
: null,
mobilePushEnabled: () => settingsStore.get().mobilePushEnabled !== false,
+ mobilePushNeedsYou: () => settingsStore.get().mobilePushNeedsYou !== false,
+ mobilePushDone: () => settingsStore.get().mobilePushDone !== false,
isPackaged: () => app.isPackaged
})
// And push each connected SSH project's slice of it onto its host
diff --git a/src/renderer/components/settings/sections/NotificationsSection.tsx b/src/renderer/components/settings/sections/NotificationsSection.tsx
index 0190cf1ca..4a6a6b473 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']
+ keywords: ['push', 'phone', 'mobile', 'apns', 'ios', 'notification', 'approval', 'question', 'done', 'completed', 'needs you']
}
}
const ENTRIES = Object.values(ROWS)
@@ -21,6 +21,8 @@ const ENTRIES = Object.values(ROWS)
export function NotificationsSection({ isActive }: { isActive: boolean }): React.JSX.Element {
const notifyOnClaudeDone = useSettings((s) => s.settings.notifyOnClaudeDone)
const mobilePushEnabled = useSettings((s) => s.settings.mobilePushEnabled)
+ const mobilePushNeedsYou = useSettings((s) => s.settings.mobilePushNeedsYou)
+ const mobilePushDone = useSettings((s) => s.settings.mobilePushDone)
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.
@@ -80,6 +82,35 @@ export function NotificationsSection({ isActive }: { isActive: boolean }): React
/>
}
/>
+ {/* Per-kind sub-gates. Inert (dimmed, non-interactive) while the master toggle is off. */}
+ <div
+ className={
+ 'mt-3 space-y-3 border-l border-white/10 pl-4' +
+ (mobilePushEnabled ? '' : ' pointer-events-none opacity-40')
+ }
+ aria-disabled={!mobilePushEnabled}
+ >
+ <FieldRow
+ label="Needs you (approvals & questions)"
+ control={
+ <Switch
+ checked={mobilePushNeedsYou}
+ ariaLabel="Push when an agent needs you"
+ onChange={(on) => update({ mobilePushNeedsYou: on })}
+ />
+ }
+ />
+ <FieldRow
+ label="Task completed"
+ control={
+ <Switch
+ checked={mobilePushDone}
+ ariaLabel="Push when a task completes"
+ onChange={(on) => update({ mobilePushDone: on })}
+ />
+ }
+ />
+ </div>
</SearchableRow>
</SettingsSection>
)
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 831cbc412..6dc28faeb 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -625,6 +625,12 @@ export interface Settings {
* question, or finishes a turn (spec: apns-push). Default on — it only fires for users who
* have paired a phone. Toggle in Settings → Notifications. */
mobilePushEnabled: boolean
+ /** Push when an agent needs you: approval requests + questions. Default on. Sub-gate under
+ * `mobilePushEnabled` (the master switch). Toggle in Settings → Notifications. */
+ mobilePushNeedsYou: boolean
+ /** Push when an agent finishes a turn (the `done` kind). Default on. Sub-gate under
+ * `mobilePushEnabled` (the master switch). Toggle in Settings → Notifications. */
+ mobilePushDone: boolean
/** Dictation (desktop/server). Written as a whole object by the renderer. */
speech: SpeechSettings
}
@@ -665,6 +671,8 @@ export const DEFAULT_SETTINGS: Settings = {
telemetryEnabled: false,
phoneAccessEnabled: false,
mobilePushEnabled: true,
+ mobilePushNeedsYou: true,
+ mobilePushDone: true,
speech: { engine: 'whisper', model: 'tiny', language: 'auto', shortcut: 'Cmd+Alt' },
}