From c0a805ef54cc2a343682faf19edc6325b13b1253 Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Mon, 16 Nov 2026 06:53:38 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Inbox:=20fact=20is=20a=20sta?= =?UTF-8?q?tus,=20not=20a=20button;=20machine=20transcripts=20become=20kno?= =?UTF-8?q?wledge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the ๐Ÿ“š Fact button from the Inbox action row. What the item's Knowledge fact holds is now a non-interactive status pill (Pending text, In knowledge (machine text), In knowledge), and opening the fact is a plain link in the metadata line. A finished machine transcription is now written into the item's fact, fenced as untrusted data and marked attr__content: machine with attr_transcript_provider, keeping source attrs, metadata and highlights. Connector syncs that still find no upstream text leave a machine fact alone; Plaud and meeting refetch keep re-reading machine facts so the source's own text replaces it when it arrives. Signed-off-by: Andy Anderson --- changelog.d/fixed-inbox-fact-indicator.md | 1 + src/docs/design/email-inbox.md | 2 +- src/docs/inbox-transcription.md | 19 +- src/docs/inbox-voice-sources.md | 76 +++++- src/pkg/dashboard/static-src/js/inbox.js | 22 +- src/pkg/dashboard/static/index.html | 22 +- src/pkg/inbox/factsource.go | 4 + src/pkg/inbox/factwriteback.go | 228 ++++++++++++++++++ src/pkg/inbox/factwriteback_test.go | 197 +++++++++++++++ src/pkg/inbox/inbox.go | 7 + src/pkg/inbox/plaudsource.go | 2 +- src/pkg/inbox/service.go | 3 + src/pkg/inbox/transcription.go | 20 +- .../knowledge/connector/fact_content_test.go | 117 +++++++++ src/pkg/knowledge/connector/factwriter.go | 62 ++++- src/pkg/knowledge/connector/meeting.go | 10 +- src/pkg/knowledge/connector/plaud_content.go | 10 +- 17 files changed, 779 insertions(+), 23 deletions(-) create mode 100644 changelog.d/fixed-inbox-fact-indicator.md create mode 100644 src/pkg/inbox/factwriteback.go create mode 100644 src/pkg/inbox/factwriteback_test.go create mode 100644 src/pkg/knowledge/connector/fact_content_test.go diff --git a/changelog.d/fixed-inbox-fact-indicator.md b/changelog.d/fixed-inbox-fact-indicator.md new file mode 100644 index 0000000000..3bab2090ec --- /dev/null +++ b/changelog.d/fixed-inbox-fact-indicator.md @@ -0,0 +1 @@ +- **Inbox machine transcripts now become knowledge, and the "๐Ÿ“š Fact" button is gone.** A finished machine transcription (whisper, Gemini or Deepgram) is written into the item's Knowledge fact, fenced as untrusted data and marked `attr__content: machine` with `attr_transcript_provider`, so knowledge search, nous and agents see the words instead of a pending placeholder; later syncs keep it until the source produces its own text, which then replaces it. The action row no longer has a "๐Ÿ“š Fact" button: a status pill (*Pending text*, *In knowledge (machine text)*, *In knowledge*) shows what the fact holds, and an *open in Knowledge* link in the metadata line opens it. diff --git a/src/docs/design/email-inbox.md b/src/docs/design/email-inbox.md index d9067b22b7..9df8139ab7 100644 --- a/src/docs/design/email-inbox.md +++ b/src/docs/design/email-inbox.md @@ -77,7 +77,7 @@ reads the vendor directly, with `PreferDirect` merging the two emits pages on an interval. Email is push. So the email source is a native `inbox.Source` over its own on-disk spool, and it optionally writes a Knowledge fact per message through the same `FactWriter` slug scheme -(`src/pkg/knowledge/connector/factwriter.go:34`) so "๐Ÿ“š Fact" keeps working. +(`src/pkg/knowledge/connector/factwriter.go:34`) so the Inbox's *open in Knowledge* link keeps working. `SetSources` already lets a source appear without restart (`src/pkg/inbox/service.go:70-78`). diff --git a/src/docs/inbox-transcription.md b/src/docs/inbox-transcription.md index 4325c345c8..00af59b942 100644 --- a/src/docs/inbox-transcription.md +++ b/src/docs/inbox-transcription.md @@ -172,8 +172,9 @@ Transcription is spoke-local. Nothing about it is shared or central: account. No hive pays for, or sees, another hive's transcriptions. - **Your data volume.** The transcript is written only to this hive's data volume, under `connector-state/transcripts//.json` (mode - `0600`, written atomically). It is not sent to the hub, to other spokes, or - back to the recording's source. + `0600`, written atomically), and into the item's Knowledge fact on the + same volume. It is not sent to the hub, to other spokes, or back to the + recording's source. - **Your budget.** Monthly minutes, a daily item cap and size/duration limits are configured per hive and checked before any audio is uploaded. With whisper the minutes budget limits CPU time on the hive, not money. @@ -350,10 +351,16 @@ and the boot log line `inbox transcription enabled` name the hosts. See ## Upstream text wins -The machine transcript is a fallback. If the source later produces its own -summary or transcript (for example the owner runs transcription in the Plaud -app), the Inbox shows the source's text and the machine transcript is no -longer used. If the source is unreachable, the stored machine transcript +The machine transcript is a fallback. When a run finishes, the hive also +writes the transcript into the item's Knowledge fact (marked +`attr__content: machine` with `attr_transcript_provider`), so knowledge +search, nous and agents see the text, not only the Inbox; see +[What knowledge an Inbox item becomes](inbox-voice-sources.md#what-knowledge-an-inbox-item-becomes). +Later syncs that still find no text upstream keep that fact as it is. If +the source later produces its own summary or transcript (for example the +owner runs transcription in the Plaud app), the next sync replaces the +machine text in the fact, the Inbox shows the source's text and the machine +transcript is no longer used. If the source is unreachable, the stored machine transcript still serves the item's content. ## Cost diff --git a/src/docs/inbox-voice-sources.md b/src/docs/inbox-voice-sources.md index 4b1c5a1db9..b85401e85b 100644 --- a/src/docs/inbox-voice-sources.md +++ b/src/docs/inbox-voice-sources.md @@ -29,7 +29,9 @@ see the issue linked from the changelog entry. `:` in `attr_slack_huddle_recording_id`; for Otter the conversation id in `attr_otter_recording_id`; for Granola the note id in `attr_granola_recording_id`; for Limitless the lifelog id in `attr_limitless_recording_id`; for Fathom the recording id in `attr_fathom_recording_id`; for Fireflies the transcript id in `attr_fireflies_recording_id`). When the source is connected the Inbox lists recordings directly from it, so an item may appear before the sync has written its Knowledge fact; the Inbox only tracks what you did with it. - "๐Ÿ“š Fact" opens the fact in Knowledge once that fact exists. + Once that fact exists, the item's metadata line carries an *open in + Knowledge* link, and a status pill says what the fact holds (see + [What knowledge an Inbox item becomes](#what-knowledge-an-inbox-item-becomes)). - **Destination** โ€” where an item goes: - **โ†’ RFC** (`spek_rfc`): the hive hands the item to a spoke agent with a kick prompt: `inbox.spek.agent` if set, otherwise the first enabled, @@ -126,6 +128,78 @@ transcription/summary in the Plaud app to fill it. Facts written before this behaviour, whose body carries the "not available" line, are refreshed the same way. +## What knowledge an Inbox item becomes + +Every Inbox item is backed by one Knowledge fact, written by its connector's +sync under `/connectors//--.md`. +That fact, not the Inbox view, is what knowledge search, nous and agents +read. Its `attr__content` key (`attr_plaud_content` for Plaud, +`attr_meeting_content` for the meeting connectors) records which of three +shapes it has, and the Inbox shows it as a status pill (not a button): + +- **Audio only (pending)**, pill *Pending text*. The source has no summary + and no transcript. The fact holds metadata only: the title, the + recording time, the duration, the device highlights when there are any, + and the pending note; it is marked `attr__content: pending` and the + connector re-reads it on every sync. A Plaud example: + + ```markdown + --- + title: Drive home + type: reference + layer: personal + status: active + tags: [connector, plaud, plaud] + source: plaud + connector: plaud + source_id: rec-2 + source_path: Plaud + attr_duration_ms: 61000 + attr_plaud_content: pending + attr_plaud_file_id: rec-2 + synthesized: 2026-11-11T18:00:00Z + synced_at: 2026-11-11T20:00:00Z + --- + + # Drive home + + - **Recorded:** 2026-11-11T18:00:00Z + - **Duration:** 1m1s + + _Plaud has not transcribed this recording yet. Open it in the Plaud app to run transcription and the AI summary; the hive re-checks it on every sync until text arrives._ + + ## Highlights + + Moments flagged with the device button: + + - 05:03 + ``` + + Knowledge search finds the title, never the words that were spoken. +- **After machine transcription**, pill *In knowledge (machine text)*. When + a [machine transcription](inbox-transcription.md) finishes, the hive + writes the transcript into the same fact: `attr__content: machine`, + `attr_transcript_provider: /` (for example + `whisper/base.en`), `attr_transcript_language` and `attr_transcribed_at` + are set, the pending note is replaced by a `## Transcript (machine: + /)` section ahead of the highlights, and every other + attribute, the metadata bullets and the highlights stay. The transcript + is spoken by third parties, so it is fenced in the same + `` envelope the + Inbox uses when it hands item text to an agent. A transcript that + finished before the fact existed is written the next time the Inbox is + listed. The connector keeps re-reading the recording, and a sync that + still finds no text upstream leaves the machine fact alone; it is never + reset to pending. +- **After upstream transcription**, pill *In knowledge*. When the source + produces its own summary or transcript (the owner runs transcription in + the Plaud app, the meeting platform finishes processing), the next sync + rewrites the fact with the source's text and `attr__content: ready`, + replacing any machine transcript. + +An item listed straight from a connected source before its first sync shows +*Not in knowledge yet*. + ## Meeting recordings (Zoom, Teams) Zoom and Teams items look like Plaud items: the title is the meeting topic, diff --git a/src/pkg/dashboard/static-src/js/inbox.js b/src/pkg/dashboard/static-src/js/inbox.js index 567e03efef..57de4ee0d5 100644 --- a/src/pkg/dashboard/static-src/js/inbox.js +++ b/src/pkg/dashboard/static-src/js/inbox.js @@ -181,6 +181,20 @@ (elapsed ? '' + escapeHtml(elapsed) + '' : '') + ''; } + // What the item's Knowledge fact holds, as a status pill (not a + // control): the source's own text, this hive's machine transcript, or + // metadata only while no text exists yet. + const INBOX_FACT_STATES = { + ready: { label: 'In knowledge', status: 'ok', title: 'Stored as a Knowledge fact with the source\'s own text; knowledge search and agents see it.' }, + machine: { label: 'In knowledge (machine text)', status: 'ok', title: 'Stored as a Knowledge fact with this hive\'s machine transcript; the source\'s own text replaces it when it exists.' }, + pending: { label: 'Pending text', status: 'not loaded', title: 'Stored as a Knowledge fact with metadata only (title, date, duration, highlights); no text yet, so knowledge search finds no words.' }, + }; + function inboxFactPillHtml(it) { + if (!it.fact_slug) return 'Not in knowledge yet'; + const fs = INBOX_FACT_STATES[it.fact_state] || INBOX_FACT_STATES.ready; + return '' + escapeHtml(fs.label) + ''; + } + // Machine transcription: a state pill (spinner while queued/running, the // reason when it failed or was skipped), the progress bar while busy, and // the ๐ŸŽง Transcribe / Retry button on pending items with audio, for @@ -188,7 +202,7 @@ function inboxTranscriptionHtml(it, key) { const st = it.transcription; const src = escapeHtml(it.source), id = escapeHtml(it.id); - let html = ''; + let html = inboxFactPillHtml(it); if (st && st.status) { const busy = st.status === 'queued' || st.status === 'running'; const pill = st.status === 'done' ? 'ok' : (st.status === 'failed' ? 'error' : (busy ? 'syncing' : '')); @@ -289,7 +303,10 @@ const checked = _inboxSelected.has(key) ? ' checked' : ''; const when = it.recorded_at && !String(it.recorded_at).startsWith('0001') ? relativeTimeShort(it.recorded_at) : ''; const dur = inboxFmtDuration(it.duration_ms); - const meta = [escapeHtml(it.source), when ? 'recorded ' + when : '', dur].filter(Boolean).join(' ยท '); + // The backing Knowledge fact is a plain link in the metadata line, not + // an action: it only opens the fact. + const factLink = it.fact_slug ? 'open in Knowledge' : ''; + const meta = [escapeHtml(it.source), when ? 'recorded ' + when : '', dur, factLink].filter(Boolean).join(' ยท '); const routes = it.routes || {}; let pills = ''; for (const d of Object.keys(routes)) pills += inboxStatePill(d, routes[d]) + ' '; @@ -307,7 +324,6 @@ else actions += ''; } actions += ''; - if (it.fact_slug) actions += ''; return '
' + (owner ? '' : '') + '
' + inboxSourceIcon(it.source) + '
' + diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index a42b40c53c..fe2354928b 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -47515,6 +47515,20 @@ (elapsed ? '' + escapeHtml(elapsed) + '' : '') + '
'; } + // What the item's Knowledge fact holds, as a status pill (not a + // control): the source's own text, this hive's machine transcript, or + // metadata only while no text exists yet. + const INBOX_FACT_STATES = { + ready: { label: 'In knowledge', status: 'ok', title: 'Stored as a Knowledge fact with the source\'s own text; knowledge search and agents see it.' }, + machine: { label: 'In knowledge (machine text)', status: 'ok', title: 'Stored as a Knowledge fact with this hive\'s machine transcript; the source\'s own text replaces it when it exists.' }, + pending: { label: 'Pending text', status: 'not loaded', title: 'Stored as a Knowledge fact with metadata only (title, date, duration, highlights); no text yet, so knowledge search finds no words.' }, + }; + function inboxFactPillHtml(it) { + if (!it.fact_slug) return 'Not in knowledge yet'; + const fs = INBOX_FACT_STATES[it.fact_state] || INBOX_FACT_STATES.ready; + return '' + escapeHtml(fs.label) + ''; + } + // Machine transcription: a state pill (spinner while queued/running, the // reason when it failed or was skipped), the progress bar while busy, and // the ๐ŸŽง Transcribe / Retry button on pending items with audio, for @@ -47522,7 +47536,7 @@ function inboxTranscriptionHtml(it, key) { const st = it.transcription; const src = escapeHtml(it.source), id = escapeHtml(it.id); - let html = ''; + let html = inboxFactPillHtml(it); if (st && st.status) { const busy = st.status === 'queued' || st.status === 'running'; const pill = st.status === 'done' ? 'ok' : (st.status === 'failed' ? 'error' : (busy ? 'syncing' : '')); @@ -47623,7 +47637,10 @@ const checked = _inboxSelected.has(key) ? ' checked' : ''; const when = it.recorded_at && !String(it.recorded_at).startsWith('0001') ? relativeTimeShort(it.recorded_at) : ''; const dur = inboxFmtDuration(it.duration_ms); - const meta = [escapeHtml(it.source), when ? 'recorded ' + when : '', dur].filter(Boolean).join(' ยท '); + // The backing Knowledge fact is a plain link in the metadata line, not + // an action: it only opens the fact. + const factLink = it.fact_slug ? 'open in Knowledge' : ''; + const meta = [escapeHtml(it.source), when ? 'recorded ' + when : '', dur, factLink].filter(Boolean).join(' ยท '); const routes = it.routes || {}; let pills = ''; for (const d of Object.keys(routes)) pills += inboxStatePill(d, routes[d]) + ' '; @@ -47641,7 +47658,6 @@ else actions += ''; } actions += ''; - if (it.fact_slug) actions += ''; return '
' + (owner ? '' : '') + '
' + inboxSourceIcon(it.source) + '
' + diff --git a/src/pkg/inbox/factsource.go b/src/pkg/inbox/factsource.go index c1e40952e5..5a78511c78 100644 --- a/src/pkg/inbox/factsource.go +++ b/src/pkg/inbox/factsource.go @@ -9,6 +9,8 @@ import ( "strings" "time" "unicode/utf8" + + "github.com/hivecommons/hive/pkg/knowledge/connector" ) // excerptRunes bounds the list excerpt. @@ -93,6 +95,7 @@ func itemFromFact(fm map[string]string, body, layer, path string) Item { it.Summary = truncateRunes(sections["summary"], SummaryRunes) it.HasTranscript = sections["transcript"] != "" it.Pending = it.Summary == "" && !it.HasTranscript + it.FactState = factState(fm, it.Pending) for _, key := range []string{"attr_recorded_at", "synthesized"} { if t, err := time.Parse(time.RFC3339, fm[key]); err == nil { it.RecordedAt = t.UTC() @@ -131,6 +134,7 @@ func (f *FactSource) Fetch(_ context.Context, it Item) (Content, error) { sections := splitSections(body) c.Summary, c.Transcript, c.Highlights = sections["summary"], sections["transcript"], sections["highlights"] c.Pending = c.Summary == "" && c.Transcript == "" + c.machineFact = connector.FactContentState(fm) == connector.FactContentMachine return c, nil } diff --git a/src/pkg/inbox/factwriteback.go b/src/pkg/inbox/factwriteback.go new file mode 100644 index 0000000000..e1498e4426 --- /dev/null +++ b/src/pkg/inbox/factwriteback.go @@ -0,0 +1,228 @@ +package inbox + +import ( + "fmt" + "os" + "path/filepath" + "strings" + "time" + + "github.com/hivecommons/hive/pkg/knowledge" + "github.com/hivecommons/hive/pkg/knowledge/connector" +) + +const ( + // factFileMode matches the mode connector facts are written with. + factFileMode = 0o644 + // factTranscriptProviderKey names the provider/model that made a + // machine transcript written into a fact. + factTranscriptProviderKey = "attr_transcript_provider" + // factTranscriptLanguageKey is the language the provider reported. + factTranscriptLanguageKey = "attr_transcript_language" + // factTranscribedAtKey is when the machine transcript finished. + factTranscribedAtKey = "attr_transcribed_at" + // factHighlightsHeading opens the highlights section the machine + // transcript is placed in front of. + factHighlightsHeading = "## Highlights" + // factDateLayout is the day shown in the machine-transcript note. + factDateLayout = "2006-01-02" +) + +// factPendingNotes are the pending lines connectors write into a fact with +// no text; the machine transcript replaces them. +var factPendingNotes = []string{ + "_" + connector.PlaudPendingText + "_", + "_" + connector.MeetingPendingText + "_", +} + +// factState is the Item.FactState of a fact: its recorded content state, or +// for facts written before connectors recorded one, pending when the fact +// has no summary and no transcript and ready otherwise. +func factState(fm map[string]string, pending bool) string { + if st := connector.FactContentState(fm); st != "" { + return st + } + if pending { + return connector.FactContentPending + } + return connector.FactContentReady +} + +// writeMachineFact writes a done machine transcript into the item's +// Knowledge fact while the source still has no text, so knowledge search, +// nous and agents see the words, not just the Inbox. It reports whether the +// fact changed. Items without a fact (not synced yet) are left for a later +// listing; facts that already carry text (source text, or this machine +// transcript) are never touched. +func (s *Service) writeMachineFact(it Item, rec TranscriptRecord) (bool, error) { + if it.FactPath == "" || rec.Status != TranscriptionDone || strings.TrimSpace(rec.Text) == "" { + return false, nil + } + s.factMu.Lock() + defer s.factMu.Unlock() + data, err := os.ReadFile(it.FactPath) + if err != nil { + if os.IsNotExist(err) { + return false, nil + } + return false, err + } + out, ok := machineFact(string(data), it, rec) + if !ok { + return false, nil + } + if err := writeFactAtomic(it.FactPath, out); err != nil { + return false, err + } + return true, nil +} + +// machineFact returns content with the machine transcript written in, or +// ok=false when the fact must stay as it is. +func machineFact(content string, it Item, rec TranscriptRecord) (string, bool) { + if !strings.HasPrefix(content, "---\n") { + return "", false + } + end := strings.Index(content[4:], "\n---") + if end < 0 { + return "", false + } + fm, body := splitFrontMatter(content) + if fm["status"] == "deprecated" || connector.FactContentState(fm) == connector.FactContentMachine { + return "", false + } + sections := splitSections(body) + if sections["summary"] != "" || sections["transcript"] != "" { + return "", false + } + + contentKey := connector.FactContentKey(fm) + if contentKey == "" { + contentKey = "attr_" + strings.ReplaceAll(factKeyPart(it.Source), "-", "_") + "_content" + } + set := map[string]string{ + contentKey: connector.FactContentMachine, + factTranscriptProviderKey: rec.Provider + "/" + rec.Model, + factTranscribedAtKey: rec.UpdatedAt.UTC().Format(time.RFC3339), + } + if rec.Language != "" { + set[factTranscriptLanguageKey] = rec.Language + } + head := setFrontMatter(strings.Split(content[4:4+end], "\n"), set, []string{contentKey, factTranscriptProviderKey, factTranscriptLanguageKey, factTranscribedAtKey}) + + return "---\n" + strings.Join(head, "\n") + "\n---\n\n" + machineFactBody(body, it, rec) + "\n", true +} + +// setFrontMatter replaces the lines of keys in set and appends the missing +// ones, in order, before synthesized/synced_at (or at the end). +func setFrontMatter(lines []string, set map[string]string, order []string) []string { + done := map[string]bool{} + out := make([]string, 0, len(lines)+len(set)) + for _, l := range lines { + k, _, ok := strings.Cut(l, ":") + k = strings.TrimSpace(k) + if v, want := set[k]; ok && want { + out = append(out, k+": "+knowledge.SanitizeFrontmatterValue(v)) + done[k] = true + continue + } + out = append(out, l) + } + at := len(out) + for i, l := range out { + if strings.HasPrefix(l, "synthesized:") || strings.HasPrefix(l, "synced_at:") { + at = i + break + } + } + var add []string + for _, k := range order { + if v, want := set[k]; want && !done[k] { + add = append(add, k+": "+knowledge.SanitizeFrontmatterValue(v)) + } + } + return append(out[:at:at], append(add, out[at:]...)...) +} + +// machineFactBody drops the pending note and places the machine transcript, +// fenced as untrusted data, ahead of the highlights (or at the end). The +// metadata bullets and highlights are kept as they are. +func machineFactBody(body string, it Item, rec TranscriptRecord) string { + var kept []string + for _, l := range strings.Split(strings.TrimSpace(body), "\n") { + if isPendingNote(l) { + continue + } + kept = append(kept, l) + } + body = strings.Join(kept, "\n") + label := it.Source + 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) + + 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")) + } + return collapseBlankLines(strings.TrimRight(body, "\n") + "\n\n" + section) +} + +func isPendingNote(line string) bool { + line = strings.TrimSpace(line) + for _, n := range factPendingNotes { + if line == n { + return true + } + } + return false +} + +// collapseBlankLines squeezes runs of blank lines left by the removed note. +func collapseBlankLines(s string) string { + for strings.Contains(s, "\n\n\n") { + s = strings.ReplaceAll(s, "\n\n\n", "\n\n") + } + return strings.TrimSpace(s) +} + +// factKeyPart reduces a source type to [a-z0-9-] for an attr key. +func factKeyPart(s string) string { + var b strings.Builder + for _, r := range strings.ToLower(s) { + if (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == '-' { + b.WriteRune(r) + } + } + if b.Len() == 0 { + return "source" + } + return b.String() +} + +// writeFactAtomic writes a fact through a temp file and a rename, with the +// mode connector facts use. +func writeFactAtomic(path, content string) error { + dir := filepath.Dir(path) + f, err := os.CreateTemp(dir, ".tmp-fact-*") + if err != nil { + return err + } + tmp := f.Name() + _, werr := f.WriteString(content) + if cerr := f.Close(); werr == nil { + werr = cerr + } + if werr == nil { + werr = os.Chmod(tmp, factFileMode) + } + if werr == nil { + werr = os.Rename(tmp, path) + } + if werr != nil { + _ = os.Remove(tmp) + } + return werr +} diff --git a/src/pkg/inbox/factwriteback_test.go b/src/pkg/inbox/factwriteback_test.go new file mode 100644 index 0000000000..8b49507b9e --- /dev/null +++ b/src/pkg/inbox/factwriteback_test.go @@ -0,0 +1,197 @@ +package inbox + +import ( + "context" + "net/http" + "os" + "path/filepath" + "strings" + "testing" + "time" + + "github.com/hivecommons/hive/pkg/config" + "github.com/hivecommons/hive/pkg/knowledge/connector" + "github.com/hivecommons/hive/pkg/transcribe" +) + +// audioFactSource is a fact-backed source whose items have audio, the way +// PreferDirect serves Plaud: list and read the facts, mint links upstream. +type audioFactSource struct { + *FactSource + link string +} + +func (s *audioFactSource) AudioLink(context.Context, Item) (AudioLink, error) { + return AudioLink{URL: s.link, ExpiresAt: time.Now().Add(time.Hour)}, nil +} + +// audioOnlyFact is what the Plaud connector writes for a recording Plaud +// never transcribed (see TestPlaudAudioOnlyFactShape for the real render). +func audioOnlyFact() string { + return "---\ntitle: Drive home\ntype: reference\nlayer: personal\nstatus: active\ntags: [connector, plaud, plaud]\n" + + "source: plaud\nconnector: plaud\nsource_id: rec-2\nsource_path: Plaud\nattr_duration_ms: 61000\n" + + "attr_plaud_content: pending\nattr_plaud_file_id: rec-2\nsynthesized: 2026-11-11T18:00:00Z\nsynced_at: 2026-11-11T20:00:00Z\n---\n\n" + + "# Drive home\n\n- **Recorded:** 2026-11-11T18:00:00Z\n- **Duration:** 1m1s\n\n_" + connector.PlaudPendingText + "_\n\n" + + "## Highlights\n\nMoments flagged with the device button:\n\n- 05:03\n" +} + +type factEnv struct { + svc *Service + store *TranscriptStore + path string + now time.Time +} + +func newFactEnv(t *testing.T, writeFact bool) *factEnv { + t.Helper() + srv := audioServer(t, http.StatusOK, txAudio) + dir := t.TempDir() + layer := filepath.Join(dir, "personal") + if err := os.MkdirAll(layer, 0o755); err != nil { + t.Fatal(err) + } + e := &factEnv{path: filepath.Join(layer, "plaud-plaud-rec-2.md"), now: time.Date(2026, 11, 15, 10, 0, 0, 0, time.UTC)} + if writeFact { + e.writeFact(t, audioOnlyFact()) + } + src := &audioFactSource{FactSource: &FactSource{ConnectorsDir: dir, SourceType: "plaud"}, link: srv.URL + "/rec-2.mp3?sig=secret"} + e.svc = NewService(config.InboxConfig{Transcription: activeTx()}, NewStore(filepath.Join(t.TempDir(), "inbox.json")), []Source{src}, nil, nil) + e.svc.Run = func(fn func()) { fn() } + e.svc.Now = func() time.Time { return e.now } + e.store = NewTranscriptStore(filepath.Join(t.TempDir(), "transcripts")) + e.svc.EnableTranscription(e.store) + fake := &transcribe.Fake{Result: transcribe.Result{ + Segments: []transcribe.Segment{{Start: time.Second, Text: "pick up milk"}}, + Language: "en", Duration: 61 * time.Second, + }} + e.svc.NewTranscriber = func(config.InboxTranscription) (transcribe.Transcriber, error) { return fake, nil } + e.svc.TranscribeBackoff = func(int) time.Duration { return 0 } + return e +} + +func (e *factEnv) writeFact(t *testing.T, content string) { + t.Helper() + if err := os.WriteFile(e.path, []byte(content), 0o644); err != nil { + t.Fatal(err) + } +} + +func (e *factEnv) readFact(t *testing.T) (map[string]string, string) { + t.Helper() + data, err := os.ReadFile(e.path) + if err != nil { + t.Fatal(err) + } + return splitFrontMatter(string(data)) +} + +func (e *factEnv) item(t *testing.T) Item { + t.Helper() + it, ok, err := e.svc.Find(context.Background(), "plaud", "rec-2") + if !ok || err != nil { + t.Fatalf("find = %v %v", ok, err) + } + return it +} + +func TestAudioOnlyFactIsPendingBeforeTranscription(t *testing.T) { + e := newFactEnv(t, true) + it := e.item(t) + if !it.Pending || it.HasTranscript || it.FactState != connector.FactContentPending || it.FactSlug != "plaud-plaud-rec-2" { + t.Fatalf("audio-only item = %+v", it) + } + c, err := e.svc.Content(context.Background(), it) + if err != nil || !c.Pending || c.Transcript != "" || c.Summary != "" || c.Highlights == "" { + t.Fatalf("audio-only content = %+v %v", c, err) + } +} + +func TestTranscriptionWritesMachineFact(t *testing.T) { + e := newFactEnv(t, true) + ctx := context.Background() + it := e.item(t) + if _, err := e.svc.Transcribe(ctx, it, TranscribeOptions{}); err != nil { + t.Fatal(err) + } + rec, ok := e.store.Get("plaud", "rec-2") + if !ok || rec.Status != TranscriptionDone { + t.Fatalf("record = %+v", rec) + } + + fm, body := e.readFact(t) + if fm["attr_plaud_content"] != connector.FactContentMachine || fm["attr_transcript_provider"] != rec.Provider+"/"+rec.Model || fm["attr_transcript_language"] != "en" { + t.Fatalf("machine fact front matter = %v", fm) + } + // Source attrs and provenance are kept. + if fm["source"] != "plaud" || fm["source_id"] != "rec-2" || fm["attr_plaud_file_id"] != "rec-2" || fm["attr_duration_ms"] != "61000" || fm["title"] != "Drive home" { + t.Fatalf("source attrs lost: %v", fm) + } + if strings.Contains(body, connector.PlaudPendingText) { + t.Fatalf("pending note kept:\n%s", body) + } + for _, want := range []string{"- **Duration:** 1m1s", "## " + rec.Label(), "<" + UntrustedTag + ` source="plaud" id="rec-2"`, "[00:01] pick up milk", " strings.Index(body, "## Highlights") { + t.Fatalf("transcript must come before highlights:\n%s", body) + } + + // The item reads as transcribed and in knowledge; the Inbox shows the + // stored text unwrapped, under its machine label. + it = e.item(t) + if it.Pending || !it.HasTranscript || it.FactState != connector.FactContentMachine { + t.Fatalf("item after write-back = %+v", it) + } + c, err := e.svc.Content(ctx, it) + if err != nil || c.Transcript != rec.Text || c.TranscriptLabel != rec.Label() { + t.Fatalf("content = %+v %v", c, err) + } + // A second listing does not rewrite the fact. + before, _ := os.ReadFile(e.path) + _ = e.item(t) + after, _ := os.ReadFile(e.path) + if string(before) != string(after) { + t.Fatal("listing rewrote a machine fact") + } +} + +func TestMachineTranscriptReachesFactWrittenLater(t *testing.T) { + e := newFactEnv(t, false) + // The transcript finished before the sync wrote the fact (or before + // write-back existed). + if err := e.store.Put(TranscriptRecord{Source: "plaud", ID: "rec-2", Status: TranscriptionDone, Provider: "whisper", Model: "base.en", Text: "[00:01] pick up milk", UpdatedAt: e.now}); err != nil { + t.Fatal(err) + } + e.writeFact(t, audioOnlyFact()) + it := e.item(t) + if it.FactState != connector.FactContentMachine { + t.Fatalf("item = %+v", it) + } + fm, body := e.readFact(t) + if fm["attr_plaud_content"] != connector.FactContentMachine || fm["attr_transcript_provider"] != "whisper/base.en" || !strings.Contains(body, "pick up milk") { + t.Fatalf("backfilled fact = %v\n%s", fm, body) + } +} + +func TestUpstreamTextIsNeverOverwrittenByMachineFact(t *testing.T) { + e := newFactEnv(t, false) + if err := e.store.Put(TranscriptRecord{Source: "plaud", ID: "rec-2", Status: TranscriptionDone, Provider: "whisper", Model: "base.en", Text: "[00:01] pick up milk", UpdatedAt: e.now}); err != nil { + t.Fatal(err) + } + ready := strings.Replace(audioOnlyFact(), "attr_plaud_content: pending", "attr_plaud_content: ready", 1) + ready = strings.Replace(ready, "_"+connector.PlaudPendingText+"_", "## Transcript\n\n[00:00] Andy: real words", 1) + e.writeFact(t, ready) + it := e.item(t) + if it.FactState != connector.FactContentReady { + t.Fatalf("item = %+v", it) + } + if data, _ := os.ReadFile(e.path); string(data) != ready { + t.Fatalf("upstream fact rewritten:\n%s", data) + } + c, err := e.svc.Content(context.Background(), it) + if err != nil || c.Transcript != "[00:00] Andy: real words" || c.TranscriptLabel != "" { + t.Fatalf("content = %+v %v", c, err) + } +} diff --git a/src/pkg/inbox/inbox.go b/src/pkg/inbox/inbox.go index 7b13dc3a17..cf55790f23 100644 --- a/src/pkg/inbox/inbox.go +++ b/src/pkg/inbox/inbox.go @@ -49,6 +49,10 @@ type Item struct { FactSlug string `json:"fact_slug"` FactPath string `json:"fact_path,omitempty"` Layer string `json:"layer,omitempty"` + // FactState is what the backing fact holds: "ready" (the source's own + // text), "pending" (metadata only, no text yet) or "machine" (this + // hive's machine transcript). Empty when no fact exists yet. + FactState string `json:"fact_state,omitempty"` // Routes holds per-destination state; absent means never routed. Routes map[string]*RouteState `json:"routes,omitempty"` // Dismissed marks "knowledge only": the item stays a fact, no further route. @@ -103,6 +107,9 @@ type Content struct { Pending bool `json:"pending"` // Provenance is a stable reference such as plaud://recordings/. Provenance string `json:"provenance"` + // machineFact marks content read from a fact whose text is this hive's + // machine transcript (written back by writeMachineFact). + machineFact bool } // AudioLink is a fresh, short-lived link to an item's audio. It is minted on diff --git a/src/pkg/inbox/plaudsource.go b/src/pkg/inbox/plaudsource.go index e732d2cee5..6f4d87a8da 100644 --- a/src/pkg/inbox/plaudsource.go +++ b/src/pkg/inbox/plaudsource.go @@ -213,7 +213,7 @@ func mergeDirect(direct, facts []Item) []Item { for _, it := range direct { if f, ok := byID[it.ID]; ok { it.FactSlug, it.FactPath, it.Layer, it.Excerpt = f.FactSlug, f.FactPath, f.Layer, f.Excerpt - it.Summary, it.HasTranscript, it.Pending = f.Summary, f.HasTranscript, f.Pending + it.Summary, it.HasTranscript, it.Pending, it.FactState = f.Summary, f.HasTranscript, f.Pending, f.FactState if it.Title == "" { it.Title = f.Title } diff --git a/src/pkg/inbox/service.go b/src/pkg/inbox/service.go index 79cc033195..07979530e0 100644 --- a/src/pkg/inbox/service.go +++ b/src/pkg/inbox/service.go @@ -83,6 +83,9 @@ type Service struct { // HIVE_WHISPER_* environment on first use. Tests inject a fake sandbox. Whisper *WhisperRuntime whisperMu sync.Mutex + // factMu serialises machine-transcript write-backs into Knowledge facts + // (see factwriteback.go). + factMu sync.Mutex } // NewService builds a service for cfg with the given sources/destinations. diff --git a/src/pkg/inbox/transcription.go b/src/pkg/inbox/transcription.go index 691a4c0b3e..ca90ce88ab 100644 --- a/src/pkg/inbox/transcription.go +++ b/src/pkg/inbox/transcription.go @@ -245,6 +245,15 @@ func (s *Service) applyTranscripts(items []Item) { st := rec.State() s.txLive(it.Source, it.ID, &st) it.Transcription = &st + if rec.Status == TranscriptionDone && it.FactState == connector.FactContentPending { + // A transcript that finished before the fact existed (or + // before write-back did) reaches Knowledge now. + if changed, err := s.writeMachineFact(*it, rec); err != nil { + s.Logger.Warn("inbox: write machine transcript to fact", "item", it.Key(), "error", err) + } else if changed { + it.FactState = connector.FactContentMachine + } + } if rec.Status == TranscriptionDone && it.Pending { it.Pending, it.HasTranscript = false, true } @@ -267,7 +276,9 @@ func (s *Service) withMachineTranscript(it Item, c Content, err error) (Content, if store == nil { return c, err } - if err == nil && !c.Pending && (c.Transcript != "" || c.Summary != "") { + // Source text wins. A fact holding this hive's own machine transcript + // is not source text: the stored record serves it unwrapped, labelled. + if err == nil && !c.Pending && !c.machineFact && (c.Transcript != "" || c.Summary != "") { return c, nil } rec, ok := store.Get(it.Source, it.ID) @@ -414,6 +425,13 @@ func (s *Service) runTranscription(it Item, cfg config.InboxTranscription, rec T } } s.putTranscript(store, rec) + if rec.Status == TranscriptionDone { + // The transcript becomes the item's Knowledge fact text, so search, + // nous and agents see it, not only the Inbox. + if _, ferr := s.writeMachineFact(it, rec); ferr != nil { + s.Logger.Warn("inbox: write machine transcript to fact", "item", key, "error", ferr) + } + } s.auditTranscription(opts, rec, billed) s.Logger.Info("inbox: transcription finished", "item", key, "status", rec.Status, "provider", rec.Provider, "model", rec.Model, "audio_seconds", int(billed)) } diff --git a/src/pkg/knowledge/connector/fact_content_test.go b/src/pkg/knowledge/connector/fact_content_test.go new file mode 100644 index 0000000000..fc748cd65f --- /dev/null +++ b/src/pkg/knowledge/connector/fact_content_test.go @@ -0,0 +1,117 @@ +package connector + +import ( + "context" + "os" + "path/filepath" + "strings" + "testing" + "time" +) + +// syncPlaudInto runs one Plaud sync and writes every page with w, the way +// the syncer does. +func syncPlaudInto(t *testing.T, pc *plaudConnector, w *FactWriter) { + t.Helper() + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + cfg := pc.cfg + if _, err := pc.Sync(ctx, "", func(p Page) error { _, _, err := w.Write(cfg, p); return err }); err != nil { + t.Fatal(err) + } +} + +// An audio-only recording (Plaud has no summary or transcript) becomes a +// pending fact: metadata, the pending note and the highlights, no text. +func TestPlaudAudioOnlyFactShape(t *testing.T) { + pc := newTestPlaud(t, newPlaudTestServer(), nil) + w := testWriter(t) + syncPlaudInto(t, pc, w) + data, err := os.ReadFile(filepath.Join(w.Dir, Slug(TypePlaud, "plaud", "rec-2")+".md")) + if err != nil { + t.Fatal(err) + } + fact := string(data) + fm, body := splitFactFrontMatter(fact) + if fm["attr_plaud_content"] != FactContentPending || FactContentState(fm) != FactContentPending || fm["attr_plaud_file_id"] != "rec-2" || fm["attr_duration_ms"] != "61000" || fm["title"] != "Drive home" || fm["source_id"] != "rec-2" { + t.Fatalf("audio-only front matter = %v", fm) + } + for _, want := range []string{"# Drive home", "- **Recorded:** 2026-11-11T18:00:00Z", "- **Duration:** 1m1s", "_" + PlaudPendingText + "_", "## Highlights", "- 05:03"} { + if !strings.Contains(body, want) { + t.Errorf("audio-only body missing %q:\n%s", want, fact) + } + } + if strings.Contains(body, "## Transcript") || strings.Contains(body, "## Summary") { + t.Fatalf("audio-only fact has a text section:\n%s", fact) + } +} + +// machineVersion turns a pending Plaud fact into what the Inbox write-back +// leaves: content machine, a machine transcript section, same metadata. +func machineVersion(fact string) string { + fact = strings.Replace(fact, "attr_plaud_content: pending", "attr_plaud_content: machine\nattr_transcript_provider: whisper/base.en", 1) + return strings.Replace(fact, "_"+PlaudPendingText+"_", "## Transcript (machine: whisper/base.en)\n\n[00:01] pick up milk", 1) +} + +func TestFactWriterKeepsMachineFactUntilSourceText(t *testing.T) { + pc := newTestPlaud(t, newPlaudTestServer(), nil) + w := testWriter(t) + syncPlaudInto(t, pc, w) + path := filepath.Join(w.Dir, Slug(TypePlaud, "plaud", "rec-2")+".md") + data, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + machine := machineVersion(string(data)) + if err := os.WriteFile(path, []byte(machine), 0o644); err != nil { + t.Fatal(err) + } + + // The next sync still finds no text upstream: the machine fact stays. + syncPlaudInto(t, pc, w) + if got, _ := os.ReadFile(path); string(got) != machine { + t.Fatalf("pending sync clobbered the machine fact:\n%s", got) + } + + // A machine fact keeps being re-read so source text can replace it. + fm, body := splitFactFrontMatter(machine) + if !plaudFactNeedsRefetch(fm, body) { + t.Fatal("machine Plaud fact must be refetched") + } + if !meetingFactNeedsRefetch(map[string]string{"attr_meeting_content": FactContentMachine}) || meetingFactNeedsRefetch(map[string]string{"attr_meeting_content": FactContentReady}) { + t.Fatal("meeting refetch must cover machine facts and skip ready ones") + } + + // Source text arrives: it replaces the machine transcript. + cfg := pc.cfg + ready := Page{ID: "rec-2", Title: "Drive home", Markdown: "# Drive home\n\n## Transcript\n\n[00:00] Andy: real words\n", Attrs: map[string]string{"plaud_file_id": "rec-2", plaudContentAttr: FactContentReady}} + if _, changed, err := w.Write(cfg, ready); err != nil || !changed { + t.Fatalf("ready write = %v %v", changed, err) + } + got, _ := os.ReadFile(path) + fm, _ = splitFactFrontMatter(string(got)) + if fm["attr_plaud_content"] != FactContentReady || fm["attr_transcript_provider"] != "" || !strings.Contains(string(got), "real words") || strings.Contains(string(got), "pick up milk") { + t.Fatalf("upstream fact = %s", got) + } + + // An archived page still tombstones a machine fact. + if err := os.WriteFile(path, []byte(machine), 0o644); err != nil { + t.Fatal(err) + } + archived := Page{ID: "rec-2", Title: "Drive home", Archived: true, Attrs: map[string]string{plaudContentAttr: FactContentPending}} + if _, changed, err := w.Write(cfg, archived); err != nil || !changed { + t.Fatalf("archived write = %v %v", changed, err) + } +} + +func TestFactContentState(t *testing.T) { + if got := FactContentState(map[string]string{"attr_meeting_content": "machine", "title": "x"}); got != FactContentMachine { + t.Fatalf("state = %q", got) + } + if got := FactContentKey(map[string]string{"title": "x"}); got != "" { + t.Fatalf("key = %q", got) + } + if !pageContentPending(map[string]string{"zoom_recording_id": "1", "meeting_content": "pending"}) || pageContentPending(map[string]string{"meeting_content": "ready"}) { + t.Fatal("pageContentPending") + } +} diff --git a/src/pkg/knowledge/connector/factwriter.go b/src/pkg/knowledge/connector/factwriter.go index 5e1b2f9157..1f7be475c3 100644 --- a/src/pkg/knowledge/connector/factwriter.go +++ b/src/pkg/knowledge/connector/factwriter.go @@ -20,6 +20,58 @@ const ( StatusDeprecated = "deprecated" ) +// Fact content states, the value of a connector's `attr__content` key +// (attr_plaud_content, attr_meeting_content): whether the fact carries text +// and where that text came from. +const ( + // FactContentReady: the source produced its own summary or transcript. + FactContentReady = "ready" + // FactContentPending: the source has no text yet; the fact holds only + // metadata (title, date, duration, highlights) and a pending note, and + // the connector re-reads it on every sync. + FactContentPending = "pending" + // FactContentMachine: the source still has no text, and the hive wrote + // its own machine transcript into the fact. The connector keeps + // re-reading the recording, and its own text replaces the machine one + // when it arrives; a sync that still finds no text leaves the fact alone. + FactContentMachine = "machine" +) + +// factContentSuffix ends every content-state attr key. +const factContentSuffix = "_content" + +// FactContentKey returns the front-matter key holding the fact's content +// state ("attr_plaud_content", "attr_meeting_content"), or "" when the fact +// has none. The lexically first key wins if a fact somehow carries several. +func FactContentKey(fm map[string]string) string { + best := "" + for k := range fm { + if strings.HasPrefix(k, "attr_") && strings.HasSuffix(k, factContentSuffix) && (best == "" || k < best) { + best = k + } + } + return best +} + +// FactContentState returns the fact's content state (FactContentReady, +// FactContentPending, FactContentMachine), or "" when it records none. +func FactContentState(fm map[string]string) string { + if k := FactContentKey(fm); k != "" { + return fm[k] + } + return "" +} + +// pageContentPending reports whether a page says its source has no text yet. +func pageContentPending(attrs map[string]string) bool { + for k, v := range attrs { + if strings.HasSuffix(k, factContentSuffix) && v == FactContentPending { + return true + } + } + return false +} + // DefaultMaxPageBytes caps the markdown body of a single synced page. const DefaultMaxPageBytes = 1 << 20 @@ -98,8 +150,16 @@ func (w *FactWriter) Write(cfg ConnectorConfig, p Page) (string, bool, error) { if p.Archived { status = StatusDeprecated } - content := w.render(cfg, p, slug, status) path := w.path(slug) + // A page that still has no text never overwrites a machine transcript + // the hive wrote into the fact: the machine text stays until the source + // produces its own. + if !p.Archived && pageContentPending(p.Attrs) { + if old, err := os.ReadFile(path); err == nil && FactContentState(frontMatter(string(old))) == FactContentMachine { + return slug, false, nil + } + } + content := w.render(cfg, p, slug, status) if old, err := os.ReadFile(path); err == nil && stripVolatile(string(old)) == stripVolatile(content) { return slug, false, nil } diff --git a/src/pkg/knowledge/connector/meeting.go b/src/pkg/knowledge/connector/meeting.go index 45add2b038..1e9a4f6be9 100644 --- a/src/pkg/knowledge/connector/meeting.go +++ b/src/pkg/knowledge/connector/meeting.go @@ -308,9 +308,15 @@ func meetingParticipants(rec MeetingRecording, content MeetingContent) []string return out } -// meetingFactNeedsRefetch reports whether a stored meeting fact has no text. +// meetingFactNeedsRefetch reports whether a stored meeting fact has no text +// from the platform yet: pending, or holding only the hive's machine +// transcript (so the platform's own text replaces it once it exists). func meetingFactNeedsRefetch(fm map[string]string) bool { - return fm["attr_"+meetingContentAttr] == plaudContentPending + switch fm["attr_"+meetingContentAttr] { + case plaudContentPending, FactContentMachine: + return true + } + return false } // --- WebVTT --- diff --git a/src/pkg/knowledge/connector/plaud_content.go b/src/pkg/knowledge/connector/plaud_content.go index 73c614399b..46939095e3 100644 --- a/src/pkg/knowledge/connector/plaud_content.go +++ b/src/pkg/knowledge/connector/plaud_content.go @@ -47,8 +47,8 @@ const ( // plaudContentAttr is the fact attr recording whether the page carries // text: plaudContentReady or plaudContentPending. plaudContentAttr = "plaud_content" - plaudContentReady = "ready" - plaudContentPending = "pending" + plaudContentReady = FactContentReady + plaudContentPending = FactContentPending // PlaudPendingText is written into a fact (and shown by the Inbox) when // Plaud has produced neither a summary nor a transcript for a recording. PlaudPendingText = "Plaud has not transcribed this recording yet. Open it in the Plaud app to run transcription and the AI summary; the hive re-checks it on every sync until text arrives." @@ -404,10 +404,12 @@ func (c *plaudConnector) pendingRefetch(listed map[string]bool) []plaudFile { return out } -// plaudFactNeedsRefetch reports whether a stored fact carries no text yet. +// plaudFactNeedsRefetch reports whether a stored fact carries no text from +// Plaud yet: pending, or holding only the hive's machine transcript (so +// Plaud's own text replaces it once it exists). func plaudFactNeedsRefetch(fm map[string]string, body string) bool { switch fm["attr_"+plaudContentAttr] { - case plaudContentPending: + case plaudContentPending, FactContentMachine: return true case plaudContentReady: return false From eca2eb1a8f74482b5c0428dc5dfc3b1e52ce65ea Mon Sep 17 00:00:00 2001 From: Andy Anderson Date: Mon, 16 Nov 2026 07:00:04 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Inbox:=20inline=20the=20fact?= =?UTF-8?q?=20pill=20so=20extracted-function=20tests=20see=20it;=20test=20?= =?UTF-8?q?the=20pill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andy Anderson --- dashboard/test/inbox-item.test.js | 15 ++++++++++++++ src/docs/inbox-voice-sources.md | 4 ++-- src/pkg/dashboard/static-src/js/inbox.js | 25 ++++++++++-------------- src/pkg/dashboard/static/index.html | 25 ++++++++++-------------- 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/dashboard/test/inbox-item.test.js b/dashboard/test/inbox-item.test.js index 02f6fe4d3e..09be6f6957 100644 --- a/dashboard/test/inbox-item.test.js +++ b/dashboard/test/inbox-item.test.js @@ -71,6 +71,21 @@ test('pending item explains that Plaud has no text yet and never shows the MCP e assert.doesNotMatch(html, /
'; } - // What the item's Knowledge fact holds, as a status pill (not a - // control): the source's own text, this hive's machine transcript, or - // metadata only while no text exists yet. - const INBOX_FACT_STATES = { - ready: { label: 'In knowledge', status: 'ok', title: 'Stored as a Knowledge fact with the source\'s own text; knowledge search and agents see it.' }, - machine: { label: 'In knowledge (machine text)', status: 'ok', title: 'Stored as a Knowledge fact with this hive\'s machine transcript; the source\'s own text replaces it when it exists.' }, - pending: { label: 'Pending text', status: 'not loaded', title: 'Stored as a Knowledge fact with metadata only (title, date, duration, highlights); no text yet, so knowledge search finds no words.' }, - }; - function inboxFactPillHtml(it) { - if (!it.fact_slug) return 'Not in knowledge yet'; - const fs = INBOX_FACT_STATES[it.fact_state] || INBOX_FACT_STATES.ready; - return '' + escapeHtml(fs.label) + ''; - } - // Machine transcription: a state pill (spinner while queued/running, the // reason when it failed or was skipped), the progress bar while busy, and // the ๐ŸŽง Transcribe / Retry button on pending items with audio, for @@ -202,7 +188,16 @@ function inboxTranscriptionHtml(it, key) { const st = it.transcription; const src = escapeHtml(it.source), id = escapeHtml(it.id); - let html = inboxFactPillHtml(it); + // What the item's Knowledge fact holds, as a status pill (not a + // control): the source's own text, this hive's machine transcript, or + // metadata only while no text exists yet. + const factStates = { + ready: { label: 'In knowledge', status: 'ok', title: 'Stored as a Knowledge fact with the source\'s own text; knowledge search and agents see it.' }, + machine: { label: 'In knowledge (machine text)', status: 'ok', title: 'Stored as a Knowledge fact with this hive\'s machine transcript; the source\'s own text replaces it when it exists.' }, + pending: { label: 'Pending text', status: 'not loaded', title: 'Stored as a Knowledge fact with metadata only (title, date, duration, highlights); no text yet, so knowledge search finds no words.' }, + }; + const fs = factStates[it.fact_state] || factStates.ready; + let html = it.fact_slug ? '' + escapeHtml(fs.label) + '' : ''; if (st && st.status) { const busy = st.status === 'queued' || st.status === 'running'; const pill = st.status === 'done' ? 'ok' : (st.status === 'failed' ? 'error' : (busy ? 'syncing' : '')); diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index fe2354928b..44de8ac73d 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -47515,20 +47515,6 @@ (elapsed ? '' + escapeHtml(elapsed) + '' : '') + ''; } - // What the item's Knowledge fact holds, as a status pill (not a - // control): the source's own text, this hive's machine transcript, or - // metadata only while no text exists yet. - const INBOX_FACT_STATES = { - ready: { label: 'In knowledge', status: 'ok', title: 'Stored as a Knowledge fact with the source\'s own text; knowledge search and agents see it.' }, - machine: { label: 'In knowledge (machine text)', status: 'ok', title: 'Stored as a Knowledge fact with this hive\'s machine transcript; the source\'s own text replaces it when it exists.' }, - pending: { label: 'Pending text', status: 'not loaded', title: 'Stored as a Knowledge fact with metadata only (title, date, duration, highlights); no text yet, so knowledge search finds no words.' }, - }; - function inboxFactPillHtml(it) { - if (!it.fact_slug) return 'Not in knowledge yet'; - const fs = INBOX_FACT_STATES[it.fact_state] || INBOX_FACT_STATES.ready; - return '' + escapeHtml(fs.label) + ''; - } - // Machine transcription: a state pill (spinner while queued/running, the // reason when it failed or was skipped), the progress bar while busy, and // the ๐ŸŽง Transcribe / Retry button on pending items with audio, for @@ -47536,7 +47522,16 @@ function inboxTranscriptionHtml(it, key) { const st = it.transcription; const src = escapeHtml(it.source), id = escapeHtml(it.id); - let html = inboxFactPillHtml(it); + // What the item's Knowledge fact holds, as a status pill (not a + // control): the source's own text, this hive's machine transcript, or + // metadata only while no text exists yet. + const factStates = { + ready: { label: 'In knowledge', status: 'ok', title: 'Stored as a Knowledge fact with the source\'s own text; knowledge search and agents see it.' }, + machine: { label: 'In knowledge (machine text)', status: 'ok', title: 'Stored as a Knowledge fact with this hive\'s machine transcript; the source\'s own text replaces it when it exists.' }, + pending: { label: 'Pending text', status: 'not loaded', title: 'Stored as a Knowledge fact with metadata only (title, date, duration, highlights); no text yet, so knowledge search finds no words.' }, + }; + const fs = factStates[it.fact_state] || factStates.ready; + let html = it.fact_slug ? '' + escapeHtml(fs.label) + '' : ''; if (st && st.status) { const busy = st.status === 'queued' || st.status === 'running'; const pill = st.status === 'done' ? 'ok' : (st.status === 'failed' ? 'error' : (busy ? 'syncing' : ''));