From e02c9281fd20b53301c48e85a8c9760e091a754c Mon Sep 17 00:00:00 2001 From: dillonstreator Date: Tue, 1 Dec 2026 19:59:25 -0600 Subject: [PATCH] Cite every line of meeting notes and check decisions against the transcript. - Each summary sentence, decision, action item and open question ends with a [m:ss] time; the summary card links it to that line in the transcript. - Decisions and open questions quote what was said, like action items; a quote must match one to three lines in a row, which drops made-up items and locates the citation. - Prompts ask for what was settled rather than "X discussed", with made-up examples; code drops copied examples, "discussed/suggested" decisions, "None" items, talk-only tasks, and open questions past three per part. - NOTES_PIPELINE 3, so Settings offers to rewrite older notes. --- .changeset/notes-citations.md | 5 + .../lyra/src/main/meeting/notesFormat.test.ts | 67 +++++-- apps/lyra/src/main/meeting/notesFormat.ts | 119 ++++++++--- .../lyra/src/main/meeting/notesLimits.test.ts | 12 +- apps/lyra/src/main/meeting/notesLimits.ts | 6 +- .../src/main/meeting/notesPipeline.test.ts | 141 +++++++++++-- apps/lyra/src/main/meeting/notesPipeline.ts | 185 +++++++++++++++--- apps/lyra/src/main/meeting/ollama.test.ts | 32 +-- apps/lyra/src/main/meeting/writers.test.ts | 2 +- apps/lyra/src/main/searchIndex/record.test.ts | 12 ++ apps/lyra/src/main/searchIndex/record.ts | 4 +- apps/lyra/src/main/tasks/screenshot.ts | 2 +- apps/lyra/src/main/tasks/smoke.ts | 35 ++-- apps/lyra/src/renderer/src/App.tsx | 16 +- .../src/renderer/src/components/Summary.tsx | 58 +++++- apps/lyra/src/shared/notesCites.test.ts | 26 +++ apps/lyra/src/shared/notesCites.ts | 33 ++++ 17 files changed, 626 insertions(+), 129 deletions(-) create mode 100644 .changeset/notes-citations.md create mode 100644 apps/lyra/src/main/searchIndex/record.test.ts create mode 100644 apps/lyra/src/shared/notesCites.test.ts create mode 100644 apps/lyra/src/shared/notesCites.ts diff --git a/.changeset/notes-citations.md b/.changeset/notes-citations.md new file mode 100644 index 00000000..663097ae --- /dev/null +++ b/.changeset/notes-citations.md @@ -0,0 +1,5 @@ +--- +'lyra': patch +--- + +Meeting summaries now link to where they come from: each sentence of the summary, decision, action item and open question ends with a time, and clicking it shows that moment in the transcript. The notes are also more trustworthy. Decisions and open questions must quote what was said, like action items already did, so made-up ones are dropped. A decision now says what was settled rather than "they discussed". Vague tasks like "Discuss…" are no longer listed as action items, and each part of a long meeting keeps at most three open questions. Settings offers to rewrite older summaries. diff --git a/apps/lyra/src/main/meeting/notesFormat.test.ts b/apps/lyra/src/main/meeting/notesFormat.test.ts index 69426e93..b5615542 100644 --- a/apps/lyra/src/main/meeting/notesFormat.test.ts +++ b/apps/lyra/src/main/meeting/notesFormat.test.ts @@ -38,18 +38,18 @@ describe('cleanTitle', () => { describe('tidyNotes', () => { it('trims entries, drops empty ones and gives an ownerless task to Unassigned', () => { const tidy = tidyNotes({ - summary: ' What we covered. ', - decisions: [' Ship Monday ', '', ' '], + summary: [{ text: ' What we covered. ', at: 0 }], + decisions: [{ text: ' Ship Monday ', at: 4 }, { text: '', at: null }, { text: ' ', at: 5 }], actionItems: [ - { owner: ' ', task: ' Send the draft ' }, - { owner: 'Bo', task: ' ' } + { owner: ' ', task: ' Send the draft ', at: 9 }, + { owner: 'Bo', task: ' ', at: null } ], - openQuestions: [' '] + openQuestions: [{ text: ' ', at: null }] }) expect(tidy).toEqual({ - summary: 'What we covered.', - decisions: ['Ship Monday'], - actionItems: [{ owner: 'Unassigned', task: 'Send the draft' }], + summary: [{ text: 'What we covered.', at: 0 }], + decisions: [{ text: 'Ship Monday', at: 4 }], + actionItems: [{ owner: 'Unassigned', task: 'Send the draft', at: 9 }], openQuestions: [] }) }) @@ -58,10 +58,10 @@ describe('tidyNotes', () => { describe('renderNotes', () => { it('writes every section, with "- None" for an empty one', () => { const text = renderNotes({ - summary: 'We met.', + summary: [{ text: 'We met.', at: null }], decisions: [], - actionItems: [{ owner: 'Ana', task: 'Send it' }], - openQuestions: ['When?'], + actionItems: [{ owner: 'Ana', task: 'Send it', at: null }], + openQuestions: [{ text: 'When?', at: null }], sections: [] }) expect(text).toBe( @@ -80,6 +80,39 @@ describe('renderNotes', () => { ].join('\n') ) }) + + it('cites each line where it comes from, and a sentence only where the moment changes', () => { + const text = renderNotes({ + summary: [ + { text: 'Ana opened.', at: 5 }, + { text: 'Ana went on.', at: 5 }, + { text: 'Ben chose blue.', at: 3725 }, + { text: 'All agreed.', at: null } + ], + decisions: [{ text: 'Use blue', at: 3725 }], + actionItems: [{ owner: 'Ben', task: 'Buy paint', at: 760 }], + openQuestions: [{ text: 'How much?', at: null }], + sections: [{ start: 0, end: 60, title: 'Colour', summary: 'Picked one.' }] + }) + expect(text).toBe( + [ + 'Summary', + 'Ana opened. [0:05] Ana went on. Ben chose blue. [1:02:05] All agreed.', + '', + 'Sections', + '- 0:00 Colour: Picked one.', + '', + 'Decisions', + '- Use blue [1:02:05]', + '', + 'Action items', + '- [ ] Ben: Buy paint [12:40]', + '', + 'Open questions', + '- How much?' + ].join('\n') + ) + }) }) describe('splitNotes', () => { @@ -93,7 +126,13 @@ describe('splitNotes', () => { }) it('round-trips rendered notes', () => { - const notes = { summary: 'S', decisions: ['D'], actionItems: [], openQuestions: [], sections: [] } + const notes = { + summary: [{ text: 'S', at: null }], + decisions: [{ text: 'D', at: 3 }], + actionItems: [], + openQuestions: [], + sections: [] + } const body = `${renderNotes(notes)}\n\n${TRANSCRIPT_DIVIDER}\n\nAna: hi` expect(splitNotes(body).notes).toBe(renderNotes(notes)) }) @@ -101,12 +140,12 @@ describe('splitNotes', () => { describe('MeetingNotes', () => { it('refuses a reply with fields it does not know or without one it needs', () => { - const notes = { summary: 'S', decisions: [], actionItems: [], openQuestions: [] } + const notes = { summary: [], decisions: [], actionItems: [], openQuestions: [] } expect(MeetingNotes.safeParse(notes).success).toBe(true) expect(MeetingNotes.safeParse({ ...notes, extra: 1 }).success).toBe(false) expect(MeetingNotes.safeParse({ summary: 'S' }).success).toBe(false) expect( - MeetingNotes.safeParse({ ...notes, actionItems: [{ owner: 'A', task: 'B', due: 'C' }] }).success + MeetingNotes.safeParse({ ...notes, actionItems: [{ owner: 'A', task: 'B', at: null, due: 'C' }] }).success ).toBe(false) }) }) diff --git a/apps/lyra/src/main/meeting/notesFormat.ts b/apps/lyra/src/main/meeting/notesFormat.ts index 90ebd2e9..ce3aa3f4 100644 --- a/apps/lyra/src/main/meeting/notesFormat.ts +++ b/apps/lyra/src/main/meeting/notesFormat.ts @@ -4,20 +4,32 @@ import { z } from 'zod' /** On the notes worker's command line when the app is packaged (it can't ask `app` itself). */ export const PACKAGED_FLAG = '--packaged' +/** + * Where in the recording a line of the notes comes from: seconds from its start, for a link to + * that moment in the transcript. Null when Lyra couldn't tell (the model's words matched nothing). + */ +export const CiteAt = z.number().nullable() + +/** A line of the notes (a decision, an open question, a sentence of the summary) and its source. */ +export const Cited = z.strictObject({ text: z.string(), at: CiteAt }) +export type Cited = z.infer + export const ActionItem = z.strictObject({ /** The speaker name exactly as written, or "Unassigned". */ owner: z.string(), /** A short imperative ("Send the budget draft to finance"). */ - task: z.string() + task: z.string(), + at: CiteAt }) export type ActionItem = z.infer /** A meeting's notes, put together from the calls below (notesPipeline.ts). */ export const MeetingNotes = z.strictObject({ - decisions: z.array(z.string()), + decisions: z.array(Cited), actionItems: z.array(ActionItem), - openQuestions: z.array(z.string()), - summary: z.string() + openQuestions: z.array(Cited), + /** The summary, a sentence at a time, so each can link to where it comes from. */ + summary: z.array(Cited) }) export type MeetingNotes = z.infer @@ -25,12 +37,16 @@ export type MeetingNotes = z.infer * What a notes call fills: the AI SDK's structured output, and llama.cpp's grammar (from * `z.toJSONSchema`). Field order matters: constrained decoding fills fields in this order, and * extracting the lists before writing the summary makes small models less likely to skip them. - * The action items get a call of their own (`ActionItemsFound`). Asked for in the same call, a small model files tasks as decisions or - * leaves the list empty; asked for alone, with the words that commit to each, it finds them. + * Each decision and question starts with the words that settle or raise it, copied from the + * transcript: copying first keeps a small model on what was said, an item it can't quote is one + * it made up (or took from the prompt's examples), and the quote is how Lyra finds the moment to + * link to. The action items get a call of their own (`ActionItemsFound`). Asked for in the same + * call, a small model files tasks as decisions or leaves the list empty; asked for alone, with + * the words that commit to each, it finds them. */ export const NotesDraft = z.strictObject({ - decisions: z.array(z.string()), - openQuestions: z.array(z.string()), + decisions: z.array(z.strictObject({ quote: z.string(), decision: z.string() })), + openQuestions: z.array(z.strictObject({ quote: z.string(), question: z.string() })), summary: z.string() }) export type NotesDraft = z.infer @@ -66,12 +82,34 @@ export type NoteSection = z.infer export const WrittenNotes = z.strictObject({ ...MeetingNotes.shape, sections: z.array(NoteSection) }) export type WrittenNotes = z.infer -/** What every notes prompt asks for in its lists, so a section and a whole meeting agree. */ +/** + * What every notes prompt asks for in its lists, so a section and a whole meeting agree. The + * examples are made up and far from any real meeting: a small model copies an example it was + * shown into its answer ("let's ship it Monday" turned up as a decision), even with a real quote + * beside it, so the pipeline drops any decision that repeats one. + */ +export const PROMPT_EXAMPLES = ['Paint the shed green', 'The trip moves to May'] + const LIST_RULES = [ - '- decisions: plans, dates, or choices the group settled on ("let\'s ship it Monday",', - ' "we\'ll go with option B"). A task someone takes on is not a decision. Empty only if', - ' nothing was settled.', - '- openQuestions: questions raised but not answered. Empty if none.' + '- decisions: what the group settled: a choice made, a plan agreed, a date set, a rule adopted.', + ' For each:', + ' - quote: the words from the transcript that settle it, copied exactly.', + ` - decision: the outcome as one short statement ("${PROMPT_EXAMPLES.join('", "')}").`, + ' Never write "X and Y discussed…" or "X suggested…": say what was settled.', + ' An idea someone floats, an opinion, a topic talked about, or a task someone takes on is not', + ' a decision. Most stretches of talk settle nothing: then the list is empty.', + '- openQuestions: questions about the work that were left unanswered and still matter after', + ' the meeting. For each:', + ' - quote: the words that raise it, copied exactly.', + ' - question: the question in one short line, clear without the transcript.', + ' Not rhetorical questions, jokes, small talk, or questions answered soon after. At most 3.', + ' Usually empty.' +] + +/** How every summary is written: what happened, not that something was talked about. */ +const SUMMARY_RULE = [ + ' Say what was concluded and why, with names and specifics (choices, numbers, dates, next', + ' steps). Not "they discussed X": say what was said about X.' ] /** @@ -93,6 +131,7 @@ export const NOTES_SYSTEM_PROMPT = [ 'Return:', ...LIST_RULES, '- summary: 3-5 plain sentences on what the meeting covered and concluded.', + ...SUMMARY_RULE, 'Use only what the transcript says. Be brief.', ...PEOPLE_RULE, ...DATA_RULE @@ -105,7 +144,10 @@ export const SECTION_SYSTEM_PROMPT = [ 'Return, for this part only:', ...LIST_RULES, '- summary: 2-4 plain sentences on what this part covered and concluded.', - '- title: 2-6 plain words naming this part\'s topic ("Hiring plan", "Q3 budget").', + ...SUMMARY_RULE, + '- title: 2-6 plain words naming this part\'s topic ("Hiring plan", "Q3 budget"). No filler', + ' words like "discussion" or "meeting". If the recap\'s last part had the same topic, name', + ' what is new in this one.', 'Use only what this part\'s transcript says. Be brief.', ...PEOPLE_RULE, ...DATA_RULE @@ -114,8 +156,10 @@ export const SECTION_SYSTEM_PROMPT = [ export const OVERVIEW_SYSTEM_PROMPT = [ 'You summarize a whole meeting from notes on its parts, given in order, each with its start', 'time and topic.', - 'Return summary: 3-5 plain sentences on what the meeting covered and concluded, in the order', - 'it happened. Use only what the notes say.', + 'Return summary: 3-6 plain sentences on what the meeting concluded, in the order it happened,', + 'one sentence per main topic. Say what was decided or found and what happens next, with names', + 'and specifics. Not "the meeting covered" or "they discussed X": say what was said about X.', + 'Leave out small talk. Use only what the notes say.', ...PEOPLE_RULE, ...DATA_RULE ].join('\n') @@ -127,9 +171,12 @@ export const ACTION_SYSTEM_PROMPT = [ 'Return actionItems, one per task, in the order they come up:', '- quote: the words from the transcript that commit to the task, copied exactly.', '- owner: the name of the person who will do it, exactly as written before a line, or', - ' "Unassigned". In "Priya: Marcus, can you book the room?" the owner is Marcus.', - '- task: a short imperative ("Book the room", "Send the budget draft to finance").', - 'A question or a decision is not an action item unless someone takes on the work.', + ' "Unassigned". In "Priya: Marcus, can you book the room?" the owner is Marcus. "I" is the', + ' person speaking the line.', + '- task: a short imperative that says what gets done, clear without the transcript ("Book the', + ' room for Thursday", not "Do it" or "Get the info").', + 'A question, a decision, a wish ("we should someday…") or a vague intention ("understand the', + 'changes", "think about it") is not an action item unless someone takes on concrete work.', 'Return an empty list only if nobody took on anything. Use only what the transcript says.', ...DATA_RULE, '', @@ -139,6 +186,7 @@ export const ACTION_SYSTEM_PROMPT = [ 'Ben: I will update the slides by Monday.', 'Ana: Ben, can you also invite the client?', 'Ben: Sure.', + 'Ana: We should rethink the logo someday.', 'Answer: {"actionItems": [{"quote": "I will update the slides by Monday.", "owner": "Ben",', '"task": "Update the slides by Monday"}, {"quote": "Ben, can you also invite the client?",', '"owner": "Ben", "task": "Invite the client"}]}' @@ -180,23 +228,20 @@ export function cleanTitle(title: string): string | null { /** Separates generated notes (above) from the labeled transcript (below) in the export. */ export const TRANSCRIPT_DIVIDER = '──── Transcript ────' -/** Notes as a model returned them, trimmed, with empty entries dropped. */ +/** Notes with every entry trimmed and the empty ones dropped. */ export function tidyNotes(notes: MeetingNotes): MeetingNotes { - const lines = (items: string[]): string[] => items.map((item) => item.trim()).filter(Boolean) + const lines = (items: Cited[]): Cited[] => + items.map((item) => ({ ...item, text: item.text.trim() })).filter((item) => item.text) return { - summary: notes.summary.trim(), + summary: lines(notes.summary), decisions: lines(notes.decisions), actionItems: notes.actionItems - .map((item) => ({ owner: item.owner.trim() || 'Unassigned', task: item.task.trim() })) + .map((item) => ({ ...item, owner: item.owner.trim() || 'Unassigned', task: item.task.trim() })) .filter((item) => item.task), openQuestions: lines(notes.openQuestions) } } -function list(items: string[]): string { - return items.length ? items.map((item) => `- ${item}`).join('\n') : '- None' -} - /** `0:05`, `12:40`, `1:02:03`: a time from the recording's start. */ export function clockTime(seconds: number): string { const total = Math.max(0, Math.floor(seconds)) @@ -206,6 +251,22 @@ export function clockTime(seconds: number): string { return hours ? `${String(hours)}:${String(minutes).padStart(2, '0')}:${secs}` : `${String(minutes)}:${secs}` } +/** ` [12:40]` after a line of the notes: where it comes from (src/shared/notesCites.ts reads it back). */ +function cite(at: number | null): string { + return at === null ? '' : ` [${clockTime(at)}]` +} + +function list(items: Cited[]): string { + return items.length ? items.map((item) => `- ${item.text}${cite(item.at)}`).join('\n') : '- None' +} + +/** The summary's sentences, each cited unless it comes from the same moment as the one before. */ +function paragraph(sentences: Cited[]): string { + return sentences + .map((sentence, index) => `${sentence.text}${sentence.at === sentences[index - 1]?.at ? '' : cite(sentence.at)}`) + .join(' ') +} + /** Plain text that reads well in both .txt and .md files. Sections appear only when there are any. */ export function renderNotes(notes: WrittenNotes): string { const sections = notes.sections.length @@ -213,7 +274,7 @@ export function renderNotes(notes: WrittenNotes): string { : [] return [ 'Summary', - notes.summary, + paragraph(notes.summary), '', ...sections, 'Decisions', @@ -221,7 +282,7 @@ export function renderNotes(notes: WrittenNotes): string { '', 'Action items', notes.actionItems.length - ? notes.actionItems.map((item) => `- [ ] ${item.owner}: ${item.task}`).join('\n') + ? notes.actionItems.map((item) => `- [ ] ${item.owner}: ${item.task}${cite(item.at)}`).join('\n') : '- None', '', 'Open questions', diff --git a/apps/lyra/src/main/meeting/notesLimits.test.ts b/apps/lyra/src/main/meeting/notesLimits.test.ts index 1a162e8a..de19af39 100644 --- a/apps/lyra/src/main/meeting/notesLimits.test.ts +++ b/apps/lyra/src/main/meeting/notesLimits.test.ts @@ -10,8 +10,16 @@ describe('limitNotesSchema', () => { expect(limitNotesSchema(jsonSchema(SectionNotes))).toMatchObject({ type: 'object', properties: { - decisions: { type: 'array', maxItems: 8, items: { type: 'string', maxLength: 200 } }, - openQuestions: { type: 'array', maxItems: 8, items: { type: 'string', maxLength: 200 } }, + decisions: { + type: 'array', + maxItems: 8, + items: { properties: { quote: { maxLength: 200 }, decision: { maxLength: 160 } } } + }, + openQuestions: { + type: 'array', + maxItems: 4, + items: { properties: { quote: { maxLength: 200 }, question: { maxLength: 160 } } } + }, summary: { type: 'string', maxLength: 1200 }, title: { type: 'string', maxLength: 80 } } diff --git a/apps/lyra/src/main/meeting/notesLimits.ts b/apps/lyra/src/main/meeting/notesLimits.ts index de529911..21a48266 100644 --- a/apps/lyra/src/main/meeting/notesLimits.ts +++ b/apps/lyra/src/main/meeting/notesLimits.ts @@ -12,11 +12,13 @@ const FIELD_CHARS: Readonly> = { title: 80, quote: 200, owner: 40, - task: 120 + task: 120, + decision: 160, + question: 160 } /** A string in a list (a decision, an open question). */ const ITEM_CHARS = 200 -const ITEMS: Readonly> = { actionItems: 12 } +const ITEMS: Readonly> = { actionItems: 12, openQuestions: 4 } /** Decisions and open questions: more than this from one call is a model repeating itself. */ const LIST_ITEMS = 8 diff --git a/apps/lyra/src/main/meeting/notesPipeline.test.ts b/apps/lyra/src/main/meeting/notesPipeline.test.ts index 1a57f737..9e333426 100644 --- a/apps/lyra/src/main/meeting/notesPipeline.test.ts +++ b/apps/lyra/src/main/meeting/notesPipeline.test.ts @@ -1,7 +1,15 @@ import { describe, expect, it } from 'vitest' import { estimateTokens } from './notesChunks' import { ActionItemsFound, NotesDraft, OverviewNotes, SectionNotes, type NotesLine } from './notesFormat' -import { callKey, quotedFrom, sameItem, uniqueItems, writeNotes, type NotesCall } from './notesPipeline' +import { + callKey, + citeSentences, + quoteAt, + sameItem, + uniqueItems, + writeNotes, + type NotesCall +} from './notesPipeline' const TOPICS = [ ['budget', 'spending', 'quarter', 'finance', 'invoice', 'forecast'], @@ -65,9 +73,46 @@ describe('writeNotes', () => { ]) expect(calls[1]?.prompt).toContain('Sam: We ship Friday. I will send the deck.') expect(notes.sections).toEqual([]) - expect(notes.summary).toBe('Part summary 0.') + expect(notes.summary).toEqual([{ text: 'Part summary 0.', at: null }]) // Nobody said anything about lunch: an item the model can't quote is dropped. - expect(notes.actionItems).toEqual([{ owner: 'Sam', task: 'Send the deck' }]) + expect(notes.actionItems).toEqual([{ owner: 'Sam', task: 'Send the deck', at: 0 }]) + }) + + it('keeps only decisions and questions it can quote, that settle something, each cited', async () => { + const lines: NotesLine[] = [ + { speaker: 'Ana', text: 'Morning, how was the weekend?', start: 0, end: 4 }, + { speaker: 'Ben', text: 'Fine. So the logo, I think blue works better than red.', start: 5, end: 9 }, + { speaker: 'Ana', text: 'Agreed, we go with blue for the logo.', start: 10, end: 14 }, + { speaker: 'Ben', text: 'Who prints the posters, though? No idea yet.', start: 15, end: 19 } + ] + const { ask } = recorder((call, index) => + call.schema === NotesDraft + ? { + decisions: [ + { quote: 'we go with blue for the logo', decision: ' Use blue for the logo ' }, + { quote: "let's ship it Monday", decision: 'Ship it Monday' }, + { quote: 'I think blue works better than red', decision: 'Ana and Ben discussed the logo colour' }, + { quote: 'I think blue works better than red', decision: 'Ben suggested blue' }, + // The prompt's own example, beside a real quote. + { quote: 'we go with blue for the logo', decision: 'Paint the shed green' }, + { quote: '', decision: 'Print in-house' } + ], + openQuestions: [ + { quote: 'Who prints the posters', question: 'Who prints the posters?' }, + { quote: 'how was the weekend', question: 'No open questions were raised.' } + ], + summary: 'Ana and Ben settled the logo. The posters have no printer yet.' + } + : defaultAnswer(call, index) + ) + const notes = await writeNotes({ lines, budget: 1000, count: estimateTokens, ask }) + expect(notes.decisions).toEqual([{ text: 'Use blue for the logo', at: 10 }]) + expect(notes.actionItems).toEqual([]) + expect(notes.openQuestions).toEqual([{ text: 'Who prints the posters?', at: 15 }]) + expect(notes.summary).toEqual([ + { text: 'Ana and Ben settled the logo.', at: 5 }, + { text: 'The posters have no printer yet.', at: 15 } + ]) }) it('reads a long meeting by sections, each with a recap of the ones before', async () => { @@ -96,7 +141,7 @@ describe('writeNotes', () => { expect(calls[1]?.prompt).not.toContain('') expect(calls[1]?.prompt).toContain('budget') expect(calls[1]?.prompt).not.toContain('hiring') - expect(notes.summary).toBe('The whole meeting.') + expect(notes.summary).toEqual([{ text: 'The whole meeting.', at: null }]) expect(notes.sections.map((part) => [part.start, part.end, part.title])).toEqual([ [0, 599, 'Topic 0'], [600, 1199, 'Topic 1'], @@ -104,6 +149,22 @@ describe('writeNotes', () => { ]) }) + it('keeps the first three open questions of an answer', async () => { + const lines: NotesLine[] = [{ speaker: 'Ana', text: 'Who, what, when, where, why?', start: 0, end: 4 }] + const questions = ['Who?', 'What?', 'When?', 'Where?', 'Why?'] + const { ask } = recorder((call, index) => + call.schema === NotesDraft + ? { + decisions: [], + openQuestions: questions.map((question) => ({ quote: question, question })), + summary: 'Questions.' + } + : defaultAnswer(call, index) + ) + const notes = await writeNotes({ lines, budget: 1000, count: estimateTokens, ask }) + expect(notes.openQuestions.map((item) => item.text)).toEqual(['Who?', 'What?', 'When?']) + }) + it("combines the sections' items in code, dropping restatements but not look-alikes", async () => { const quote = 'okay so' const { ask } = recorder((call, index) => { @@ -118,20 +179,26 @@ describe('writeNotes', () => { ][index] return { actionItems: found ?? [] } } + const decision = (text: string): { quote: string; decision: string } => ({ quote, decision: text }) + const question = (text: string): { quote: string; question: string } => ({ quote, question: text }) const items = [ - { decisions: ['Ship on May 5'], openQuestions: ['Who owns QA?'] }, - { decisions: ['ship on may 5.', 'Ship on May 6'], openQuestions: [] }, - { decisions: [], openQuestions: [' '] } + { decisions: [decision('Ship on May 5')], openQuestions: [question('Who owns QA?')] }, + { decisions: [decision('ship on may 5.'), decision('Ship on May 6')], openQuestions: [] }, + { decisions: [], openQuestions: [question(' ')] } ][index] ?? { decisions: [], openQuestions: [] } return { ...items, summary: 'x', title: '' } }) const notes = await writeNotes({ lines: meeting(10), budget: 8000, count: estimateTokens, ask }) - expect(notes.decisions).toEqual(['Ship on May 5', 'Ship on May 6']) + // Each is cited at the first line of its section that holds its quote. + expect(notes.decisions).toEqual([ + { text: 'Ship on May 5', at: 0 }, + { text: 'Ship on May 6', at: 600 } + ]) expect(notes.actionItems).toEqual([ - { owner: 'Sam', task: 'Fix the installer' }, - { owner: 'Ana', task: 'Fix the installer' } + { owner: 'Sam', task: 'Fix the installer', at: 0 }, + { owner: 'Ana', task: 'Fix the installer', at: 600 } ]) - expect(notes.openQuestions).toEqual(['Who owns QA?']) + expect(notes.openQuestions).toEqual([{ text: 'Who owns QA?', at: 0 }]) // A section the model didn't name is numbered. expect(notes.sections.map((part) => part.title)).toEqual(['Part 1', 'Part 2', 'Part 3']) }) @@ -186,13 +253,51 @@ describe('writeNotes', () => { }) }) -describe('quotedFrom', () => { - it('accepts a loose copy of what was said, not words nobody said', () => { - const said = 'Sam: Sure, I will send the budget draft to finance by Thursday.' - expect(quotedFrom('I will send the budget draft to finance', said)).toBe(true) - expect(quotedFrom('I will send the budget draft over to finance', said)).toBe(true) - expect(quotedFrom('Ana books the offsite venue', said)).toBe(false) - expect(quotedFrom('', said)).toBe(true) +describe('quoteAt', () => { + const lines: NotesLine[] = [ + { speaker: 'Ana', text: 'Can you send the budget?', start: 3, end: 5 }, + { speaker: 'Sam', text: 'Sure, I will send the budget draft', start: 6, end: 8 }, + { speaker: 'Sam', text: 'to finance by Thursday.', start: 9, end: 11 } + ] + + it('finds the line that holds the quote, or the lines it runs across', () => { + expect(quoteAt('I will send the budget draft', lines)).toBe(6) + expect(quoteAt('I will send the budget draft to finance by Thursday', lines)).toBe(6) + expect(quoteAt('to finance by Thursday', lines)).toBe(9) + }) + + it('takes a loose copy, with the speaker or a time in front', () => { + expect(quoteAt('I will send the budget draft over to finance', lines)).toBe(6) + expect(quoteAt('Sam: I will send the budget draft', lines)).toBe(6) + expect(quoteAt('[0:06] Sam: I will send the budget draft', lines)).toBe(6) + }) + + it('finds nothing for words nobody said, or said far apart', () => { + expect(quoteAt('book the offsite venue', lines)).toBeNull() + expect(quoteAt('', lines)).toBeNull() + const apart: NotesLine[] = [ + { speaker: 'Ana', text: 'The budget is tight.', start: 0, end: 1 }, + { speaker: 'Sam', text: 'Lunch was good.', start: 2, end: 3 }, + { speaker: 'Ana', text: 'Weather is nice.', start: 4, end: 5 }, + { speaker: 'Sam', text: 'Coffee later?', start: 6, end: 7 }, + { speaker: 'Ana', text: 'Finance wants a draft.', start: 8, end: 9 } + ] + expect(quoteAt('finance budget draft tight', apart)).toBeNull() + }) +}) + +describe('citeSentences', () => { + it('cites each sentence at the source it shares the rarest words with', () => { + const sources = [ + { at: 0, text: 'Hiring plan: the team will hire two engineers this quarter' }, + { at: 600, text: 'Budget: the team cut the travel budget by a third' }, + { at: 1200, text: 'Release: the team moves the release to June' } + ] + expect(citeSentences('The team will hire two engineers. Travel was cut. Nothing else.', sources)).toEqual([ + { text: 'The team will hire two engineers.', at: 0 }, + { text: 'Travel was cut.', at: 600 }, + { text: 'Nothing else.', at: null } + ]) }) }) diff --git a/apps/lyra/src/main/meeting/notesPipeline.ts b/apps/lyra/src/main/meeting/notesPipeline.ts index 85e5ebd7..e986e6db 100644 --- a/apps/lyra/src/main/meeting/notesPipeline.ts +++ b/apps/lyra/src/main/meeting/notesPipeline.ts @@ -6,10 +6,15 @@ * short recap of the sections before it: the recap keeps references across sections straight, * which plain map-reduce loses (Chang et al., "BooookScore", 2024, on incremental updating vs. * hierarchical merging). Action items get a call of their own on the same text: a small model - * asked for everything at once files them as decisions or skips them. Decisions, action items and open questions are combined in code, not - * by another model call, so a small model can't drop them while merging. Only the meeting's - * summary is written from the sections' summaries, which are short enough to fit even a 4k - * context; past that they are summarized in groups first. Pure: the model is the `ask` callback. + * asked for everything at once files them as decisions or skips them. Decisions, action items + * and open questions are combined in code, not by another model call, so a small model can't + * drop them while merging. Only the meeting's summary is written from the sections' summaries, + * which are short enough to fit even a 4k context; past that they are summarized in groups + * first. Pure: the model is the `ask` callback. + * + * Every line of the notes is cited: a decision, question or action item at the line its quote + * comes from, a sentence of the summary at the line (or, for a long meeting, the section) it + * shares the most telling words with. The window links each one to that moment in the transcript. */ import { createHash } from 'node:crypto' import type { z } from 'zod' @@ -26,10 +31,12 @@ import { ACTION_SYSTEM_PROMPT, ActionItemsFound, cleanTitle, + type Cited, NOTES_SYSTEM_PROMPT, NotesDraft, OVERVIEW_SYSTEM_PROMPT, OverviewNotes, + PROMPT_EXAMPLES, SECTION_SYSTEM_PROMPT, SectionNotes, tidyNotes, @@ -86,9 +93,10 @@ export function rememberedAsk(ask: NotesAsk, answers: NotesAnswers | undefined): * The pipeline's version, recorded with each session's notes (`NotesRun`). Bump it when a change * would make old notes worth rewriting (better items, a new part of the notes): Settings then * offers to rewrite the untouched notes made before it. History: 1, one call or map-reduce; - * 2, topic sections with a recap, and action items in a call of their own. + * 2, topic sections with a recap, and action items in a call of their own; 3, decisions and + * questions quoted (and checked) like action items, and every line cited to its moment. */ -export const NOTES_PIPELINE = 2 +export const NOTES_PIPELINE = 3 /** * A meeting this long gets sections even when it fits one call: an hour of notes reads better @@ -101,8 +109,10 @@ const RECAP_TOKENS = 300 const RECAP_SECTIONS = 3 /** Duplicate items share at least this much of their words (Jaccard), in any order. */ const SAME_ITEM = 0.8 -/** An action item whose quote shares less than this of its words with the text was made up. */ -const QUOTED = 0.5 +/** An item whose quote shares less than this of its words with any few lines in a row was made up. */ +const QUOTED = 0.6 +/** A quote may run across this many lines in a row (a sentence split across a turn or a chunk). */ +const QUOTE_LINES = 3 export type WriteNotesOptions = { lines: NotesLine[] @@ -141,18 +151,130 @@ export function sameItem(a: string, b: string): boolean { return shared / (left.size + right.size - shared) >= SAME_ITEM } -/** Whether `quote` is (close to) words from `text`: small models copy loosely, not freely. */ -export function quotedFrom(quote: string, text: string): boolean { - const words = wordSet(quote) - if (!words.size) return true - const said = wordSet(text) +/** The share of `words` that `said` holds. */ +function coverage(words: Set, said: Set): number { + if (!words.size) return 0 let found = 0 for (const word of words) if (said.has(word)) found++ - return found / words.size >= QUOTED + return found / words.size +} + +/** A quote as models write it, sometimes with the speaker or a time in front: just the words. */ +function quoteWords(quote: string): Set { + return wordSet(quote.replace(/^\s*(\[[\d:]+\]\s*)?([^:\n]{1,40}:\s)?/, '')) +} + +/** + * When `quote` was said: the start of the line, or of the few lines in a row, that hold the most + * of its words (small models copy loosely, not freely), the earliest on a tie. Null when no few + * lines hold enough of them: then the quote was made up, or pieced together from words said all + * over the part, and so is the item it backs. An empty quote quotes nothing. + */ +export function quoteAt(quote: string, lines: NotesLine[]): number | null { + const words = quoteWords(quote) + if (!words.size) return null + const said = lines.map((line) => wordSet(line.text)) + let best: { at: number; score: number } | null = null + for (const [index, line] of lines.entries()) { + const run = new Set() + for (let size = 1; size <= QUOTE_LINES; size++) { + const next = said[index + size - 1] + if (!next) break + for (const word of next) run.add(word) + // A longer run holds more words by chance: the shortest that holds the quote wins. + const score = coverage(words, run) - (size - 1) * 0.02 + if (!best || score > best.score) best = { at: line.start, score } + } + } + return best && best.score >= QUOTED ? best.at : null +} + +/** A text to cite and when it starts: a transcript line, or a section of a long meeting. */ +type Source = { at: number; text: string } + +/** + * The summary, a sentence at a time, each cited at the source it shares the most telling words + * with. A word's weight is how rare it is among the sources (inverse document frequency), so + * "Clerk" points somewhere and "the" doesn't. A sentence that shares nothing telling is uncited. + */ +export function citeSentences(summary: string, sources: Source[]): Cited[] { + const sets = sources.map((source) => wordSet(source.text)) + const df = new Map() + for (const set of sets) for (const word of set) df.set(word, (df.get(word) ?? 0) + 1) + const weight = (word: string): number => { + const seen = df.get(word) ?? 0 + // Words in nearly every source tell nothing apart; words in none can't point anywhere. + return seen ? Math.max(0, Math.log(sources.length / seen)) : 0 + } + // A small model sometimes writes the summary as a list: each item is a sentence of it. + const sentences = summary + .split('\n') + .map((line) => line.replace(/^\s*[-*•]\s+/, '')) + .flatMap((line) => [...sentenceSegmenter.segment(line)].map((part) => part.segment.trim())) + .filter(Boolean) + return sentences.map((text) => { + const words = [...wordSet(text)] + let best: { at: number; score: number } | null = null + for (const [index, set] of sets.entries()) { + const source = sources[index] + if (!source) continue + let score = 0 + for (const word of words) if (set.has(word)) score += weight(word) + if (score > (best?.score ?? 0)) best = { at: source.at, score } + } + return { text, at: best?.at ?? null } + }) +} + +const sentenceSegmenter = new Intl.Segmenter(undefined, { granularity: 'sentence' }) + +/** + * A decision that only says a topic came up or an idea was put forward ("Ana and Ben discussed + * the logo", "Ben suggested blue") settles nothing; small models write these however they're + * told not to. + */ +const NOT_SETTLED = + /\b(discuss(?:es|ed|ing)?|talk(?:s|ed)? about|debat(?:es|ed|ing)|consider(?:s|ed|ing)|explor(?:es|ed|ing)|suggest(?:s|ed)?|propos(?:es|ed)|recommend(?:s|ed)?)\b/i +/** "None", "No open questions were raised": a model filling a list it should have left empty. */ +const NOTHING = /^(none\b|no\s+(open\s+)?(questions?|decisions?)\b|n\/a\b)/i +/** + * Open questions kept from one notes answer, the first ones: the prompt asks for at most this + * many, and a model past it is listing every question anyone asked. + */ +const OPEN_QUESTIONS = 3 +/** + * A task that is only more talk or thought ("Discuss the launch", "Understand the changes") + * commits nobody to anything; a small model lists them as action items anyway. + */ +const VAGUE_TASK = /^(discuss|consider|continue|understand|listen|reflect|think|talk)\b/i + +/** + * Decisions and open questions from one notes answer, each cited where its quote was said: only + * those whose quote is in `lines`, and not ones that only name a topic, say there are none, or + * repeat the prompt's own made-up examples. + */ +function listsOf(draft: NotesDraft, lines: NotesLine[]): Pick { + const cited = (items: { quote: string; text: string }[], keep: (text: string) => boolean): Cited[] => + items.flatMap((item) => { + const text = item.text.trim() + const at = quoteAt(item.quote, lines) + return at !== null && !NOTHING.test(text) && keep(text) ? [{ text, at }] : [] + }) + return { + decisions: cited( + draft.decisions.map((item) => ({ quote: item.quote, text: item.decision })), + (text) => !NOT_SETTLED.test(text) && !PROMPT_EXAMPLES.some((example) => sameItem(example, text)) + ), + openQuestions: cited( + draft.openQuestions.map((item) => ({ quote: item.quote, text: item.question })), + () => true + ).slice(0, OPEN_QUESTIONS) + } } -/** The action items in `transcript` (one call), keeping only those it can quote. */ -async function actionItemsOf(transcript: string, ask: NotesAsk, final: boolean): Promise { +/** The action items in `lines` (one call), keeping only those it can quote, each cited. */ +async function actionItemsOf(lines: NotesLine[], ask: NotesAsk, final: boolean): Promise { + const transcript = lines.map(lineText).join('\n') const answer = ActionItemsFound.parse( await ask({ system: ACTION_SYSTEM_PROMPT, @@ -162,10 +284,11 @@ async function actionItemsOf(transcript: string, ask: NotesAsk, final: boolean): final }) ) - return answer.actionItems - .filter((item) => quotedFrom(item.quote, transcript)) - .map((item) => ({ owner: item.owner.trim() || 'Unassigned', task: item.task.trim() })) - .filter((item) => item.task) + return answer.actionItems.flatMap((item) => { + const task = item.task.trim() + const at = quoteAt(item.quote, lines) + return at !== null && task && !VAGUE_TASK.test(task) ? [{ owner: item.owner.trim() || 'Unassigned', task, at }] : [] + }) } /** Items in order with later restatements dropped; `group` keeps apart items that only look alike. */ @@ -254,9 +377,10 @@ export async function writeNotes(input: WriteNotesOptions): Promise ({ at: line.start, text: line.text }))) + return { ...tidyNotes({ ...listsOf(draft, lines), actionItems, summary }), sections: [] } } if (fits && durationOf(lines) < SECTION_AFTER_SECONDS) return single() @@ -281,24 +405,29 @@ export async function writeNotes(input: WriteNotesOptions): Promise item.owner.toLowerCase() + const textOf = (item: Cited): string => item.text return { - summary, - decisions: uniqueItems(found.flatMap((notes) => notes.decisions), String), + summary: citeSentences( + overview, + sections.map((section) => ({ at: section.start, text: `${section.title} ${section.summary}` })) + ).filter((sentence) => sentence.text), + decisions: uniqueItems(found.flatMap((notes) => notes.decisions), textOf), actionItems: uniqueItems(found.flatMap((notes) => notes.actionItems), (item) => item.task, owner), - openQuestions: uniqueItems(found.flatMap((notes) => notes.openQuestions), String), + openQuestions: uniqueItems(found.flatMap((notes) => notes.openQuestions), textOf), sections } } diff --git a/apps/lyra/src/main/meeting/ollama.test.ts b/apps/lyra/src/main/meeting/ollama.test.ts index 48c4642a..5d7deb86 100644 --- a/apps/lyra/src/main/meeting/ollama.test.ts +++ b/apps/lyra/src/main/meeting/ollama.test.ts @@ -46,20 +46,30 @@ function linesOf(transcript: string, seconds = 5): NotesLine[] { } const notes: MeetingNotes = { - decisions: ['Ship Friday'], - actionItems: [{ owner: 'Sam', task: 'Fix the installer' }], + decisions: [{ text: 'Ship Friday', at: 0 }], + actionItems: [{ owner: 'Sam', task: 'Fix the installer', at: 0 }], openQuestions: [], - summary: 'Planned the release.' + summary: [{ text: 'Planned the release.', at: null }] } -/** Answers a chat request in the shape its `format` asks for: notes, action items or a summary. */ +const ChatBody = z.object({ + format: z.object({ properties: z.record(z.string(), z.unknown()) }), + messages: z.array(z.object({ role: z.string(), content: z.string() })) +}) + +/** + * Answers a chat request in the shape its `format` asks for: notes, action items or a summary, + * each item quoting the first line of the transcript it was sent (as a model would). + */ function answerFor(body: unknown): unknown { - const shape = z.object({ format: z.object({ properties: z.record(z.string(), z.unknown()) }) }).parse(body) - const keys = Object.keys(shape.format.properties) - const { actionItems, ...draft } = notes + const request = ChatBody.parse(body) + const keys = Object.keys(request.format.properties) + const prompt = request.messages.at(-1)?.content ?? '' + const first = /\n[^:\n]*: ([^\n]*)/.exec(prompt)?.[1] ?? '' if (keys.includes('actionItems')) { - return { actionItems: actionItems.map((item) => ({ quote: 'I will fix the installer', ...item })) } + return { actionItems: [{ quote: first, owner: 'Sam', task: 'Fix the installer' }] } } + const draft = { decisions: [{ quote: first, decision: 'Ship Friday' }], openQuestions: [], summary: 'Planned the release.' } if (keys.includes('title')) return { ...draft, title: 'Budget' } return keys.length === 1 ? { summary: 'All of it.' } : draft } @@ -136,9 +146,9 @@ describe('createOllamaNotesWriter', () => { const transcript = Array.from({ length: 600 }, (_, i) => `Speaker: 第${String(i)}句 我们讨论预算和时间表`).join('\n') const written = await writer.notes(linesOf(transcript)) expect(written.sections.length).toBeGreaterThan(1) - expect(written.summary).toBe('All of it.') - // The same decision from every section is kept once. - expect(written.decisions).toEqual(['Ship Friday']) + expect(written.summary).toEqual([{ text: 'All of it.', at: null }]) + // The same decision from every section is kept once, cited where it first came up. + expect(written.decisions).toEqual([{ text: 'Ship Friday', at: 0 }]) const chat = calls.filter((call) => call.url.endsWith('/api/chat')).map((call) => RequestBody.parse(call.body)) expect(chat.length).toBeGreaterThan(2) expect(chat.filter((body) => body.keep_alive === 0)).toHaveLength(1) diff --git a/apps/lyra/src/main/meeting/writers.test.ts b/apps/lyra/src/main/meeting/writers.test.ts index 3ffd7c60..e0718749 100644 --- a/apps/lyra/src/main/meeting/writers.test.ts +++ b/apps/lyra/src/main/meeting/writers.test.ts @@ -13,7 +13,7 @@ vi.hoisted(() => { vi.stubEnv('OPENAI_BASE_URL', undefined) }) -const notes: MeetingNotes = { decisions: [], actionItems: [], openQuestions: [], summary: 'Done.' } +const notes: MeetingNotes = { decisions: [], actionItems: [], openQuestions: [], summary: [{ text: 'Done.', at: null }] } const draft = { decisions: [], openQuestions: [], summary: 'Done.' } /** `Name: text` lines as the notes pipeline gets them, `seconds` apart. */ diff --git a/apps/lyra/src/main/searchIndex/record.test.ts b/apps/lyra/src/main/searchIndex/record.test.ts new file mode 100644 index 00000000..d0834c19 --- /dev/null +++ b/apps/lyra/src/main/searchIndex/record.test.ts @@ -0,0 +1,12 @@ +import { describe, expect, it } from 'vitest' +import { actionItemsOf } from './record' + +describe('actionItemsOf', () => { + it('reads owner, task and done from the notes, without the citation', () => { + const summary = ['Action items', '- [ ] Ana: Send the deck [12:40]', '- [x] Book the room', '- Not a task'].join('\n') + expect(actionItemsOf(summary)).toEqual([ + { owner: 'Ana', task: 'Send the deck', done: false }, + { owner: null, task: 'Book the room', done: true } + ]) + }) +}) diff --git a/apps/lyra/src/main/searchIndex/record.ts b/apps/lyra/src/main/searchIndex/record.ts index 6386531f..41086f1e 100644 --- a/apps/lyra/src/main/searchIndex/record.ts +++ b/apps/lyra/src/main/searchIndex/record.ts @@ -1,5 +1,6 @@ import { createHash } from 'node:crypto' import type { SessionSnapshot } from '../../shared/sessionDoc' +import { withoutCites } from '../../shared/notesCites' import type { SessionManifest } from '../sessionStore' import type { ChunkRecord, SessionRecord } from './protocol' @@ -108,7 +109,8 @@ export function actionItemsOf(summary: string): SessionRecord['actionItems'] { const owner = colon > 0 ? rest.slice(0, colon).trim() : '' items.push({ owner: owner || null, - task: (colon > 0 ? rest.slice(colon + 2) : rest).trim(), + // Without the citation (` [12:40]`) the notes end each item with. + task: withoutCites(colon > 0 ? rest.slice(colon + 2) : rest).trim(), done: mark !== ' ' }) } diff --git a/apps/lyra/src/main/tasks/screenshot.ts b/apps/lyra/src/main/tasks/screenshot.ts index 3c13f4e5..29cf2d19 100644 --- a/apps/lyra/src/main/tasks/screenshot.ts +++ b/apps/lyra/src/main/tasks/screenshot.ts @@ -24,7 +24,7 @@ async function seedScreenshotMeeting(): Promise { editDoc(doc, { title: 'Design review', summary: - 'Summary\nAgreed to ship the dock redesign first, then settings.\n\nSections\n- 0:00 The dock: what people see first\n- 0:15 Shortcuts and the meeting button\n- 0:31 First run and support\n\nAction items\n- [ ] Dana: port tokens into styles.css\n- [ ] Sam: check contrast in dark mode' + 'Summary\nAgreed to ship the dock redesign first, then settings. [0:02]\n\nSections\n- 0:00 The dock: what people see first\n- 0:15 Shortcuts and the meeting button\n- 0:31 First run and support\n\nDecisions\n- Show the shortcut on hover [0:22]\n\nAction items\n- [ ] Dana: port tokens into styles.css\n- [ ] Sam: check contrast in dark mode [0:09]' }) upsertSpeaker(doc, 'c0', { name: 'Dana', personId: null, confirmed: true, confidence: 0.96, matches: [] }) upsertSpeaker(doc, 'c1', { diff --git a/apps/lyra/src/main/tasks/smoke.ts b/apps/lyra/src/main/tasks/smoke.ts index 148e00b7..c796fa7d 100644 --- a/apps/lyra/src/main/tasks/smoke.ts +++ b/apps/lyra/src/main/tasks/smoke.ts @@ -167,13 +167,15 @@ async function checkNotesWriters(): Promise { const fail = (message: string): never => { throw new Error(`notes writers: ${message}`) } - const notes = { - decisions: [' Ship Friday '], - actionItems: [{ owner: 'Sam', task: 'Fix the installer' }, { owner: '', task: 'Update the changelog' }], - openQuestions: [''], - summary: ' Planned the release. ' - } - const local = createFakeNotesWriter({ notes, title: 'Local title' }) + const local = createFakeNotesWriter({ + notes: { + decisions: [{ text: 'Ship Friday', at: 0 }], + actionItems: [{ owner: 'Sam', task: 'Fix the installer', at: 0 }], + openQuestions: [], + summary: [{ text: 'Planned the release.', at: null }] + }, + title: 'Local title' + }) const withSettings = (patch: Partial, keys: Partial> = {}) => chooseWriter({ settings: () => ({ ...getSettings(), ...patch }), @@ -198,8 +200,18 @@ async function checkNotesWriters(): Promise { // The AI SDK adapter against a mock model: structured output parsed by the zod schema, tidied. // Each call answered in its own shape: the notes, then the action items (with their quotes). - const { actionItems, ...draft } = notes - const found = { actionItems: actionItems.map((item) => ({ quote: 'I will fix the installer', ...item })) } + const quote = 'I will fix the installer' + const draft = { + decisions: [{ quote, decision: ' Ship Friday ' }], + openQuestions: [{ quote, question: '' }], + summary: ' Planned the release. ' + } + const found = { + actionItems: [ + { quote, owner: 'Sam', task: 'Fix the installer' }, + { quote, owner: '', task: 'Update the changelog' } + ] + } const model = new MockLanguageModelV4({ doGenerate: (options) => Promise.resolve({ @@ -217,7 +229,8 @@ async function checkNotesWriters(): Promise { const written = await createModelNotesWriter(model, 'mock').notes([ { speaker: 'Sam', text: 'I will fix the installer.', start: 0, end: 2 } ]) - if (written.summary !== 'Planned the release.' || written.decisions.join() !== 'Ship Friday') { + const summaryText = written.summary.map((sentence) => sentence.text).join(' ') + if (summaryText !== 'Planned the release.' || written.decisions.map((item) => item.text).join() !== 'Ship Friday') { fail(`adapter did not tidy: ${JSON.stringify(written)}`) } if (written.actionItems[1]?.owner !== 'Unassigned' || written.openQuestions.length) fail('adapter kept empty entries') @@ -1248,7 +1261,7 @@ async function checkResume(): Promise { replaceTranscript(doc, [{ id: 'r0', rawId: 'r0', start: 0, end: 2, cluster: 'c0', confidence: null, text: 'We ship Friday.' }]) }) const writer = createFakeNotesWriter({ - notes: { decisions: [], actionItems: [], openQuestions: [], summary: 'Shipping.' }, + notes: { decisions: [], actionItems: [], openQuestions: [], summary: [{ text: 'Shipping.', at: null }] }, title: null }) await writeCheckpoint(owesNotes.id, 'notes', { writer: writer.name, answers: { a: 1 } }) diff --git a/apps/lyra/src/renderer/src/App.tsx b/apps/lyra/src/renderer/src/App.tsx index ee046eac..e4730808 100644 --- a/apps/lyra/src/renderer/src/App.tsx +++ b/apps/lyra/src/renderer/src/App.tsx @@ -812,6 +812,16 @@ export default function App(): React.JSX.Element { const transcriptCount = current?.transcript.length ?? 0 const newLines = away === null ? 0 : Math.max(0, transcriptCount - away) + /** Shows the transcript line at `seconds` (from the timeline or a citation in the summary). */ + const seekTranscript = (seconds: number): void => { + if (!current) return + const line = current.transcript.find((entry) => entry.end >= seconds) ?? current.transcript.at(-1) + if (!line) return + // On a narrow window the transcript is its own tab; revealLine waits for it to render. + if (width === 'compact') setCompactTab('transcript') + revealLine(line.id, 0, 'instant') + } + const summaryCard = current ? ( current.summary.trim() ? ( ) : engine.notesEngine !== 'off' && hasTranscript ? (
@@ -934,10 +945,7 @@ export default function App(): React.JSX.Element { sections={sections} view={transcriptRange} onSpeaker={(speaker, target) => setPickerRequest({ speaker, anchor: target.getBoundingClientRect() })} - onSeek={(seconds) => { - const line = current.transcript.find((entry) => entry.end >= seconds) ?? current.transcript.at(-1) - if (line) revealLine(line.id, 0, 'instant') - }} + onSeek={seekTranscript} /> ) : null diff --git a/apps/lyra/src/renderer/src/components/Summary.tsx b/apps/lyra/src/renderer/src/components/Summary.tsx index 1c51ba33..65331daa 100644 --- a/apps/lyra/src/renderer/src/components/Summary.tsx +++ b/apps/lyra/src/renderer/src/components/Summary.tsx @@ -1,8 +1,10 @@ -import { useId, useState } from 'react' +import { useId, useState, type MouseEvent as ReactMouseEvent } from 'react' +import { citedParts, withoutCites } from '../../../shared/notesCites' import { SECTIONS_HEADING } from '../../../shared/summarySections' import { cn } from '../lib/utils' import { ChevronDownIcon } from './Icons' import { SummaryButton } from './SummaryButton' +import { tip } from './Tooltip' import { Button } from './ui/button' import { Checkbox } from './ui/checkbox' @@ -94,12 +96,48 @@ function Owner({ name }: { name: string }) { ) } +/** + * Text with its citations (`[12:40]`, see shared/notesCites.ts) as links to that moment in the + * transcript; plain times when there's no transcript to go to. + */ +function CitedText({ text, onCite }: { text: string; onCite: ((seconds: number) => void) | undefined }) { + return ( + <> + {citedParts(text).map((part, index) => + part.kind === 'text' ? ( + part.text + ) : onCite ? ( + + ) : ( + + {part.label} + + ) + )} + + ) +} + /** Past this, the overview folds to five lines with a Show more. */ const LONG_OVERVIEW = 360 /** A folded summary: its first lines, clamped, and how many of each list it holds. */ function Folded({ sections, onOpen }: { sections: Section[]; onOpen: () => void }) { - const lead = sections.find((section) => section.paragraphs.length)?.paragraphs.join(' ') ?? '' + const lead = withoutCites(sections.find((section) => section.paragraphs.length)?.paragraphs.join(' ') ?? '') const counts = countsOf(sections) if (!lead && !counts.length) return null return ( @@ -117,6 +155,8 @@ type Props = { onChange: (value: string) => void /** Whether summaries can be written (an engine is chosen in Settings), so Rewrite is offered. */ canRewrite: boolean + /** Shows the transcript at `seconds`, for a citation; absent when there's no transcript. */ + onCite?: ((seconds: number) => void) | undefined } /** @@ -124,7 +164,7 @@ type Props = { * edited here (Rewrite asks for a new one); ticking an action item marks that one line done. * The header folds it away. */ -export function Summary({ pageId, value, onChange, canRewrite }: Props) { +export function Summary({ pageId, value, onChange, canRewrite, onCite }: Props) { const [more, setMore] = useState(false) const [collapsed, setCollapsed] = useState(readCollapsed) const bodyId = useId() @@ -199,7 +239,7 @@ export function Summary({ pageId, value, onChange, canRewrite }: Props) {
{section.paragraphs.map((paragraph, at) => (

- {paragraph} +

))}
@@ -216,7 +256,9 @@ export function Summary({ pageId, value, onChange, canRewrite }: Props) { return item.done === null ? (
  • ) : ( @@ -225,10 +267,12 @@ export function Summary({ pageId, value, onChange, canRewrite }: Props) { toggle(item.line)} /> - {text} + + + {owner ? : null} diff --git a/apps/lyra/src/shared/notesCites.test.ts b/apps/lyra/src/shared/notesCites.test.ts new file mode 100644 index 00000000..6ee3dc20 --- /dev/null +++ b/apps/lyra/src/shared/notesCites.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from 'vitest' +import { citedParts, withoutCites } from './notesCites' + +describe('citedParts', () => { + it('splits text at each citation, in order', () => { + expect(citedParts('Ana opened. [0:05] Ben chose blue. [1:02:05] All agreed.')).toEqual([ + { kind: 'text', text: 'Ana opened.' }, + { kind: 'cite', at: 5, label: '0:05' }, + { kind: 'text', text: ' Ben chose blue.' }, + { kind: 'cite', at: 3725, label: '1:02:05' }, + { kind: 'text', text: ' All agreed.' } + ]) + }) + + it('leaves text without citations, and brackets that are not times, as they are', () => { + expect(citedParts('Use blue')).toEqual([{ kind: 'text', text: 'Use blue' }]) + expect(citedParts('See [docs] and [1:75]')).toEqual([{ kind: 'text', text: 'See [docs] and [1:75]' }]) + }) +}) + +describe('withoutCites', () => { + it('drops the citations and the space before each', () => { + expect(withoutCites('Buy paint [12:40]')).toBe('Buy paint') + expect(withoutCites('One. [0:05] Two. [0:09]')).toBe('One. Two.') + }) +}) diff --git a/apps/lyra/src/shared/notesCites.ts b/apps/lyra/src/shared/notesCites.ts new file mode 100644 index 00000000..3bff4df3 --- /dev/null +++ b/apps/lyra/src/shared/notesCites.ts @@ -0,0 +1,33 @@ +/** + * Citations in generated notes: `renderNotes` (src/main/meeting/notesFormat.ts) ends a line, or a + * sentence of the summary, with ` [12:40]`, the moment in the recording it comes from. The file + * keeps them as plain text; the window turns each into a link to that moment in the transcript. + */ +import { parseClock } from './summarySections' + +/** A citation: a clock time in square brackets, after a space. */ +const CITE = /\s\[(\d+(?::[0-5]\d){1,2})\]/g + +/** Text and the citations after it, in order: plain text, or a moment (seconds). */ +export type CitedPart = { kind: 'text'; text: string } | { kind: 'cite'; at: number; label: string } + +/** `text` split at its citations; text with none is one part. */ +export function citedParts(text: string): CitedPart[] { + const parts: CitedPart[] = [] + let from = 0 + for (const match of text.matchAll(CITE)) { + const label = match[1] ?? '' + const at = parseClock(label) + if (at === null) continue + if (match.index > from) parts.push({ kind: 'text', text: text.slice(from, match.index) }) + parts.push({ kind: 'cite', at, label }) + from = match.index + match[0].length + } + if (from < text.length) parts.push({ kind: 'text', text: text.slice(from) }) + return parts +} + +/** `text` without its citations, for places that show or store just the words. */ +export function withoutCites(text: string): string { + return text.replace(CITE, '') +}