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(sfx): retro sound effects when a turn finishes / a session needs you

enesf104650a3922
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index e17d6f704..ec7314400 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
+import { playSfx, primeSfx } from '@renderer/lib/sfx'
import {
addEdge,
applyEdgeChanges,
@@ -5246,7 +5247,22 @@ export function Canvas() {
// normalizers (`shared/agents/normalize.ts`): working / waiting / blocked / done. On a turn
// finishing / needing attention while the window is in the background: mark unread +
// (with consent, throttled) notify.
+ // Browsers (Server Edition) keep an AudioContext suspended until a user gesture, so the very
+ // first chirp would be swallowed. Prime it on the first interaction; Electron doesn't need it.
+ useEffect(() => {
+ const prime = (): void => primeSfx()
+ window.addEventListener('pointerdown', prime, { once: true })
+ window.addEventListener('keydown', prime, { once: true })
+ return () => {
+ window.removeEventListener('pointerdown', prime)
+ window.removeEventListener('keydown', prime)
+ }
+ }, [])
+
const notifyCooldownRef = useRef<Record<string, number>>({})
+ // Sound effects have their OWN cooldown: they fire whether or not the window is focused, so they
+ // can't share the notification one (which only ticks in the background).
+ const sfxCooldownRef = useRef<Record<string, number>>({})
useEffect(() => {
// Notification context = the node's folder name (or its title).
const contextFor = (nodeId: string): string => {
@@ -5265,12 +5281,22 @@ export function Canvas() {
if (e.sessionId) cs.setSessionId(e.nodeId, e.sessionId)
const agentLabel = agentConfig(e.agentId)?.label ?? 'Agent'
// "<folder> — Claude finished" + last assistant message as the body.
- const alert = (statusText: string, fallbackBody: string) => {
+ const alert = (statusText: string, fallbackBody: string, sound: 'done' | 'needsYou') => {
// Unread unless the user is actively in this node's terminal (focused window +
// this node is the active terminal). So a finish while you're in another terminal,
// or with nothing focused, still flags unread.
const watching = document.hasFocus() && cs.activeId === e.nodeId
if (!watching) cs.markUnread(e.nodeId)
+ // Sound first: it is the one alert that also fires while you're in the app but looking at
+ // another node — the case OS notifications deliberately skip.
+ const snd = useSettings.getState().settings
+ if (snd.soundEffects) {
+ const t = Date.now()
+ if (t - (sfxCooldownRef.current[e.nodeId] ?? 0) >= 5000) {
+ sfxCooldownRef.current[e.nodeId] = t
+ playSfx(sound, snd.soundVolume)
+ }
+ }
// OS notification only when the whole window is in the background.
if (document.hasFocus()) return
const s = useSettings.getState().settings
@@ -5301,10 +5327,12 @@ export function Canvas() {
// Interrupted turns (Esc/Ctrl-C) alert nobody: the user did it themselves, and
// the turn didn't complete, so it isn't a loop iteration either.
cs.bumpLoop(e.nodeId, e.lastMessage) // count loop iterations + summary (no-op if not looping)
- alert('finished', `${agentLabel} finished its turn.`)
+ alert('finished', `${agentLabel} finished its turn.`, 'done')
}
- if (e.state === 'blocked') alert('needs input', `${agentLabel} needs permission to continue.`)
- else if (e.state === 'waiting') alert('needs input', `${agentLabel} is waiting for your response.`)
+ if (e.state === 'blocked')
+ alert('needs input', `${agentLabel} needs permission to continue.`, 'needsYou')
+ else if (e.state === 'waiting')
+ alert('needs input', `${agentLabel} is waiting for your response.`, 'needsYou')
break
case 'subagent-start':
if (e.toolUseId) {
diff --git a/src/renderer/components/settings/sections/NotificationsSection.tsx b/src/renderer/components/settings/sections/NotificationsSection.tsx
index 6ecc50fba..fbe8c585d 100644
--- a/src/renderer/components/settings/sections/NotificationsSection.tsx
+++ b/src/renderer/components/settings/sections/NotificationsSection.tsx
@@ -5,12 +5,17 @@ import { SearchableRow } from '../SearchableRow'
import { FieldRow } from '../FieldRow'
import { Switch } from '@renderer/ui/Switch'
import { Button } from '@renderer/ui/Button'
+import { playSfx } from '@renderer/lib/sfx'
const ROWS = {
notify: {
title: 'Notify when a turn finishes in the background',
keywords: ['notify', 'notification', 'claude', 'background', 'turn', 'done']
},
+ sound: {
+ title: 'Play a sound when a turn finishes or needs you',
+ keywords: ['sound', 'audio', 'sfx', 'effect', 'chime', 'beep', 'retro', '8-bit', 'chiptune', 'volume', 'mute', 'finished', 'needs you']
+ },
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', 'presence', 'idle', 'hold', 'defer', 'at this computer']
@@ -20,6 +25,8 @@ const ENTRIES = Object.values(ROWS)
export function NotificationsSection({ isActive }: { isActive: boolean }): React.JSX.Element {
const notifyOnClaudeDone = useSettings((s) => s.settings.notifyOnClaudeDone)
+ const soundEffects = useSettings((s) => s.settings.soundEffects)
+ const soundVolume = useSettings((s) => s.settings.soundVolume)
const mobilePushEnabled = useSettings((s) => s.settings.mobilePushEnabled)
const mobilePushNeedsYou = useSettings((s) => s.settings.mobilePushNeedsYou)
const mobilePushDone = useSettings((s) => s.settings.mobilePushDone)
@@ -72,6 +79,62 @@ export function NotificationsSection({ isActive }: { isActive: boolean }): React
</div>
)}
</SearchableRow>
+ <SearchableRow {...ROWS.sound}>
+ <FieldRow
+ label="Play a sound when a turn finishes or needs you"
+ description="A short retro chirp for a finished turn and a crackly one when a session needs you. Plays whether or not the window is focused, so you catch a finish while looking at another node."
+ control={
+ <Switch
+ checked={soundEffects}
+ ariaLabel="Sound effects"
+ onChange={(on) => {
+ update({ soundEffects: on })
+ // Enabling plays the finish chirp — it doubles as the volume preview AND as the
+ // user gesture a browser needs before it will let us make noise at all.
+ if (on) playSfx('done', soundVolume)
+ }}
+ />
+ }
+ />
+ <div
+ className={
+ 'mt-3 space-y-3 border-l border-white/10 pl-4' +
+ (soundEffects ? '' : ' pointer-events-none opacity-40')
+ }
+ aria-disabled={!soundEffects}
+ >
+ <FieldRow
+ label="Volume"
+ control={
+ <div className="flex items-center gap-3">
+ <input
+ type="range"
+ min={0}
+ max={100}
+ step={5}
+ value={Math.round(soundVolume * 100)}
+ aria-label="Sound effect volume"
+ onChange={(e) => update({ soundVolume: Number(e.target.value) / 100 })}
+ onMouseUp={() => playSfx('done', soundVolume)}
+ className="w-40 accent-[var(--accent)]"
+ />
+ <span className="w-9 text-right text-[12px] text-white/50 tabular-nums">
+ {Math.round(soundVolume * 100)}%
+ </span>
+ </div>
+ }
+ />
+ <FieldRow
+ label="Preview"
+ control={
+ <div className="flex items-center gap-2">
+ <Button onClick={() => playSfx('done', soundVolume)}>Finished</Button>
+ <Button onClick={() => playSfx('needsYou', soundVolume)}>Needs you</Button>
+ </div>
+ }
+ />
+ </div>
+ </SearchableRow>
<SearchableRow {...ROWS.mobilePush}>
<FieldRow
label="Send push notifications to your paired phone"
diff --git a/src/renderer/lib/sfx.test.ts b/src/renderer/lib/sfx.test.ts
new file mode 100644
index 000000000..caca1d7df
--- /dev/null
+++ b/src/renderer/lib/sfx.test.ts
@@ -0,0 +1,34 @@
+import { describe, it, expect } from 'vitest'
+import { sfxScore } from './sfx'
+
+describe('sfxScore', () => {
+ it('done is a short rising arpeggio of tones', () => {
+ const s = sfxScore('done')
+ expect(s.length).toBeGreaterThanOrEqual(3)
+ expect(s.every((v) => v.kind === 'tone')).toBe(true)
+ // Strictly rising — that's what makes it read as "finished" rather than "alert".
+ for (let i = 1; i < s.length; i++) expect(s[i].freq).toBeGreaterThan(s[i - 1].freq)
+ // Voices are scheduled in order and the whole effect is brief.
+ for (let i = 1; i < s.length; i++) expect(s[i].at).toBeGreaterThanOrEqual(s[i - 1].at)
+ expect(Math.max(...s.map((v) => v.at + v.dur))).toBeLessThan(0.4)
+ })
+
+ it('needsYou mixes a noise crackle with falling tones', () => {
+ const s = sfxScore('needsYou')
+ expect(s.some((v) => v.kind === 'noise')).toBe(true)
+ const tones = s.filter((v) => v.kind === 'tone')
+ expect(tones.length).toBeGreaterThan(0)
+ // Falling — the opposite gesture to `done`, so the two are distinguishable by ear alone.
+ for (const t of tones) expect(t.freqTo!).toBeLessThan(t.freq)
+ expect(Math.max(...s.map((v) => v.at + v.dur))).toBeLessThan(0.4)
+ })
+
+ it('keeps every voice inside the relative gain range', () => {
+ for (const kind of ['done', 'needsYou'] as const)
+ for (const v of sfxScore(kind)) {
+ expect(v.gain).toBeGreaterThan(0)
+ expect(v.gain).toBeLessThanOrEqual(1)
+ expect(v.dur).toBeGreaterThan(0)
+ }
+ })
+})
diff --git a/src/renderer/lib/sfx.ts b/src/renderer/lib/sfx.ts
new file mode 100644
index 000000000..069731a67
--- /dev/null
+++ b/src/renderer/lib/sfx.ts
@@ -0,0 +1,144 @@
+// Retro sound effects for the two agent edges you actually wait on: a turn FINISHING and a session
+// NEEDING YOU (permission prompt / question). Synthesized with WebAudio — no audio assets, so
+// there's nothing to bundle, license or keep in sync, and the tone is tunable in code.
+//
+// Two distinct voices on purpose (owner's call): "done" is a short rising 8-bit arpeggio (the
+// pac-man pellet register), "needs you" is a crackly glitch bleep — you can tell them apart without
+// looking at the screen. Both are < 300 ms and deliberately quiet.
+//
+// Three surfaces: this is pure renderer, so desktop AND the browser Server Edition get it for free.
+// The mobile companion is a separate app with its own notification sounds — not applicable here.
+
+export type SfxKind = 'done' | 'needsYou'
+
+/** One scheduled voice. `noise` is a filtered white-noise burst; everything else is an oscillator. */
+export interface SfxVoice {
+ kind: 'tone' | 'noise'
+ /** Seconds from the start of the effect. */
+ at: number
+ /** Seconds. */
+ dur: number
+ /** Start frequency (Hz). For `noise`, the band-pass center. */
+ freq: number
+ /** Optional end frequency — the voice sweeps freq → freqTo over `dur`. */
+ freqTo?: number
+ /** Peak gain, relative to the master volume (0..1). */
+ gain: number
+ wave?: OscillatorType
+}
+
+/**
+ * The score for an effect. PURE — no WebAudio, so the shape of each effect is unit-testable and
+ * tweaking a sound never means booting a renderer.
+ */
+export function sfxScore(kind: SfxKind): SfxVoice[] {
+ if (kind === 'done') {
+ // Four square blips climbing a major-ish arpeggio, the last one bent upward — bright, brief,
+ // unmistakably "finished".
+ const notes = [784, 988, 1319, 1568]
+ return notes.map((freq, i) => ({
+ kind: 'tone' as const,
+ at: i * 0.045,
+ dur: i === notes.length - 1 ? 0.11 : 0.06,
+ freq,
+ ...(i === notes.length - 1 ? { freqTo: 1976 } : {}),
+ gain: 0.55,
+ wave: 'square' as const
+ }))
+ }
+ // "Needs you": two crackle-and-drop pairs — a band-passed noise burst (the computer crackle)
+ // over a saw tone falling in pitch, which reads as a question/alert rather than a success.
+ return [
+ { kind: 'noise', at: 0, dur: 0.05, freq: 1400, gain: 0.35 },
+ { kind: 'tone', at: 0.01, dur: 0.1, freq: 320, freqTo: 180, gain: 0.5, wave: 'sawtooth' },
+ { kind: 'noise', at: 0.14, dur: 0.05, freq: 1100, gain: 0.3 },
+ { kind: 'tone', at: 0.15, dur: 0.12, freq: 300, freqTo: 150, gain: 0.45, wave: 'sawtooth' }
+ ]
+}
+
+/** Master trim on top of the user's volume — these are notification chirps, not music. */
+const MASTER = 0.22
+
+let ctx: AudioContext | null = null
+let noiseBuf: AudioBuffer | null = null
+
+function audio(): AudioContext | null {
+ if (ctx) return ctx
+ const Ctor: typeof AudioContext | undefined =
+ typeof window === 'undefined'
+ ? undefined
+ : window.AudioContext ||
+ (window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext
+ if (!Ctor) return null
+ try {
+ ctx = new Ctor()
+ } catch {
+ return null
+ }
+ return ctx
+}
+
+/**
+ * Resume the audio context. Browsers (Server Edition) start it `suspended` until a user gesture;
+ * Electron does not care. Safe to call repeatedly — it's a no-op once running.
+ */
+export function primeSfx(): void {
+ const c = audio()
+ if (c && c.state === 'suspended') void c.resume()
+}
+
+function noise(c: AudioContext): AudioBuffer {
+ if (noiseBuf) return noiseBuf
+ const len = Math.floor(c.sampleRate * 0.25)
+ const buf = c.createBuffer(1, len, c.sampleRate)
+ const data = buf.getChannelData(0)
+ for (let i = 0; i < len; i++) data[i] = Math.random() * 2 - 1
+ noiseBuf = buf
+ return buf
+}
+
+/**
+ * Play an effect. Never throws and never blocks: an unavailable/blocked audio context is simply
+ * silence — a sound effect must not be able to break the agent-status path that calls it.
+ */
+export function playSfx(kind: SfxKind, volume = 0.5): void {
+ const c = audio()
+ if (!c) return
+ if (c.state === 'suspended') void c.resume()
+ const vol = Math.max(0, Math.min(1, volume)) * MASTER
+ if (vol <= 0) return
+ const t0 = c.currentTime + 0.01
+ try {
+ for (const v of sfxScore(kind)) {
+ const g = c.createGain()
+ const peak = vol * v.gain
+ // Fast attack, exponential-ish decay to silence — a linear release rings like a click.
+ g.gain.setValueAtTime(0, t0 + v.at)
+ g.gain.linearRampToValueAtTime(peak, t0 + v.at + 0.005)
+ g.gain.exponentialRampToValueAtTime(0.0001, t0 + v.at + v.dur)
+ g.connect(c.destination)
+
+ if (v.kind === 'noise') {
+ const src = c.createBufferSource()
+ src.buffer = noise(c)
+ const bp = c.createBiquadFilter()
+ bp.type = 'bandpass'
+ bp.frequency.value = v.freq
+ bp.Q.value = 1.2
+ src.connect(bp).connect(g)
+ src.start(t0 + v.at)
+ src.stop(t0 + v.at + v.dur)
+ } else {
+ const osc = c.createOscillator()
+ osc.type = v.wave ?? 'square'
+ osc.frequency.setValueAtTime(v.freq, t0 + v.at)
+ if (v.freqTo) osc.frequency.exponentialRampToValueAtTime(v.freqTo, t0 + v.at + v.dur)
+ osc.connect(g)
+ osc.start(t0 + v.at)
+ osc.stop(t0 + v.at + v.dur)
+ }
+ }
+ } catch {
+ // Nothing to do — losing a chirp is never worth surfacing.
+ }
+}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index bb5ed4c07..76e443b66 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -633,6 +633,12 @@ export interface Settings {
gitAutoFetch: boolean
/** Whether the one-time notification consent prompt has been shown. */
notifyConsentAsked: boolean
+ /** Play a retro sound effect when a turn finishes / a session needs you (renderer/lib/sfx.ts).
+ * Unlike OS notifications this fires whether or not the window is focused — the point is to
+ * catch a finish while you're looking at ANOTHER node. Throttled per node. */
+ soundEffects: boolean
+ /** Sound-effect volume, 0..1. */
+ soundVolume: number
/** User-defined agents (BYO CLI) appended to the Add menus. */
customAgents: CustomAgent[]
/** Managed Claude accounts (config-dir isolated). See ClaudeAccount. */
@@ -721,6 +727,8 @@ export const DEFAULT_SETTINGS: Settings = {
notifyOnClaudeDone: true,
gitAutoFetch: true,
notifyConsentAsked: false,
+ soundEffects: true,
+ soundVolume: 0.5,
customAgents: [],
claudeAccounts: [],
systemAccountLabel: '',