Skip to content

Commit ed59633

Browse files
authored
Merge pull request #27 from SirDarcanos/fix/regenerate-summary
Add a button to regenerate meeting summaries
2 parents 4318d72 + 6f59e21 commit ed59633

6 files changed

Lines changed: 180 additions & 16 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,13 @@ them all to the Trash.
184184
away with its transcript and notes, and its summary and to-dos are written in the background
185185
and appear in the meeting when they're ready. If the summary can't be written (the model's
186186
download was interrupted, a server of your own that's down), the meeting says why in plain words
187-
(the raw message is behind Details) and shows **Write summary** to try again later. Your notes
188-
steer what the summary focuses on but aren't copied into it. A long turn in the transcript is
187+
(the raw message is behind Details) and shows **Write summary** to try again later.
188+
To write a summary or its to-dos again (after changing the instructions in Settings ›
189+
Summaries, say), choose **Regenerate › Regenerate summary** or **Regenerate to-dos** in the
190+
Summary tab's toolbar and confirm. Only that part is asked for and replaced, edits and ticks
191+
included; the rest of the meeting stays as it is. The old one stays until the new one is
192+
ready, and stays if it fails or is changed somewhere else meanwhile. Your notes steer what the summary focuses
193+
on but aren't copied into it. A long turn in the transcript is
189194
broken at a pause about every half minute, each part with its own time.
190195
Tabs: Summary (with the meeting's to-dos at the top), Transcript and My notes (⌘1–⌘3),
191196
each Rendered or as editable Markdown from the switch at the top right of the note (saved as

‎Sources/Oatcake/Jobs.swift‎

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ final class Jobs {
4646
/// Meetings whose summary is being written now, and why the last attempt failed, by path.
4747
var summarising = Set<String>()
4848
var summaryErrors: [String: String] = [:]
49+
/// What Regenerate is writing again, by path; kept after a failure, so Try again knows what to retry.
50+
var regenerating: [String: SummaryPart] = [:]
4951
/// Where each meeting being summarised lives now: it can be renamed or moved while the model writes.
5052
private var summaryJobs: [UUID: String] = [:]
5153
var reviewDrafts: [String: ReviewDraft] = [:]
@@ -81,6 +83,7 @@ final class Jobs {
8183
summarising = Set(summarising.map(remap))
8284
summaryJobs = summaryJobs.mapValues(remap)
8385
summaryErrors = Dictionary(summaryErrors.map { (remap($0.key), $0.value) }, uniquingKeysWith: { a, _ in a })
86+
regenerating = Dictionary(regenerating.map { (remap($0.key), $0.value) }, uniquingKeysWith: { a, _ in a })
8487
todoProblems = Dictionary(todoProblems.map { (remap($0.key), $0.value) }, uniquingKeysWith: { a, _ in a })
8588
// A recording waiting in Who's who is still saved into the folder it was set to, wherever that is now.
8689
reviewDrafts = reviewDrafts.mapValues { draft in with(draft) { $0.folder = remap($0.folder) } }
@@ -181,24 +184,50 @@ final class Jobs {
181184
tidying.async { Recordings.tidySaved(meetingsRoot: root) }
182185
}
183186

187+
/// Regenerate summary or Regenerate to-dos: asks first, as it replaces what's there. The old one
188+
/// stays until the new one is written.
189+
func regenerate(_ part: SummaryPart, _ path: String) {
190+
guard !summarising.contains(path) else { return }
191+
let confirmation = part == .summary
192+
? Confirmation(title: "Regenerate this summary?",
193+
text: "It’s written again with your current instructions in Settings and replaces this summary, including any edits. Your transcript, notes and to-dos are kept.",
194+
ok: "Regenerate summary", cancel: "Cancel") { [self] in writeSummary(path, only: .summary) }
195+
: Confirmation(title: "Regenerate these to-dos?",
196+
text: "They’re written again with your current instructions in Settings and replace these to-dos, including any you’ve ticked, added or edited. Your transcript, notes and summary are kept.",
197+
ok: "Regenerate to-dos", cancel: "Cancel") { [self] in writeSummary(path, only: .todos) }
198+
app.confirm(confirmation)
199+
}
200+
184201
/// Writes a saved meeting's summary and to-dos in the background: after every save, and from
185-
/// Write summary when an earlier attempt couldn't reach the model.
186-
func writeSummary(_ path: String) {
202+
/// Write summary when an earlier attempt couldn't reach the model. With `only`, that one part is
203+
/// written again in place of what's there (Regenerate).
204+
func writeSummary(_ path: String, only part: SummaryPart? = nil) {
187205
guard !summarising.contains(path) else { return }
188206
summarising.insert(path)
189207
summaryErrors.removeValue(forKey: path)
190-
todoProblems.removeValue(forKey: path)
208+
if part != .summary { todoProblems.removeValue(forKey: path) }
209+
regenerating[path] = part
191210
let job = UUID()
192211
summaryJobs[job] = path
193212
let config = config
194213
Task {
195214
do {
215+
// What's there now: if it's changed by the time the model is done, it isn't replaced.
216+
let previous = try part.map { part in
217+
let files = try Meetings(root: config.meetingsRoot).read(path)
218+
return part == .summary ? files.summary : files.todo
219+
}
196220
try await downloads.ensureModel()
197221
// Where the meeting is now: it may have been renamed or moved while the model downloaded.
198-
let draft = try await OatcakeCore.draftSummary(config, meeting: summaryJobs[job] ?? path)
199-
try OatcakeCore.writeSummary(draft, config: config, meeting: summaryJobs[job] ?? path)
200-
// The summary is there, but its to-dos couldn't be read from what the model sent.
201-
if let problem = draft.todoProblem { todoProblems[summaryJobs[job] ?? path] = problem }
222+
let draft = try await OatcakeCore.draftSummary(config, meeting: summaryJobs[job] ?? path, only: part)
223+
if let part, let previous {
224+
try OatcakeCore.writeRegenerated(part, draft, config: config, meeting: summaryJobs[job] ?? path, previous: previous)
225+
regenerating.removeValue(forKey: summaryJobs[job] ?? path)
226+
} else {
227+
try OatcakeCore.writeSummary(draft, config: config, meeting: summaryJobs[job] ?? path)
228+
// The summary is there, but its to-dos couldn't be read from what the model sent.
229+
if let problem = draft.todoProblem { todoProblems[summaryJobs[job] ?? path] = problem }
230+
}
202231
} catch {
203232
summaryErrors[summaryJobs[job] ?? path] = error.localizedDescription
204233
}

‎Sources/Oatcake/MeetingView.swift‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ struct MeetingView: View {
232232
}
233233
.font(.callout)
234234
}
235+
if tab == .summary, !(files?[.summary] ?? "").trimmed.isEmpty {
236+
Menu {
237+
Button("Regenerate summary") { regenerate(.summary) }
238+
Button("Regenerate to-dos") { regenerate(.todos) }
239+
} label: {
240+
// Named on the image too: a toolbar menu is read out by its image's name, "Refresh".
241+
Label { Text("Regenerate") } icon: { Image(systemName: "arrow.clockwise").accessibilityLabel("Regenerate") }
242+
}
243+
.accessibilityLabel("Regenerate")
244+
.disabled(model.jobs.summarising.contains(path) || (files?[.transcript] ?? "").trimmed.isEmpty)
245+
.help("Write the summary or the to-dos again with the current instructions in Settings")
246+
}
235247
let what = tab == .summary ? "summary and to-dos" : tab == .transcript ? "transcript" : "notes"
236248
Button { copy() } label: { Label(copied ? "Copied" : "Copy", systemImage: copied ? "checkmark" : "doc.on.doc") }
237249
.help("Copy the \(what) as Markdown")
@@ -322,6 +334,26 @@ struct MeetingView: View {
322334
Notice(tone: .grey) { Text(granolaNotice(files)) }.padding(.top, 14)
323335
}
324336
Spacer().frame(height: 22)
337+
if tab == .summary, let part = model.jobs.regenerating[path] {
338+
let what = part == .summary ? "summary" : "to-dos"
339+
if model.jobs.summarising.contains(path) {
340+
Notice(tone: .blue) {
341+
Text("Regenerating the \(what)…").fontWeight(.semibold)
342+
Text(part == .summary ? "Your summary stays until the new one is ready." : "Your to-dos stay until the new ones are ready.")
343+
}.padding(.bottom, 16)
344+
} else if let error = model.jobs.summaryErrors[path] {
345+
Notice(tone: .red) {
346+
ModelError(raw: error, prefix: "Couldn’t regenerate the \(what). ")
347+
Text(part == .summary ? "Your previous summary was kept." : "Your previous to-dos were kept.")
348+
HStack(spacing: 10) {
349+
Button("Try again") { regenerate(part) }
350+
.disabled((files[.transcript] ?? "").trimmed.isEmpty)
351+
SettingsPaneLink(pane: "summaries", title: "Open Settings").buttonStyle(.link)
352+
}
353+
.padding(.top, 6)
354+
}.padding(.bottom, 16)
355+
}
356+
}
325357
if markdown {
326358
markdownEditors(files)
327359
} else {
@@ -471,6 +503,13 @@ struct MeetingView: View {
471503
}
472504
}
473505

506+
private func regenerate(_ part: SummaryPart) {
507+
// Save edits before asking for a replacement; a failed save must not discard pending text.
508+
flush()
509+
guard pending.isEmpty else { return }
510+
model.jobs.regenerate(part, path)
511+
}
512+
474513
/// A meeting without its summary: it's being written now (after a save), or the model couldn't
475514
/// be reached and it can be written when it can.
476515
@ViewBuilder private var summaryLater: some View {

‎Sources/OatcakeCore/Save.swift‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,34 @@ public func writeSummary(_ draft: SummaryDraft, config: Config, meeting rel: Str
158158
}
159159
}
160160

161-
/// Asks the model for a meeting's summary and to-dos. Nothing is written.
162-
public func draftSummary(_ config: Config, meeting rel: String) async throws -> SummaryDraft {
161+
/// What Regenerate writes again: a meeting's summary, or its to-dos.
162+
public enum SummaryPart: Sendable { case summary, todos }
163+
164+
/// Regenerate: puts a new draft of one part in place of the old one. `previous` is that part as it was
165+
/// when the model was asked. If it has changed since (edited somewhere else), nothing is written.
166+
public func writeRegenerated(_ part: SummaryPart, _ draft: SummaryDraft, config: Config, meeting rel: String, previous: String) throws {
167+
let meetings = Meetings(root: config.meetingsRoot)
168+
let now = try meetings.read(rel)
169+
switch part {
170+
case .summary:
171+
guard now.summary == previous else { throw OatcakeError("The summary was changed while it was being regenerated.") }
172+
guard !draft.summary.trimmed.isEmpty else { throw OatcakeError("The model returned an empty summary.") }
173+
try meetings.write(rel, .summary, draft.summary)
174+
case .todos:
175+
guard now.todo == previous else { throw OatcakeError("The to-dos were changed while they were being regenerated.") }
176+
if let problem = draft.todoProblem { throw OatcakeError(problem) }
177+
try meetings.write(rel, .todo, draft.todo)
178+
}
179+
}
180+
181+
/// Asks the model for a meeting's summary and to-dos, or for just one of them. Nothing is written.
182+
public func draftSummary(_ config: Config, meeting rel: String, only part: SummaryPart? = nil) async throws -> SummaryDraft {
163183
let meetings = Meetings(root: config.meetingsRoot)
164184
let files = try meetings.read(rel)
165185
guard !files.transcript.trimmed.isEmpty else { throw OatcakeError("This meeting has no transcript to summarise.") }
166186
let notes = parseNotes(files.notes).map { Note(at: $0.stamp.map(seconds), text: $0.text) }
167187
return try await summarise(config, title: titleOfMeeting(rel, files.meta), participants: files.meta.participants ?? [config.myName],
168-
notes: notes, transcript: files.transcript)
188+
notes: notes, transcript: files.transcript, only: part)
169189
}
170190

171191
/// A paragraph of the transcript runs for about this long at most before the next pause starts a new one.
@@ -239,7 +259,7 @@ let todosSchema = #"{"type":"object","properties":{"todos":{"type":"array","item
239259
* has just read the same transcript. A call too long for the model to take in at once on this Mac
240260
* is done in parts, and the parts' notes are joined.
241261
*/
242-
private func summarise(_ config: Config, title: String, participants: [String], notes: [Note], transcript: String) async throws -> SummaryDraft {
262+
private func summarise(_ config: Config, title: String, participants: [String], notes: [Note], transcript: String, only: SummaryPart?) async throws -> SummaryDraft {
243263
// The notes stay the note-taker's own (notes.md). Here they only tell the model what mattered.
244264
let notesBlock = notes.isEmpty ? "" : ([
245265
"\(config.myName) took these notes ([mm:ss] = time into the call; \"before the call\" = prep written",
@@ -263,15 +283,22 @@ private func summarise(_ config: Config, title: String, participants: [String],
263283
let which = parts.count > 1 ? ", part \(i + 1) of \(parts.count)" : ""
264284
let prompt = "\(head)\n\nTranscript ([mm:ss] is the time into the call)\(which):\n\(part)\n\n"
265285
let (summary, items) = try await withModel(config.llm, tokens: LocalModels.tokens(in: prompt) + overhead) { model, _ in
266-
(summaryBody(try await model.complete([system, ChatMessage("user", prompt + summaryTask)], think: reasoning.summary, maxTokens: replyTokens)),
267-
todoLines(try await model.complete([system, ChatMessage("user", prompt + todosTask)], schema: todosSchema, think: reasoning.todos, maxTokens: replyTokens)))
286+
// Regenerate asks only for the part being written again.
287+
var summary = "", items: [String]? = []
288+
if only != .todos {
289+
summary = summaryBody(try await model.complete([system, ChatMessage("user", prompt + summaryTask)], think: reasoning.summary, maxTokens: replyTokens))
290+
}
291+
if only != .summary {
292+
items = todoLines(try await model.complete([system, ChatMessage("user", prompt + todosTask)], schema: todosSchema, think: reasoning.todos, maxTokens: replyTokens))
293+
}
294+
return (summary, items)
268295
}
269296
summaries.append(summary)
270297
todos += items ?? []
271298
if items == nil { todosUnread = true }
272299
}
273300
var summary = summaries.first ?? ""
274-
if summaries.count > 1 {
301+
if summaries.count > 1, only != .todos {
275302
let joined = summaries.enumerated().map { "Notes on part \($0 + 1) of \(summaries.count):\n\($1)" }.joined(separator: "\n\n")
276303
let prompt = "\(head)\n\nThe meeting was long, so notes were written on each part of it in turn. Here they are, in order.\n\n\(joined)\n\n\(mergeTask)\n\(summaryTask)"
277304
summary = try await withModel(config.llm, tokens: LocalModels.tokens(in: prompt) + replyTokens) { model, _ in

‎Tests/OatcakeCoreTests/SaveTests.swift‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,45 @@ import Testing
5151
#expect(try meetings.read(renamed).summary == "My own line.\n\n## Topic\nDone.\n")
5252
}
5353

54+
/// Regenerate puts the new part in place of the old and leaves the rest of the meeting alone. It
55+
/// writes nothing when that part was changed meanwhile, or the model's answer is empty or unreadable.
56+
@Test func regenerateReplacesOnePart() throws {
57+
let meetings = TestMeetings()
58+
defer { meetings.remove() }
59+
let rel = "Team/2026-11-09 1000 Weekly sync"
60+
let old = "## Old summary\nMy edits.\n"
61+
try meetings.write(rel, .summary, old)
62+
try meetings.write(rel, .transcript, "**[00:00] Sam:** A decision.\n")
63+
try meetings.write(rel, .notes, "- My notes\n")
64+
try meetings.write(rel, .todo, "- [x] Done\n- [ ] My own task\n")
65+
var config = Config.defaults()
66+
config.outputDir = meetings.root.path
67+
let before = try Meetings(root: meetings.root).read(rel)
68+
let draft = SummaryDraft(summary: "## New summary\nA decision.\n", todo: "- [ ] Generated task\n")
69+
try writeRegenerated(.summary, draft, config: config, meeting: rel, previous: old)
70+
var after = try Meetings(root: meetings.root).read(rel)
71+
#expect(after.summary == draft.summary)
72+
#expect(after.transcript == before.transcript && after.notes == before.notes && after.todo == before.todo && after.meta == before.meta)
73+
try writeRegenerated(.todos, draft, config: config, meeting: rel, previous: before.todo)
74+
after = try Meetings(root: meetings.root).read(rel)
75+
#expect(after.todo == draft.todo && after.summary == draft.summary && after.notes == before.notes)
76+
// Changed in another editor while the model was writing: what's there now stays.
77+
#expect(throws: (any Error).self) { try writeRegenerated(.summary, draft, config: config, meeting: rel, previous: old) }
78+
#expect(throws: (any Error).self) { try writeRegenerated(.todos, draft, config: config, meeting: rel, previous: before.todo) }
79+
// An empty summary, or to-dos that couldn't be read from the model's reply: the old ones stay.
80+
#expect(throws: (any Error).self) {
81+
try writeRegenerated(.summary, SummaryDraft(summary: " \n", todo: ""), config: config, meeting: rel, previous: draft.summary)
82+
}
83+
#expect(throws: (any Error).self) {
84+
try writeRegenerated(.todos, SummaryDraft(summary: "", todo: "", todoProblem: todosUnreadMessage), config: config, meeting: rel, previous: draft.todo)
85+
}
86+
after = try Meetings(root: meetings.root).read(rel)
87+
#expect(after.summary == draft.summary && after.todo == draft.todo)
88+
// A call the model now finds no to-dos in: the list is emptied.
89+
try writeRegenerated(.todos, SummaryDraft(summary: "", todo: ""), config: config, meeting: rel, previous: draft.todo)
90+
#expect(try Meetings(root: meetings.root).read(rel).todo == "")
91+
}
92+
5493
/// Two voices merged into one person in review give one fingerprint for the call, from the one
5594
/// that spoke most. With no name set in Settings, your own lines are saved as "Me".
5695
@Test func mergedVoicesAndNoNameOfYourOwn() throws {

0 commit comments

Comments
 (0)