diff --git a/changelog.d/fixed-recording-ux-display.md b/changelog.d/fixed-recording-ux-display.md new file mode 100644 index 0000000000..c9078eca3a --- /dev/null +++ b/changelog.d/fixed-recording-ux-display.md @@ -0,0 +1 @@ +- Inbox ● Record: the "Saved to the Inbox" panel now follows the recording's item, says "Transcribed. See the item below." (or why transcription failed or is off) and then closes itself with the toast countdown; the item preview shows the plain transcript text instead of the provenance line and untrusted-data envelope; hive recordings and dropped audio files get a plain "Transcript made by this hive with / on ." line; and the player says how long the audio is kept on this hive instead of "the recording is not stored". diff --git a/src/docs/inbox-recording.md b/src/docs/inbox-recording.md index f0643cf33b..e99eb3d1f8 100644 --- a/src/docs/inbox-recording.md +++ b/src/docs/inbox-recording.md @@ -84,7 +84,17 @@ When you stop, the hive transcribes the recording automatically with its built-in whisper first, so the audio stays on the hive), with the same progress bar and time-left estimate as any other Inbox transcription. The transcriber reads the file from the hive's own disk; nothing is fetched over -HTTP. The transcript is written into the recording's Knowledge fact. +HTTP. The transcript is written into the recording's Knowledge fact under the +line `_Transcript made by this hive with whisper/base.en on 2026-11-16._` +(provider, model and day); the +Inbox preview shows the transcript text only. + +The **Saved to the Inbox** panel above the Inbox follows the item: it says +**Transcribed. See the item below.** once the transcript lands, or +**Transcription failed:** with the reason (or that transcription is off), and then +closes itself with the same countdown bar and duration as the dashboard's +toasts (hovering or focusing it pauses the countdown). **Close** dismisses it +at once. - Recording does **not** replace the hive-wide transcription consent: nothing is transcribed until an owner enables `inbox.transcription` with @@ -107,6 +117,11 @@ HTTP. The transcript is written into the recording's Knowledge fact. | Knowledge fact (personal layer, never published to the hub) | kept | | Recording metadata (title, who, when, duration, consent version) | kept | +While the audio is kept, the note under the player says **The audio is kept +on this hive until** the day the recording ended plus `retention_days`, +**then deleted; the transcript stays.** Dropped audio files say the same with +the upload retention. + After the audio is deleted the item shows **audio expired (kept 5 days)** (with the configured number of days) and has no play control; the transcript and the fact stay readable and shareable. The sweep that deletes audio runs at diff --git a/src/pkg/dashboard/inbox_audio_note.test.js b/src/pkg/dashboard/inbox_audio_note.test.js new file mode 100644 index 0000000000..1c78b13d77 --- /dev/null +++ b/src/pkg/dashboard/inbox_audio_note.test.js @@ -0,0 +1,37 @@ +// Inbox player note: audio this hive stores (hive recordings, dropped audio +// files) says how long it is kept; third-party audio is streamed, not stored. +// Run: node --test src/pkg/dashboard/*.test.js +const test = require('node:test'); +const assert = require('node:assert'); +const fs = require('node:fs'); +const path = require('node:path'); + +const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8'); +const fnSrc = name => { + const start = html.indexOf('function ' + name + '('); + assert.ok(start >= 0, name + ' not found'); + let depth = 0; + for (let i = html.indexOf('{', start); i < html.length; i++) { + if (html[i] === '{') depth++; + else if (html[i] === '}' && --depth === 0) return html.slice(start, i + 1); + } + throw new Error('unbalanced ' + name); +}; +const inboxAudioNoteText = new Function(fnSrc('inboxAudioNoteText') + '\nreturn inboxAudioNoteText;')(); +const fmt = d => 'DAY(' + d + ')'; + +test('hive-stored audio names the day retention deletes it', () => { + for (const source of ['hive-recording', 'upload']) { + const out = inboxAudioNoteText({ source, audio_expires_at: '2026-11-21T10:00:00Z' }, fmt); + assert.strictEqual(out, 'The audio is kept on this hive until DAY(2026-11-21T10:00:00Z), then deleted; the transcript stays. Click ▶ Play recording again to restart.'); + assert.doesNotMatch(out, /not stored/); + } + assert.strictEqual(inboxAudioNoteText({ source: 'upload' }, fmt), 'The audio is kept on this hive. Click ▶ Play recording again to restart.'); + assert.strictEqual(inboxAudioNoteText({ source: 'hive-recording', audio_expires_at: '0001-01-01T00:00:00Z' }, fmt), 'The audio is kept on this hive. Click ▶ Play recording again to restart.'); +}); + +test('third-party audio keeps the streaming note', () => { + for (const it of [{ source: 'plaud' }, { source: 'zoom', audio_expires_at: '2026-11-21T10:00:00Z' }, undefined]) { + assert.strictEqual(inboxAudioNoteText(it, fmt), 'Streaming through this hive; the recording is not stored. Click ▶ Play recording again to restart.'); + } +}); diff --git a/src/pkg/dashboard/inbox_audio_stream.test.js b/src/pkg/dashboard/inbox_audio_stream.test.js index c681a6eec0..16c81e94df 100644 --- a/src/pkg/dashboard/inbox_audio_stream.test.js +++ b/src/pkg/dashboard/inbox_audio_stream.test.js @@ -50,6 +50,7 @@ const harness = ({ fetchReply, share, clipboardOK = true } = {}) => { const items = [{ source: 'plaud', id: 'f_01', title: 'cost considerations' }]; const api = new Function('document', 'fetch', 'navigator', 'location', 'CSS', 'showToast', 'writeClipboardText', 'window', 'renderInbox', 'items', 'function inboxFind(src, id) { return items.find(it => it.source === src && it.id === id); }\n' + + 'function formatDashboardDate(d) { return String(d); }\n' + fnSrc('inboxAudioNoteText') + '\n' + fnSrc('inboxApiPath') + '\n' + fnSrc('inboxStreamURL') + '\n' + fnSrc('inboxAudioErrorReason') + '\n' + fnSrc('inboxPlay') + '\n' + constSrc('INBOX_SHARE_HASH') + '\n' + fnSrc('inboxShareLink') + '\n' + fnSrc('inboxFocusKeyFromHash') + '\n' + fnSrc('inboxShareCopy') + '\n' + fnSrc('inboxShareNative') + '\n' + 'return { inboxPlay, inboxStreamURL, inboxAudioErrorReason, inboxShareLink, inboxFocusKeyFromHash, inboxShareCopy, inboxShareNative };', diff --git a/src/pkg/dashboard/inbox_recorder.test.js b/src/pkg/dashboard/inbox_recorder.test.js index ae7f42e5d3..9db34d7f54 100644 --- a/src/pkg/dashboard/inbox_recorder.test.js +++ b/src/pkg/dashboard/inbox_recorder.test.js @@ -27,7 +27,8 @@ const escapeHtml = s => String(s == null ? '' : s).replace(/&/g, '&').replac const FNS = ['inboxRecSupport', 'inboxRecRoleCanRecord', 'inboxRecAvailable', 'inboxRecFmtClock', 'inboxRecLevel', 'inboxRecSplit', 'inboxRecConsentText', 'inboxRecDefaultTitle', 'inboxRecConsentHtml', 'inboxRecMemoryQueue', 'inboxRecUploader', 'inboxRecorderMachine', - 'inboxRecResumePending', 'inboxRecUploadText', 'inboxRecMeterHtml', 'inboxRecPanelHtml', 'inboxRecTabSupport', 'inboxRecSourcesHtml', 'inboxRecCaptureTab']; + 'inboxRecResumePending', 'inboxRecUploadText', 'inboxRecMeterHtml', 'inboxRecPanelHtml', 'inboxRecTabSupport', 'inboxRecSourcesHtml', 'inboxRecCaptureTab', + 'inboxRecDoneOutcome', 'inboxRecDoneText']; const lib = new Function('escapeHtml', consts() + '\n' + FNS.map(fnSrc).join('\n') + '\nreturn {' + FNS.join(',') + ', CONSENT: INBOX_REC_CONSENT_VERSION, ACK: INBOX_REC_CONSENT_ACK };')(escapeHtml); const flush = async (n = 20) => { for (let i = 0; i < n; i++) await new Promise(r => setImmediate(r)); }; @@ -397,3 +398,38 @@ test('cancelling the tab picker records the microphone only', async () => { assert.match(m.warning, /No tab was shared/); assert.strictEqual(hive.start.includes_tab_audio, false); }); + +test('the saved panel follows the item: transcribed, failed, off, stalled, waiting', () => { + const o = (it, transcribes = true, why = '', waited = false) => lib.inboxRecDoneOutcome(it, transcribes, why, waited); + assert.deepStrictEqual(o(null), { state: 'waiting', reason: '' }); + assert.deepStrictEqual(o(null, false), { state: 'off', reason: '' }); + assert.strictEqual(o({ transcription: { status: 'running' } }).state, 'waiting'); + assert.strictEqual(o({ transcription: { status: 'done' } }).state, 'transcribed'); + assert.strictEqual(o({ fact_state: 'machine' }).state, 'transcribed'); + assert.strictEqual(o({ has_transcript: true }, false).state, 'transcribed', 'text wins over transcription being off'); + assert.deepStrictEqual(o({ transcription: { status: 'failed', reason: 'whisper crashed' } }), { state: 'failed', reason: 'whisper crashed' }); + assert.deepStrictEqual(o({ transcribe_unavailable: 'budget' }, true, 'Monthly budget used'), { state: 'failed', reason: 'Monthly budget used' }); + assert.strictEqual(o({ transcribe_unavailable: 'disabled' }).state, 'off'); + assert.strictEqual(o({}, true, '', true).state, 'stalled'); + assert.strictEqual(o({ transcription: { status: 'queued' } }, true, '', true).state, 'waiting', 'a queued job is still followed'); + + assert.strictEqual(lib.inboxRecDoneText({ state: 'transcribed' }), 'Transcribed. See the item below.'); + assert.match(lib.inboxRecDoneText({ state: 'failed', reason: 'whisper crashed' }), /^Transcription failed: whisper crashed\. The recording is saved/); + assert.match(lib.inboxRecDoneText({ state: 'waiting' }), /transcribing it now/); + assert.match(lib.inboxRecDoneText({ state: 'off' }), /Transcription is off on this hive/); + + const done = { state: 'done', title: 'Standup', levels: {}, elapsedMs: () => 4000, outcome: { state: 'transcribed', reason: '' } }; + let out = lib.inboxRecPanelHtml(done); + assert.match(out, /data-inbox-rec-outcome="transcribed">Transcribed\. See the item below\.]*data-inbox-rec-outcome="failed">Transcription failed: no audio\./); +}); + +test('the saved panel auto-dismisses with the toast countdown, not its own timer', () => { + const src = fnSrc('inboxRecArmDismiss'); + assert.match(src, /toastCountdownBar\(panel, TOAST_DURATION_MS,/); + assert.match(fnSrc('inboxRecSyncDone'), /inboxRecArmDismiss\(m\)/); + assert.match(fnSrc('fetchInbox'), /inboxRecSyncDone\(_inboxCache\.items\)/); +}); diff --git a/src/pkg/dashboard/static-src/css/inbox.css b/src/pkg/dashboard/static-src/css/inbox.css index cf526b9d8c..98f8bfb0e1 100644 --- a/src/pkg/dashboard/static-src/css/inbox.css +++ b/src/pkg/dashboard/static-src/css/inbox.css @@ -45,7 +45,12 @@ .inbox-add-url { flex: 1 1 16rem; min-width: 0; } .inbox-upload .kc-error { flex-basis: 100%; } /* ● Record (inbox-recorder.js): panel, red indicator, level meters */ - .inbox-rec-panel { margin-bottom: var(--sp-4); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-left: 3px solid var(--red); border-radius: var(--r); background: var(--surface); } + .inbox-rec-panel { position: relative; overflow: hidden; margin-bottom: var(--sp-4); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-left: 3px solid var(--red); border-radius: var(--r); background: var(--surface); } + /* The saved panel auto-dismisses with the toast countdown bar (toastCountdownBar). */ + .inbox-rec-panel .toast-bar { background: color-mix(in srgb, var(--green) 40%, transparent); } + .inbox-rec-panel[data-outcome="failed"] .toast-bar { background: color-mix(in srgb, var(--red) 40%, transparent); } + .inbox-rec-panel[data-outcome="stalled"] .toast-bar { background: color-mix(in srgb, var(--status-warn) 40%, transparent); } + .inbox-rec-panel[data-outcome="off"] .toast-bar { background: color-mix(in srgb, var(--blue) 40%, transparent); } .inbox-rec-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); } .inbox-rec-dot { color: var(--red); } .inbox-rec-dot.is-live { animation: inbox-rec-pulse 1.2s ease-in-out infinite; } diff --git a/src/pkg/dashboard/static-src/js/inbox-recorder.js b/src/pkg/dashboard/static-src/js/inbox-recorder.js index 88f185af39..a41ea6e3d1 100644 --- a/src/pkg/dashboard/static-src/js/inbox-recorder.js +++ b/src/pkg/dashboard/static-src/js/inbox-recorder.js @@ -39,6 +39,12 @@ // A live recorder holds a Web Lock with this prefix, so another tab of // the same browser never finalizes a recording that is still running. const INBOX_REC_LOCK_PREFIX = 'hive-inbox-recording-'; + // After a recording is saved the panel follows its Inbox item: the + // Inbox is re-read this often while the item shows no transcription + // state yet (a running job is followed by the transcription poll), for + // at most INBOX_REC_DONE_WAIT_MS before the panel stops waiting. + const INBOX_REC_DONE_POLL_MS = 5000; + const INBOX_REC_DONE_WAIT_MS = 120000; let _inboxRec = null; @@ -597,7 +603,10 @@ if (m.uploader) html += '
' + escapeHtml(inboxRecUploadText(m.uploader.state)) + '
'; if (m.warning) html += ''; if (m.error) html += ''; - if (m.state === 'done') html += '
' + escapeHtml(m.transcribes ? 'The hive is transcribing it now; follow the progress on the item in the Inbox below.' : 'It appears in the Inbox below. Transcription is off on this hive, so it is not transcribed yet.') + '
'; + if (m.state === 'done') { + const o = m.outcome || inboxRecDoneOutcome(null, m.transcribes, '', false); + html += '
' + escapeHtml(inboxRecDoneText(o)) + '
'; + } html += '
'; if (m.state === 'recording') html += ''; if (m.state === 'paused') html += ''; @@ -607,6 +616,61 @@ if (m.state === 'done' || m.state === 'error') html += ''; return html + '
'; } + // inboxRecDoneOutcome is where a saved recording's Inbox item stands: + // transcribed (the item has text), failed (the job failed or was + // skipped, or the hive cannot transcribe it; reason says why), off + // (transcription is off on this hive), stalled (no job appeared within + // INBOX_REC_DONE_WAIT_MS: waitedOut) or waiting. Every state but waiting + // starts the panel's auto-dismiss countdown. + function inboxRecDoneOutcome(it, transcribes, unavailableText, waitedOut) { + const tx = (it && it.transcription) || null; + if (it && (it.has_transcript || it.fact_state === 'machine' || (tx && tx.status === 'done'))) return { state: 'transcribed', reason: '' }; + if (tx && (tx.status === 'failed' || tx.status === 'skipped')) return { state: 'failed', reason: tx.reason || '' }; + if (tx && (tx.status === 'queued' || tx.status === 'running')) return { state: 'waiting', reason: '' }; + if (!transcribes || (it && it.transcribe_unavailable === 'disabled')) return { state: 'off', reason: '' }; + if (it && it.transcribe_unavailable) return { state: 'failed', reason: unavailableText || '' }; + if (waitedOut) return { state: 'stalled', reason: '' }; + return { state: 'waiting', reason: '' }; + } + // inboxRecDoneText is the panel line for an outcome. + function inboxRecDoneText(o) { + switch (o && o.state) { + case 'transcribed': return 'Transcribed. See the item below.'; + case 'failed': return 'Transcription failed' + (o.reason ? ': ' + o.reason : '') + '. The recording is saved in the Inbox below; retry the transcription from the item.'; + case 'off': return 'It appears in the Inbox below. Transcription is off on this hive, so it is not transcribed yet.'; + case 'stalled': return 'Saved in the Inbox below. Transcription has not started yet; follow it on the item.'; + default: return 'The hive is transcribing it now; follow the progress on the item in the Inbox below.'; + } + } + // inboxRecSyncDone runs after every Inbox read: it finds the saved + // recording's item, updates the panel line, and once the outcome is + // final starts the same auto-dismiss countdown toasts use (bar, duration + // and pause on hover or focus). Close still dismisses at once. + function inboxRecSyncDone(items) { + const m = _inboxRec; + if (!m || m.state !== 'done' || !m.id) return; + if (!m.doneAt) m.doneAt = Date.now(); + const it = (items || []).find(x => x && x.source === 'hive-recording' && x.id === m.id) || null; + const waitedOut = Date.now() - m.doneAt >= INBOX_REC_DONE_WAIT_MS; + const why = it && it.transcribe_unavailable && typeof inboxTxUnavailableText === 'function' ? inboxTxUnavailableText(it.transcribe_unavailable) : ''; + const o = inboxRecDoneOutcome(it, m.transcribes, why, waitedOut); + const changed = !m.outcome || m.outcome.state !== o.state || m.outcome.reason !== o.reason; + m.outcome = o; + if (changed) inboxRecRender(); + clearTimeout(m.donePoll); + m.donePoll = 0; + if (o.state !== 'waiting') { inboxRecArmDismiss(m); return; } + // A running job is followed by the Inbox's own transcription poll. + const busy = it && it.transcription && (it.transcription.status === 'queued' || it.transcription.status === 'running'); + if (!busy && typeof fetchInbox === 'function') m.donePoll = setTimeout(() => { if (_inboxRec === m) fetchInbox(); }, INBOX_REC_DONE_POLL_MS); + } + function inboxRecArmDismiss(m) { + const panel = document.getElementById('inbox-rec-panel'); + if (!panel || m.dismissArmed || typeof toastCountdownBar !== 'function') return; + m.dismissArmed = true; + if (m.outcome) panel.dataset.outcome = m.outcome.state; + toastCountdownBar(panel, TOAST_DURATION_MS, () => { if (_inboxRec === m) inboxRecClose(); }); + } // The timer and meters redraw on a dashboard interval (paused while the // page is hidden); the length limit has its own timeout so it holds in // the background too. @@ -624,12 +688,27 @@ const m = _inboxRec; const panel = document.getElementById('inbox-rec-panel'); const html = inboxRecPanelHtml(m); - if (panel) { panel.hidden = !html; panel.innerHTML = html; } + if (panel) { + // A countdown belongs to the saved recording it was armed for. + if (panel._countdown && !(m && m.state === 'done' && m.dismissArmed) && typeof toastCountdownCancel === 'function') toastCountdownCancel(panel); + panel.hidden = !html; + if (m && m.outcome) panel.dataset.outcome = m.outcome.state; else delete panel.dataset.outcome; + if (panel._html !== html) { + panel._html = html; + panel.innerHTML = html; + // The rewrite dropped the countdown bar; put it back where it was. + if (panel._countdown && panel._countdown.bar) panel.appendChild(panel._countdown.bar); + } + } inboxRecIndicator(m); const live = m && (m.state === 'recording' || m.state === 'paused'); if (live && !_inboxRecTicker) { _inboxRecTicker = true; dashboardSetInterval('inbox-recorder', inboxRecTick, INBOX_REC_TICK_MS); } if (!live && _inboxRecTicker) { _inboxRecTicker = false; dashboardClearInterval('inbox-recorder'); } - if (m && m.state === 'done' && !m.listed) { m.listed = true; inboxRecWakeLock(false); if (typeof fetchInbox === 'function') fetchInbox(); } + if (m && m.state === 'done' && !m.listed) { + m.listed = true; inboxRecWakeLock(false); + if (!m.transcribes) { m.outcome = inboxRecDoneOutcome(null, false, '', false); inboxRecArmDismiss(m); } + if (typeof fetchInbox === 'function') fetchInbox(); + } if (m && m.state === 'error') inboxRecWakeLock(false); const btn = document.querySelector('#inbox-panel .inbox-rec-btn'); if (btn) btn.outerHTML = inboxRecordButtonHtml((_inboxCache || {}).settings || {}); @@ -684,7 +763,7 @@ _inboxRec = null; inboxRecRender(); } - function inboxRecClose() { _inboxRec = null; inboxRecRender(); } + function inboxRecClose() { if (_inboxRec) clearTimeout(_inboxRec.donePoll); _inboxRec = null; inboxRecRender(); } // inboxRecFinishEarlier finalizes the user's earlier recording that is // still open on the hive (another tab or device stopped sending), so a // new one can start. diff --git a/src/pkg/dashboard/static-src/js/inbox.js b/src/pkg/dashboard/static-src/js/inbox.js index d5b9f6dbdd..758dea9cb3 100644 --- a/src/pkg/dashboard/static-src/js/inbox.js +++ b/src/pkg/dashboard/static-src/js/inbox.js @@ -80,6 +80,7 @@ } _inboxCache = await r.json(); renderInbox(); + if (typeof inboxRecSyncDone === 'function') inboxRecSyncDone(_inboxCache.items); clearTimeout(_inboxBusyTimer); if (inboxRouteBusy(_inboxCache.items)) _inboxBusyTimer = setTimeout(fetchInbox, INBOX_BUSY_POLL_MS); if (inboxTxAnyBusy(_inboxCache.items)) inboxTxPollSchedule(); @@ -493,6 +494,19 @@ } catch (e) { return e.message; } return 'the browser could not play this recording'; } + // inboxAudioNoteText is the line under the player. Audio this hive + // stores itself (its own recordings, dropped audio files) is kept until + // retention deletes it (audio_expires_at); a third-party source's audio + // is only streamed through and never stored here. + function inboxAudioNoteText(it, fmtDate) { + const restart = ' Click ▶ Play recording again to restart.'; + if (it && (it.source === 'hive-recording' || it.source === 'upload')) { + const exp = it.audio_expires_at && !String(it.audio_expires_at).startsWith('0001') ? it.audio_expires_at : ''; + const when = exp && fmtDate ? fmtDate(exp) : ''; + return (when ? 'The audio is kept on this hive until ' + when + ', then deleted; the transcript stays.' : 'The audio is kept on this hive.') + restart; + } + return 'Streaming through this hive; the recording is not stored.' + restart; + } function inboxPlay(src, id) { const key = src + '/' + id; const target = document.querySelector('[data-inbox-media="' + CSS.escape(key) + '"]'); @@ -511,7 +525,7 @@ target.appendChild(audio); const note = document.createElement('div'); note.className = 'muted-xs'; - note.textContent = 'Streaming through this hive; the recording is not stored. Click ▶ Play recording again to restart.'; + note.textContent = inboxAudioNoteText(inboxFind(src, id), d => formatDashboardDate(d, { year: 'numeric', month: 'short', day: 'numeric' })); target.appendChild(note); } diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 4a43e8d843..646379f1ed 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -6117,7 +6117,12 @@ .inbox-add-url { flex: 1 1 16rem; min-width: 0; } .inbox-upload .kc-error { flex-basis: 100%; } /* ● Record (inbox-recorder.js): panel, red indicator, level meters */ - .inbox-rec-panel { margin-bottom: var(--sp-4); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-left: 3px solid var(--red); border-radius: var(--r); background: var(--surface); } + .inbox-rec-panel { position: relative; overflow: hidden; margin-bottom: var(--sp-4); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-left: 3px solid var(--red); border-radius: var(--r); background: var(--surface); } + /* The saved panel auto-dismisses with the toast countdown bar (toastCountdownBar). */ + .inbox-rec-panel .toast-bar { background: color-mix(in srgb, var(--green) 40%, transparent); } + .inbox-rec-panel[data-outcome="failed"] .toast-bar { background: color-mix(in srgb, var(--red) 40%, transparent); } + .inbox-rec-panel[data-outcome="stalled"] .toast-bar { background: color-mix(in srgb, var(--status-warn) 40%, transparent); } + .inbox-rec-panel[data-outcome="off"] .toast-bar { background: color-mix(in srgb, var(--blue) 40%, transparent); } .inbox-rec-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); } .inbox-rec-dot { color: var(--red); } .inbox-rec-dot.is-live { animation: inbox-rec-pulse 1.2s ease-in-out infinite; } @@ -47816,6 +47821,7 @@ } _inboxCache = await r.json(); renderInbox(); + if (typeof inboxRecSyncDone === 'function') inboxRecSyncDone(_inboxCache.items); clearTimeout(_inboxBusyTimer); if (inboxRouteBusy(_inboxCache.items)) _inboxBusyTimer = setTimeout(fetchInbox, INBOX_BUSY_POLL_MS); if (inboxTxAnyBusy(_inboxCache.items)) inboxTxPollSchedule(); @@ -48229,6 +48235,19 @@ } catch (e) { return e.message; } return 'the browser could not play this recording'; } + // inboxAudioNoteText is the line under the player. Audio this hive + // stores itself (its own recordings, dropped audio files) is kept until + // retention deletes it (audio_expires_at); a third-party source's audio + // is only streamed through and never stored here. + function inboxAudioNoteText(it, fmtDate) { + const restart = ' Click ▶ Play recording again to restart.'; + if (it && (it.source === 'hive-recording' || it.source === 'upload')) { + const exp = it.audio_expires_at && !String(it.audio_expires_at).startsWith('0001') ? it.audio_expires_at : ''; + const when = exp && fmtDate ? fmtDate(exp) : ''; + return (when ? 'The audio is kept on this hive until ' + when + ', then deleted; the transcript stays.' : 'The audio is kept on this hive.') + restart; + } + return 'Streaming through this hive; the recording is not stored.' + restart; + } function inboxPlay(src, id) { const key = src + '/' + id; const target = document.querySelector('[data-inbox-media="' + CSS.escape(key) + '"]'); @@ -48247,7 +48266,7 @@ target.appendChild(audio); const note = document.createElement('div'); note.className = 'muted-xs'; - note.textContent = 'Streaming through this hive; the recording is not stored. Click ▶ Play recording again to restart.'; + note.textContent = inboxAudioNoteText(inboxFind(src, id), d => formatDashboardDate(d, { year: 'numeric', month: 'short', day: 'numeric' })); target.appendChild(note); } @@ -49240,6 +49259,12 @@ // A live recorder holds a Web Lock with this prefix, so another tab of // the same browser never finalizes a recording that is still running. const INBOX_REC_LOCK_PREFIX = 'hive-inbox-recording-'; + // After a recording is saved the panel follows its Inbox item: the + // Inbox is re-read this often while the item shows no transcription + // state yet (a running job is followed by the transcription poll), for + // at most INBOX_REC_DONE_WAIT_MS before the panel stops waiting. + const INBOX_REC_DONE_POLL_MS = 5000; + const INBOX_REC_DONE_WAIT_MS = 120000; let _inboxRec = null; @@ -49798,7 +49823,10 @@ if (m.uploader) html += '
' + escapeHtml(inboxRecUploadText(m.uploader.state)) + '
'; if (m.warning) html += ''; if (m.error) html += ''; - if (m.state === 'done') html += '
' + escapeHtml(m.transcribes ? 'The hive is transcribing it now; follow the progress on the item in the Inbox below.' : 'It appears in the Inbox below. Transcription is off on this hive, so it is not transcribed yet.') + '
'; + if (m.state === 'done') { + const o = m.outcome || inboxRecDoneOutcome(null, m.transcribes, '', false); + html += '
' + escapeHtml(inboxRecDoneText(o)) + '
'; + } html += '
'; if (m.state === 'recording') html += ''; if (m.state === 'paused') html += ''; @@ -49808,6 +49836,61 @@ if (m.state === 'done' || m.state === 'error') html += ''; return html + '
'; } + // inboxRecDoneOutcome is where a saved recording's Inbox item stands: + // transcribed (the item has text), failed (the job failed or was + // skipped, or the hive cannot transcribe it; reason says why), off + // (transcription is off on this hive), stalled (no job appeared within + // INBOX_REC_DONE_WAIT_MS: waitedOut) or waiting. Every state but waiting + // starts the panel's auto-dismiss countdown. + function inboxRecDoneOutcome(it, transcribes, unavailableText, waitedOut) { + const tx = (it && it.transcription) || null; + if (it && (it.has_transcript || it.fact_state === 'machine' || (tx && tx.status === 'done'))) return { state: 'transcribed', reason: '' }; + if (tx && (tx.status === 'failed' || tx.status === 'skipped')) return { state: 'failed', reason: tx.reason || '' }; + if (tx && (tx.status === 'queued' || tx.status === 'running')) return { state: 'waiting', reason: '' }; + if (!transcribes || (it && it.transcribe_unavailable === 'disabled')) return { state: 'off', reason: '' }; + if (it && it.transcribe_unavailable) return { state: 'failed', reason: unavailableText || '' }; + if (waitedOut) return { state: 'stalled', reason: '' }; + return { state: 'waiting', reason: '' }; + } + // inboxRecDoneText is the panel line for an outcome. + function inboxRecDoneText(o) { + switch (o && o.state) { + case 'transcribed': return 'Transcribed. See the item below.'; + case 'failed': return 'Transcription failed' + (o.reason ? ': ' + o.reason : '') + '. The recording is saved in the Inbox below; retry the transcription from the item.'; + case 'off': return 'It appears in the Inbox below. Transcription is off on this hive, so it is not transcribed yet.'; + case 'stalled': return 'Saved in the Inbox below. Transcription has not started yet; follow it on the item.'; + default: return 'The hive is transcribing it now; follow the progress on the item in the Inbox below.'; + } + } + // inboxRecSyncDone runs after every Inbox read: it finds the saved + // recording's item, updates the panel line, and once the outcome is + // final starts the same auto-dismiss countdown toasts use (bar, duration + // and pause on hover or focus). Close still dismisses at once. + function inboxRecSyncDone(items) { + const m = _inboxRec; + if (!m || m.state !== 'done' || !m.id) return; + if (!m.doneAt) m.doneAt = Date.now(); + const it = (items || []).find(x => x && x.source === 'hive-recording' && x.id === m.id) || null; + const waitedOut = Date.now() - m.doneAt >= INBOX_REC_DONE_WAIT_MS; + const why = it && it.transcribe_unavailable && typeof inboxTxUnavailableText === 'function' ? inboxTxUnavailableText(it.transcribe_unavailable) : ''; + const o = inboxRecDoneOutcome(it, m.transcribes, why, waitedOut); + const changed = !m.outcome || m.outcome.state !== o.state || m.outcome.reason !== o.reason; + m.outcome = o; + if (changed) inboxRecRender(); + clearTimeout(m.donePoll); + m.donePoll = 0; + if (o.state !== 'waiting') { inboxRecArmDismiss(m); return; } + // A running job is followed by the Inbox's own transcription poll. + const busy = it && it.transcription && (it.transcription.status === 'queued' || it.transcription.status === 'running'); + if (!busy && typeof fetchInbox === 'function') m.donePoll = setTimeout(() => { if (_inboxRec === m) fetchInbox(); }, INBOX_REC_DONE_POLL_MS); + } + function inboxRecArmDismiss(m) { + const panel = document.getElementById('inbox-rec-panel'); + if (!panel || m.dismissArmed || typeof toastCountdownBar !== 'function') return; + m.dismissArmed = true; + if (m.outcome) panel.dataset.outcome = m.outcome.state; + toastCountdownBar(panel, TOAST_DURATION_MS, () => { if (_inboxRec === m) inboxRecClose(); }); + } // The timer and meters redraw on a dashboard interval (paused while the // page is hidden); the length limit has its own timeout so it holds in // the background too. @@ -49825,12 +49908,27 @@ const m = _inboxRec; const panel = document.getElementById('inbox-rec-panel'); const html = inboxRecPanelHtml(m); - if (panel) { panel.hidden = !html; panel.innerHTML = html; } + if (panel) { + // A countdown belongs to the saved recording it was armed for. + if (panel._countdown && !(m && m.state === 'done' && m.dismissArmed) && typeof toastCountdownCancel === 'function') toastCountdownCancel(panel); + panel.hidden = !html; + if (m && m.outcome) panel.dataset.outcome = m.outcome.state; else delete panel.dataset.outcome; + if (panel._html !== html) { + panel._html = html; + panel.innerHTML = html; + // The rewrite dropped the countdown bar; put it back where it was. + if (panel._countdown && panel._countdown.bar) panel.appendChild(panel._countdown.bar); + } + } inboxRecIndicator(m); const live = m && (m.state === 'recording' || m.state === 'paused'); if (live && !_inboxRecTicker) { _inboxRecTicker = true; dashboardSetInterval('inbox-recorder', inboxRecTick, INBOX_REC_TICK_MS); } if (!live && _inboxRecTicker) { _inboxRecTicker = false; dashboardClearInterval('inbox-recorder'); } - if (m && m.state === 'done' && !m.listed) { m.listed = true; inboxRecWakeLock(false); if (typeof fetchInbox === 'function') fetchInbox(); } + if (m && m.state === 'done' && !m.listed) { + m.listed = true; inboxRecWakeLock(false); + if (!m.transcribes) { m.outcome = inboxRecDoneOutcome(null, false, '', false); inboxRecArmDismiss(m); } + if (typeof fetchInbox === 'function') fetchInbox(); + } if (m && m.state === 'error') inboxRecWakeLock(false); const btn = document.querySelector('#inbox-panel .inbox-rec-btn'); if (btn) btn.outerHTML = inboxRecordButtonHtml((_inboxCache || {}).settings || {}); @@ -49885,7 +49983,7 @@ _inboxRec = null; inboxRecRender(); } - function inboxRecClose() { _inboxRec = null; inboxRecRender(); } + function inboxRecClose() { if (_inboxRec) clearTimeout(_inboxRec.donePoll); _inboxRec = null; inboxRecRender(); } // inboxRecFinishEarlier finalizes the user's earlier recording that is // still open on the hive (another tab or device stopped sending), so a // new one can start. diff --git a/src/pkg/inbox/factsource.go b/src/pkg/inbox/factsource.go index 5a78511c78..616dd18f6b 100644 --- a/src/pkg/inbox/factsource.go +++ b/src/pkg/inbox/factsource.go @@ -213,14 +213,24 @@ func truncateRunes(s string, n int) string { return strings.TrimSpace(string(r[:n])) + "…" } +// excerptHidden reports the lines a fact carries for agents and provenance, +// not for reading: the untrusted-data envelope around a machine transcript +// (its open and close markers and the preamble) and the transcript's +// provenance line. The stored fact keeps them; the excerpt shows only text. +func excerptHidden(line string) bool { + return strings.HasPrefix(line, "<"+UntrustedTag) || strings.HasPrefix(line, " 0 { diff --git a/src/pkg/inbox/factwriteback.go b/src/pkg/inbox/factwriteback.go index c1cb55b310..f3ccdb06ae 100644 --- a/src/pkg/inbox/factwriteback.go +++ b/src/pkg/inbox/factwriteback.go @@ -26,6 +26,12 @@ const ( factHighlightsHeading = "## Highlights" // factDateLayout is the day shown in the machine-transcript note. factDateLayout = "2006-01-02" + // hiveTranscriptProvenancePrefix opens the provenance line of a + // transcript of audio this hive stores itself (hive-recording, upload). + hiveTranscriptProvenancePrefix = "Transcript made by this hive with" + // machineTranscriptProvenancePrefix opens the provenance line of a + // machine transcript of a third-party source's recording. + machineTranscriptProvenancePrefix = "Machine transcript made by this hive with" ) // factPendingNotes are the pending lines connectors write into a fact with @@ -161,9 +167,7 @@ func machineFactBody(body string, it Item, rec TranscriptRecord) string { if label == "" { label = "the source" } - section := "## " + rec.Label() + "\n\n" + - fmt.Sprintf("_Machine transcript made by this hive with %s/%s on %s, because %s has no text for this recording yet. It is replaced when %s produces its own transcript or summary._\n\n", - rec.Provider, rec.Model, rec.UpdatedAt.UTC().Format(factDateLayout), label, label) + + section := "## " + rec.Label() + "\n\n" + machineProvenance(it.Source, label, rec) + "\n\n" + WrapUntrusted(it.Source, it.ID, rec.Text) + "\n" if i := strings.Index(body, "\n"+factHighlightsHeading); i >= 0 { return collapseBlankLines(strings.TrimRight(body[:i], "\n") + "\n\n" + section + "\n" + strings.TrimLeft(body[i:], "\n")) @@ -171,6 +175,33 @@ func machineFactBody(body string, it Item, rec TranscriptRecord) string { return collapseBlankLines(strings.TrimRight(body, "\n") + "\n\n" + section) } +// machineProvenance is the italic line above a machine transcript. Audio +// this hive keeps itself (its own recordings, dropped audio files) has no +// other text to wait for, so the line only names the provider and the day; +// a third-party source (Plaud, Zoom, ...) may still produce its own text, +// which then replaces the machine transcript. +func machineProvenance(source, label string, rec TranscriptRecord) string { + day := rec.UpdatedAt.UTC().Format(factDateLayout) + if hiveStoredAudioSource(source) { + return fmt.Sprintf("_%s %s/%s on %s._", hiveTranscriptProvenancePrefix, rec.Provider, rec.Model, day) + } + return fmt.Sprintf("_%s %s/%s on %s, because %s has no text for this recording yet. It is replaced when %s produces its own transcript or summary._", + machineTranscriptProvenancePrefix, rec.Provider, rec.Model, day, label, label) +} + +// hiveStoredAudioSource reports a source whose audio is stored on this hive +// and whose only text is this hive's transcript. +func hiveStoredAudioSource(source string) bool { + return source == RecordingType || source == UploadType +} + +// isMachineProvenance reports the italic provenance line machineProvenance +// writes, so displays (the Inbox excerpt) can leave it out. +func isMachineProvenance(line string) bool { + line = strings.TrimSpace(line) + return strings.HasPrefix(line, "_"+hiveTranscriptProvenancePrefix+" ") || strings.HasPrefix(line, "_"+machineTranscriptProvenancePrefix+" ") +} + func isPendingNote(line string) bool { line = strings.TrimSpace(line) for _, n := range factPendingNotes { diff --git a/src/pkg/inbox/inbox.go b/src/pkg/inbox/inbox.go index 1d6cd03103..6344be2b60 100644 --- a/src/pkg/inbox/inbox.go +++ b/src/pkg/inbox/inbox.go @@ -91,6 +91,10 @@ type Item struct { AudioExpired bool `json:"audio_expired,omitempty"` // AudioRetentionDays is how long a hive recording's audio is kept. AudioRetentionDays int `json:"audio_retention_days,omitempty"` + // AudioExpiresAt is when retention deletes audio this hive stores + // itself (a hive recording, a dropped audio file); zero when the audio + // lives elsewhere, is already gone, or is kept without a limit. + AudioExpiresAt time.Time `json:"audio_expires_at,omitzero"` // AwaitingApproval marks an item from outside the hive's allowlist (the // email source, #18395): it cannot be routed, shared or transcribed until // the owner approves it. diff --git a/src/pkg/inbox/recording_display_test.go b/src/pkg/inbox/recording_display_test.go new file mode 100644 index 0000000000..9dccd94a69 --- /dev/null +++ b/src/pkg/inbox/recording_display_test.go @@ -0,0 +1,108 @@ +package inbox + +import ( + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/knowledge/connector" +) + +// recordingPendingFact is the pending fact a finished hive recording gets +// (see RecordingSource.writeFact), reduced to what machineFact reads. +func recordingPendingFact() string { + return "---\ntitle: Standup\ntype: reference\nlayer: personal\nstatus: active\n" + + "source: hive-recording\nconnector: hive-recording\nsource_id: rec-9\nattr_hive_recording_content: pending\n" + + "synthesized: 2026-11-16T09:00:00Z\n---\n\n" + + "# Standup\n\n- **Recorded:** 2026-11-16T09:00:00Z\n- **Duration:** 4s\n\n_" + RecordingPendingText + "_\n" +} + +func displayTestRecord(source, id string) TranscriptRecord { + return TranscriptRecord{ + Source: source, ID: id, Status: TranscriptionDone, Provider: "whisper", Model: "base.en", + Text: "We ship the fix today.", UpdatedAt: time.Date(2026, 11, 16, 9, 1, 0, 0, time.UTC), + } +} + +func TestMachineProvenanceWording(t *testing.T) { + rec := displayTestRecord(RecordingType, "rec-9") + for _, src := range []string{RecordingType, UploadType} { + got := machineProvenance(src, src, rec) + if want := "_Transcript made by this hive with whisper/base.en on 2026-11-16._"; got != want { + t.Errorf("%s provenance = %q, want %q", src, got, want) + } + if !isMachineProvenance(got) { + t.Errorf("%s provenance not recognised", src) + } + } + got := machineProvenance("plaud", "plaud", rec) + want := "_Machine transcript made by this hive with whisper/base.en on 2026-11-16, because plaud has no text for this recording yet. It is replaced when plaud produces its own transcript or summary._" + if got != want { + t.Errorf("plaud provenance = %q, want %q", got, want) + } + if !isMachineProvenance(got) { + t.Error("third-party provenance not recognised") + } + if isMachineProvenance("_Transcript notes from the meeting._") { + t.Error("ordinary italic text treated as provenance") + } +} + +// The Inbox excerpt of a machine-transcribed fact is the transcript text: +// no provenance line, no envelope markers, no preamble. The stored fact +// keeps all three. +func TestExcerptHidesMachineTranscriptEnvelope(t *testing.T) { + cases := []struct { + name, content, source, id string + }{ + {"hive recording", recordingPendingFact(), RecordingType, "rec-9"}, + {"plaud", audioOnlyFact(), "plaud", "rec-2"}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + it := Item{Source: tc.source, ID: tc.id} + out, ok := machineFact(tc.content, it, displayTestRecord(tc.source, tc.id)) + if !ok { + t.Fatal("machineFact refused the pending fact") + } + for _, kept := range []string{"<" + UntrustedTag, " 0 && m.OriginalDeletedAt == nil { + it.AudioExpiresAt = m.AddedAt.Add(time.Duration(days) * hoursPerDay * time.Hour).UTC() + } if it.FactPath != "" { if data, err := os.ReadFile(it.FactPath); err == nil { fm, _ := splitFrontMatter(string(data))