Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

Merge remote-tracking branch 'origin/main' into next/issue-5309

[._.]/ Adam Eivy2e8a6b94e6ba
diff --cc docs/features/voice.md
index 58cb05acb0,df0b3be95e..0a28b12e66
--- a/docs/features/voice.md
+++ b/docs/features/voice.md
@@@ -65,16 -65,34 +65,44 @@@ a hangup
`Caller` and `PortOS`. The call audio is never persisted, and the configured
handle never appears in the transcript or its metadata.
+**Calls PortOS places on its own.** Two opt-in paths can dial without you
+asking: the Persistent Mind's `voice.call-user` grant, and the
+critical-notification escalation in **Settings → Voice**. Both are off by
+default and share one gate and one budget — never while a browser tab can speak
+the message, never inside voice quiet hours, at most 3 calls per rolling 24
+hours and at least 30 minutes apart, counted in durable state so a restart
+cannot reset them. Escalation additionally fires only for a `critical`
+notification that is *still unread* after `escalateAfterMinutes`. See
+[Chief of Staff enhancement → Persistent Mind phone calls](./cos-enhancement.md#persistent-mind-phone-calls).
+
+ ### Meeting capture
+
+ The call-host page's second mode: **/voice/call-host?mode=capture** (or the
+ **Capture system audio** tab on the same page) turns live audio from a
+ Zoom/Meet/FaceTime meeting into a timestamped transcript in the daily journal
+ and the Brain inbox — no dialing, no reply, no LLM call.
+
+ **Setup.** Reads the same BlackHole 16ch device as the call bridge, so it
+ needs no separate driver — but only the input half: capture never plays
+ anything back, so BlackHole 2ch is not required. Route the meeting app's
+ output to BlackHole 16ch (a macOS Multi-Output Device lets you also hear it
+ through your speakers at the same time).
+
+ **Capturing.** Press **Start capture**; PortOS transcribes continuously with
+ the same whisper.cpp STT and energy-based endpointing (700 ms trailing
+ silence) the call bridge uses, but stops there — it never runs the LLM/tools
+ pipeline, so no AI provider is called while a meeting is being captured.
+ Press **Stop capture** (or close the tab) to finalize: the transcript is
+ appended to the daily journal under a "Meeting capture" heading with
+ start/stop timestamps, and filed as a Brain inbox item with auto-classify
+ off — exactly like a manually-typed thought with classification skipped. The
+ usual summarize/tag flow applies only once you ask for it from the inbox.
+
+ **Mutually exclusive with a call.** Both modes read the same BlackHole
+ device and the same host tab, so starting one while the other is active on
+ this tab is refused with a specific reason rather than fighting over the
+ device.
+
### Why Kokoro is the default
Kokoro is a 82M-parameter frontier TTS model that runs in-process via ONNX Runtime + transformers.js — **no Python, no extra binaries, cross-platform**. Quality is significantly higher than Piper (more natural prosody, expressive pacing). First synthesis after server start has a 2–3 s cold start as the model loads; warm calls are 200–500 ms per sentence on CPU.
diff --cc server/lib/socketEventCatalog.generated.json
index 6a0cefe7fe,b16242c22f..088b0661f3
--- a/server/lib/socketEventCatalog.generated.json
+++ b/server/lib/socketEventCatalog.generated.json
@@@ -1916,7 -1916,7 +1916,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 501
- "line": 581
++ "line": 617
}
]
},
@@@ -4537,7 -4550,7 +4550,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 450
- "line": 432
++ "line": 468
}
]
},
@@@ -4555,7 -4568,7 +4568,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 469
- "line": 459
++ "line": 495
}
]
},
@@@ -4578,7 -4591,7 +4591,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 496
- "line": 498
++ "line": 534
}
]
},
@@@ -4596,12 -4609,17 +4609,17 @@@
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 406
- "line": 398
++ "line": 424
+ },
+ {
+ "direction": "server-to-client",
+ "source": "server/sockets/voice.js",
- "line": 440
++ "line": 476
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 457
- "line": 447
++ "line": 483
}
]
},
@@@ -4619,12 -4637,81 +4637,86 @@@
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 397
+ "line": 415
+ },
+ {
+ "direction": "server-to-client",
+ "source": "server/sockets/voice.js",
- "line": 433
++ "line": 451
+ }
+ ]
+ },
+ {
+ "event": "voice:capture:start",
+ "directions": [
+ "client-to-server"
+ ],
+ "sources": [
+ {
+ "direction": "client-to-server",
+ "source": "client/src/pages/VoiceCallHost.jsx",
+ "line": 205
+ },
+ {
+ "direction": "client-to-server",
+ "source": "server/sockets/voice.js",
- "line": 536
++ "line": 572
+ }
+ ]
+ },
+ {
+ "event": "voice:capture:state",
+ "directions": [
+ "server-to-client"
+ ],
+ "sources": [
+ {
+ "direction": "server-to-client",
+ "source": "client/src/pages/VoiceCallHost.jsx",
+ "line": 249
+ },
+ {
+ "direction": "server-to-client",
+ "source": "server/sockets/voice.js",
- "line": 512
++ "line": 548
+ },
+ {
+ "direction": "server-to-client",
+ "source": "server/sockets/voice.js",
- "line": 540
++ "line": 576
+ },
+ {
+ "direction": "server-to-client",
+ "source": "server/sockets/voice.js",
- "line": 545
++ "line": 581
+ },
+ {
+ "direction": "server-to-client",
+ "source": "server/sockets/voice.js",
- "line": 550
++ "line": 586
+ }
+ ]
+ },
+ {
+ "event": "voice:capture:stop",
+ "directions": [
+ "client-to-server"
+ ],
+ "sources": [
+ {
+ "direction": "client-to-server",
+ "source": "client/src/pages/VoiceCallHost.jsx",
+ "line": 211
+ },
+ {
+ "direction": "client-to-server",
+ "source": "client/src/pages/VoiceCallHost.jsx",
+ "line": 256
+ },
+ {
+ "direction": "client-to-server",
+ "source": "server/sockets/voice.js",
- "line": 563
++ "line": 599
}
]
},
@@@ -4642,17 -4729,17 +4734,17 @@@
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 247
- "line": 258
++ "line": 261
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 271
- "line": 282
++ "line": 285
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 276
- "line": 287
++ "line": 290
}
]
},
@@@ -4675,7 -4762,7 +4767,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 264
- "line": 275
++ "line": 278
}
]
},
@@@ -4693,67 -4780,82 +4785,82 @@@
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 155
- "line": 166
++ "line": 169
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 168
- "line": 179
++ "line": 182
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 177
- "line": 188
++ "line": 191
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 182
- "line": 193
++ "line": 196
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 186
- "line": 197
++ "line": 200
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 202
- "line": 213
++ "line": 216
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 211
- "line": 222
++ "line": 225
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 216
- "line": 227
++ "line": 230
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 220
- "line": 231
++ "line": 234
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 226
- "line": 237
++ "line": 240
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 279
- "line": 290
++ "line": 293
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 443
- "line": 425
++ "line": 461
+ },
+ {
+ "direction": "server-to-client",
+ "source": "server/sockets/voice.js",
- "line": 455
++ "line": 491
+ },
+ {
+ "direction": "server-to-client",
+ "source": "server/sockets/voice.js",
- "line": 523
++ "line": 559
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 465
- "line": 559
++ "line": 595
+ },
+ {
+ "direction": "server-to-client",
+ "source": "server/sockets/voice.js",
- "line": 577
++ "line": 613
}
]
},
@@@ -4771,17 -4873,17 +4878,17 @@@
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 156
- "line": 167
++ "line": 170
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 236
- "line": 247
++ "line": 250
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 248
- "line": 259
++ "line": 262
}
]
},
@@@ -4815,12 -4917,12 +4922,12 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 230
- "line": 241
++ "line": 244
},
{
"direction": "server-to-client",
"source": "server/sockets/voice.js",
- "line": 485
- "line": 478
++ "line": 514
}
]
},
@@@ -4838,7 -4940,7 +4945,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 364
- "line": 375
++ "line": 378
}
]
},
@@@ -4856,7 -4958,7 +4963,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 372
- "line": 383
++ "line": 386
}
]
},
@@@ -4905,7 -5007,7 +5012,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 239
- "line": 250
++ "line": 253
}
]
},
@@@ -4923,7 -5025,7 +5030,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 324
- "line": 335
++ "line": 338
}
]
},
@@@ -4959,7 -5061,7 +5066,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 206
- "line": 217
++ "line": 220
}
]
},
@@@ -5008,7 -5110,7 +5115,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 172
- "line": 183
++ "line": 186
}
]
},
@@@ -5026,7 -5128,7 +5133,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 287
- "line": 298
++ "line": 301
}
]
},
@@@ -5057,7 -5159,7 +5164,7 @@@
{
"direction": "client-to-server",
"source": "server/sockets/voice.js",
- "line": 342
- "line": 353
++ "line": 356
}
]
},
diff --cc server/sockets/voice.js
index 5af0468210,4733fe8206..33fafc0b7d
--- a/server/sockets/voice.js
+++ b/server/sockets/voice.js
@@@ -35,9 -38,17 +39,19 @@@ import
noteCallerSpeech,
recordTurn,
setCallStateListener,
+ takeCallOpeningLine,
} from '../services/voice/callSession.js';
+import { synthesize } from '../services/voice/tts.js';
+ import {
+ attachCaptureHost,
+ detachCaptureHost,
+ endCapture,
+ getCaptureHost,
+ isCaptureActive,
+ recordUtterance,
+ setCaptureStateListener,
+ startCapture,
+ } from '../services/voice/captureSession.js';
// Cap by messages (each user utterance + assistant reply is ~2). 24 → ~12 turns.
const HISTORY_MESSAGES = 24;
diff --cc server/sockets/voice.test.js
index 96a092ed60,86f94c1fc5..ad054aac2e
--- a/server/sockets/voice.test.js
+++ b/server/sockets/voice.test.js
@@@ -12,11 -12,9 +12,14 @@@ vi.mock(import('../services/voice/confi
};
});
+// The call host speaks its opening line through the real TTS entry point;
+// stub it so the suite never loads a speech model.
+vi.mock('../services/voice/tts.js', () => ({
+ synthesize: vi.fn(async (text) => ({ wav: Buffer.from(`wav:${text}`), latencyMs: 1 })),
+}));
+ // Meeting capture transcribes over the network (whisper.cpp's HTTP server);
+ // stub it so the capture-routing tests below run offline and deterministically.
+ vi.mock('../services/voice/stt.js', () => ({ transcribe: vi.fn() }));
const { truncateOnWordBoundary, registerVoiceHandlers } = await import('./voice.js');
const {
@@@ -24,12 -22,13 +27,19 @@@
emitVoiceOutput,
__resetVoiceOutput,
} = await import('../services/voice/voiceOutput.js');
+ const { transcribe } = await import('../services/voice/stt.js');
-const { attachHost: attachCallHost, __resetCallSession } = await import('../services/voice/callSession.js');
+const {
++ attachHost: attachCallHost,
+ __resetCallSession,
+ __setCallSessionDeps,
+ pollCall,
+ startCall,
+} = await import('../services/voice/callSession.js');
+ const {
+ __resetCaptureSession,
+ __setCaptureSessionDeps,
+ getCaptureState,
+ } = await import('../services/voice/captureSession.js');
// Minimal fake socket: records on() handlers so tests can fire inbound events,
// and captures emit() calls. No real Socket.IO needed — the voice:ui:index /
@@@ -270,50 -269,119 +280,167 @@@ describe('voice:output single-recipien
});
});
+describe('call host opening line', () => {
+ const flush = () => new Promise((resolve) => setTimeout(resolve, 0));
+
+ beforeEach(() => {
+ __resetCallSession();
+ __setCallSessionDeps({
+ probe: vi.fn(async () => ({ state: 'connected' })),
+ call: vi.fn(async () => ({ state: 'dialing' })),
+ hangup: vi.fn(async () => ({ state: 'ended' })),
+ appendJournal: vi.fn(async () => ({})),
+ enqueueMindMessage: vi.fn(async () => ({})),
+ });
+ });
+
+ it('speaks the line into the call once the far end picks up, and only once', async () => {
+ // This is the end of the mind's call path: without it a placed call
+ // connects to silence and the user hears nothing at all.
+ const host = makeFakeSocket();
+ registerVoiceHandlers(host);
+ await host.fire('voice:call:attach');
+
+ await startCall({ openingLine: 'This is PortOS about your backups.', origin: 'mind' });
+ await pollCall();
+ await flush();
+
+ const spoken = host.emitted.filter((e) => e.event === 'voice:call:tts');
+ expect(spoken).toHaveLength(1);
+ expect(spoken[0].payload.sentence).toBe('This is PortOS about your backups.');
+
+ // Every state transition re-broadcasts; the line must not be repeated.
+ await pollCall();
+ await flush();
+ expect(host.emitted.filter((e) => e.event === 'voice:call:tts')).toHaveLength(1);
+ });
+
+ it('says nothing extra on a call the user placed themselves', async () => {
+ const host = makeFakeSocket();
+ registerVoiceHandlers(host);
+ await host.fire('voice:call:attach');
+
+ await startCall();
+ await pollCall();
+ await flush();
+
+ expect(host.emitted.filter((e) => e.event === 'voice:call:tts')).toHaveLength(0);
+ });
+});
++
+ describe('voice:capture socket handlers (meeting capture)', () => {
+ // ~20 ms of 16 kHz mono, matching the call-host page's frame size (see
+ // callAudioBridge.js CALL_FRAME_SAMPLES). Loud enough to clear the
+ // endpointer's RMS threshold (0.015) and long enough, over several frames,
+ // to clear its 250 ms minimum-utterance floor; the silent run after it
+ // clears the 700 ms trailing-silence endpoint.
+ const FRAME_SAMPLES = 320;
+ const loudFrame = () => {
+ const frame = new Int16Array(FRAME_SAMPLES);
+ for (let i = 0; i < FRAME_SAMPLES; i += 1) frame[i] = Math.round(Math.sin(i / 8) * 20000);
+ return frame;
+ };
+ const silentFrame = () => new Int16Array(FRAME_SAMPLES);
+ const flushMicrotasks = () => new Promise((resolve) => setImmediate(resolve));
+
+ let appendJournal;
+ let createInboxLog;
+
+ beforeEach(() => {
+ __resetCallSession();
+ __resetCaptureSession();
+ appendJournal = vi.fn().mockResolvedValue({});
+ createInboxLog = vi.fn().mockResolvedValue({ id: 'inbox-1' });
+ __setCaptureSessionDeps({
+ appendJournal,
+ getToday: vi.fn().mockResolvedValue('2026-08-29'),
+ createInboxLog,
+ now: Date.now,
+ });
+ transcribe.mockReset();
+ });
+
+ afterEach(() => {
+ __resetCallSession();
+ __resetCaptureSession();
+ });
+
+ it('registers the capture start/stop handlers', () => {
+ const socket = makeFakeSocket();
+ registerVoiceHandlers(socket);
+ expect(socket.has('voice:capture:start')).toBe(true);
+ expect(socket.has('voice:capture:stop')).toBe(true);
+ });
+
+ it('claims the single capture-host slot and refuses a second tab', async () => {
+ const first = makeFakeSocket();
+ const second = makeFakeSocket();
+ registerVoiceHandlers(first);
+ registerVoiceHandlers(second);
+
+ await first.fire('voice:capture:start');
+ await second.fire('voice:capture:start');
+
+ const refusal = second.emitted.find((e) => e.event === 'voice:capture:state');
+ expect(refusal.payload).toMatchObject({ error: 'host-taken' });
+ });
+
+ it('refuses to start a capture on a tab already hosting a FaceTime call', async () => {
+ const socket = makeFakeSocket();
+ registerVoiceHandlers(socket);
+ attachCallHost(socket); // same tab already owns the call-host slot
+
+ await socket.fire('voice:capture:start');
+
+ const state = socket.emitted.find((e) => e.event === 'voice:capture:state');
+ expect(state.payload).toMatchObject({ error: 'call-active' });
+ });
+
+ it('refuses to attach a call host on a tab already capturing', async () => {
+ const socket = makeFakeSocket();
+ registerVoiceHandlers(socket);
+ await socket.fire('voice:capture:start');
+
+ await socket.fire('voice:call:attach');
+
+ const state = socket.emitted.find((e) => e.event === 'voice:call:state');
+ expect(state.payload).toMatchObject({ error: 'capture-active' });
+ });
+
+ it('transcribes meeting audio through STT only — never the LLM/tools pipeline — and files the journal + inbox on stop', async () => {
+ const socket = makeFakeSocket();
+ registerVoiceHandlers(socket);
+ transcribe.mockResolvedValue({ text: 'let’s ship the capture mode', latencyMs: 5 });
+
+ await socket.fire('voice:capture:start');
+ expect(getCaptureState()).toMatchObject({ active: true });
+
+ for (let i = 0; i < 14; i += 1) socket.fire('voice:call:audio', { pcm: loudFrame() });
+ for (let i = 0; i < 36; i += 1) socket.fire('voice:call:audio', { pcm: silentFrame() });
+ await flushMicrotasks();
+
+ // One STT call for the one utterance — routed away from runTurn entirely,
+ // so nothing from the LLM/tools pipeline ever fired.
+ expect(transcribe).toHaveBeenCalledTimes(1);
+ expect(socket.emitted.some((e) => e.event === 'voice:llm:done')).toBe(false);
+ const states = socket.emitted.filter((e) => e.event === 'voice:capture:state');
+ expect(states.some((e) => e.payload.turns === 1)).toBe(true);
+
+ await socket.fire('voice:capture:stop');
+
+ expect(appendJournal).toHaveBeenCalledTimes(1);
+ expect(appendJournal.mock.calls[0][1]).toContain('let’s ship the capture mode');
+ expect(appendJournal.mock.calls[0][2]).toEqual({ source: 'voice' });
+ expect(createInboxLog).toHaveBeenCalledWith(expect.objectContaining({ status: 'needs_review', source: 'voice' }));
+ // No AI provider call anywhere in this flow — createInboxLog never carries
+ // classifier metadata, matching the auto-classify-off inbox shape.
+ expect(createInboxLog).toHaveBeenCalledWith(expect.not.objectContaining({ ai: expect.anything() }));
+ });
+
+ it('ignores voice:call:audio on a tab that never attached either host', () => {
+ const socket = makeFakeSocket();
+ registerVoiceHandlers(socket);
+ expect(() => socket.fire('voice:call:audio', { pcm: loudFrame() })).not.toThrow();
+ expect(transcribe).not.toHaveBeenCalled();
+ });
+ });