From b8b0cd2811a40692b0e397875256139c605914c5 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sun, 29 Nov 2026 00:54:17 +0000 Subject: [PATCH 1/7] fix(notes): ask before Update notes replaces an edited summary --- .../meetings_ui/documents/bar/health_line.rs | 9 +- .../src/meetings_ui/documents/cap_ai.rs | 1 + .../src/meetings_ui/documents/pane.rs | 26 +++-- .../src/meetings_ui/documents/tests.rs | 101 ++++++++++++++++++ 4 files changed, 124 insertions(+), 13 deletions(-) diff --git a/apps/desktop-gpui/src/meetings_ui/documents/bar/health_line.rs b/apps/desktop-gpui/src/meetings_ui/documents/bar/health_line.rs index cb614922616..74f9b823d50 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/bar/health_line.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/bar/health_line.rs @@ -61,11 +61,14 @@ pub fn is_recovered(doc: &DocMeta) -> bool { /// unexpectedly", how much audio the meeting missed while it recorded, or, /// when a repair added words after the notes were written, "Transcript /// updated" with a way to update the notes. -/// `dismissed` runs after the note's flags are cleared. +/// `dismissed` runs after the note's flags are cleared. `update_notes` is +/// the pane's own Write notes, so an edited summary is never replaced +/// without asking. pub fn recovered( doc: Option<&DocMeta>, palette: &Palette, dismissed: impl Fn(&mut App) + 'static, + update_notes: impl Fn(&mut App) + 'static, ) -> Option { let doc = doc?; let recovered = is_recovered(doc); @@ -107,9 +110,7 @@ pub fn recovered( )); } let update: cap_ai::Handler = Box::new(move |_, _, cx| { - if let Some(meetings) = Meetings::try_global(cx) { - meetings.update(cx, |m, cx| m.update_notes(&id, cx)); - } + update_notes(cx); clear(cx); }); Some(cap_ai::dock_line( diff --git a/apps/desktop-gpui/src/meetings_ui/documents/cap_ai.rs b/apps/desktop-gpui/src/meetings_ui/documents/cap_ai.rs index f1df8d39d72..3e81aeb8243 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/cap_ai.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/cap_ai.rs @@ -462,6 +462,7 @@ pub fn dock_line( el.child( div() .id("cap-ai-dock-action") + .debug_selector(|| "cap-ai-dock-action".into()) .h(px(22.)) .px(px(9.)) .flex() diff --git a/apps/desktop-gpui/src/meetings_ui/documents/pane.rs b/apps/desktop-gpui/src/meetings_ui/documents/pane.rs index fa4a036fcea..f53320558e1 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/pane.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/pane.rs @@ -3995,15 +3995,23 @@ impl Pane { return None; } let pane = cx.weak_entity(); - if let Some(line) = super::bar::health_line::recovered(self.doc.as_ref(), &palette, move |cx| { - pane.update(cx, |p, cx| { - if let Some(doc) = p.doc.as_mut() { - super::bar::health_line::forget(doc); - } - cx.notify(); - }) - .ok(); - }) { + let writer = cx.weak_entity(); + if let Some(line) = super::bar::health_line::recovered( + self.doc.as_ref(), + &palette, + move |cx| { + pane.update(cx, |p, cx| { + if let Some(doc) = p.doc.as_mut() { + super::bar::health_line::forget(doc); + } + cx.notify(); + }) + .ok(); + }, + move |cx| { + writer.update(cx, |p, cx| p.write_notes(None, cx)).ok(); + }, + ) { return Some(line); } if self.too_short && !self.has_enhanced() { diff --git a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs index bf9761f9621..d23831ba806 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs @@ -2713,3 +2713,104 @@ fn a_long_list_item_in_an_answer_wraps_like_the_lines_around_it(cx: &mut TestApp assert!(height(url, cx) > line * 2., "{url}: an unbroken link wraps"); } } + +/// A finished meeting whose summary was written before a repair added +/// words, so the note offers "Transcript updated ยท Update notes", drawn in +/// its own window with Cap Notes running. +fn stale_summary( + edited: bool, + cx: &mut TestAppContext, +) -> ( + tempfile::TempDir, + String, + Entity, + &mut VisualTestContext, +) { + let dir = tempfile::tempdir().unwrap(); + let library = Library::open(dir.path().join("documents")).unwrap(); + let now = Utc::now(); + let mut meta = library + .create(DocKind::Meeting, now - ChronoDuration::hours(1), 7) + .unwrap(); + meta.title = "Weekly".into(); + meta.title_is_auto = false; + meta.meeting = Some(MeetingDetails { + started_at: Some(now - ChronoDuration::hours(1)), + ended_at: Some(now - ChronoDuration::minutes(30)), + duration_ms: 30 * 60_000, + has_enhanced: true, + ..MeetingDetails::default() + }); + crate::meetings::persist::set_flag(&mut meta, crate::meetings::persist::NOTES_STALE_KEY, true); + library.save(&meta).unwrap(); + let summary = Document::from_markdown("### Summary\n\nShip the deck on Friday\n"); + library + .write_enhanced(&meta.id, &summary.to_json()) + .unwrap(); + let id = meta.id.clone(); + let calendar_dir = dir.path().join("calendar"); + cx.update(|cx| { + crate::meetings::Meetings::install_for_tests( + cap_meetings::settings::MeetingSettings::default(), + calendar_dir, + cx, + ); + }); + let store = cx.new(|cx| DocStore::with_library(Some(library.clone()), cx)); + let theme = Theme::light(); + let pane_store = store.clone(); + let (pane, cx) = cx.add_window_view(|window, cx| { + Pane::new( + pane_store, + gpui::WeakEntity::new_invalid(), + &theme, + window, + cx, + ) + }); + cx.simulate_resize(gpui::size(gpui::px(1000.), gpui::px(700.))); + cx.run_until_parked(); + store.update(cx, |s, cx| s.open(Some(id.clone()), cx)); + cx.run_until_parked(); + if edited { + pane.update(cx, |p, _| p.enhanced_edited = true); + } + cx.run_until_parked(); + (dir, id, pane, cx) +} + +fn notes_started(id: &str, cx: &mut VisualTestContext) -> bool { + cx.update(|_, cx| { + crate::meetings::Meetings::global(cx) + .read(cx) + .notes_state(id) + .is_some() + }) +} + +#[gpui::test] +fn update_notes_on_the_transcript_line_never_replaces_an_edited_summary_without_asking( + cx: &mut TestAppContext, +) { + let (_dir, id, _pane, cx) = stale_summary(true, cx); + let action = cx + .debug_bounds("cap-ai-dock-action") + .expect("the transcript updated line offers Update notes"); + cx.simulate_click(action.center(), gpui::Modifiers::none()); + cx.run_until_parked(); + assert!( + !notes_started(&id, cx), + "an edited summary is only replaced after the person confirms" + ); +} + +#[gpui::test] +fn update_notes_on_the_transcript_line_still_writes_an_unedited_summary(cx: &mut TestAppContext) { + let (_dir, id, _pane, cx) = stale_summary(false, cx); + let action = cx + .debug_bounds("cap-ai-dock-action") + .expect("the transcript updated line offers Update notes"); + cx.simulate_click(action.center(), gpui::Modifiers::none()); + cx.run_until_parked(); + assert!(notes_started(&id, cx), "Update notes writes new notes"); +} From 857f5c7a60dc2b997e93f434ffb0612a5ece5e92 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:03:05 +0000 Subject: [PATCH 2/7] test(notes): wait for queued saves before checking Update notes --- apps/desktop-gpui/src/meetings_ui/documents/tests.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs index d23831ba806..15828d80ebb 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs @@ -2779,6 +2779,14 @@ fn stale_summary( (dir, id, pane, cx) } +/// Waits for the save writer, since Write notes starts only once every +/// queued save has landed. +fn after_queued_saves(cx: &mut VisualTestContext) { + cx.run_until_parked(); + assert!(super::writer::flush_blocking(std::time::Duration::from_secs(5))); + cx.run_until_parked(); +} + fn notes_started(id: &str, cx: &mut VisualTestContext) -> bool { cx.update(|_, cx| { crate::meetings::Meetings::global(cx) @@ -2797,7 +2805,7 @@ fn update_notes_on_the_transcript_line_never_replaces_an_edited_summary_without_ .debug_bounds("cap-ai-dock-action") .expect("the transcript updated line offers Update notes"); cx.simulate_click(action.center(), gpui::Modifiers::none()); - cx.run_until_parked(); + after_queued_saves(cx); assert!( !notes_started(&id, cx), "an edited summary is only replaced after the person confirms" @@ -2811,6 +2819,6 @@ fn update_notes_on_the_transcript_line_still_writes_an_unedited_summary(cx: &mut .debug_bounds("cap-ai-dock-action") .expect("the transcript updated line offers Update notes"); cx.simulate_click(action.center(), gpui::Modifiers::none()); - cx.run_until_parked(); + after_queued_saves(cx); assert!(notes_started(&id, cx), "Update notes writes new notes"); } From 00f3a3e363b2c0ca9e6492e5204e968ef5f5dfe4 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:13:52 +0000 Subject: [PATCH 3/7] test(notes): seed the summary as Cap's own --- apps/desktop-gpui/src/meetings_ui/documents/tests.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs index 15828d80ebb..75321d8138b 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs @@ -2743,7 +2743,10 @@ fn stale_summary( }); crate::meetings::persist::set_flag(&mut meta, crate::meetings::persist::NOTES_STALE_KEY, true); library.save(&meta).unwrap(); - let summary = Document::from_markdown("### Summary\n\nShip the deck on Friday\n"); + let mut summary = Document::from_markdown("### Summary\n\nShip the deck on Friday\n"); + for block in &mut summary.blocks { + block.origin = cap_notes::Origin::Generated; + } library .write_enhanced(&meta.id, &summary.to_json()) .unwrap(); From b0ed4b404dd21b2a373eed94efb2f57f99b25299 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:30:14 +0000 Subject: [PATCH 4/7] fix(notes): keep the update reminder until new notes land --- .../meetings_ui/documents/bar/health_line.rs | 7 ++- .../src/meetings_ui/documents/tests.rs | 48 ++++++++++++++----- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/apps/desktop-gpui/src/meetings_ui/documents/bar/health_line.rs b/apps/desktop-gpui/src/meetings_ui/documents/bar/health_line.rs index 74f9b823d50..e064a7d9e1b 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/bar/health_line.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/bar/health_line.rs @@ -109,10 +109,9 @@ pub fn recovered( Some(dismiss), )); } - let update: cap_ai::Handler = Box::new(move |_, _, cx| { - update_notes(cx); - clear(cx); - }); + // The line stays until new notes land (writing them clears the flag), so + // cancelling "Replace notes?" keeps the reminder. + let update: cap_ai::Handler = Box::new(move |_, _, cx| update_notes(cx)); Some(cap_ai::dock_line( palette, tr::documents::notes::transcript_updated().into(), diff --git a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs index 75321d8138b..ca9d0022081 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs @@ -2771,6 +2771,9 @@ fn stale_summary( cx, ) }); + cx.update(|window, cx| { + crate::meetings_ui::MeetingWindows::get(cx).documents = Some(window.window_handle()); + }); cx.simulate_resize(gpui::size(gpui::px(1000.), gpui::px(700.))); cx.run_until_parked(); store.update(cx, |s, cx| s.open(Some(id.clone()), cx)); @@ -2786,7 +2789,9 @@ fn stale_summary( /// queued save has landed. fn after_queued_saves(cx: &mut VisualTestContext) { cx.run_until_parked(); - assert!(super::writer::flush_blocking(std::time::Duration::from_secs(5))); + assert!(super::writer::flush_blocking( + std::time::Duration::from_secs(5) + )); cx.run_until_parked(); } @@ -2799,29 +2804,50 @@ fn notes_started(id: &str, cx: &mut VisualTestContext) -> bool { }) } -#[gpui::test] -fn update_notes_on_the_transcript_line_never_replaces_an_edited_summary_without_asking( - cx: &mut TestAppContext, -) { - let (_dir, id, _pane, cx) = stale_summary(true, cx); +fn click_update_notes(cx: &mut VisualTestContext) { let action = cx .debug_bounds("cap-ai-dock-action") .expect("the transcript updated line offers Update notes"); cx.simulate_click(action.center(), gpui::Modifiers::none()); + cx.run_until_parked(); +} + +#[gpui::test] +fn update_notes_on_the_transcript_line_asks_before_replacing_an_edited_summary( + cx: &mut TestAppContext, +) { + let (_dir, id, _pane, cx) = stale_summary(true, cx); + click_update_notes(cx); + assert!(cx.has_pending_prompt(), "Replace notes? is asked first"); + cx.simulate_prompt_answer(crate::i18n::tr::common::cancel()); after_queued_saves(cx); assert!( !notes_started(&id, cx), - "an edited summary is only replaced after the person confirms" + "cancelling keeps the edited summary" + ); + assert!( + cx.debug_bounds("cap-ai-dock-action").is_some(), + "cancelling keeps the reminder to update the notes" ); } +#[gpui::test] +fn update_notes_on_the_transcript_line_replaces_an_edited_summary_once_confirmed( + cx: &mut TestAppContext, +) { + let (_dir, id, _pane, cx) = stale_summary(true, cx); + click_update_notes(cx); + assert!(cx.has_pending_prompt(), "Replace notes? is asked first"); + cx.simulate_prompt_answer(crate::i18n::tr::documents::confirm::replace()); + after_queued_saves(cx); + assert!(notes_started(&id, cx), "confirming writes new notes"); +} + #[gpui::test] fn update_notes_on_the_transcript_line_still_writes_an_unedited_summary(cx: &mut TestAppContext) { let (_dir, id, _pane, cx) = stale_summary(false, cx); - let action = cx - .debug_bounds("cap-ai-dock-action") - .expect("the transcript updated line offers Update notes"); - cx.simulate_click(action.center(), gpui::Modifiers::none()); + click_update_notes(cx); + assert!(!cx.has_pending_prompt(), "nothing to ask about"); after_queued_saves(cx); assert!(notes_started(&id, cx), "Update notes writes new notes"); } From d3fd497931219a9ee162adc1642ecbccd0a3db6c Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:37:39 +0000 Subject: [PATCH 5/7] test(notes): seed an edited summary the way a person edits it --- .../src/meetings_ui/documents/tests.rs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs index ca9d0022081..151f7c34a5f 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/tests.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/tests.rs @@ -2743,9 +2743,22 @@ fn stale_summary( }); crate::meetings::persist::set_flag(&mut meta, crate::meetings::persist::NOTES_STALE_KEY, true); library.save(&meta).unwrap(); - let mut summary = Document::from_markdown("### Summary\n\nShip the deck on Friday\n"); - for block in &mut summary.blocks { - block.origin = cap_notes::Origin::Generated; + // Cap wrote the summary; an edited one also has a line the person typed. + let markdown = if edited { + "### Summary\n\nShip the deck on Friday\n\nAsk Sam about pricing\n" + } else { + "### Summary\n\nShip the deck on Friday\n" + }; + let mut summary = Document::from_markdown(markdown); + let typed = if edited { + summary.blocks.len() - 1 + } else { + usize::MAX + }; + for (index, block) in summary.blocks.iter_mut().enumerate() { + if index != typed { + block.origin = cap_notes::Origin::Generated; + } } library .write_enhanced(&meta.id, &summary.to_json()) @@ -2778,10 +2791,15 @@ fn stale_summary( cx.run_until_parked(); store.update(cx, |s, cx| s.open(Some(id.clone()), cx)); cx.run_until_parked(); - if edited { - pane.update(cx, |p, _| p.enhanced_edited = true); - } + assert!(super::writer::flush_blocking( + std::time::Duration::from_secs(5) + )); cx.run_until_parked(); + assert_eq!( + pane.read_with(cx, |p, _| p.enhanced_edited), + edited, + "the loaded summary reads as edited only when the person typed in it" + ); (dir, id, pane, cx) } From ff9fcd14a95e2622bdf8d0656a04d5928e489d9a Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:44:55 +0000 Subject: [PATCH 6/7] fix(notes): open Replace notes? after the click that asked for it --- .../src/meetings_ui/documents/pane.rs | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/apps/desktop-gpui/src/meetings_ui/documents/pane.rs b/apps/desktop-gpui/src/meetings_ui/documents/pane.rs index f53320558e1..7f494cca98a 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/pane.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/pane.rs @@ -2707,34 +2707,39 @@ impl Pane { return; } if self.has_enhanced() && self.enhanced_edited { - let Some(window) = cx - .windows() - .into_iter() - .find(|w| Some(*w) == crate::meetings_ui::MeetingWindows::get(cx).documents) - else { - return; - }; - let pane = cx.weak_entity(); - window - .update(cx, |_, window, cx| { - let answer = window.prompt( - gpui::PromptLevel::Warning, - tr::documents::confirm::replace_notes(), - Some(tr::documents::confirm::replace_notes_detail()), - &[ - gpui::PromptButton::ok(tr::documents::confirm::replace()), - gpui::PromptButton::cancel(tr::common::cancel()), - ], - cx, - ); - cx.spawn(async move |cx| { - if answer.await.ok() == Some(0) { - pane.update(cx, |pane, cx| pane.generate(options, cx)).ok(); - } + // Deferred: a click or menu action in the documents window is + // still dispatching there, and the window can't be updated from + // inside its own event. + cx.defer(move |_, cx| { + let Some(window) = cx + .windows() + .into_iter() + .find(|w| Some(*w) == crate::meetings_ui::MeetingWindows::get(cx).documents) + else { + return; + }; + let pane = cx.weak_entity(); + window + .update(cx, |_, window, cx| { + let answer = window.prompt( + gpui::PromptLevel::Warning, + tr::documents::confirm::replace_notes(), + Some(tr::documents::confirm::replace_notes_detail()), + &[ + gpui::PromptButton::ok(tr::documents::confirm::replace()), + gpui::PromptButton::cancel(tr::common::cancel()), + ], + cx, + ); + cx.spawn(async move |cx| { + if answer.await.ok() == Some(0) { + pane.update(cx, |pane, cx| pane.generate(options, cx)).ok(); + } + }) + .detach(); }) - .detach(); - }) - .ok(); + .ok(); + }); return; } self.generate(options, cx); From cba8ac15f44232e41bd47c750b7d9d3992b6725a Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sun, 29 Nov 2026 01:49:37 +0000 Subject: [PATCH 7/7] fix(notes): defer takes the app context --- apps/desktop-gpui/src/meetings_ui/documents/pane.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/desktop-gpui/src/meetings_ui/documents/pane.rs b/apps/desktop-gpui/src/meetings_ui/documents/pane.rs index 7f494cca98a..64e67b1fcaf 100644 --- a/apps/desktop-gpui/src/meetings_ui/documents/pane.rs +++ b/apps/desktop-gpui/src/meetings_ui/documents/pane.rs @@ -2710,7 +2710,8 @@ impl Pane { // Deferred: a click or menu action in the documents window is // still dispatching there, and the window can't be updated from // inside its own event. - cx.defer(move |_, cx| { + let pane = cx.weak_entity(); + cx.defer(move |cx| { let Some(window) = cx .windows() .into_iter() @@ -2718,7 +2719,6 @@ impl Pane { else { return; }; - let pane = cx.weak_entity(); window .update(cx, |_, window, cx| { let answer = window.prompt(