From e85274829abfaeae793434af34ec7873b996f562 Mon Sep 17 00:00:00 2001 From: Codex Automation Date: Tue, 26 May 2026 15:03:51 +0200 Subject: [PATCH] Make meeting lifecycle stateful --- .../AsrDiagnosticEndpointTests.cs | 49 ++ .../AzureSpeechSpeakerIdentityMatcherTests.cs | 36 +- ...eechStreamingTranscriptionProviderTests.cs | 59 +- ...edSpeechRecognitionPipelineFactoryTests.cs | 95 ++- .../LaunchProfileOptionsProviderTests.cs | 72 +++ .../MeetingArtifactStoreTests.cs | 89 ++- .../MeetingSummaryArtifactResolverTests.cs | 52 ++ .../MeetingSummaryFailureWriterTests.cs | 3 + .../MeetingSummaryToolTests.cs | 62 ++ .../RecordingCoordinatorTests.cs | 598 +++++++++++++++++- .../SpeakerIdentityMergeServiceTests.cs | 40 +- .../SpeakerIdentityServiceTests.cs | 207 +++++- .../Hotkeys/GlobalHotkeyService.cs | 56 +- .../LaunchProfileOptionsProvider.cs | 153 +++++ MeetingAssistant/MeetingAssistant.csproj | 1 + MeetingAssistant/MeetingAssistantOptions.cs | 6 +- .../MeetingNotes/IMeetingArtifactStore.cs | 8 + .../MeetingNotes/IMeetingNoteStore.cs | 8 + .../MarkdownMeetingArtifactStore.cs | 93 ++- .../MeetingNotes/MarkdownMeetingNoteStore.cs | 10 +- .../MeetingArtifactFrontmatter.cs | 62 +- .../MeetingNotes/MeetingAttendeeNames.cs | 11 + MeetingAssistant/Program.cs | 255 +++++++- .../Recording/IRecordedAudioStore.cs | 7 + .../Recording/ITranscriptStore.cs | 7 + .../Recording/MeetingRecordingCoordinator.cs | 435 +++++++++---- .../Recording/TemporaryRecordedAudioStore.cs | 13 +- .../Recording/VaultTranscriptStore.cs | 9 +- .../AzureSpeechSpeakerIdentityMatcher.cs | 35 +- .../Speakers/SpeakerIdentificationModels.cs | 5 +- MeetingAssistant/Speakers/SpeakerIdentity.cs | 81 ++- .../SpeakerIdentityAttendeeCanonicalizer.cs | 124 ++++ .../Speakers/SpeakerIdentityMergeService.cs | 18 +- .../Speakers/SpeakerIdentitySchema.cs | 19 + .../Speakers/SpeakerIdentityService.cs | 132 +++- .../SpeakerIdentityTranscriptAudit.cs | 59 ++ .../Summary/BoundMeetingProjectResolver.cs | 74 +++ .../IMeetingSummaryInstructionBuilder.cs | 8 + .../Summary/IMeetingSummaryPipeline.cs | 8 + .../Summary/MeetingSummaryArtifactResolver.cs | 22 +- .../Summary/MeetingSummaryFailureWriter.cs | 25 +- .../MeetingSummaryInstructionBuilder.cs | 78 +-- .../Summary/MeetingSummaryTools.cs | 93 ++- .../OpenAiMeetingSummaryAgentPipeline.cs | 18 +- .../Summary/SummaryAgentWriteAudit.cs | 117 ++++ .../Transcription/AsrDiagnosticService.cs | 50 +- .../AzureSpeechRecognitionPipelineBuilder.cs | 18 + ...ureSpeechStreamingTranscriptionProvider.cs | 36 +- ...figuredSpeechRecognitionPipelineFactory.cs | 68 +- .../FunAsrSpeechRecognitionPipelineBuilder.cs | 22 + .../Transcription/IDictationWordStore.cs | 15 + .../ISpeechRecognitionPipeline.cs | 5 + .../ISpeechRecognitionPipelineBuilder.cs | 8 + .../MarkdownDictationWordStore.cs | 21 +- .../SpeechRecognitionPipelineBuilder.cs | 25 + ...erLocalSpeechRecognitionPipelineBuilder.cs | 20 + MeetingAssistant/appsettings.json | 22 +- README.md | 2 +- .../add-cross-platform-build-targets/tasks.md | 11 - .../proposal.md | 15 + .../specs/meeting-recording/spec.md | 33 + .../specs/meeting-transcription/spec.md | 16 + .../2026-05-21-add-launch-profiles/tasks.md | 18 + .../proposal.md | 0 .../specs/meeting-transcription/spec.md | 7 + .../tasks.md | 4 +- .../proposal.md | 0 .../specs/meeting-summary/spec.md | 0 .../tasks.md | 0 .../proposal.md | 12 + .../specs/meeting-transcription/spec.md | 27 + .../tasks.md | 14 + .../proposal.md | 4 + .../specs/build-targets/spec.md | 0 .../tasks.md | 15 + .../proposal.md | 12 + .../specs/meeting-transcription/spec.md | 107 ++++ .../tasks.md | 10 + .../proposal.md | 12 + .../specs/meeting-summary/spec.md | 82 +++ .../tasks.md | 9 + .../proposal.md | 11 + .../specs/meeting-recording/spec.md | 22 + .../tasks.md | 8 + .../proposal.md | 11 + .../specs/meeting-session/spec.md | 16 + .../tasks.md | 8 + openspec/specs/meeting-recording/spec.md | 47 ++ openspec/specs/meeting-session/spec.md | 43 +- openspec/specs/meeting-summary/spec.md | 63 +- openspec/specs/meeting-transcription/spec.md | 194 ++++++ 91 files changed, 4076 insertions(+), 479 deletions(-) create mode 100644 MeetingAssistant.Tests/LaunchProfileOptionsProviderTests.cs create mode 100644 MeetingAssistant/LaunchProfiles/LaunchProfileOptionsProvider.cs create mode 100644 MeetingAssistant/MeetingNotes/MeetingAttendeeNames.cs create mode 100644 MeetingAssistant/Speakers/SpeakerIdentityAttendeeCanonicalizer.cs create mode 100644 MeetingAssistant/Speakers/SpeakerIdentityTranscriptAudit.cs create mode 100644 MeetingAssistant/Summary/BoundMeetingProjectResolver.cs create mode 100644 MeetingAssistant/Summary/SummaryAgentWriteAudit.cs create mode 100644 MeetingAssistant/Transcription/AzureSpeechRecognitionPipelineBuilder.cs create mode 100644 MeetingAssistant/Transcription/FunAsrSpeechRecognitionPipelineBuilder.cs create mode 100644 MeetingAssistant/Transcription/ISpeechRecognitionPipelineBuilder.cs create mode 100644 MeetingAssistant/Transcription/SpeechRecognitionPipelineBuilder.cs create mode 100644 MeetingAssistant/Transcription/WhisperLocalSpeechRecognitionPipelineBuilder.cs delete mode 100644 openspec/changes/add-cross-platform-build-targets/tasks.md create mode 100644 openspec/changes/archive/2026-05-21-add-launch-profiles/proposal.md create mode 100644 openspec/changes/archive/2026-05-21-add-launch-profiles/specs/meeting-recording/spec.md create mode 100644 openspec/changes/archive/2026-05-21-add-launch-profiles/specs/meeting-transcription/spec.md create mode 100644 openspec/changes/archive/2026-05-21-add-launch-profiles/tasks.md rename openspec/changes/{add-speaker-identity-learning => archive/2026-05-21-add-speaker-identity-learning}/proposal.md (100%) rename openspec/changes/{add-speaker-identity-learning => archive/2026-05-21-add-speaker-identity-learning}/specs/meeting-transcription/spec.md (95%) rename openspec/changes/{add-speaker-identity-learning => archive/2026-05-21-add-speaker-identity-learning}/tasks.md (91%) rename openspec/changes/{configure-summary-agent-instructions => archive/2026-05-21-configure-summary-agent-instructions}/proposal.md (100%) rename openspec/changes/{configure-summary-agent-instructions => archive/2026-05-21-configure-summary-agent-instructions}/specs/meeting-summary/spec.md (100%) rename openspec/changes/{configure-summary-agent-instructions => archive/2026-05-21-configure-summary-agent-instructions}/tasks.md (100%) create mode 100644 openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/proposal.md create mode 100644 openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/specs/meeting-transcription/spec.md create mode 100644 openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/tasks.md rename openspec/changes/{add-cross-platform-build-targets => archive/2026-05-22-add-cross-platform-build-targets}/proposal.md (88%) rename openspec/changes/{add-cross-platform-build-targets => archive/2026-05-22-add-cross-platform-build-targets}/specs/build-targets/spec.md (100%) create mode 100644 openspec/changes/archive/2026-05-22-add-cross-platform-build-targets/tasks.md create mode 100644 openspec/changes/archive/2026-05-22-add-speaker-identity-references/proposal.md create mode 100644 openspec/changes/archive/2026-05-22-add-speaker-identity-references/specs/meeting-transcription/spec.md create mode 100644 openspec/changes/archive/2026-05-22-add-speaker-identity-references/tasks.md create mode 100644 openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/proposal.md create mode 100644 openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/specs/meeting-summary/spec.md create mode 100644 openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/tasks.md create mode 100644 openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/proposal.md create mode 100644 openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/specs/meeting-recording/spec.md create mode 100644 openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/tasks.md create mode 100644 openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/proposal.md create mode 100644 openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/specs/meeting-session/spec.md create mode 100644 openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/tasks.md diff --git a/MeetingAssistant.Tests/AsrDiagnosticEndpointTests.cs b/MeetingAssistant.Tests/AsrDiagnosticEndpointTests.cs index 97b8142..2c3bfec 100644 --- a/MeetingAssistant.Tests/AsrDiagnosticEndpointTests.cs +++ b/MeetingAssistant.Tests/AsrDiagnosticEndpointTests.cs @@ -30,6 +30,37 @@ public sealed class AsrDiagnosticEndpointTests Assert.StartsWith("endpoint-bytes:", segment.Text, StringComparison.Ordinal); } + [Fact] + public async Task NamedProfileEndpointPassesProfileToConfiguredProvider() + { + var pipelineFactory = new CapturingProfileSpeechRecognitionPipelineFactory(); + await using var factory = new WebApplicationFactory() + .WithWebHostBuilder(builder => + { + builder.ConfigureAppConfiguration((_, configuration) => + { + configuration.AddInMemoryCollection(new Dictionary + { + ["MeetingAssistant:FunAsr:Backend:Enabled"] = "false", + ["MeetingAssistant:LaunchProfiles:english:Hotkey:Toggle"] = "Ctrl+Alt+E", + ["MeetingAssistant:LaunchProfiles:english:AzureSpeech:Language"] = "en-US" + }); + }); + builder.ConfigureTestServices(services => + { + services.RemoveAll(); + services.AddSingleton(pipelineFactory); + }); + }); + using var client = factory.CreateClient(); + var wavPath = Path.Combine(AppContext.BaseDirectory, "Fixtures", "sample-16khz-mono.wav"); + + using var response = await client.PostAsJsonAsync("/profiles/english/asr/transcribe-file", new { path = wavPath }); + + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal("english", pipelineFactory.LastProfileName); + } + [Fact] public async Task EndpointReportsProviderFailuresAsBadGateway() { @@ -179,6 +210,24 @@ public sealed class AsrDiagnosticEndpointTests } } + private sealed class CapturingProfileSpeechRecognitionPipelineFactory : ISpeechRecognitionPipelineFactory + { + public string? LastProfileName { get; private set; } + + public ISpeechRecognitionPipeline Create() + { + return Create(null); + } + + public ISpeechRecognitionPipeline Create(string? launchProfileName) + { + LastProfileName = launchProfileName; + return new TestSpeechRecognitionPipeline( + new EndpointFakeTranscriptionProvider(), + (_, liveSegments, _, _) => Task.FromResult(liveSegments)); + } + } + private sealed class TestSpeechRecognitionPipeline : StreamingSpeechRecognitionPipeline { private readonly Func, SpeechRecognitionPipelineOptions, CancellationToken, Task>> finalize; diff --git a/MeetingAssistant.Tests/AzureSpeechSpeakerIdentityMatcherTests.cs b/MeetingAssistant.Tests/AzureSpeechSpeakerIdentityMatcherTests.cs index 31c433d..1364f9b 100644 --- a/MeetingAssistant.Tests/AzureSpeechSpeakerIdentityMatcherTests.cs +++ b/MeetingAssistant.Tests/AzureSpeechSpeakerIdentityMatcherTests.cs @@ -100,7 +100,27 @@ public sealed class AzureSpeechSpeakerIdentityMatcherTests Assert.Null(match); } - private static AzureSpeechSpeakerIdentityMatcher CreateMatcher(ISpeakerIdentityDiarizationClient diarizationClient) + [Fact] + public async Task MatcherReturnsNullWhenDiarizationTimesOut() + { + var matcher = CreateMatcher( + new HangingSpeakerIdentityDiarizationClient(), + TimeSpan.FromMilliseconds(20)); + var snippet = CreateWavSnippet(); + + var match = await matcher.MatchAsync( + new SpeakerIdentityMatchRequest( + "Guest03", + snippet, + [new SpeakerIdentityMatchCandidate(42, "Chris", 5, [snippet])]), + CancellationToken.None); + + Assert.Null(match); + } + + private static AzureSpeechSpeakerIdentityMatcher CreateMatcher( + ISpeakerIdentityDiarizationClient diarizationClient, + TimeSpan? matchTimeout = null) { return new AzureSpeechSpeakerIdentityMatcher( diarizationClient, @@ -108,7 +128,8 @@ public sealed class AzureSpeechSpeakerIdentityMatcherTests { SpeakerIdentification = new SpeakerIdentificationOptions { - SilenceBetweenSnippetsSeconds = 1 + SilenceBetweenSnippetsSeconds = 1, + MatchTimeout = matchTimeout ?? TimeSpan.FromMinutes(1) } }), NullLogger.Instance); @@ -145,4 +166,15 @@ public sealed class AzureSpeechSpeakerIdentityMatcherTests return Task.FromResult(segments); } } + + private sealed class HangingSpeakerIdentityDiarizationClient : ISpeakerIdentityDiarizationClient + { + public async Task> DiarizeAsync( + string wavPath, + CancellationToken cancellationToken) + { + await Task.Delay(Timeout.InfiniteTimeSpan, cancellationToken); + return []; + } + } } diff --git a/MeetingAssistant.Tests/AzureSpeechStreamingTranscriptionProviderTests.cs b/MeetingAssistant.Tests/AzureSpeechStreamingTranscriptionProviderTests.cs index 2d06d1d..a280c8c 100644 --- a/MeetingAssistant.Tests/AzureSpeechStreamingTranscriptionProviderTests.cs +++ b/MeetingAssistant.Tests/AzureSpeechStreamingTranscriptionProviderTests.cs @@ -1,5 +1,6 @@ using MeetingAssistant.Recording; using MeetingAssistant.Transcription; +using Microsoft.CognitiveServices.Speech; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -62,6 +63,50 @@ public sealed class AzureSpeechStreamingTranscriptionProviderTests ])); } + [Fact] + public void CreateSpeechConfigSkipsConfiguredPostProcessingOptionForConversationTranscriber() + { + var provider = new AzureSpeechStreamingTranscriptionProvider( + Options.Create(new MeetingAssistantOptions + { + AzureSpeech = new AzureSpeechOptions + { + Endpoint = "wss://westeurope.stt.speech.microsoft.com/speech/universal/v2", + Language = "de-DE", + Key = "test-key", + PostProcessingOption = "PostRefinement" + } + }), + NullLogger.Instance); + + var speechConfig = provider.CreateSpeechConfig(); + + Assert.True(string.IsNullOrEmpty( + speechConfig.GetProperty(PropertyId.SpeechServiceResponse_PostProcessingOption))); + } + + [Fact] + public void CreateSpeechConfigDoesNotApplyBlankPostProcessingOption() + { + var provider = new AzureSpeechStreamingTranscriptionProvider( + Options.Create(new MeetingAssistantOptions + { + AzureSpeech = new AzureSpeechOptions + { + Endpoint = "wss://westeurope.stt.speech.microsoft.com/speech/universal/v2", + Language = "de-DE", + Key = "test-key", + PostProcessingOption = " " + } + }), + NullLogger.Instance); + + var speechConfig = provider.CreateSpeechConfig(); + + Assert.True(string.IsNullOrEmpty( + speechConfig.GetProperty(PropertyId.SpeechServiceResponse_PostProcessingOption))); + } + [Fact] public void ResolveKeyFallsBackToUserEnvironment() { @@ -82,15 +127,17 @@ public sealed class AzureSpeechStreamingTranscriptionProviderTests } [Fact] - public void EndpointDefaultsToUniversalV2SpeechEndpointForRegion() + public void CreateSpeechConfigUsesSubscriptionWhenEndpointIsBlank() { - Assert.Equal( - new Uri("wss://germanywestcentral.stt.speech.microsoft.com/speech/universal/v2"), - AzureSpeechStreamingTranscriptionProvider.GetEndpoint(new AzureSpeechOptions + var speechConfig = AzureSpeechStreamingTranscriptionProvider.CreateSpeechConfig( + new AzureSpeechOptions { Endpoint = "", - Region = "germanywestcentral" - })); + Region = "westeurope" + }, + "test-key"); + + Assert.NotNull(speechConfig); } [Theory] diff --git a/MeetingAssistant.Tests/ConfiguredSpeechRecognitionPipelineFactoryTests.cs b/MeetingAssistant.Tests/ConfiguredSpeechRecognitionPipelineFactoryTests.cs index aa96b57..29dc452 100644 --- a/MeetingAssistant.Tests/ConfiguredSpeechRecognitionPipelineFactoryTests.cs +++ b/MeetingAssistant.Tests/ConfiguredSpeechRecognitionPipelineFactoryTests.cs @@ -1,4 +1,7 @@ +using MeetingAssistant.LaunchProfiles; +using MeetingAssistant.Recording; using MeetingAssistant.Transcription; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -24,11 +27,101 @@ public sealed class ConfiguredSpeechRecognitionPipelineFactoryTests services.AddTransient(); var provider = services.BuildServiceProvider(); var factory = new ConfiguredSpeechRecognitionPipelineFactory( - provider, + [new AzureSpeechRecognitionPipelineBuilder(provider)], provider.GetRequiredService>()); await using var pipeline = factory.Create(); Assert.IsType(pipeline); } + + [Fact] + public async Task FactoryPassesResolvedLaunchProfileOptionsToSelectedBuilder() + { + var services = new ServiceCollection().BuildServiceProvider(); + var builder = new CapturingPipelineBuilder(); + var launchProfiles = new ConfigurationLaunchProfileOptionsProvider( + new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + ["MeetingAssistant:Recording:TranscriptionProvider"] = "capturing", + ["MeetingAssistant:Agent:Model"] = "default-model", + ["MeetingAssistant:LaunchProfiles:english:Hotkey:Toggle"] = "Ctrl+Alt+E", + ["MeetingAssistant:LaunchProfiles:english:Recording:TranscriptionProvider"] = "capturing", + ["MeetingAssistant:LaunchProfiles:english:Agent:Model"] = "english-model" + }) + .Build()); + var factory = new ConfiguredSpeechRecognitionPipelineFactory( + [builder], + Options.Create(launchProfiles.GetRequiredProfile(null).Options), + launchProfiles); + + await using var pipeline = factory.Create("english"); + + Assert.IsType(pipeline); + Assert.Equal("english-model", builder.Options?.Agent.Model); + } + + private sealed class CapturingPipelineBuilder : ISpeechRecognitionPipelineBuilder + { + public string ProviderName => "capturing"; + + public MeetingAssistantOptions? Options { get; private set; } + + public ISpeechRecognitionPipeline Create(MeetingAssistantOptions options) + { + Options = options; + return new CapturingPipeline(); + } + } + + private sealed class CapturingPipeline : ISpeechRecognitionPipeline + { + public Task InitializeAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public Task InitializeAsync( + SpeechRecognitionPipelineOptions options, + CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public Task WaitUntilReadyAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public ValueTask WriteAsync(AudioChunk chunk, CancellationToken cancellationToken) + { + return ValueTask.CompletedTask; + } + + public Task CompleteAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public async IAsyncEnumerable ReadLiveTranscriptAsync( + [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken) + { + await Task.CompletedTask; + yield break; + } + + public Task> ReadFinishedTranscriptAsync( + string audioPath, + SpeechRecognitionPipelineOptions options, + CancellationToken cancellationToken) + { + return Task.FromResult>([]); + } + + public ValueTask DisposeAsync() + { + return ValueTask.CompletedTask; + } + } } diff --git a/MeetingAssistant.Tests/LaunchProfileOptionsProviderTests.cs b/MeetingAssistant.Tests/LaunchProfileOptionsProviderTests.cs new file mode 100644 index 0000000..e840738 --- /dev/null +++ b/MeetingAssistant.Tests/LaunchProfileOptionsProviderTests.cs @@ -0,0 +1,72 @@ +using MeetingAssistant.LaunchProfiles; +using Microsoft.Extensions.Configuration; + +namespace MeetingAssistant.Tests; + +public sealed class LaunchProfileOptionsProviderTests +{ + [Fact] + public void DefaultProfileUsesRootMeetingAssistantConfiguration() + { + var provider = CreateProvider(new Dictionary + { + ["MeetingAssistant:Hotkey:Toggle"] = "Ctrl+Alt+M", + ["MeetingAssistant:Recording:TranscriptionProvider"] = "azure-speech", + ["MeetingAssistant:AzureSpeech:Language"] = "de-DE" + }); + + var profile = provider.GetRequiredProfile(null); + + Assert.Equal("default", profile.Name); + Assert.Equal("Ctrl+Alt+M", profile.Options.Hotkey.Toggle); + Assert.Equal("azure-speech", profile.Options.Recording.TranscriptionProvider); + Assert.Equal("de-DE", profile.Options.AzureSpeech.Language); + } + + [Fact] + public void NamedProfileMergesOverrideOntoDefaultConfiguration() + { + var provider = CreateProvider(new Dictionary + { + ["MeetingAssistant:Hotkey:Toggle"] = "Ctrl+Alt+M", + ["MeetingAssistant:Recording:TranscriptionProvider"] = "azure-speech", + ["MeetingAssistant:AzureSpeech:Region"] = "germanywestcentral", + ["MeetingAssistant:AzureSpeech:Language"] = "de-DE", + ["MeetingAssistant:AzureSpeech:AutoDetectLanguages:0"] = "de-DE", + ["MeetingAssistant:LaunchProfiles:english:Hotkey:Toggle"] = "Ctrl+Alt+E", + ["MeetingAssistant:LaunchProfiles:english:AzureSpeech:Language"] = "en-US", + ["MeetingAssistant:LaunchProfiles:english:AzureSpeech:AutoDetectLanguages:0"] = "en-US" + }); + + var profile = provider.GetRequiredProfile("english"); + + Assert.Equal("english", profile.Name); + Assert.Equal("Ctrl+Alt+E", profile.Options.Hotkey.Toggle); + Assert.Equal("azure-speech", profile.Options.Recording.TranscriptionProvider); + Assert.Equal("germanywestcentral", profile.Options.AzureSpeech.Region); + Assert.Equal("en-US", profile.Options.AzureSpeech.Language); + Assert.Equal(["en-US"], profile.Options.AzureSpeech.AutoDetectLanguages); + } + + [Fact] + public void DuplicateProfileHotkeysAreRejected() + { + var provider = CreateProvider(new Dictionary + { + ["MeetingAssistant:Hotkey:Toggle"] = "Ctrl+Alt+M", + ["MeetingAssistant:LaunchProfiles:english:Hotkey:Toggle"] = "Ctrl+Alt+M" + }); + + var exception = Assert.Throws(() => provider.GetHotkeys()); + Assert.Contains("Ctrl+Alt+M", exception.Message, StringComparison.OrdinalIgnoreCase); + } + + private static ConfigurationLaunchProfileOptionsProvider CreateProvider( + IReadOnlyDictionary values) + { + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(values) + .Build(); + return new ConfigurationLaunchProfileOptionsProvider(configuration); + } +} diff --git a/MeetingAssistant.Tests/MeetingArtifactStoreTests.cs b/MeetingAssistant.Tests/MeetingArtifactStoreTests.cs index c532a18..3de51aa 100644 --- a/MeetingAssistant.Tests/MeetingArtifactStoreTests.cs +++ b/MeetingAssistant.Tests/MeetingArtifactStoreTests.cs @@ -16,9 +16,13 @@ public sealed class MeetingArtifactStoreTests TranscriptPath: Path.Combine(root, "Meetings", "Transcripts", "20260519-transcript.md"), AssistantContextPath: contextPath, SummaryPath: Path.Combine(root, "Meetings", "Summaries", "20260519-summary.md")); + var meetingNote = MeetingNoteTemplate.Create( + "Planning Sync", + DateTimeOffset.Parse("2026-05-19T10:00:00+02:00")); await artifactStore.CreateAssistantContextAsync( artifacts, + meetingNote, "Review previous decisions\nAgree next steps", DateTimeOffset.Parse("2026-05-19T11:00:00+02:00"), CancellationToken.None); @@ -26,7 +30,9 @@ public sealed class MeetingArtifactStoreTests var content = await File.ReadAllTextAsync(contextPath); Assert.Contains("# Assistant Context", content); Assert.StartsWith("---", content, StringComparison.Ordinal); - Assert.Contains("state: transcribing", content); + Assert.Contains("title: Planning Sync", content); + Assert.Contains("start_time: \"2026-05-19T10:00:00.0000000+02:00\"", content); + Assert.Contains("state: collecting metadata", content); Assert.Contains("agenda: |-", content); Assert.Contains(" Review previous decisions", content); Assert.Contains(" Agree next steps", content); @@ -34,6 +40,7 @@ public sealed class MeetingArtifactStoreTests Assert.Contains("meeting: \"[[../Notes/20260519-meeting|Meeting Note]]\"", content); Assert.Contains("transcript: \"[[../Transcripts/20260519-transcript|Transcript]]\"", content); Assert.Contains("summary: \"[[../Summaries/20260519-summary|Summary]]\"", content); + Assert.DoesNotContain("assistant_context:", content); Assert.Contains("[[../Notes/20260519-meeting|Meeting Note]]", content); Assert.Contains("[[../Transcripts/20260519-transcript|Transcript]]", content); Assert.Contains("[[../Summaries/20260519-summary|Summary]]", content); @@ -50,9 +57,13 @@ public sealed class MeetingArtifactStoreTests TranscriptPath: Path.Combine(root, "Meetings", "Transcripts", "20260519-transcript.md"), AssistantContextPath: contextPath, SummaryPath: Path.Combine(root, "Meetings", "Summaries", "20260519-summary.md")); + var meetingNote = MeetingNoteTemplate.Create( + "Planning Sync", + DateTimeOffset.Parse("2026-05-19T10:00:00+02:00")); await artifactStore.CreateAssistantContextAsync( artifacts, + meetingNote, "Initial agenda", DateTimeOffset.Parse("2026-05-19T11:00:00+02:00"), CancellationToken.None); @@ -65,6 +76,8 @@ public sealed class MeetingArtifactStoreTests var content = await File.ReadAllTextAsync(contextPath); Assert.Contains("state: summarizing", content); + Assert.Contains("title: Planning Sync", content); + Assert.Contains("start_time: \"2026-05-19T10:00:00.0000000+02:00\"", content); Assert.Contains("agenda: |-", content); Assert.Contains(" Initial agenda", content); Assert.Contains("scheduled_end: \"2026-05-19T11:00:00.0000000+02:00\"", content); @@ -82,10 +95,82 @@ public sealed class MeetingArtifactStoreTests TranscriptPath: Path.Combine(root, "Meetings", "Transcripts", "20260519-transcript.md"), AssistantContextPath: contextPath, SummaryPath: Path.Combine(root, "Meetings", "Summaries", "20260519-summary.md")); + var meetingNote = MeetingNoteTemplate.Create( + "Planning Sync", + DateTimeOffset.Parse("2026-05-19T10:00:00+02:00")); - await artifactStore.CreateAssistantContextAsync(artifacts, "", null, CancellationToken.None); + await artifactStore.CreateAssistantContextAsync(artifacts, meetingNote, "", null, CancellationToken.None); var content = await File.ReadAllTextAsync(contextPath); Assert.DoesNotContain("scheduled_end:", content); } + + [Fact] + public async Task StoreUpdatesAssistantContextMetadataAndMeetingFrontmatter() + { + var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N")); + var contextPath = Path.Combine(root, "Meetings", "Assistant Context", "20260519-context.md"); + var artifactStore = new MarkdownMeetingArtifactStore(NullLogger.Instance); + var artifacts = new MeetingSessionArtifacts( + MeetingNotePath: Path.Combine(root, "Meetings", "Notes", "20260519-meeting.md"), + TranscriptPath: Path.Combine(root, "Meetings", "Transcripts", "20260519-transcript.md"), + AssistantContextPath: contextPath, + SummaryPath: Path.Combine(root, "Meetings", "Summaries", "20260519-summary.md")); + await artifactStore.CreateAssistantContextAsync( + artifacts, + MeetingNoteTemplate.Create("Meeting 2026-05-19 10:00", DateTimeOffset.Parse("2026-05-19T10:00:00+02:00")), + "", + null, + CancellationToken.None); + + await artifactStore.UpdateAssistantContextMetadataAsync( + artifacts, + MeetingNoteTemplate.Create("Architecture Sync", DateTimeOffset.Parse("2026-05-19T10:00:00+02:00")), + "Calendar agenda", + DateTimeOffset.Parse("2026-05-19T11:00:00+02:00"), + CancellationToken.None); + + var content = await File.ReadAllTextAsync(contextPath); + Assert.Contains("title: Architecture Sync", content); + Assert.Contains("start_time: \"2026-05-19T10:00:00.0000000+02:00\"", content); + Assert.Contains("state: collecting metadata", content); + Assert.Contains("agenda: |-", content); + Assert.Contains(" Calendar agenda", content); + Assert.Contains("scheduled_end: \"2026-05-19T11:00:00.0000000+02:00\"", content); + } + + [Fact] + public async Task StoreUpdatesAssistantContextMeetingEndAndPreservesCalendarMetadata() + { + var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N")); + var contextPath = Path.Combine(root, "Meetings", "Assistant Context", "20260519-context.md"); + var artifactStore = new MarkdownMeetingArtifactStore(NullLogger.Instance); + var artifacts = new MeetingSessionArtifacts( + MeetingNotePath: Path.Combine(root, "Meetings", "Notes", "20260519-meeting.md"), + TranscriptPath: Path.Combine(root, "Meetings", "Transcripts", "20260519-transcript.md"), + AssistantContextPath: contextPath, + SummaryPath: Path.Combine(root, "Meetings", "Summaries", "20260519-summary.md")); + await artifactStore.CreateAssistantContextAsync( + artifacts, + MeetingNoteTemplate.Create("Architecture Sync", DateTimeOffset.Parse("2026-05-19T10:00:00+02:00")), + "Calendar agenda", + DateTimeOffset.Parse("2026-05-19T11:00:00+02:00"), + CancellationToken.None); + + await artifactStore.UpdateAssistantContextMeetingAsync( + artifacts, + MeetingNoteTemplate.Create( + "Architecture Sync", + DateTimeOffset.Parse("2026-05-19T10:00:00+02:00"), + DateTimeOffset.Parse("2026-05-19T10:30:00+02:00")), + CancellationToken.None); + + var content = await File.ReadAllTextAsync(contextPath); + Assert.Contains("title: Architecture Sync", content); + Assert.Contains("start_time: \"2026-05-19T10:00:00.0000000+02:00\"", content); + Assert.Contains("end_time: \"2026-05-19T10:30:00.0000000+02:00\"", content); + Assert.Contains("agenda: |-", content); + Assert.Contains(" Calendar agenda", content); + Assert.Contains("scheduled_end: \"2026-05-19T11:00:00.0000000+02:00\"", content); + } } diff --git a/MeetingAssistant.Tests/MeetingSummaryArtifactResolverTests.cs b/MeetingAssistant.Tests/MeetingSummaryArtifactResolverTests.cs index b83a545..cf877ae 100644 --- a/MeetingAssistant.Tests/MeetingSummaryArtifactResolverTests.cs +++ b/MeetingAssistant.Tests/MeetingSummaryArtifactResolverTests.cs @@ -73,4 +73,56 @@ public sealed class MeetingSummaryArtifactResolverTests Assert.Null(artifacts); } + + [Fact] + public async Task ResolverUsesSuppliedProfileOptionsForSummaryLookup() + { + var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N")); + var defaultRoot = Path.Combine(root, "default"); + var englishRoot = Path.Combine(root, "english"); + var englishNotes = Path.Combine(englishRoot, "Notes"); + var englishSummaries = Path.Combine(englishRoot, "Summaries"); + Directory.CreateDirectory(englishNotes); + Directory.CreateDirectory(englishSummaries); + var notePath = Path.Combine(englishNotes, "meeting.md"); + await File.WriteAllTextAsync( + notePath, + """ + --- + title: Meeting + attendees: + projects: + transcript: "[[../Transcripts/transcript|Transcript]]" + assistant_context: "[[../Assistant Context/context|Assistant Context]]" + summary: "[[../Summaries/summary|Summary]]" + --- + + User notes. + """); + var defaultOptions = Options.Create(new MeetingAssistantOptions + { + Vault = new VaultOptions + { + MeetingNotesFolder = Path.Combine(defaultRoot, "Notes"), + SummariesFolder = Path.Combine(defaultRoot, "Summaries") + } + }); + var profileOptions = new MeetingAssistantOptions + { + Vault = new VaultOptions + { + MeetingNotesFolder = englishNotes, + SummariesFolder = englishSummaries + } + }; + var resolver = new MeetingSummaryArtifactResolver( + defaultOptions, + new MarkdownMeetingNoteStore(defaultOptions, NullLogger.Instance)); + + var artifacts = await resolver.ResolveBySummaryPathAsync("summary.md", profileOptions, CancellationToken.None); + + Assert.NotNull(artifacts); + Assert.Equal(notePath, artifacts.MeetingNotePath); + Assert.Equal(Path.Combine(englishSummaries, "summary.md"), artifacts.SummaryPath); + } } diff --git a/MeetingAssistant.Tests/MeetingSummaryFailureWriterTests.cs b/MeetingAssistant.Tests/MeetingSummaryFailureWriterTests.cs index c648003..d930970 100644 --- a/MeetingAssistant.Tests/MeetingSummaryFailureWriterTests.cs +++ b/MeetingAssistant.Tests/MeetingSummaryFailureWriterTests.cs @@ -55,6 +55,9 @@ public sealed class MeetingSummaryFailureWriterTests Assert.Contains("Summary Generation Failed", content); Assert.Contains("title: Failure Meeting", content); Assert.Contains("meeting: \"[[../Notes/meeting|Meeting Note]]\"", content); + Assert.Contains("transcript: \"[[../Transcripts/transcript|Transcript]]\"", content); + Assert.Contains("assistant_context: \"[[../Assistant Context/context|Assistant Context]]\"", content); + Assert.DoesNotContain("summary:", content); Assert.Contains( "[Retry summary generation](http://localhost:5090/meetings/summary/retry?summaryPath=summary.md)", content); diff --git a/MeetingAssistant.Tests/MeetingSummaryToolTests.cs b/MeetingAssistant.Tests/MeetingSummaryToolTests.cs index 292ba1b..fc39195 100644 --- a/MeetingAssistant.Tests/MeetingSummaryToolTests.cs +++ b/MeetingAssistant.Tests/MeetingSummaryToolTests.cs @@ -1,5 +1,7 @@ using MeetingAssistant.MeetingNotes; using MeetingAssistant.Summary; +using MeetingAssistant.Transcription; +using Microsoft.Extensions.Options; namespace MeetingAssistant.Tests; @@ -55,6 +57,7 @@ public sealed class MeetingSummaryToolTests Assert.Contains("meeting: \"[[../Notes/meeting|Meeting Note]]\"", summary); Assert.Contains("transcript: \"[[../Transcripts/transcript|Transcript]]\"", summary); Assert.Contains("assistant_context: \"[[../Assistant Context/context|Assistant Context]]\"", summary); + Assert.DoesNotContain("summary:", summary); Assert.Contains("# Summary\n\n- Done.", summary); } @@ -142,4 +145,63 @@ public sealed class MeetingSummaryToolTests Assert.Contains("state: summarizing", context); Assert.Contains("replacement\ninserted\nline two", context); } + + [Fact] + public async Task ExternalAgentWritesAreAppendedToAssistantContextAsDiffs() + { + var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N")); + var projectsRoot = Path.Combine(root, "Projects"); + var projectRoot = Path.Combine(projectsRoot, "MeetingAssistant"); + var projectFile = Path.Combine(projectRoot, "notes.md"); + var dictionaryPath = Path.Combine(root, "Meetings", "Dictionary.md"); + var artifacts = new MeetingSessionArtifacts( + MeetingNotePath: Path.Combine(root, "Meetings", "Notes", "meeting.md"), + TranscriptPath: Path.Combine(root, "Meetings", "Transcripts", "transcript.md"), + AssistantContextPath: Path.Combine(root, "Meetings", "Assistant Context", "context.md"), + SummaryPath: Path.Combine(root, "Meetings", "Summaries", "summary.md")); + Directory.CreateDirectory(projectRoot); + Directory.CreateDirectory(Path.GetDirectoryName(artifacts.MeetingNotePath)!); + Directory.CreateDirectory(Path.GetDirectoryName(artifacts.AssistantContextPath)!); + await File.WriteAllTextAsync(projectFile, "one\ntwo\nthree"); + await File.WriteAllTextAsync( + artifacts.MeetingNotePath, + """ + --- + title: Meeting + projects: + - MeetingAssistant + --- + """); + await File.WriteAllTextAsync(artifacts.AssistantContextPath, "Context before."); + var options = new MeetingAssistantOptions + { + Vault = + { + DictationWordsPath = dictionaryPath, + ProjectsFolder = projectsRoot + } + }; + var audit = new SummaryAgentWriteAudit(artifacts); + var tools = new MeetingSummaryTools( + artifacts, + options, + new MarkdownDictationWordStore(Options.Create(options)), + audit); + + await tools.WriteContext("owned context"); + await tools.WriteSummary("owned summary"); + await tools.WriteProjectFile("MeetingAssistant", "notes.md", "TWO", from: 2, to: 2); + await tools.AddDictationWord("PBI"); + await audit.AppendToAssistantContextAsync(CancellationToken.None); + + var context = await File.ReadAllTextAsync(artifacts.AssistantContextPath); + Assert.Contains("## Summary Agent External File Changes", context); + Assert.Contains(projectFile, context); + Assert.Contains("- two", context); + Assert.Contains("+ TWO", context); + Assert.Contains(dictionaryPath, context); + Assert.Contains("+ - PBI", context); + Assert.DoesNotContain("owned summary", context); + Assert.DoesNotContain("- Context before.", context); + } } diff --git a/MeetingAssistant.Tests/RecordingCoordinatorTests.cs b/MeetingAssistant.Tests/RecordingCoordinatorTests.cs index 04b1900..f7a3dd1 100644 --- a/MeetingAssistant.Tests/RecordingCoordinatorTests.cs +++ b/MeetingAssistant.Tests/RecordingCoordinatorTests.cs @@ -1,8 +1,10 @@ using MeetingAssistant.Recording; +using MeetingAssistant.LaunchProfiles; using MeetingAssistant.Speakers; using MeetingAssistant.Transcription; using MeetingAssistant.MeetingNotes; using MeetingAssistant.Summary; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using System.Threading.Channels; @@ -105,6 +107,8 @@ public sealed class RecordingCoordinatorTests Assert.Equal("C:\\Vault\\Meetings\\Transcripts\\20260519-transcript.md", artifactStore.CreatedArtifacts?.TranscriptPath); Assert.StartsWith("C:\\Vault\\Meetings\\Assistant Context\\", artifactStore.CreatedArtifacts?.AssistantContextPath, StringComparison.Ordinal); Assert.StartsWith("C:\\Vault\\Meetings\\Summaries\\", artifactStore.CreatedArtifacts?.SummaryPath, StringComparison.Ordinal); + Assert.Equal(noteStore.SavedNote?.Frontmatter.Title, artifactStore.ContextMeetingNote?.Frontmatter.Title); + Assert.Equal(noteStore.SavedNote?.Frontmatter.StartTime, artifactStore.ContextMeetingNote?.Frontmatter.StartTime); await coordinator.StopAsync(CancellationToken.None); } @@ -137,12 +141,47 @@ public sealed class RecordingCoordinatorTests Assert.Equal("Architecture Sync", noteStore.SavedNote?.Frontmatter.Title); Assert.Equal(["Ada ", "Grace"], noteStore.SavedNote?.Frontmatter.Attendees); + Assert.Equal("Architecture Sync", artifactStore.ContextMeetingNote?.Frontmatter.Title); Assert.Equal("Review API shape", artifactStore.Agenda); Assert.Equal(DateTimeOffset.Parse("2026-05-19T11:00:00+02:00"), artifactStore.ScheduledEnd); await coordinator.StopAsync(CancellationToken.None); } + [Fact] + public async Task StartCanonicalizesOutlookMeetingAttendeesBeforeWritingNote() + { + var audioSource = new ControlledAudioSource(); + var noteStore = new InMemoryMeetingNoteStore("C:\\Vault\\Meetings\\Notes\\metadata-meeting.md"); + var artifactStore = new InMemoryMeetingArtifactStore(); + var coordinator = new MeetingRecordingCoordinator( + audioSource, + new TestSpeechRecognitionPipelineFactory(new EchoStreamingTranscriptionProvider()), + new InMemoryTranscriptStore(), + noteStore, + new CapturingMeetingNoteOpener(), + artifactStore, + new InMemoryRecordedAudioStore(), + new CapturingMeetingSummaryPipeline(), + Options.Create(new MeetingAssistantOptions()), + NullLogger.Instance, + meetingMetadataProvider: new FixedMeetingMetadataProvider(new MeetingMetadata( + "Architecture Sync", + ["Karl Berger ", "Berger, Karl ", "Ada"], + "", + null)), + attendeeCanonicalizer: new FixedAttendeeCanonicalizer(["Karl Berger", "Ada"])); + + await coordinator.StartAsync(CancellationToken.None); + await WaitUntilAsync(() => + noteStore.SavedNote?.Frontmatter.Title == "Architecture Sync" && + noteStore.SavedNote.Frontmatter.Attendees.Count > 0); + + Assert.Equal(["Karl Berger", "Ada"], noteStore.SavedNote?.Frontmatter.Attendees); + + await coordinator.StopAsync(CancellationToken.None); + } + [Fact] public async Task StartDoesNotWaitForSlowMeetingMetadataButAppliesItLater() { @@ -182,6 +221,61 @@ public sealed class RecordingCoordinatorTests await coordinator.StopAsync(CancellationToken.None); } + [Fact] + public async Task StartCanCreateNewRunWhilePreviousRunIsStillFinalizing() + { + var audioSource = new ControlledAudioSource(); + var transcriptStore = new SequencedTranscriptStore(); + var noteStore = new SequencedMeetingNoteStore(); + var artifactStore = new CapturingArtifactStore(); + var summaryPipeline = new RecordingSummaryPipeline(); + var finalizer = new BlockingFirstFinalizer(); + var coordinator = new MeetingRecordingCoordinator( + audioSource, + new TestSpeechRecognitionPipelineFactory( + new EchoStreamingTranscriptionProvider(), + finalizer.FinalizeAsync), + transcriptStore, + noteStore, + new CapturingMeetingNoteOpener(), + artifactStore, + new InMemoryRecordedAudioStore(), + summaryPipeline, + Options.Create(new MeetingAssistantOptions()), + NullLogger.Instance); + + var firstStarted = await coordinator.StartAsync(CancellationToken.None); + await audioSource.WriteAsync(new AudioChunk([1, 0], 16000, 1), CancellationToken.None); + await transcriptStore.WaitForAppendCountAsync(1); + + var stopFirst = coordinator.StopAsync(CancellationToken.None); + await finalizer.WaitUntilFirstFinalizerIsBlockedAsync(); + var secondStarted = await coordinator.StartAsync(CancellationToken.None); + await audioSource.WriteAsync(new AudioChunk([2, 0, 3, 0], 16000, 1), CancellationToken.None); + await transcriptStore.WaitForAppendCountAsync(2); + finalizer.ReleaseFirstFinalizer(); + await stopFirst.WaitAsync(TimeSpan.FromSeconds(5)); + await coordinator.StopAsync(CancellationToken.None); + + Assert.True(secondStarted.IsRecording); + Assert.NotEqual(firstStarted.TranscriptPath, secondStarted.TranscriptPath); + Assert.NotEqual(firstStarted.MeetingNotePath, secondStarted.MeetingNotePath); + Assert.Contains(summaryPipeline.ArtifactHistory, artifacts => artifacts.MeetingNotePath == firstStarted.MeetingNotePath); + Assert.Contains(summaryPipeline.ArtifactHistory, artifacts => artifacts.MeetingNotePath == secondStarted.MeetingNotePath); + Assert.Contains(transcriptStore.ReplacementHistory, entry => + entry.Session.TranscriptPath == firstStarted.TranscriptPath && + entry.Segments.Single().Text == "final run 1"); + Assert.Contains(transcriptStore.ReplacementHistory, entry => + entry.Session.TranscriptPath == secondStarted.TranscriptPath && + entry.Segments.Single().Text == "final run 2"); + Assert.All( + transcriptStore.MetadataHistory.Where(entry => entry.Session.TranscriptPath == firstStarted.TranscriptPath), + entry => Assert.Equal(firstStarted.MeetingNotePath, entry.MeetingNote.Path)); + Assert.All( + transcriptStore.MetadataHistory.Where(entry => entry.Session.TranscriptPath == secondStarted.TranscriptPath), + entry => Assert.Equal(secondStarted.MeetingNotePath, entry.MeetingNote.Path)); + } + [Fact] public async Task StartCreatesMeetingNoteWhenMetadataProviderFails() { @@ -300,6 +394,63 @@ public sealed class RecordingCoordinatorTests await coordinator.StopAsync(CancellationToken.None); } + [Fact] + public async Task StartPassesLaunchProfileToSpeechPipelineFactory() + { + var audioSource = new ControlledAudioSource(); + var pipelineFactory = new CapturingProfileSpeechRecognitionPipelineFactory(new EchoStreamingTranscriptionProvider()); + var launchProfiles = CreateLaunchProfiles( + Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N"), "default"), + Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N"), "english")); + var coordinator = new MeetingRecordingCoordinator( + audioSource, + pipelineFactory, + new InMemoryTranscriptStore(), + new InMemoryMeetingNoteStore(), + new CapturingMeetingNoteOpener(), + new InMemoryMeetingArtifactStore(), + new InMemoryRecordedAudioStore(), + new CapturingMeetingSummaryPipeline(), + Options.Create(launchProfiles.GetRequiredProfile(null).Options), + NullLogger.Instance, + launchProfiles: launchProfiles); + + await coordinator.StartAsync("english", CancellationToken.None); + + Assert.Equal("english", pipelineFactory.LastProfileName); + await coordinator.StopAsync(CancellationToken.None); + } + + [Fact] + public async Task StartUsesLaunchProfileStorageAndSummaryOptions() + { + var defaultRoot = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N"), "default"); + var englishRoot = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N"), "english"); + var launchProfiles = CreateLaunchProfiles(defaultRoot, englishRoot); + var summaryPipeline = new CapturingMeetingSummaryPipeline(); + var coordinator = new MeetingRecordingCoordinator( + new CapturedChunkThenCancelAudioSource(new AudioChunk([1, 0], 16000, 1)), + new TestSpeechRecognitionPipelineFactory(new FinalSegmentOnAudioCompletionProvider()), + new ProfileAwareTranscriptStore(), + new ProfileAwareMeetingNoteStore(), + new CapturingMeetingNoteOpener(), + new InMemoryMeetingArtifactStore(), + new ProfileAwareRecordedAudioStore(), + summaryPipeline, + Options.Create(launchProfiles.GetRequiredProfile(null).Options), + NullLogger.Instance, + launchProfiles: launchProfiles); + + var started = await coordinator.StartAsync("english", CancellationToken.None); + await coordinator.StopAsync(CancellationToken.None); + + Assert.StartsWith(Path.Combine(englishRoot, "Transcripts"), started.TranscriptPath, StringComparison.OrdinalIgnoreCase); + Assert.StartsWith(Path.Combine(englishRoot, "Notes"), started.MeetingNotePath, StringComparison.OrdinalIgnoreCase); + Assert.StartsWith(Path.Combine(englishRoot, "Context"), started.AssistantContextPath, StringComparison.OrdinalIgnoreCase); + Assert.StartsWith(Path.Combine(englishRoot, "Summaries"), started.SummaryPath, StringComparison.OrdinalIgnoreCase); + Assert.Equal("english-summary-model", summaryPipeline.Options?.Agent.Model); + } + [Fact] public async Task StartPassesDictationWordsToSpeechPipeline() { @@ -512,9 +663,9 @@ public sealed class RecordingCoordinatorTests await coordinator.StartAsync(CancellationToken.None); await audioSource.WriteAsync(new AudioChunk(Samples(0, 1, 2, 3, 4, 5, 6, 7), 4, 1), CancellationToken.None); - await WaitUntilAsync(() => transcriptStore.Segments.Any(segment => segment.Text.Contains("first", StringComparison.Ordinal))); + await WaitUntilAsync(() => transcriptStore.Segments.Any(segment => segment.Text?.Contains("first", StringComparison.Ordinal) == true)); await speakerIdentification.IdentificationObserved.Task.WaitAsync(TimeSpan.FromSeconds(5)); - await WaitUntilAsync(() => transcriptStore.ReplacedSegments.Any(segment => segment.Text.Contains("first", StringComparison.Ordinal))); + await WaitUntilAsync(() => transcriptStore.ReplacedSegments.Any(segment => segment.Text?.Contains("first", StringComparison.Ordinal) == true)); Assert.Equal("Chris", transcriptStore.ReplacedSegments.Single().Speaker); await Task.Delay(50); await audioSource.WriteAsync(new AudioChunk(Samples(8, 9, 10, 11, 12, 13, 14, 15), 4, 1), CancellationToken.None); @@ -528,7 +679,7 @@ public sealed class RecordingCoordinatorTests second => Assert.Equal("Chris", second.Speaker)); Assert.Contains( transcriptStore.ReplacedSegments, - segment => segment.Text.Contains("first", StringComparison.Ordinal) && segment.Speaker == "Chris"); + segment => segment.Text?.Contains("first", StringComparison.Ordinal) == true && segment.Speaker == "Chris"); } [Fact] @@ -714,13 +865,14 @@ public sealed class RecordingCoordinatorTests { var audioSource = new CapturedChunkThenCancelAudioSource(new AudioChunk([1, 0, 2, 0], 16000, 1)); var transcriptStore = new InMemoryTranscriptStore(); + var artifactStore = new InMemoryMeetingArtifactStore(); var coordinator = new MeetingRecordingCoordinator( audioSource, new TestSpeechRecognitionPipelineFactory(new FinalSegmentOnAudioCompletionProvider()), transcriptStore, new InMemoryMeetingNoteStore(), new CapturingMeetingNoteOpener(), - new InMemoryMeetingArtifactStore(), + artifactStore, new InMemoryRecordedAudioStore(), new CapturingMeetingSummaryPipeline(), Options.Create(new MeetingAssistantOptions()), @@ -732,6 +884,7 @@ public sealed class RecordingCoordinatorTests await coordinator.StopAsync(CancellationToken.None); Assert.NotNull(transcriptStore.MetadataMeetingNote?.Frontmatter.EndTime); + Assert.Equal(transcriptStore.MetadataMeetingNote?.Frontmatter.EndTime, artifactStore.ContextMeetingNote?.Frontmatter.EndTime); } [Fact] @@ -757,7 +910,7 @@ public sealed class RecordingCoordinatorTests await coordinator.StopAsync(CancellationToken.None); Assert.Equal( - [AssistantContextState.Summarizing, AssistantContextState.Finished], + [AssistantContextState.Transcribing, AssistantContextState.Summarizing, AssistantContextState.Finished], artifactStore.States); } @@ -784,7 +937,7 @@ public sealed class RecordingCoordinatorTests await coordinator.StopAsync(CancellationToken.None); Assert.Equal( - [AssistantContextState.Summarizing, AssistantContextState.Error], + [AssistantContextState.Transcribing, AssistantContextState.Summarizing, AssistantContextState.Error], artifactStore.States); } @@ -818,7 +971,7 @@ public sealed class RecordingCoordinatorTests await coordinator.StopAsync(CancellationToken.None); Assert.Equal( - [AssistantContextState.SpeakerRecognition, AssistantContextState.Summarizing, AssistantContextState.Finished], + [AssistantContextState.Transcribing, AssistantContextState.SpeakerRecognition, AssistantContextState.Summarizing, AssistantContextState.Finished], artifactStore.States); } @@ -842,6 +995,23 @@ public sealed class RecordingCoordinatorTests Assert.True(Directory.Exists(vaultFolder)); Assert.EndsWith(".md", session.TranscriptPath, StringComparison.Ordinal); Assert.Contains("hello vault", await File.ReadAllTextAsync(session.TranscriptPath)); + + var artifacts = new MeetingSessionArtifacts( + MeetingNotePath: Path.Combine(vaultFolder, "meeting.md"), + TranscriptPath: session.TranscriptPath, + AssistantContextPath: Path.Combine(vaultFolder, "context.md"), + SummaryPath: Path.Combine(vaultFolder, "summary.md")); + await store.UpdateMetadataAsync( + session, + artifacts, + MeetingNoteTemplate.Create("Transcript Metadata", transcriptPath: session.TranscriptPath), + CancellationToken.None); + + var content = await File.ReadAllTextAsync(session.TranscriptPath); + Assert.Contains("meeting: \"[[meeting|Meeting Note]]\"", content); + Assert.Contains("assistant_context: \"[[context|Assistant Context]]\"", content); + Assert.Contains("summary: \"[[summary|Summary]]\"", content); + Assert.DoesNotContain("transcript:", content); } [Fact] @@ -903,6 +1073,29 @@ public sealed class RecordingCoordinatorTests }; } + private static ILaunchProfileOptionsProvider CreateLaunchProfiles( + string defaultRoot, + string englishRoot) + { + var configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + ["MeetingAssistant:Vault:BaseFolder"] = defaultRoot, + ["MeetingAssistant:Vault:TranscriptsFolder"] = "Transcripts", + ["MeetingAssistant:Vault:MeetingNotesFolder"] = "Notes", + ["MeetingAssistant:Vault:AssistantContextFolder"] = "Context", + ["MeetingAssistant:Vault:SummariesFolder"] = "Summaries", + ["MeetingAssistant:Recording:TemporaryRecordingsFolder"] = Path.Combine(defaultRoot, "Recordings"), + ["MeetingAssistant:Agent:Model"] = "default-summary-model", + ["MeetingAssistant:LaunchProfiles:english:Hotkey:Toggle"] = "Ctrl+Alt+E", + ["MeetingAssistant:LaunchProfiles:english:Vault:BaseFolder"] = englishRoot, + ["MeetingAssistant:LaunchProfiles:english:Recording:TemporaryRecordingsFolder"] = Path.Combine(englishRoot, "Recordings"), + ["MeetingAssistant:LaunchProfiles:english:Agent:Model"] = "english-summary-model" + }) + .Build(); + return new ConfigurationLaunchProfileOptionsProvider(configuration); + } + private sealed class InMemoryTranscriptStore : ITranscriptStore { private readonly List segments = []; @@ -931,7 +1124,7 @@ public sealed class RecordingCoordinatorTests var deadline = DateTimeOffset.UtcNow.AddSeconds(5); while (DateTimeOffset.UtcNow < deadline) { - if (segments.Any(segment => segment.Text.Contains(text, StringComparison.Ordinal))) + if (segments.Any(segment => segment.Text?.Contains(text, StringComparison.Ordinal) == true)) { return; } @@ -968,6 +1161,82 @@ public sealed class RecordingCoordinatorTests } } + private sealed class SequencedTranscriptStore : ITranscriptStore + { + private int created; + private int appendCount; + private TaskCompletionSource appendObserved = new(TaskCreationOptions.RunContinuationsAsynchronously); + + public List AppendHistory { get; } = []; + + public List ReplacementHistory { get; } = []; + + public List MetadataHistory { get; } = []; + + public Task CreateSessionAsync(CancellationToken cancellationToken) + { + var index = Interlocked.Increment(ref created); + return Task.FromResult(new TranscriptSession($"memory-transcript-{index}.md")); + } + + public Task AppendAsync(TranscriptSession session, TranscriptionSegment segment, CancellationToken cancellationToken) + { + AppendHistory.Add(new TranscriptWrite(session, segment)); + Interlocked.Increment(ref appendCount); + appendObserved.TrySetResult(); + return Task.CompletedTask; + } + + public async Task WaitForAppendCountAsync(int expectedCount) + { + var deadline = DateTimeOffset.UtcNow.AddSeconds(5); + while (DateTimeOffset.UtcNow < deadline) + { + if (Volatile.Read(ref appendCount) >= expectedCount) + { + return; + } + + var observed = appendObserved; + await observed.Task.WaitAsync(TimeSpan.FromMilliseconds(100)); + if (ReferenceEquals(observed, appendObserved)) + { + appendObserved = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + } + } + + throw new TimeoutException($"Expected {expectedCount} transcript append(s)."); + } + + public Task ReplaceAsync( + TranscriptSession session, + IReadOnlyList replacementSegments, + CancellationToken cancellationToken) + { + ReplacementHistory.Add(new TranscriptReplacement(session, replacementSegments)); + return Task.CompletedTask; + } + + public Task UpdateMetadataAsync( + TranscriptSession session, + MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, + CancellationToken cancellationToken) + { + MetadataHistory.Add(new TranscriptMetadataUpdate(session, artifacts, meetingNote)); + return Task.CompletedTask; + } + + public sealed record TranscriptWrite(TranscriptSession Session, TranscriptionSegment Segment); + + public sealed record TranscriptReplacement(TranscriptSession Session, IReadOnlyList Segments); + + public sealed record TranscriptMetadataUpdate( + TranscriptSession Session, + MeetingSessionArtifacts Artifacts, + MeetingNote MeetingNote); + } + private sealed class InMemoryMeetingNoteStore : IMeetingNoteStore { private readonly string notePath; @@ -1006,6 +1275,29 @@ public sealed class RecordingCoordinatorTests } } + private sealed class SequencedMeetingNoteStore : IMeetingNoteStore + { + private int saved; + private readonly Dictionary notes = new(StringComparer.OrdinalIgnoreCase); + + public Task SaveAsync(MeetingNote note, CancellationToken cancellationToken) + { + var path = string.IsNullOrWhiteSpace(note.Path) + ? $"memory-meeting-{Interlocked.Increment(ref saved)}.md" + : note.Path; + var savedNote = note with { Path = path }; + notes[path] = savedNote; + return Task.FromResult(savedNote); + } + + public Task ReadAsync(string path, CancellationToken cancellationToken) + { + return Task.FromResult(notes.TryGetValue(path, out var note) + ? note + : throw new FileNotFoundException(path)); + } + } + private sealed class CapturingMeetingNoteOpener : IMeetingNoteOpener { public string? OpenedPath { get; private set; } @@ -1027,13 +1319,17 @@ public sealed class RecordingCoordinatorTests public DateTimeOffset? ScheduledEnd { get; private set; } + public MeetingNote? ContextMeetingNote { get; private set; } + public Task CreateAssistantContextAsync( MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, string agenda, DateTimeOffset? scheduledEnd, CancellationToken cancellationToken) { CreatedArtifacts = artifacts; + ContextMeetingNote = meetingNote; Agenda = agenda; ScheduledEnd = scheduledEnd; return Task.CompletedTask; @@ -1050,14 +1346,70 @@ public sealed class RecordingCoordinatorTests public Task UpdateAssistantContextMetadataAsync( MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, string agenda, DateTimeOffset? scheduledEnd, CancellationToken cancellationToken) { + ContextMeetingNote = meetingNote; Agenda = agenda; ScheduledEnd = scheduledEnd; return Task.CompletedTask; } + + public Task UpdateAssistantContextMeetingAsync( + MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, + CancellationToken cancellationToken) + { + ContextMeetingNote = meetingNote; + return Task.CompletedTask; + } + } + + private sealed class CapturingArtifactStore : IMeetingArtifactStore + { + public List CreatedArtifacts { get; } = []; + + public List<(MeetingSessionArtifacts Artifacts, AssistantContextState State)> States { get; } = []; + + public Task CreateAssistantContextAsync( + MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, + string agenda, + DateTimeOffset? scheduledEnd, + CancellationToken cancellationToken) + { + CreatedArtifacts.Add(artifacts); + return Task.CompletedTask; + } + + public Task UpdateAssistantContextMetadataAsync( + MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, + string agenda, + DateTimeOffset? scheduledEnd, + CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public Task UpdateAssistantContextMeetingAsync( + MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, + CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public Task UpdateAssistantContextStateAsync( + MeetingSessionArtifacts artifacts, + AssistantContextState state, + CancellationToken cancellationToken) + { + States.Add((artifacts, state)); + return Task.CompletedTask; + } } private sealed class FixedMeetingMetadataProvider : IMeetingMetadataProvider @@ -1130,6 +1482,8 @@ public sealed class RecordingCoordinatorTests public MeetingSessionArtifacts? Artifacts { get; private set; } + public MeetingAssistantOptions? Options { get; private set; } + public Task RunAsync( MeetingSessionArtifacts artifacts, CancellationToken cancellationToken) @@ -1141,6 +1495,192 @@ public sealed class RecordingCoordinatorTests succeeded, succeeded ? null : "error")); } + + public Task RunAsync( + MeetingSessionArtifacts artifacts, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + Options = options; + return RunAsync(artifacts, cancellationToken); + } + } + + private sealed class RecordingSummaryPipeline : IMeetingSummaryPipeline + { + public List ArtifactHistory { get; } = []; + + public Task RunAsync( + MeetingSessionArtifacts artifacts, + CancellationToken cancellationToken) + { + ArtifactHistory.Add(artifacts); + return Task.FromResult(new MeetingSummaryRunResult(artifacts.SummaryPath, "summary ok")); + } + + public Task RunAsync( + MeetingSessionArtifacts artifacts, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return RunAsync(artifacts, cancellationToken); + } + } + + private sealed class BlockingFirstFinalizer + { + private readonly TaskCompletionSource firstFinalizerBlocked = + new(TaskCreationOptions.RunContinuationsAsynchronously); + private readonly TaskCompletionSource releaseFirstFinalizer = + new(TaskCreationOptions.RunContinuationsAsynchronously); + private int calls; + + public Task WaitUntilFirstFinalizerIsBlockedAsync() + { + return firstFinalizerBlocked.Task.WaitAsync(TimeSpan.FromSeconds(5)); + } + + public void ReleaseFirstFinalizer() + { + releaseFirstFinalizer.TrySetResult(); + } + + public async Task> FinalizeAsync( + string audioPath, + IReadOnlyList liveSegments, + SpeechRecognitionPipelineOptions options, + CancellationToken cancellationToken) + { + var call = Interlocked.Increment(ref calls); + if (call == 1) + { + firstFinalizerBlocked.TrySetResult(); + await releaseFirstFinalizer.Task.WaitAsync(cancellationToken); + } + + return + [ + new TranscriptionSegment( + TimeSpan.Zero, + TimeSpan.FromSeconds(1), + "Unknown", + $"final run {call}") + ]; + } + } + + private sealed class ProfileAwareTranscriptStore : ITranscriptStore + { + public Task CreateSessionAsync(CancellationToken cancellationToken) + { + throw new InvalidOperationException("Profile options were not supplied."); + } + + public Task CreateSessionAsync( + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + var folder = VaultPath.Resolve(options.Vault, options.Vault.TranscriptsFolder); + return Task.FromResult(new TranscriptSession(Path.Combine(folder, "transcript.md"))); + } + + public Task AppendAsync(TranscriptSession session, TranscriptionSegment segment, CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public Task ReplaceAsync( + TranscriptSession session, + IReadOnlyList replacementSegments, + CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public Task UpdateMetadataAsync( + TranscriptSession session, + MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, + CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + } + + private sealed class ProfileAwareMeetingNoteStore : IMeetingNoteStore + { + private MeetingNote? savedNote; + + public Task SaveAsync(MeetingNote note, CancellationToken cancellationToken) + { + throw new InvalidOperationException("Profile options were not supplied."); + } + + public Task SaveAsync( + MeetingNote note, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + var folder = VaultPath.Resolve(options.Vault, options.Vault.MeetingNotesFolder); + savedNote = note with { Path = string.IsNullOrWhiteSpace(note.Path) ? Path.Combine(folder, "meeting.md") : note.Path }; + return Task.FromResult(savedNote); + } + + public Task ReadAsync(string path, CancellationToken cancellationToken) + { + return Task.FromResult(savedNote ?? throw new FileNotFoundException(path)); + } + } + + private sealed class ProfileAwareRecordedAudioStore : IRecordedAudioStore + { + public Task CreateSessionAsync(CancellationToken cancellationToken) + { + throw new InvalidOperationException("Profile options were not supplied."); + } + + public Task CreateSessionAsync( + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + var folder = VaultPath.Resolve(options.Recording.TemporaryRecordingsFolder); + return Task.FromResult(new Sink(Path.Combine(folder, "recording.wav"))); + } + + public Task DeleteStaleRecordingsAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + private sealed class Sink : IRecordedAudioSink + { + public Sink(string audioPath) + { + AudioPath = audioPath; + } + + public string AudioPath { get; } + + public Task AppendAsync(AudioChunk chunk, CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public Task CompleteAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public ValueTask DisposeAsync() + { + return ValueTask.CompletedTask; + } + + public Task DeleteAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + } } private sealed class InMemoryRecordedAudioStore : IRecordedAudioStore @@ -1233,6 +1773,31 @@ public sealed class RecordingCoordinatorTests } } + private sealed class CapturingProfileSpeechRecognitionPipelineFactory : ISpeechRecognitionPipelineFactory + { + private readonly IStreamingTranscriptionProvider provider; + + public CapturingProfileSpeechRecognitionPipelineFactory(IStreamingTranscriptionProvider provider) + { + this.provider = provider; + } + + public string? LastProfileName { get; private set; } + + public ISpeechRecognitionPipeline Create() + { + return Create(null); + } + + public ISpeechRecognitionPipeline Create(string? launchProfileName) + { + LastProfileName = launchProfileName; + return new TestSpeechRecognitionPipeline( + provider, + (_, _, _, _) => Task.FromResult>([])); + } + } + private sealed class TestSpeechRecognitionPipeline : StreamingSpeechRecognitionPipeline { private readonly Func, SpeechRecognitionPipelineOptions, CancellationToken, Task>> finalize; @@ -1397,6 +1962,23 @@ public sealed class RecordingCoordinatorTests } } + private sealed class FixedAttendeeCanonicalizer : ISpeakerIdentityAttendeeCanonicalizer + { + private readonly IReadOnlyList attendees; + + public FixedAttendeeCanonicalizer(IReadOnlyList attendees) + { + this.attendees = attendees; + } + + public Task> CanonicalizeAsync( + IReadOnlyList attendees, + CancellationToken cancellationToken) + { + return Task.FromResult(this.attendees); + } + } + private sealed class CapturingPipelineOptionsProvider : IStreamingTranscriptionProvider { public TaskCompletionSource OptionsObserved { get; } = diff --git a/MeetingAssistant.Tests/SpeakerIdentityMergeServiceTests.cs b/MeetingAssistant.Tests/SpeakerIdentityMergeServiceTests.cs index 7e5d87f..32e17d4 100644 --- a/MeetingAssistant.Tests/SpeakerIdentityMergeServiceTests.cs +++ b/MeetingAssistant.Tests/SpeakerIdentityMergeServiceTests.cs @@ -17,13 +17,13 @@ public sealed class SpeakerIdentityMergeServiceTests aliases: ["M. Schweigert"], snippets: [[1], [2], [3]], createdAt: DateTimeOffset.UtcNow.AddMonths(-2), - transcriptionCount: 5); + referenceCount: 5); var recent = await fixture.AddIdentityAsync( canonicalName: "Guest Manuel", aliases: [], snippets: [[4], [5]], createdAt: DateTimeOffset.UtcNow.AddDays(-1), - transcriptionCount: 2); + referenceCount: 2); fixture.Matcher.MatchIdentityIds.Enqueue(older.Id); fixture.Matcher.MatchIdentityIds.Enqueue(older.Id); var service = fixture.CreateService(); @@ -36,7 +36,9 @@ public sealed class SpeakerIdentityMergeServiceTests Assert.Equal([5], fixture.Matcher.Requests[1].UnknownSnippet); var savedOlder = await fixture.LoadIdentityAsync(older.Id); Assert.Equal("Manuel", savedOlder.CanonicalName); - Assert.Equal(7, savedOlder.TranscriptionCount); + Assert.Equal(7, savedOlder.References.Count); + Assert.All(savedOlder.References, reference => + Assert.Contains("Manuel and Guest Manuel were merged", File.ReadAllText(reference.TranscriptPath))); Assert.True(savedOlder.UpdatedAt > older.UpdatedAt); Assert.Equal(["Guest Manuel", "M. Schweigert"], savedOlder.Aliases.Select(alias => alias.Name).Order()); Assert.Equal(3, savedOlder.Snippets.Count); @@ -74,10 +76,12 @@ public sealed class SpeakerIdentityMergeServiceTests private sealed class SpeakerIdentityMergeFixture : IAsyncDisposable { + private readonly string tempDirectory; private readonly string dbPath; - private SpeakerIdentityMergeFixture(string dbPath, SpeakerIdentityDbContext context) + private SpeakerIdentityMergeFixture(string tempDirectory, string dbPath, SpeakerIdentityDbContext context) { + this.tempDirectory = tempDirectory; this.dbPath = dbPath; Context = context; } @@ -88,13 +92,14 @@ public sealed class SpeakerIdentityMergeServiceTests public static async Task CreateAsync() { - var dbPath = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", $"{Guid.NewGuid():N}.db"); - Directory.CreateDirectory(Path.GetDirectoryName(dbPath)!); + var tempDirectory = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(tempDirectory); + var dbPath = Path.Combine(tempDirectory, "speaker-identities.db"); var context = new SpeakerIdentityDbContext(new DbContextOptionsBuilder() .UseSqlite($"Data Source={dbPath};Pooling=False") .Options); await SpeakerIdentitySchema.EnsureCreatedOrUpdatedAsync(context, CancellationToken.None); - return new SpeakerIdentityMergeFixture(dbPath, context); + return new SpeakerIdentityMergeFixture(tempDirectory, dbPath, context); } public SpeakerIdentityMergeService CreateService() @@ -118,14 +123,13 @@ public sealed class SpeakerIdentityMergeServiceTests IReadOnlyList aliases, IReadOnlyList snippets, DateTimeOffset createdAt, - int transcriptionCount) + int referenceCount) { var identity = new SpeakerIdentity { CanonicalName = canonicalName, CreatedAt = createdAt, UpdatedAt = createdAt, - TranscriptionCount = transcriptionCount, Aliases = aliases.Select(alias => new SpeakerAlias { Name = alias }).ToList(), Snippets = snippets .Select((snippet, index) => new SpeakerSnippet @@ -133,6 +137,19 @@ public sealed class SpeakerIdentityMergeServiceTests WavBytes = snippet, CreatedAt = createdAt.AddMinutes(index) }) + .ToList(), + References = Enumerable.Range(0, referenceCount) + .Select(index => + { + var transcriptPath = Path.Combine(tempDirectory, $"reference-{Guid.NewGuid():N}-{index}.md"); + File.WriteAllText(transcriptPath, "Transcript"); + return new SpeakerIdentityReference + { + MeetingNotePath = Path.Combine(tempDirectory, $"reference-{Guid.NewGuid():N}-{index}.md"), + TranscriptPath = transcriptPath, + CreatedAt = createdAt.AddMinutes(index) + }; + }) .ToList() }; Context.SpeakerIdentities.Add(identity); @@ -146,15 +163,16 @@ public sealed class SpeakerIdentityMergeServiceTests return Context.SpeakerIdentities .Include(identity => identity.Aliases) .Include(identity => identity.Snippets) + .Include(identity => identity.References) .SingleAsync(identity => identity.Id == id); } public async ValueTask DisposeAsync() { await Context.DisposeAsync(); - if (File.Exists(dbPath)) + if (Directory.Exists(tempDirectory)) { - File.Delete(dbPath); + Directory.Delete(tempDirectory, recursive: true); } } } diff --git a/MeetingAssistant.Tests/SpeakerIdentityServiceTests.cs b/MeetingAssistant.Tests/SpeakerIdentityServiceTests.cs index df3cdbc..758fa0e 100644 --- a/MeetingAssistant.Tests/SpeakerIdentityServiceTests.cs +++ b/MeetingAssistant.Tests/SpeakerIdentityServiceTests.cs @@ -14,7 +14,7 @@ public sealed class SpeakerIdentityServiceTests public async Task MatchedUnnamedIdentityEliminatesCandidatesAndPromotesCanonicalName() { await using var fixture = await SpeakerIdentityFixture.CreateAsync(); - var identity = await fixture.AddIdentityAsync(["John", "Mike"], [1, 2, 3]); + var identity = await fixture.AddIdentityAsync(["John", "Mike"], [1, 2, 3], referenceCount: 2); fixture.Matcher.MatchIdentityId = identity.Id; var service = fixture.CreateService(); @@ -27,7 +27,9 @@ public sealed class SpeakerIdentityServiceTests var saved = await fixture.LoadIdentityAsync(identity.Id); Assert.Equal("John", saved.CanonicalName); Assert.Equal(["John"], saved.CandidateNames.Select(candidate => candidate.Name)); - Assert.Equal(1, saved.TranscriptionCount); + Assert.Equal(3, saved.References.Count); + Assert.All(saved.References, reference => + Assert.Contains("Guest01 was identified as John", File.ReadAllText(reference.TranscriptPath))); Assert.Equal("John", result.Segments.Single().Speaker); Assert.Equal("John", result.SpeakerMappings["Guest01"]); } @@ -41,7 +43,7 @@ public sealed class SpeakerIdentityServiceTests [], [1, 2, 3], "Chris", - transcriptionCount: 5, + referenceCount: 5, updatedAt: oldTimestamp); fixture.Matcher.MatchIdentityId = identity.Id; var service = fixture.CreateService(); @@ -54,6 +56,7 @@ public sealed class SpeakerIdentityServiceTests var saved = await fixture.LoadIdentityAsync(identity.Id); Assert.True(saved.UpdatedAt > oldTimestamp); + Assert.Equal(6, saved.References.Count); } [Fact] @@ -73,6 +76,7 @@ public sealed class SpeakerIdentityServiceTests var saved = await fixture.LoadIdentityAsync(identity.Id); Assert.Null(saved.CanonicalName); Assert.Equal(["Chris", "Jane"], saved.CandidateNames.Select(candidate => candidate.Name).Order()); + Assert.Single(saved.References); Assert.Equal([7, 8, 9], saved.Snippets.Single().WavBytes); } @@ -93,13 +97,28 @@ public sealed class SpeakerIdentityServiceTests var saved = await fixture.LoadIdentityAsync(identity.Id); Assert.Equal("Michael", saved.CanonicalName); Assert.Equal(["Michael"], saved.CandidateNames.Select(candidate => candidate.Name)); + Assert.Contains("Guest01 was identified as Michael", File.ReadAllText(saved.References.Single().TranscriptPath)); + } + + [Fact] + public async Task AttendeeCanonicalizerDeduplicatesExactIdentityAliases() + { + await using var fixture = await SpeakerIdentityFixture.CreateAsync(); + await fixture.AddIdentityAsync([], [1, 2, 3], "Karl Berger", aliases: ["Berger, Karl"]); + var canonicalizer = fixture.CreateAttendeeCanonicalizer(); + + var attendees = await canonicalizer.CanonicalizeAsync( + ["Karl Berger ", "Berger, Karl ", "Ada"], + CancellationToken.None); + + Assert.Equal(["Karl Berger", "Ada"], attendees); } [Fact] public async Task UnmatchedDiarizedSpeakersCreateCandidateIdentitiesFromUnmatchedAttendees() { await using var fixture = await SpeakerIdentityFixture.CreateAsync(); - var chris = await fixture.AddIdentityAsync([], [1, 2, 3], "Chris", transcriptionCount: 5); + var chris = await fixture.AddIdentityAsync([], [1, 2, 3], "Chris", referenceCount: 5); fixture.Matcher.MatchIdentityId = chris.Id; var service = fixture.CreateService(); @@ -115,6 +134,7 @@ public sealed class SpeakerIdentityServiceTests var learned = await fixture.Context.SpeakerIdentities .Include(identity => identity.CandidateNames) + .Include(identity => identity.References) .Where(identity => identity.CanonicalName == null) .OrderBy(identity => identity.Id) .ToListAsync(); @@ -124,6 +144,7 @@ public sealed class SpeakerIdentityServiceTests { Assert.NotEqual(default, identity.CreatedAt); Assert.NotEqual(default, identity.UpdatedAt); + Assert.Single(identity.References); Assert.Equal(["John", "Mike"], identity.CandidateNames.Select(candidate => candidate.Name).Order()); }); } @@ -132,7 +153,7 @@ public sealed class SpeakerIdentityServiceTests public async Task UnmatchedSpeakersExcludeAliasesOfMatchedIdentitiesFromCandidates() { await using var fixture = await SpeakerIdentityFixture.CreateAsync(); - var michael = await fixture.AddIdentityAsync([], [1, 2, 3], "Michael", transcriptionCount: 5, aliases: ["Mike"]); + var michael = await fixture.AddIdentityAsync([], [1, 2, 3], "Michael", referenceCount: 5, aliases: ["Mike"]); fixture.Matcher.MatchIdentityId = michael.Id; var service = fixture.CreateService(); @@ -147,16 +168,42 @@ public sealed class SpeakerIdentityServiceTests var learned = await fixture.Context.SpeakerIdentities .Include(identity => identity.CandidateNames) - .Where(identity => identity.CanonicalName == null) + .Include(identity => identity.References) + .Where(identity => identity.CanonicalName == "Jane") .SingleAsync(); + Assert.Equal("Jane", learned.CanonicalName); Assert.Equal(["Jane"], learned.CandidateNames.Select(candidate => candidate.Name)); + Assert.Single(learned.References); + Assert.Contains("Guest01 was identified as Jane", File.ReadAllText(learned.References.Single().TranscriptPath)); + } + + [Fact] + public async Task UnmatchedSpeakerWithSingleRemainingCandidateIsPromotedOnInsert() + { + await using var fixture = await SpeakerIdentityFixture.CreateAsync(); + var service = fixture.CreateService(); + + await service.ProcessFinishedTranscriptAsync( + fixture.CreateRequest( + ["Manuel"], + [new TranscriptionSegment(TimeSpan.Zero, TimeSpan.FromSeconds(4), "Guest01", "unknown")]), + CancellationToken.None); + + var learned = await fixture.Context.SpeakerIdentities + .Include(identity => identity.CandidateNames) + .Include(identity => identity.References) + .SingleAsync(); + Assert.Equal("Manuel", learned.CanonicalName); + Assert.Equal(["Manuel"], learned.CandidateNames.Select(candidate => candidate.Name)); + Assert.Single(learned.References); + Assert.Contains("Guest01 was identified as Manuel", File.ReadAllText(learned.References.Single().TranscriptPath)); } [Fact] public async Task SuppliedSpeakerSamplesAreUsedBeforeExtractingFromAudioFile() { await using var fixture = await SpeakerIdentityFixture.CreateAsync(); - var chris = await fixture.AddIdentityAsync([], [1, 2, 3], "Chris", transcriptionCount: 5); + var chris = await fixture.AddIdentityAsync([], [1, 2, 3], "Chris", referenceCount: 5); fixture.Matcher.MatchIdentityId = chris.Id; var service = fixture.CreateService(); var segment = new TranscriptionSegment(TimeSpan.Zero, TimeSpan.FromSeconds(5), "Guest03", "hello from the live buffer"); @@ -177,7 +224,7 @@ public sealed class SpeakerIdentityServiceTests public async Task LiveKnownSpeakerIdentificationDoesNotMutateIdentityDatabase() { await using var fixture = await SpeakerIdentityFixture.CreateAsync(); - var identity = await fixture.AddIdentityAsync(["John", "Mike"], [1, 2, 3], transcriptionCount: 5); + var identity = await fixture.AddIdentityAsync(["John", "Mike"], [1, 2, 3], referenceCount: 5); fixture.Matcher.MatchIdentityId = identity.Id; var service = fixture.CreateService(); @@ -190,7 +237,7 @@ public sealed class SpeakerIdentityServiceTests var saved = await fixture.LoadIdentityAsync(identity.Id); Assert.Null(saved.CanonicalName); Assert.Equal(["John", "Mike"], saved.CandidateNames.Select(candidate => candidate.Name).Order()); - Assert.Equal(5, saved.TranscriptionCount); + Assert.Equal(5, saved.References.Count); Assert.Single(saved.Snippets); Assert.Equal("Guest01", result.Segments.Single().Speaker); Assert.Empty(result.SpeakerMappings); @@ -200,9 +247,9 @@ public sealed class SpeakerIdentityServiceTests public async Task SpeakerMatchingPrioritizesAttendeeDisplayNamesAndAliases() { await using var fixture = await SpeakerIdentityFixture.CreateAsync(); - var unrelated = await fixture.AddIdentityAsync([], [1], "Frequent", transcriptionCount: 99); - var aliasMatch = await fixture.AddIdentityAsync([], [2], "Michael", transcriptionCount: 1, aliases: ["Mike"]); - var displayNameMatch = await fixture.AddIdentityAsync([], [3], "Jane", transcriptionCount: 2); + var unrelated = await fixture.AddIdentityAsync([], [1], "Frequent", referenceCount: 99); + var aliasMatch = await fixture.AddIdentityAsync([], [2], "Michael", referenceCount: 1, aliases: ["Mike"]); + var displayNameMatch = await fixture.AddIdentityAsync([], [3], "Jane", referenceCount: 2); var service = fixture.CreateService(); await service.IdentifyKnownSpeakersAsync( @@ -223,10 +270,10 @@ public sealed class SpeakerIdentityServiceTests options.MaxMatchCandidates = 2; options.MatchIdentityActiveAge = TimeSpan.FromDays(365); }); - var activeHigh = await fixture.AddIdentityAsync([], [1], "Active High", transcriptionCount: 50); - await fixture.AddIdentityAsync([], [2], "Stale High", transcriptionCount: 100, updatedAt: DateTimeOffset.UtcNow.AddYears(-2)); - var activeLow = await fixture.AddIdentityAsync([], [3], "Active Low", transcriptionCount: 5); - var staleAttendee = await fixture.AddIdentityAsync([], [4], "Former Employee", transcriptionCount: 1, updatedAt: DateTimeOffset.UtcNow.AddYears(-2), aliases: ["Former"]); + var activeHigh = await fixture.AddIdentityAsync([], [1], "Active High", referenceCount: 50); + await fixture.AddIdentityAsync([], [2], "Stale High", referenceCount: 100, updatedAt: DateTimeOffset.UtcNow.AddYears(-2)); + var activeLow = await fixture.AddIdentityAsync([], [3], "Active Low", referenceCount: 5); + var staleAttendee = await fixture.AddIdentityAsync([], [4], "Former Employee", referenceCount: 1, updatedAt: DateTimeOffset.UtcNow.AddYears(-2), aliases: ["Former"]); var service = fixture.CreateService(); await service.IdentifyKnownSpeakersAsync( @@ -240,6 +287,68 @@ public sealed class SpeakerIdentityServiceTests Assert.DoesNotContain(activeLow.Id, requestedIds); } + [Fact] + public async Task KnownSpeakerMappingsExcludeMappedSpeakersAndIdentitiesFromMatching() + { + await using var fixture = await SpeakerIdentityFixture.CreateAsync(); + var manuel = await fixture.AddIdentityAsync([], [1], "Manuel", referenceCount: 99); + var daniel = await fixture.AddIdentityAsync([], [2], "Daniel", referenceCount: 5); + var service = fixture.CreateService(); + + await service.IdentifyKnownSpeakersAsync( + fixture.CreateRequest( + ["Manuel", "Daniel"], + [ + new TranscriptionSegment(TimeSpan.Zero, TimeSpan.FromSeconds(4), "Guest-2", "already identified"), + new TranscriptionSegment(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(8), "Guest-1", "unresolved") + ], + [ + new SpeakerAudioSample( + "Guest-2", + new TranscriptionSegment(TimeSpan.Zero, TimeSpan.FromSeconds(4), "Guest-2", "already identified"), + [4], + 90), + new SpeakerAudioSample( + "Guest-1", + new TranscriptionSegment(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(8), "Guest-1", "unresolved"), + [5], + 90) + ], + new Dictionary(StringComparer.OrdinalIgnoreCase) + { + ["Guest-2"] = "Manuel" + }), + CancellationToken.None); + + var request = fixture.Matcher.Requests.Single(); + Assert.Equal("Guest-1", request.DiarizedSpeaker); + Assert.Equal([daniel.Id], request.Candidates.Select(candidate => candidate.IdentityId)); + Assert.DoesNotContain(manuel.Id, request.Candidates.Select(candidate => candidate.IdentityId)); + } + + [Fact] + public async Task NamedSpeakersExcludeTheirIdentityFromFurtherMatching() + { + await using var fixture = await SpeakerIdentityFixture.CreateAsync(); + var manuel = await fixture.AddIdentityAsync([], [1], "Manuel", referenceCount: 99); + var daniel = await fixture.AddIdentityAsync([], [2], "Daniel", referenceCount: 5); + var service = fixture.CreateService(); + + await service.ProcessFinishedTranscriptAsync( + fixture.CreateRequest( + ["Manuel", "Daniel"], + [ + new TranscriptionSegment(TimeSpan.Zero, TimeSpan.FromSeconds(4), "Manuel", "already relabeled"), + new TranscriptionSegment(TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(8), "Guest-1", "unresolved") + ]), + CancellationToken.None); + + var request = fixture.Matcher.Requests.Single(); + Assert.Equal("Guest-1", request.DiarizedSpeaker); + Assert.Equal([daniel.Id], request.Candidates.Select(candidate => candidate.IdentityId)); + Assert.DoesNotContain(manuel.Id, request.Candidates.Select(candidate => candidate.IdentityId)); + } + [Fact] public async Task SchemaUpgradeAddsLastModifiedColumnInitializedFromCreatedAt() { @@ -275,14 +384,17 @@ public sealed class SpeakerIdentityServiceTests private sealed class SpeakerIdentityFixture : IAsyncDisposable { + private readonly string tempDirectory; private readonly string dbPath; private readonly SpeakerIdentificationOptions options; private SpeakerIdentityFixture( + string tempDirectory, string dbPath, SpeakerIdentityDbContext context, SpeakerIdentificationOptions options) { + this.tempDirectory = tempDirectory; this.dbPath = dbPath; Context = context; this.options = options; @@ -297,8 +409,9 @@ public sealed class SpeakerIdentityServiceTests public static async Task CreateAsync( Action? configureOptions = null) { - var dbPath = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", $"{Guid.NewGuid():N}.db"); - Directory.CreateDirectory(Path.GetDirectoryName(dbPath)!); + var tempDirectory = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N")); + Directory.CreateDirectory(tempDirectory); + var dbPath = Path.Combine(tempDirectory, "speaker-identities.db"); var options = new SpeakerIdentificationOptions { DatabasePath = dbPath, @@ -310,7 +423,7 @@ public sealed class SpeakerIdentityServiceTests .UseSqlite($"Data Source={dbPath};Pooling=False") .Options); await SpeakerIdentitySchema.EnsureCreatedOrUpdatedAsync(context, CancellationToken.None); - return new SpeakerIdentityFixture(dbPath, context, options); + return new SpeakerIdentityFixture(tempDirectory, dbPath, context, options); } public SpeakerIdentityService CreateService() @@ -323,29 +436,44 @@ public sealed class SpeakerIdentityServiceTests NullLogger.Instance); } + public SpeakerIdentityAttendeeCanonicalizer CreateAttendeeCanonicalizer() + { + return new SpeakerIdentityAttendeeCanonicalizer(new TestSpeakerIdentityDbContextFactory(dbPath)); + } + public SpeakerIdentificationRequest CreateRequest( IReadOnlyList attendees, IReadOnlyList segments, - IReadOnlyList? samples = null) + IReadOnlyList? samples = null, + IReadOnlyDictionary? knownSpeakerMappings = null) { + var meetingNotePath = Path.Combine(tempDirectory, "meeting.md"); + var transcriptPath = Path.Combine(tempDirectory, "transcript.md"); + File.WriteAllText(transcriptPath, "Transcript"); return new SpeakerIdentificationRequest( "test.wav", - MeetingNoteTemplate.Create( - "Test Meeting", - DateTimeOffset.Parse("2026-05-20T12:00:00+02:00"), - attendees: attendees, - transcriptPath: "transcript.md", - assistantContextPath: "context.md", - summaryPath: "summary.md"), + new MeetingNote( + meetingNotePath, + new MeetingNoteFrontmatter + { + Title = "Test Meeting", + StartTime = DateTimeOffset.Parse("2026-05-20T12:00:00+02:00"), + Attendees = attendees.ToList(), + Transcript = transcriptPath, + AssistantContext = Path.Combine(tempDirectory, "context.md"), + Summary = Path.Combine(tempDirectory, "summary.md") + }, + ""), segments, - samples); + samples, + knownSpeakerMappings); } public async Task AddIdentityAsync( IReadOnlyList candidates, byte[] snippet, string? canonicalName = null, - int transcriptionCount = 0, + int referenceCount = 0, IReadOnlyList? aliases = null, DateTimeOffset? updatedAt = null) { @@ -353,7 +481,6 @@ public sealed class SpeakerIdentityServiceTests var identity = new SpeakerIdentity { CanonicalName = canonicalName, - TranscriptionCount = transcriptionCount, CreatedAt = timestamp, UpdatedAt = timestamp, Aliases = aliases?.Select(alias => new SpeakerAlias { Name = alias }).ToList() ?? [], @@ -365,7 +492,20 @@ public sealed class SpeakerIdentityServiceTests WavBytes = snippet, CreatedAt = timestamp.AddMinutes(-10) } - ] + ], + References = Enumerable.Range(0, referenceCount) + .Select(index => + { + var transcriptPath = Path.Combine(tempDirectory, $"reference-{Guid.NewGuid():N}-{index}.md"); + File.WriteAllText(transcriptPath, "Transcript"); + return new SpeakerIdentityReference + { + MeetingNotePath = Path.Combine(tempDirectory, $"reference-{Guid.NewGuid():N}-{index}.md"), + TranscriptPath = transcriptPath, + CreatedAt = timestamp.AddMinutes(index) + }; + }) + .ToList() }; Context.SpeakerIdentities.Add(identity); await Context.SaveChangesAsync(); @@ -379,15 +519,16 @@ public sealed class SpeakerIdentityServiceTests .Include(identity => identity.CandidateNames) .Include(identity => identity.Aliases) .Include(identity => identity.Snippets) + .Include(identity => identity.References) .SingleAsync(identity => identity.Id == id); } public async ValueTask DisposeAsync() { await Context.DisposeAsync(); - if (File.Exists(dbPath)) + if (Directory.Exists(tempDirectory)) { - File.Delete(dbPath); + Directory.Delete(tempDirectory, recursive: true); } } } diff --git a/MeetingAssistant/Hotkeys/GlobalHotkeyService.cs b/MeetingAssistant/Hotkeys/GlobalHotkeyService.cs index aaddc60..0ffcc60 100644 --- a/MeetingAssistant/Hotkeys/GlobalHotkeyService.cs +++ b/MeetingAssistant/Hotkeys/GlobalHotkeyService.cs @@ -1,27 +1,28 @@ using System.Runtime.InteropServices; using System.Threading; +using MeetingAssistant.LaunchProfiles; using MeetingAssistant.Recording; -using Microsoft.Extensions.Options; namespace MeetingAssistant.Hotkeys; public sealed class GlobalHotkeyService : BackgroundService { - private const int HotkeyId = 0x4D41; + private const int HotkeyIdBase = 0x4D41; private const int WmHotkey = 0x0312; private const int WmQuit = 0x0012; - private readonly MeetingAssistantOptions options; + private readonly ILaunchProfileOptionsProvider launchProfiles; private readonly MeetingRecordingCoordinator coordinator; private readonly ILogger logger; + private readonly Dictionary hotkeyProfiles = []; private TaskCompletionSource? messageLoopCompletion; private uint messageThreadId; public GlobalHotkeyService( - IOptions options, + ILaunchProfileOptionsProvider launchProfiles, MeetingRecordingCoordinator coordinator, ILogger logger) { - this.options = options.Value; + this.launchProfiles = launchProfiles; this.coordinator = coordinator; this.logger = logger; } @@ -58,31 +59,49 @@ public sealed class GlobalHotkeyService : BackgroundService private void RunMessageLoop(CancellationToken stoppingToken) { - var hotkey = HotkeyDefinition.Parse(options.Hotkey.Toggle); + var hotkeys = launchProfiles.GetHotkeys(); messageThreadId = GetCurrentThreadId(); using var stoppingRegistration = stoppingToken.Register(() => PostQuitToMessageThread()); - if (!RegisterHotKey(IntPtr.Zero, HotkeyId, (uint)hotkey.Modifiers, hotkey.VirtualKey)) + for (var index = 0; index < hotkeys.Count; index++) { - logger.LogWarning("Could not register global hotkey {Hotkey}", options.Hotkey.Toggle); - return; - } + var profileHotkey = hotkeys[index]; + var hotkey = HotkeyDefinition.Parse(profileHotkey.Toggle); + var hotkeyId = HotkeyIdBase + index; + if (!RegisterHotKey(IntPtr.Zero, hotkeyId, (uint)hotkey.Modifiers, hotkey.VirtualKey)) + { + logger.LogWarning( + "Could not register global hotkey {Hotkey} for launch profile {LaunchProfile}", + profileHotkey.Toggle, + profileHotkey.ProfileName); + continue; + } - logger.LogInformation("Registered global hotkey {Hotkey}", options.Hotkey.Toggle); + hotkeyProfiles[hotkeyId] = profileHotkey.ProfileName; + logger.LogInformation( + "Registered global hotkey {Hotkey} for launch profile {LaunchProfile}", + profileHotkey.Toggle, + profileHotkey.ProfileName); + } try { while (!stoppingToken.IsCancellationRequested && GetMessage(out var message, IntPtr.Zero, 0, 0) > 0) { - if (message.Message == WmHotkey) + if (message.Message == WmHotkey && hotkeyProfiles.TryGetValue((int)message.WParam, out var profileName)) { - _ = Task.Run(ToggleRecordingAsync, CancellationToken.None); + _ = Task.Run(() => ToggleRecordingAsync(profileName), CancellationToken.None); } } } finally { - UnregisterHotKey(IntPtr.Zero, HotkeyId); + foreach (var hotkeyId in hotkeyProfiles.Keys) + { + UnregisterHotKey(IntPtr.Zero, hotkeyId); + } + + hotkeyProfiles.Clear(); messageThreadId = 0; } } @@ -93,12 +112,15 @@ public sealed class GlobalHotkeyService : BackgroundService return base.StopAsync(cancellationToken); } - private async Task ToggleRecordingAsync() + private async Task ToggleRecordingAsync(string profileName) { try { - var status = await coordinator.ToggleAsync(CancellationToken.None); - logger.LogInformation("Hotkey toggled recording. IsRecording={IsRecording}", status.IsRecording); + var status = await coordinator.ToggleAsync(profileName, CancellationToken.None); + logger.LogInformation( + "Hotkey toggled recording for launch profile {LaunchProfile}. IsRecording={IsRecording}", + profileName, + status.IsRecording); } catch (Exception exception) { diff --git a/MeetingAssistant/LaunchProfiles/LaunchProfileOptionsProvider.cs b/MeetingAssistant/LaunchProfiles/LaunchProfileOptionsProvider.cs new file mode 100644 index 0000000..08a0c3a --- /dev/null +++ b/MeetingAssistant/LaunchProfiles/LaunchProfileOptionsProvider.cs @@ -0,0 +1,153 @@ +using Microsoft.Extensions.Configuration; + +namespace MeetingAssistant.LaunchProfiles; + +public interface ILaunchProfileOptionsProvider +{ + LaunchProfile GetRequiredProfile(string? name); + + IReadOnlyList GetHotkeys(); +} + +public sealed record LaunchProfile(string Name, MeetingAssistantOptions Options); + +public sealed record LaunchProfileHotkey(string ProfileName, string Toggle); + +public sealed class ConfigurationLaunchProfileOptionsProvider : ILaunchProfileOptionsProvider +{ + public const string DefaultProfileName = "default"; + + private readonly IConfiguration configuration; + + public ConfigurationLaunchProfileOptionsProvider(IConfiguration configuration) + { + this.configuration = configuration; + } + + public LaunchProfile GetRequiredProfile(string? name) + { + var profileName = NormalizeProfileName(name); + var options = BindDefaultOptions(); + if (profileName.Equals(DefaultProfileName, StringComparison.OrdinalIgnoreCase)) + { + return new LaunchProfile(DefaultProfileName, options); + } + + var profileSection = GetProfilesSection().GetSection(profileName); + if (!profileSection.Exists()) + { + throw new KeyNotFoundException($"Launch profile '{profileName}' is not configured."); + } + + profileSection.Bind(options); + ApplyArrayOverrides(profileSection, options); + return new LaunchProfile(profileName, options); + } + + public IReadOnlyList GetHotkeys() + { + var hotkeys = GetProfileNames() + .Select(profileName => + { + var profile = GetRequiredProfile(profileName); + return new LaunchProfileHotkey(profile.Name, profile.Options.Hotkey.Toggle); + }) + .Where(hotkey => !string.IsNullOrWhiteSpace(hotkey.Toggle)) + .ToList(); + var duplicate = hotkeys + .GroupBy(hotkey => hotkey.Toggle.Trim(), StringComparer.OrdinalIgnoreCase) + .FirstOrDefault(group => group.Count() > 1); + if (duplicate is not null) + { + throw new InvalidOperationException( + $"Launch profile hotkey '{duplicate.Key}' is configured more than once for profiles {string.Join(", ", duplicate.Select(hotkey => hotkey.ProfileName))}."); + } + + return hotkeys; + } + + private IReadOnlyList GetProfileNames() + { + return new[] { DefaultProfileName } + .Concat(GetProfilesSection() + .GetChildren() + .Select(section => section.Key) + .Where(key => !key.Equals(DefaultProfileName, StringComparison.OrdinalIgnoreCase))) + .Distinct(StringComparer.OrdinalIgnoreCase) + .ToList(); + } + + private MeetingAssistantOptions BindDefaultOptions() + { + var options = new MeetingAssistantOptions(); + GetRootSection().Bind(options); + return options; + } + + private IConfigurationSection GetRootSection() + { + return configuration.GetSection("MeetingAssistant"); + } + + private IConfigurationSection GetProfilesSection() + { + return GetRootSection().GetSection("LaunchProfiles"); + } + + private static string NormalizeProfileName(string? name) + { + return string.IsNullOrWhiteSpace(name) || + name.Equals(DefaultProfileName, StringComparison.OrdinalIgnoreCase) + ? DefaultProfileName + : name.Trim(); + } + + private static void ApplyArrayOverrides( + IConfigurationSection profileSection, + MeetingAssistantOptions options) + { + var autoDetectLanguages = ReadArrayOverride(profileSection.GetSection("AzureSpeech:AutoDetectLanguages")); + if (autoDetectLanguages is not null) + { + options.AzureSpeech.AutoDetectLanguages = autoDetectLanguages; + } + + var funAsrChunkSize = ReadIntArrayOverride(profileSection.GetSection("FunAsr:ChunkSize")); + if (funAsrChunkSize is not null) + { + options.FunAsr.ChunkSize = funAsrChunkSize; + } + } + + private static string[]? ReadArrayOverride(IConfigurationSection section) + { + if (!section.Exists()) + { + return null; + } + + return section + .GetChildren() + .OrderBy(child => int.TryParse(child.Key, out var index) ? index : int.MaxValue) + .Select(child => child.Value) + .Where(value => !string.IsNullOrWhiteSpace(value)) + .Select(value => value!) + .ToArray(); + } + + private static int[]? ReadIntArrayOverride(IConfigurationSection section) + { + if (!section.Exists()) + { + return null; + } + + return section + .GetChildren() + .OrderBy(child => int.TryParse(child.Key, out var index) ? index : int.MaxValue) + .Select(child => int.TryParse(child.Value, out var value) ? value : (int?)null) + .Where(value => value.HasValue) + .Select(value => value!.Value) + .ToArray(); + } +} diff --git a/MeetingAssistant/MeetingAssistant.csproj b/MeetingAssistant/MeetingAssistant.csproj index b0d565f..7814222 100644 --- a/MeetingAssistant/MeetingAssistant.csproj +++ b/MeetingAssistant/MeetingAssistant.csproj @@ -12,6 +12,7 @@ + diff --git a/MeetingAssistant/MeetingAssistantOptions.cs b/MeetingAssistant/MeetingAssistantOptions.cs index 347464e..23653a0 100644 --- a/MeetingAssistant/MeetingAssistantOptions.cs +++ b/MeetingAssistant/MeetingAssistantOptions.cs @@ -104,7 +104,7 @@ public sealed class AzureSpeechOptions { public string Endpoint { get; set; } = ""; - public string Region { get; set; } = "germanywestcentral"; + public string Region { get; set; } = "westeurope"; public string Language { get; set; } = "auto"; @@ -120,6 +120,8 @@ public sealed class AzureSpeechOptions public bool DiarizeIntermediateResults { get; set; } = true; + public string? PostProcessingOption { get; set; } + public double PhraseListWeight { get; set; } = 1.5; } @@ -232,6 +234,8 @@ public sealed class SpeakerIdentificationOptions public TimeSpan MergeRecentIdentityAge { get; set; } = TimeSpan.FromDays(14); + public TimeSpan MatchTimeout { get; set; } = TimeSpan.FromMinutes(3); + public AzureSpeechOptions AzureSpeech { get; set; } = new(); } diff --git a/MeetingAssistant/MeetingNotes/IMeetingArtifactStore.cs b/MeetingAssistant/MeetingNotes/IMeetingArtifactStore.cs index 302b119..643fba7 100644 --- a/MeetingAssistant/MeetingNotes/IMeetingArtifactStore.cs +++ b/MeetingAssistant/MeetingNotes/IMeetingArtifactStore.cs @@ -4,16 +4,23 @@ public interface IMeetingArtifactStore { Task CreateAssistantContextAsync( MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, string agenda, DateTimeOffset? scheduledEnd, CancellationToken cancellationToken); Task UpdateAssistantContextMetadataAsync( MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, string agenda, DateTimeOffset? scheduledEnd, CancellationToken cancellationToken); + Task UpdateAssistantContextMeetingAsync( + MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, + CancellationToken cancellationToken); + Task UpdateAssistantContextStateAsync( MeetingSessionArtifacts artifacts, AssistantContextState state, @@ -22,6 +29,7 @@ public interface IMeetingArtifactStore public enum AssistantContextState { + CollectingMetadata, Transcribing, SpeakerRecognition, Summarizing, diff --git a/MeetingAssistant/MeetingNotes/IMeetingNoteStore.cs b/MeetingAssistant/MeetingNotes/IMeetingNoteStore.cs index f2a9a70..849a5bd 100644 --- a/MeetingAssistant/MeetingNotes/IMeetingNoteStore.cs +++ b/MeetingAssistant/MeetingNotes/IMeetingNoteStore.cs @@ -4,5 +4,13 @@ public interface IMeetingNoteStore { Task SaveAsync(MeetingNote note, CancellationToken cancellationToken); + Task SaveAsync( + MeetingNote note, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return SaveAsync(note, cancellationToken); + } + Task ReadAsync(string path, CancellationToken cancellationToken); } diff --git a/MeetingAssistant/MeetingNotes/MarkdownMeetingArtifactStore.cs b/MeetingAssistant/MeetingNotes/MarkdownMeetingArtifactStore.cs index 4086de8..4ce623a 100644 --- a/MeetingAssistant/MeetingNotes/MarkdownMeetingArtifactStore.cs +++ b/MeetingAssistant/MeetingNotes/MarkdownMeetingArtifactStore.cs @@ -17,6 +17,7 @@ public sealed class MarkdownMeetingArtifactStore : IMeetingArtifactStore public async Task CreateAssistantContextAsync( MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, string agenda, DateTimeOffset? scheduledEnd, CancellationToken cancellationToken) @@ -25,7 +26,8 @@ public sealed class MarkdownMeetingArtifactStore : IMeetingArtifactStore var content = Render( artifacts, - AssistantContextState.Transcribing, + meetingNote, + AssistantContextState.CollectingMetadata, agenda, scheduledEnd, "# Assistant Context" + Environment.NewLine + Environment.NewLine + "## Live Context" + Environment.NewLine); @@ -45,12 +47,13 @@ public sealed class MarkdownMeetingArtifactStore : IMeetingArtifactStore : new MarkdownDocument(false, "", "## Live Context" + Environment.NewLine); var body = existing.Body; var existingFrontmatter = ReadFrontmatter(existing.Frontmatter); + var metadata = existingFrontmatter.ToMeetingArtifactMetadata(); var agenda = existingFrontmatter.Agenda ?? ""; var scheduledEnd = ParseDateTime(existingFrontmatter.ScheduledEnd); await File.WriteAllTextAsync( artifacts.AssistantContextPath, - Render(artifacts, state, agenda, scheduledEnd, body), + Render(artifacts, metadata, state, agenda, scheduledEnd, body), cancellationToken); logger.LogInformation( "Updated assistant context note {AssistantContextPath} state to {State}", @@ -60,6 +63,7 @@ public sealed class MarkdownMeetingArtifactStore : IMeetingArtifactStore public async Task UpdateAssistantContextMetadataAsync( MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, string agenda, DateTimeOffset? scheduledEnd, CancellationToken cancellationToken) @@ -73,29 +77,68 @@ public sealed class MarkdownMeetingArtifactStore : IMeetingArtifactStore await File.WriteAllTextAsync( artifacts.AssistantContextPath, - Render(artifacts, state, agenda, scheduledEnd, existing.Body), + Render(artifacts, meetingNote, state, agenda, scheduledEnd, existing.Body), cancellationToken); logger.LogInformation( "Updated assistant context note {AssistantContextPath} calendar metadata", artifacts.AssistantContextPath); } + public async Task UpdateAssistantContextMeetingAsync( + MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, + CancellationToken cancellationToken) + { + Directory.CreateDirectory(Path.GetDirectoryName(artifacts.AssistantContextPath)!); + var existing = File.Exists(artifacts.AssistantContextPath) + ? MarkdownDocumentParser.SplitOptional(await File.ReadAllTextAsync(artifacts.AssistantContextPath, cancellationToken)) + : new MarkdownDocument(false, "", "## Live Context" + Environment.NewLine); + var existingFrontmatter = ReadFrontmatter(existing.Frontmatter); + var state = ParseState(existingFrontmatter.State); + var agenda = existingFrontmatter.Agenda ?? ""; + var scheduledEnd = ParseDateTime(existingFrontmatter.ScheduledEnd); + + await File.WriteAllTextAsync( + artifacts.AssistantContextPath, + Render(artifacts, meetingNote, state, agenda, scheduledEnd, existing.Body), + cancellationToken); + logger.LogInformation( + "Updated assistant context note {AssistantContextPath} meeting metadata", + artifacts.AssistantContextPath); + } + private static string Render( MeetingSessionArtifacts artifacts, + MeetingNote meetingNote, AssistantContextState state, string? agenda, DateTimeOffset? scheduledEnd, string body) { - var frontmatter = new MeetingArtifactFrontmatter - { - Meeting = ObsidianLink.ToWikiLink(artifacts.MeetingNotePath, artifacts.AssistantContextPath, "Meeting Note"), - Transcript = ObsidianLink.ToWikiLink(artifacts.TranscriptPath, artifacts.AssistantContextPath, "Transcript"), - Summary = ObsidianLink.ToWikiLink(artifacts.SummaryPath, artifacts.AssistantContextPath, "Summary"), - State = ToYamlState(state), - Agenda = agenda ?? "", - ScheduledEnd = scheduledEnd - }; + var metadata = new AssistantContextMeetingMetadata( + meetingNote.Frontmatter.Title, + meetingNote.Frontmatter.StartTime, + meetingNote.Frontmatter.EndTime); + return Render(artifacts, metadata, state, agenda, scheduledEnd, body); + } + + private static string Render( + MeetingSessionArtifacts artifacts, + AssistantContextMeetingMetadata metadata, + AssistantContextState state, + string? agenda, + DateTimeOffset? scheduledEnd, + string body) + { + var frontmatter = MeetingArtifactFrontmatterRenderer.Create( + artifacts, + metadata.Title, + metadata.StartTime, + metadata.EndTime, + artifacts.AssistantContextPath, + ToYamlState(state)); + frontmatter.Agenda = agenda ?? ""; + frontmatter.ScheduledEnd = scheduledEnd; return MeetingArtifactFrontmatterRenderer.Render( frontmatter, @@ -125,23 +168,46 @@ public sealed class MarkdownMeetingArtifactStore : IMeetingArtifactStore [YamlMember(Alias = "state")] public string? State { get; set; } + [YamlMember(Alias = "title")] + public string? Title { get; set; } + + [YamlMember(Alias = "start_time")] + public string? StartTime { get; set; } + + [YamlMember(Alias = "end_time")] + public string? EndTime { get; set; } + [YamlMember(Alias = "agenda")] public string? Agenda { get; set; } [YamlMember(Alias = "scheduled_end")] public string? ScheduledEnd { get; set; } + + public AssistantContextMeetingMetadata ToMeetingArtifactMetadata() + { + return new AssistantContextMeetingMetadata( + Title ?? "", + ParseDateTime(StartTime), + ParseDateTime(EndTime)); + } } + private sealed record AssistantContextMeetingMetadata( + string Title, + DateTimeOffset? StartTime, + DateTimeOffset? EndTime); + private static AssistantContextState ParseState(string? value) { return value?.Trim().ToLowerInvariant() switch { "transcribing" => AssistantContextState.Transcribing, + "collecting metadata" => AssistantContextState.CollectingMetadata, "speaker recognition" => AssistantContextState.SpeakerRecognition, "summarizing" => AssistantContextState.Summarizing, "finished" => AssistantContextState.Finished, "error" => AssistantContextState.Error, - _ => AssistantContextState.Transcribing + _ => AssistantContextState.CollectingMetadata }; } @@ -149,6 +215,7 @@ public sealed class MarkdownMeetingArtifactStore : IMeetingArtifactStore { return state switch { + AssistantContextState.CollectingMetadata => "collecting metadata", AssistantContextState.Transcribing => "transcribing", AssistantContextState.SpeakerRecognition => "speaker recognition", AssistantContextState.Summarizing => "summarizing", diff --git a/MeetingAssistant/MeetingNotes/MarkdownMeetingNoteStore.cs b/MeetingAssistant/MeetingNotes/MarkdownMeetingNoteStore.cs index e9d862a..5cfdc44 100644 --- a/MeetingAssistant/MeetingNotes/MarkdownMeetingNoteStore.cs +++ b/MeetingAssistant/MeetingNotes/MarkdownMeetingNoteStore.cs @@ -22,12 +22,20 @@ public sealed class MarkdownMeetingNoteStore : IMeetingNoteStore } public async Task SaveAsync(MeetingNote note, CancellationToken cancellationToken) + { + return await SaveAsync(note, options, cancellationToken); + } + + public async Task SaveAsync( + MeetingNote note, + MeetingAssistantOptions options, + CancellationToken cancellationToken) { var folder = VaultPath.Resolve(options.Vault, options.Vault.MeetingNotesFolder); Directory.CreateDirectory(folder); var path = string.IsNullOrWhiteSpace(note.Path) - ? Path.Combine(folder, $"{DateTimeOffset.Now:yyyyMMdd-HHmmss}-{Slugify(note.Frontmatter.Title)}.md") + ? Path.Combine(folder, $"{DateTimeOffset.Now:yyyyMMdd-HHmmss-fffffff}-{Slugify(note.Frontmatter.Title)}.md") : note.Path; var frontmatter = PrepareFrontmatter(note.Frontmatter, path); var content = Render(frontmatter, note.UserNotes); diff --git a/MeetingAssistant/MeetingNotes/MeetingArtifactFrontmatter.cs b/MeetingAssistant/MeetingNotes/MeetingArtifactFrontmatter.cs index 215051c..05036f6 100644 --- a/MeetingAssistant/MeetingNotes/MeetingArtifactFrontmatter.cs +++ b/MeetingAssistant/MeetingNotes/MeetingArtifactFrontmatter.cs @@ -36,10 +36,10 @@ public static class MeetingArtifactFrontmatterRenderer AppendScalar(builder, "title", frontmatter.Title); AppendDateTime(builder, "start_time", frontmatter.StartTime); AppendDateTime(builder, "end_time", frontmatter.EndTime); - AppendQuoted(builder, "meeting", frontmatter.Meeting); - AppendQuoted(builder, "transcript", frontmatter.Transcript); - AppendQuoted(builder, "assistant_context", frontmatter.AssistantContext); - AppendQuoted(builder, "summary", frontmatter.Summary); + AppendQuotedIfNotEmpty(builder, "meeting", frontmatter.Meeting); + AppendQuotedIfNotEmpty(builder, "transcript", frontmatter.Transcript); + AppendQuotedIfNotEmpty(builder, "assistant_context", frontmatter.AssistantContext); + AppendQuotedIfNotEmpty(builder, "summary", frontmatter.Summary); if (!string.IsNullOrWhiteSpace(frontmatter.State)) { AppendScalar(builder, "state", frontmatter.State); @@ -73,16 +73,33 @@ public static class MeetingArtifactFrontmatterRenderer string title, string sourceNotePath, string? state = null) + { + return Create( + artifacts, + title, + meetingNote.Frontmatter.StartTime, + meetingNote.Frontmatter.EndTime, + sourceNotePath, + state); + } + + public static MeetingArtifactFrontmatter Create( + MeetingSessionArtifacts artifacts, + string title, + DateTimeOffset? startTime, + DateTimeOffset? endTime, + string sourceNotePath, + string? state = null) { return new MeetingArtifactFrontmatter { Title = title, - StartTime = meetingNote.Frontmatter.StartTime, - EndTime = meetingNote.Frontmatter.EndTime, - Meeting = ObsidianLink.ToWikiLink(artifacts.MeetingNotePath, sourceNotePath, "Meeting Note"), - Transcript = ObsidianLink.ToWikiLink(artifacts.TranscriptPath, sourceNotePath, "Transcript"), - AssistantContext = ObsidianLink.ToWikiLink(artifacts.AssistantContextPath, sourceNotePath, "Assistant Context"), - Summary = ObsidianLink.ToWikiLink(artifacts.SummaryPath, sourceNotePath, "Summary"), + StartTime = startTime, + EndTime = endTime, + Meeting = LinkUnlessSelf(artifacts.MeetingNotePath, sourceNotePath, "Meeting Note"), + Transcript = LinkUnlessSelf(artifacts.TranscriptPath, sourceNotePath, "Transcript"), + AssistantContext = LinkUnlessSelf(artifacts.AssistantContextPath, sourceNotePath, "Assistant Context"), + Summary = LinkUnlessSelf(artifacts.SummaryPath, sourceNotePath, "Summary"), State = state }; } @@ -108,6 +125,16 @@ public static class MeetingArtifactFrontmatterRenderer builder.AppendLine(EscapeQuoted(value)); } + private static void AppendQuotedIfNotEmpty(StringBuilder builder, string key, string? value) + { + if (string.IsNullOrWhiteSpace(value)) + { + return; + } + + AppendQuoted(builder, key, value); + } + private static void AppendDateTime(StringBuilder builder, string key, DateTimeOffset? value) { builder.Append(key); @@ -145,4 +172,19 @@ public static class MeetingArtifactFrontmatterRenderer : value; } + private static string LinkUnlessSelf(string targetPath, string sourceNotePath, string label) + { + return IsSamePath(targetPath, sourceNotePath) + ? "" + : ObsidianLink.ToWikiLink(targetPath, sourceNotePath, label); + } + + private static bool IsSamePath(string first, string second) + { + return string.Equals( + Path.GetFullPath(first), + Path.GetFullPath(second), + StringComparison.OrdinalIgnoreCase); + } + } diff --git a/MeetingAssistant/MeetingNotes/MeetingAttendeeNames.cs b/MeetingAssistant/MeetingNotes/MeetingAttendeeNames.cs new file mode 100644 index 0000000..d493574 --- /dev/null +++ b/MeetingAssistant/MeetingNotes/MeetingAttendeeNames.cs @@ -0,0 +1,11 @@ +namespace MeetingAssistant.MeetingNotes; + +internal static class MeetingAttendeeNames +{ + public static string NormalizeDisplayName(string attendee) + { + var trimmed = attendee.Trim(); + var emailStart = trimmed.IndexOf('<', StringComparison.Ordinal); + return emailStart > 0 ? trimmed[..emailStart].Trim() : trimmed; + } +} diff --git a/MeetingAssistant/Program.cs b/MeetingAssistant/Program.cs index 9de2c51..ea68276 100644 --- a/MeetingAssistant/Program.cs +++ b/MeetingAssistant/Program.cs @@ -1,5 +1,6 @@ using MeetingAssistant; using MeetingAssistant.Hotkeys; +using MeetingAssistant.LaunchProfiles; using MeetingAssistant.MeetingNotes; using MeetingAssistant.Recording; using MeetingAssistant.Speakers; @@ -10,6 +11,7 @@ using Microsoft.Extensions.Options; var builder = WebApplication.CreateBuilder(args); builder.Services.Configure(builder.Configuration.GetSection("MeetingAssistant")); +builder.Services.AddSingleton(); #if WINDOWS builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -40,6 +42,7 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -54,6 +57,9 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); +builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddHostedService(); @@ -72,17 +78,54 @@ app.MapGet("/health", () => Results.Ok(new })); app.MapGet("/recording/status", (MeetingRecordingCoordinator coordinator) => Results.Ok(coordinator.CurrentStatus)); +app.MapGet("/profiles/{launchProfile}/recording/status", ( + string launchProfile, + MeetingRecordingCoordinator coordinator) => Results.Ok(coordinator.CurrentStatus)); app.MapGet("/diagnostics/outlook/current-meeting", async ( IMeetingMetadataProvider metadataProvider, IOptions options, DateTimeOffset? startedAt, double? timeoutSeconds, CancellationToken cancellationToken) => + await DiagnoseOutlookMeetingAsync( + null, + metadataProvider, + options.Value, + null, + startedAt, + timeoutSeconds, + cancellationToken)); +app.MapGet("/profiles/{launchProfile}/diagnostics/outlook/current-meeting", async ( + string launchProfile, + IMeetingMetadataProvider metadataProvider, + IOptions options, + ILaunchProfileOptionsProvider launchProfiles, + DateTimeOffset? startedAt, + double? timeoutSeconds, + CancellationToken cancellationToken) => + await DiagnoseOutlookMeetingAsync( + launchProfile, + metadataProvider, + options.Value, + launchProfiles, + startedAt, + timeoutSeconds, + cancellationToken)); + +static async Task DiagnoseOutlookMeetingAsync( + string? launchProfile, + IMeetingMetadataProvider metadataProvider, + MeetingAssistantOptions defaultOptions, + ILaunchProfileOptionsProvider? launchProfiles, + DateTimeOffset? startedAt, + double? timeoutSeconds, + CancellationToken cancellationToken) { + var profileOptions = ResolveProfileOptions(launchProfile, defaultOptions, launchProfiles); var lookupStartedAt = startedAt ?? DateTimeOffset.Now; var timeout = timeoutSeconds is > 0 ? TimeSpan.FromSeconds(timeoutSeconds.Value) - : options.Value.Recording.MetadataLookupTimeout; + : profileOptions.Recording.MetadataLookupTimeout; if (metadataProvider is IMeetingMetadataDiagnosticProvider diagnostics) { return Results.Ok(await diagnostics.DiagnoseCurrentMeetingAsync( @@ -102,78 +145,224 @@ app.MapGet("/diagnostics/outlook/current-meeting", async ( stopwatch.ElapsedMilliseconds, metadata, metadata is null ? "No meeting metadata provider result was available." : null)); -}); +} + +static MeetingAssistantOptions ResolveProfileOptions( + string? launchProfile, + MeetingAssistantOptions defaultOptions, + ILaunchProfileOptionsProvider? launchProfiles) +{ + if (launchProfiles is not null) + { + return launchProfiles.GetRequiredProfile(launchProfile).Options; + } + + if (string.IsNullOrWhiteSpace(launchProfile) || + launchProfile.Equals(ConfigurationLaunchProfileOptionsProvider.DefaultProfileName, StringComparison.OrdinalIgnoreCase)) + { + return defaultOptions; + } + + throw new InvalidOperationException( + $"Launch profile '{launchProfile}' was requested, but no launch profile provider is registered."); +} + app.MapPost("/diagnostics/speaker-identities/merge", async ( SpeakerIdentityMergeDiagnosticRequest request, ISpeakerIdentityMergeService mergeService, IOptions options, CancellationToken cancellationToken) => + await MergeSpeakerIdentitiesAsync(null, request, mergeService, options.Value, null, cancellationToken)); +app.MapPost("/profiles/{launchProfile}/diagnostics/speaker-identities/merge", async ( + string launchProfile, + SpeakerIdentityMergeDiagnosticRequest request, + ISpeakerIdentityMergeService mergeService, + IOptions options, + ILaunchProfileOptionsProvider launchProfiles, + CancellationToken cancellationToken) => + await MergeSpeakerIdentitiesAsync(launchProfile, request, mergeService, options.Value, launchProfiles, cancellationToken)); + +static async Task MergeSpeakerIdentitiesAsync( + string? launchProfile, + SpeakerIdentityMergeDiagnosticRequest request, + ISpeakerIdentityMergeService mergeService, + MeetingAssistantOptions defaultOptions, + ILaunchProfileOptionsProvider? launchProfiles, + CancellationToken cancellationToken) { + var profileOptions = ResolveProfileOptions(launchProfile, defaultOptions, launchProfiles); var recentAge = request.RecentDays is > 0 ? TimeSpan.FromDays(request.RecentDays.Value) - : options.Value.SpeakerIdentification.MergeRecentIdentityAge; + : profileOptions.SpeakerIdentification.MergeRecentIdentityAge; return Results.Ok(await mergeService.MergeRecentIdentitiesAsync(recentAge, cancellationToken)); -}); +} app.MapPost("/recording/toggle", async (MeetingRecordingCoordinator coordinator, CancellationToken cancellationToken) => Results.Ok(await coordinator.ToggleAsync(cancellationToken))); +app.MapPost("/profiles/{launchProfile}/recording/toggle", async ( + string launchProfile, + MeetingRecordingCoordinator coordinator, + CancellationToken cancellationToken) => + Results.Ok(await coordinator.ToggleAsync(launchProfile, cancellationToken))); app.MapPost("/recording/start", async (MeetingRecordingCoordinator coordinator, CancellationToken cancellationToken) => Results.Ok(await coordinator.StartAsync(cancellationToken))); +app.MapPost("/profiles/{launchProfile}/recording/start", async ( + string launchProfile, + MeetingRecordingCoordinator coordinator, + CancellationToken cancellationToken) => + Results.Ok(await coordinator.StartAsync(launchProfile, cancellationToken))); app.MapPost("/recording/stop", async (MeetingRecordingCoordinator coordinator, CancellationToken cancellationToken) => Results.Ok(await coordinator.StopAsync(cancellationToken))); +app.MapPost("/profiles/{launchProfile}/recording/stop", async ( + string launchProfile, + MeetingRecordingCoordinator coordinator, + CancellationToken cancellationToken) => + Results.Ok(await coordinator.StopAsync(cancellationToken))); app.MapPost("/meetings/current/summary/run", async ( MeetingRecordingCoordinator coordinator, IMeetingSummaryPipeline summaryPipeline, + IOptions options, CancellationToken cancellationToken) => + await RunCurrentSummaryAsync( + null, + coordinator, + summaryPipeline, + options.Value, + null, + cancellationToken)); +app.MapPost("/profiles/{launchProfile}/meetings/current/summary/run", async ( + string launchProfile, + MeetingRecordingCoordinator coordinator, + IMeetingSummaryPipeline summaryPipeline, + IOptions options, + ILaunchProfileOptionsProvider launchProfiles, + CancellationToken cancellationToken) => + await RunCurrentSummaryAsync( + launchProfile, + coordinator, + summaryPipeline, + options.Value, + launchProfiles, + cancellationToken)); + +static async Task RunCurrentSummaryAsync( + string? launchProfile, + MeetingRecordingCoordinator coordinator, + IMeetingSummaryPipeline summaryPipeline, + MeetingAssistantOptions defaultOptions, + ILaunchProfileOptionsProvider? launchProfiles, + CancellationToken cancellationToken) { if (coordinator.CurrentArtifacts is null) { return Results.Conflict(new { error = "No meeting session has been started yet." }); } - return Results.Ok(await summaryPipeline.RunAsync(coordinator.CurrentArtifacts, cancellationToken)); -}); + var profileOptions = ResolveProfileOptions(launchProfile, defaultOptions, launchProfiles); + return Results.Ok(await summaryPipeline.RunAsync(coordinator.CurrentArtifacts, profileOptions, cancellationToken)); +} + app.MapPost("/meetings/summary/retry", async ( SummaryRetryRequest request, IMeetingSummaryArtifactResolver artifactResolver, IMeetingSummaryPipeline summaryPipeline, + IOptions options, CancellationToken cancellationToken) => -{ - if (string.IsNullOrWhiteSpace(request.SummaryPath)) - { - return Results.BadRequest(new { error = "A summary path is required." }); - } - - var artifacts = await artifactResolver.ResolveBySummaryPathAsync(request.SummaryPath, cancellationToken); - if (artifacts is null) - { - return Results.NotFound(new { error = $"No meeting note links to summary '{request.SummaryPath}'." }); - } - - return Results.Ok(await summaryPipeline.RunAsync(artifacts, cancellationToken)); -}); + await RetrySummaryAsync( + null, + request.SummaryPath, + artifactResolver, + summaryPipeline, + options.Value, + null, + cancellationToken)); +app.MapPost("/profiles/{launchProfile}/meetings/summary/retry", async ( + string launchProfile, + SummaryRetryRequest request, + IMeetingSummaryArtifactResolver artifactResolver, + IMeetingSummaryPipeline summaryPipeline, + IOptions options, + ILaunchProfileOptionsProvider launchProfiles, + CancellationToken cancellationToken) => + await RetrySummaryAsync( + launchProfile, + request.SummaryPath, + artifactResolver, + summaryPipeline, + options.Value, + launchProfiles, + cancellationToken)); app.MapGet("/meetings/summary/retry", async ( string summaryPath, IMeetingSummaryArtifactResolver artifactResolver, IMeetingSummaryPipeline summaryPipeline, + IOptions options, CancellationToken cancellationToken) => + await RetrySummaryAsync( + null, + summaryPath, + artifactResolver, + summaryPipeline, + options.Value, + null, + cancellationToken)); +app.MapGet("/profiles/{launchProfile}/meetings/summary/retry", async ( + string launchProfile, + string summaryPath, + IMeetingSummaryArtifactResolver artifactResolver, + IMeetingSummaryPipeline summaryPipeline, + IOptions options, + ILaunchProfileOptionsProvider launchProfiles, + CancellationToken cancellationToken) => + await RetrySummaryAsync( + launchProfile, + summaryPath, + artifactResolver, + summaryPipeline, + options.Value, + launchProfiles, + cancellationToken)); + +static async Task RetrySummaryAsync( + string? launchProfile, + string? summaryPath, + IMeetingSummaryArtifactResolver artifactResolver, + IMeetingSummaryPipeline summaryPipeline, + MeetingAssistantOptions defaultOptions, + ILaunchProfileOptionsProvider? launchProfiles, + CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(summaryPath)) { return Results.BadRequest(new { error = "A summary path is required." }); } - var artifacts = await artifactResolver.ResolveBySummaryPathAsync(summaryPath, cancellationToken); + var profileOptions = ResolveProfileOptions(launchProfile, defaultOptions, launchProfiles); + var artifacts = await artifactResolver.ResolveBySummaryPathAsync(summaryPath, profileOptions, cancellationToken); if (artifacts is null) { return Results.NotFound(new { error = $"No meeting note links to summary '{summaryPath}'." }); } - return Results.Ok(await summaryPipeline.RunAsync(artifacts, cancellationToken)); -}); + return Results.Ok(await summaryPipeline.RunAsync(artifacts, profileOptions, cancellationToken)); +} + app.MapPost("/asr/transcribe-file", async ( AsrDiagnosticRequest request, AsrDiagnosticService diagnostics, CancellationToken cancellationToken) => + await TranscribeFileAsync(null, request, diagnostics, cancellationToken)); +app.MapPost("/profiles/{launchProfile}/asr/transcribe-file", async ( + string launchProfile, + AsrDiagnosticRequest request, + AsrDiagnosticService diagnostics, + CancellationToken cancellationToken) => + await TranscribeFileAsync(launchProfile, request, diagnostics, cancellationToken)); + +static async Task TranscribeFileAsync( + string? launchProfile, + AsrDiagnosticRequest request, + AsrDiagnosticService diagnostics, + CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(request.Path)) { @@ -182,7 +371,7 @@ app.MapPost("/asr/transcribe-file", async ( try { - return Results.Ok(await diagnostics.TranscribeWavAsync(request.Path, cancellationToken)); + return Results.Ok(await diagnostics.TranscribeWavAsync(request.Path, launchProfile, cancellationToken)); } catch (FileNotFoundException exception) { @@ -199,11 +388,24 @@ app.MapPost("/asr/transcribe-file", async ( statusCode: StatusCodes.Status502BadGateway, title: "ASR backend failed while processing the WAV file."); } -}); +} app.MapPost("/asr/diarize-file", async ( AsrDiagnosticRequest request, AsrDiagnosticService diagnostics, CancellationToken cancellationToken) => + await DiarizeFileAsync(null, request, diagnostics, cancellationToken)); +app.MapPost("/profiles/{launchProfile}/asr/diarize-file", async ( + string launchProfile, + AsrDiagnosticRequest request, + AsrDiagnosticService diagnostics, + CancellationToken cancellationToken) => + await DiarizeFileAsync(launchProfile, request, diagnostics, cancellationToken)); + +static async Task DiarizeFileAsync( + string? launchProfile, + AsrDiagnosticRequest request, + AsrDiagnosticService diagnostics, + CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(request.Path)) { @@ -221,6 +423,7 @@ app.MapPost("/asr/diarize-file", async ( return Results.Ok(await diagnostics.DiarizeWavAsync( fullPath, new SpeechRecognitionPipelineOptions(request.NumSpeakers), + launchProfile, cancellationToken)); } catch (Exception exception) @@ -230,7 +433,7 @@ app.MapPost("/asr/diarize-file", async ( statusCode: StatusCodes.Status502BadGateway, title: "ASR diarization backend failed while processing the WAV file."); } -}); +} try { diff --git a/MeetingAssistant/Recording/IRecordedAudioStore.cs b/MeetingAssistant/Recording/IRecordedAudioStore.cs index 5bab82b..bc6b02f 100644 --- a/MeetingAssistant/Recording/IRecordedAudioStore.cs +++ b/MeetingAssistant/Recording/IRecordedAudioStore.cs @@ -4,6 +4,13 @@ public interface IRecordedAudioStore { Task CreateSessionAsync(CancellationToken cancellationToken); + Task CreateSessionAsync( + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return CreateSessionAsync(cancellationToken); + } + Task DeleteStaleRecordingsAsync(CancellationToken cancellationToken); } diff --git a/MeetingAssistant/Recording/ITranscriptStore.cs b/MeetingAssistant/Recording/ITranscriptStore.cs index 025931e..5b98324 100644 --- a/MeetingAssistant/Recording/ITranscriptStore.cs +++ b/MeetingAssistant/Recording/ITranscriptStore.cs @@ -7,6 +7,13 @@ public interface ITranscriptStore { Task CreateSessionAsync(CancellationToken cancellationToken); + Task CreateSessionAsync( + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return CreateSessionAsync(cancellationToken); + } + Task AppendAsync(TranscriptSession session, TranscriptionSegment segment, CancellationToken cancellationToken); Task ReplaceAsync( diff --git a/MeetingAssistant/Recording/MeetingRecordingCoordinator.cs b/MeetingAssistant/Recording/MeetingRecordingCoordinator.cs index d9091aa..6b500cc 100644 --- a/MeetingAssistant/Recording/MeetingRecordingCoordinator.cs +++ b/MeetingAssistant/Recording/MeetingRecordingCoordinator.cs @@ -1,5 +1,6 @@ using System.Threading.Channels; using System.Collections.Concurrent; +using MeetingAssistant.LaunchProfiles; using MeetingAssistant.MeetingNotes; using MeetingAssistant.Speakers; using MeetingAssistant.Summary; @@ -20,7 +21,9 @@ public sealed class MeetingRecordingCoordinator private readonly IRecordedAudioStore recordedAudioStore; private readonly IMeetingSummaryPipeline summaryPipeline; private readonly ISpeakerIdentificationService? speakerIdentificationService; + private readonly ISpeakerIdentityAttendeeCanonicalizer attendeeCanonicalizer; private readonly IDictationWordStore dictationWordStore; + private readonly ILaunchProfileOptionsProvider? launchProfiles; private readonly MeetingAssistantOptions options; private readonly ILogger logger; private readonly SemaphoreSlim gate = new(1, 1); @@ -42,7 +45,9 @@ public sealed class MeetingRecordingCoordinator ILogger logger, IMeetingMetadataProvider? meetingMetadataProvider = null, ISpeakerIdentificationService? speakerIdentificationService = null, - IDictationWordStore? dictationWordStore = null) + IDictationWordStore? dictationWordStore = null, + ISpeakerIdentityAttendeeCanonicalizer? attendeeCanonicalizer = null, + ILaunchProfileOptionsProvider? launchProfiles = null) { this.audioSource = audioSource; this.speechRecognitionPipelineFactory = speechRecognitionPipelineFactory; @@ -55,6 +60,8 @@ public sealed class MeetingRecordingCoordinator this.summaryPipeline = summaryPipeline; this.dictationWordStore = dictationWordStore ?? new EmptyDictationWordStore(); this.speakerIdentificationService = speakerIdentificationService; + this.attendeeCanonicalizer = attendeeCanonicalizer ?? PassthroughSpeakerIdentityAttendeeCanonicalizer.Instance; + this.launchProfiles = launchProfiles; this.options = options.Value; this.logger = logger; } @@ -71,13 +78,27 @@ public sealed class MeetingRecordingCoordinator private bool IsRecording => currentRun is { IsCaptureStopping: false }; public async Task ToggleAsync(CancellationToken cancellationToken) + { + return await ToggleAsync(null, cancellationToken); + } + + public async Task ToggleAsync( + string? launchProfileName, + CancellationToken cancellationToken) { return IsRecording ? await StopAsync(cancellationToken) - : await StartAsync(cancellationToken); + : await StartAsync(launchProfileName, cancellationToken); } public async Task StartAsync(CancellationToken cancellationToken) + { + return await StartAsync(null, cancellationToken); + } + + public async Task StartAsync( + string? launchProfileName, + CancellationToken cancellationToken) { await gate.WaitAsync(cancellationToken); try @@ -87,11 +108,12 @@ public sealed class MeetingRecordingCoordinator return CurrentStatus; } - currentSession = await transcriptStore.CreateSessionAsync(cancellationToken); - var recordedAudio = await recordedAudioStore.CreateSessionAsync(cancellationToken); + var runOptions = ResolveOptions(launchProfileName); + currentSession = await transcriptStore.CreateSessionAsync(runOptions, cancellationToken); + var recordedAudio = await recordedAudioStore.CreateSessionAsync(runOptions, cancellationToken); var startedAt = DateTimeOffset.Now; - var assistantContextPath = GetAssistantContextPath(startedAt); - var summaryPath = GetSummaryPath(startedAt); + var assistantContextPath = GetAssistantContextPath(startedAt, runOptions); + var summaryPath = GetSummaryPath(startedAt, runOptions); currentMeetingNote = await meetingNoteStore.SaveAsync( MeetingNoteTemplate.Create( title: $"Meeting {startedAt:yyyy-MM-dd HH:mm}", @@ -100,16 +122,14 @@ public sealed class MeetingRecordingCoordinator transcriptPath: currentSession.TranscriptPath, assistantContextPath: assistantContextPath, summaryPath: summaryPath), + runOptions, cancellationToken); currentArtifacts = new MeetingSessionArtifacts( currentMeetingNote.Path, currentSession.TranscriptPath, assistantContextPath, summaryPath); - await meetingArtifactStore.CreateAssistantContextAsync(currentArtifacts, "", null, cancellationToken); - _ = Task.Run( - () => ApplyMeetingMetadataWhenAvailableAsync(startedAt, currentArtifacts, currentMeetingNote.Path), - CancellationToken.None); + await meetingArtifactStore.CreateAssistantContextAsync(currentArtifacts, currentMeetingNote, "", null, cancellationToken); await transcriptStore.UpdateMetadataAsync( currentSession, currentArtifacts, @@ -118,18 +138,28 @@ public sealed class MeetingRecordingCoordinator await OpenMeetingNoteAsync(currentMeetingNote.Path, cancellationToken); var captureCancellation = new CancellationTokenSource(); var transcriptionCancellation = new CancellationTokenSource(); - var pipeline = speechRecognitionPipelineFactory.Create(); - var pipelineOptions = await BuildSpeechRecognitionPipelineOptionsAsync(cancellationToken); + var pipeline = speechRecognitionPipelineFactory.Create(launchProfileName); + var pipelineOptions = await BuildSpeechRecognitionPipelineOptionsAsync( + runOptions, + currentMeetingNote.Path, + cancellationToken); var run = new RecordingRun( captureCancellation, transcriptionCancellation, + currentSession, + currentMeetingNote.Path, + currentArtifacts, recordedAudio, pipeline, pipelineOptions, - options.SpeakerIdentification.LiveSampleBufferDuration, - options.SpeakerIdentification.MaxSnippetsPerSpeaker); - run.Task = Task.Run(() => RecordAsync(currentSession, run), CancellationToken.None); + runOptions, + runOptions.SpeakerIdentification.LiveSampleBufferDuration, + runOptions.SpeakerIdentification.MaxSnippetsPerSpeaker); + run.Task = Task.Run(() => RecordAsync(run), CancellationToken.None); currentRun = run; + _ = Task.Run( + () => ApplyMeetingMetadataWhenAvailableAsync(startedAt, run), + CancellationToken.None); logger.LogInformation("Meeting recording started"); return CurrentStatus; @@ -170,7 +200,7 @@ public sealed class MeetingRecordingCoordinator try { - await run.Task.WaitAsync(options.Recording.StopProcessingTimeout, cancellationToken); + await run.Task.WaitAsync(run.Options.Recording.StopProcessingTimeout, cancellationToken); } catch (OperationCanceledException) { @@ -187,19 +217,17 @@ public sealed class MeetingRecordingCoordinator return CurrentStatus; } - private async Task RecordAsync( - TranscriptSession session, - RecordingRun run) + private async Task RecordAsync(RecordingRun run) { await run.Pipeline.InitializeAsync(run.PipelineOptions, run.TranscriptionCancellation); var liveTranscriptTask = Task.Run( - () => StoreLiveTranscriptAsync(session, run, run.TranscriptionCancellation), + () => StoreLiveTranscriptAsync(run, run.TranscriptionCancellation), CancellationToken.None); var captureTask = Task.Run( () => CaptureAudioAsync(run), CancellationToken.None); var liveIdentificationTask = Task.Run( - () => IdentifyLiveSpeakersAsync(session, run, run.TranscriptionCancellation), + () => IdentifyLiveSpeakersAsync(run, run.TranscriptionCancellation), CancellationToken.None); try @@ -210,30 +238,34 @@ public sealed class MeetingRecordingCoordinator run.CancelLiveIdentification(); await liveIdentificationTask; await run.RecordedAudio.DisposeAsync(); - var artifacts = currentArtifacts; - if (artifacts is not null && HasConfiguredFinalizer()) + var artifacts = run.Artifacts; + if (HasConfiguredFinalizer(run.Options)) { - await meetingArtifactStore.UpdateAssistantContextStateAsync( - artifacts, + await TransitionMeetingAsync( + run, AssistantContextState.SpeakerRecognition, run.TranscriptionCancellation); } - await RewriteTranscriptWithFinishedSegmentsAsync(session, run.Pipeline, run, run.TranscriptionCancellation); - var completedMeetingNote = await CompleteMeetingNoteAsync(run.TranscriptionCancellation); - if (artifacts is not null && completedMeetingNote is not null) + await RewriteTranscriptWithFinishedSegmentsAsync(run, run.TranscriptionCancellation); + var completedMeetingNote = await CompleteMeetingNoteAsync( + run.MeetingNotePath, + run.Options, + run.TranscriptionCancellation); + if (completedMeetingNote is not null) { await transcriptStore.UpdateMetadataAsync( - session, + run.Session, + artifacts, + completedMeetingNote, + run.TranscriptionCancellation); + await meetingArtifactStore.UpdateAssistantContextMeetingAsync( artifacts, completedMeetingNote, run.TranscriptionCancellation); } - if (artifacts is not null) - { - await RunSummaryAsync(artifacts, run.TranscriptionCancellation); - } + await RunSummaryAsync(run, run.TranscriptionCancellation); } catch (OperationCanceledException) when (run.TranscriptionCancellation.IsCancellationRequested) { @@ -298,7 +330,6 @@ public sealed class MeetingRecordingCoordinator } private async Task StoreLiveTranscriptAsync( - TranscriptSession session, RecordingRun run, CancellationToken cancellationToken) { @@ -307,22 +338,21 @@ public sealed class MeetingRecordingCoordinator run.TryAddSpeakerSample(segment); var relabeledSegment = run.Relabel(segment); run.AddLiveSegment(relabeledSegment); - await transcriptStore.AppendAsync(session, relabeledSegment, cancellationToken); + await transcriptStore.AppendAsync(run.Session, relabeledSegment, cancellationToken); } } private async Task IdentifyLiveSpeakersAsync( - TranscriptSession session, RecordingRun run, CancellationToken cancellationToken) { - if (speakerIdentificationService is null || !options.SpeakerIdentification.Enabled) + if (speakerIdentificationService is null || !run.Options.SpeakerIdentification.Enabled) { return; } - var initialDelay = options.SpeakerIdentification.InitialDelay; - var interval = options.SpeakerIdentification.Interval; + var initialDelay = run.Options.SpeakerIdentification.InitialDelay; + var interval = run.Options.SpeakerIdentification.Interval; try { if (initialDelay > TimeSpan.Zero) @@ -332,7 +362,7 @@ public sealed class MeetingRecordingCoordinator while (!run.LiveIdentificationCancellation.IsCancellationRequested) { - await IdentifyLiveSpeakersOnceAsync(session, run, run.LiveIdentificationCancellation); + await IdentifyLiveSpeakersOnceAsync(run, run.LiveIdentificationCancellation); await Task.Delay(interval > TimeSpan.Zero ? interval : TimeSpan.FromMinutes(1), run.LiveIdentificationCancellation); } } @@ -342,11 +372,10 @@ public sealed class MeetingRecordingCoordinator } private async Task IdentifyLiveSpeakersOnceAsync( - TranscriptSession session, RecordingRun run, CancellationToken cancellationToken) { - if (string.IsNullOrWhiteSpace(currentMeetingNote?.Path)) + if (string.IsNullOrWhiteSpace(run.MeetingNotePath)) { return; } @@ -360,7 +389,7 @@ public sealed class MeetingRecordingCoordinator try { - var meetingNote = await meetingNoteStore.ReadAsync(currentMeetingNote.Path, cancellationToken); + var meetingNote = await meetingNoteStore.ReadAsync(run.MeetingNotePath, cancellationToken); var checkpoint = run.CreateLiveIdentificationCheckpoint(meetingNote); if (checkpoint is null) { @@ -368,14 +397,23 @@ public sealed class MeetingRecordingCoordinator } var result = await speakerIdentificationService!.IdentifyKnownSpeakersAsync( - new SpeakerIdentificationRequest("", meetingNote, segments, samples), + new SpeakerIdentificationRequest( + "", + meetingNote, + segments, + samples, + run.GetSpeakerMappingsSnapshot()), cancellationToken); run.MarkLiveIdentificationAttempted(checkpoint); - await AddIdentifiedSpeakersToMeetingAttendeesAsync(result.AttendeeMatches, cancellationToken); + await AddIdentifiedSpeakersToMeetingAttendeesAsync( + result.AttendeeMatches, + run.MeetingNotePath, + run.Options, + cancellationToken); if (run.AddSpeakerMappings(result.SpeakerMappings)) { await transcriptStore.ReplaceAsync( - session, + run.Session, run.GetRelabeledLiveSegmentsSnapshot(), cancellationToken); } @@ -392,52 +430,75 @@ public sealed class MeetingRecordingCoordinator private async Task ApplyMeetingMetadataWhenAvailableAsync( DateTimeOffset startedAt, - MeetingSessionArtifacts artifacts, - string meetingNotePath) + RecordingRun run) { - var metadata = await GetMeetingMetadataAsync( - startedAt, - options.Recording.BackgroundMetadataLookupTimeout, - CancellationToken.None); - if (metadata is null) - { - return; - } - - await gate.WaitAsync(CancellationToken.None); try { - var meetingNote = await meetingNoteStore.ReadAsync(meetingNotePath, CancellationToken.None); - ApplyMeetingMetadata(meetingNote, metadata); - meetingNote = await meetingNoteStore.SaveAsync(meetingNote, CancellationToken.None); - if (currentMeetingNote?.Path == meetingNote.Path) + var metadata = await GetMeetingMetadataAsync( + startedAt, + run.Options.Recording.BackgroundMetadataLookupTimeout, + CancellationToken.None); + if (metadata is null) { - currentMeetingNote = meetingNote; + return; } - await meetingArtifactStore.UpdateAssistantContextMetadataAsync( - artifacts, - metadata.Agenda, - metadata.ScheduledEnd, - CancellationToken.None); - logger.LogInformation( - "Applied Outlook meeting metadata to {MeetingNotePath}", - meetingNotePath); + await gate.WaitAsync(CancellationToken.None); + try + { + var meetingNote = await meetingNoteStore.ReadAsync(run.MeetingNotePath, CancellationToken.None); + await ApplyMeetingMetadataAsync(meetingNote, metadata, CancellationToken.None); + meetingNote = await meetingNoteStore.SaveAsync(meetingNote, run.Options, CancellationToken.None); + if (currentMeetingNote?.Path == meetingNote.Path) + { + currentMeetingNote = meetingNote; + } + + await meetingArtifactStore.UpdateAssistantContextMetadataAsync( + run.Artifacts, + meetingNote, + metadata.Agenda, + metadata.ScheduledEnd, + CancellationToken.None); + logger.LogInformation( + "Applied Outlook meeting metadata to {MeetingNotePath}", + run.MeetingNotePath); + } + finally + { + gate.Release(); + } } catch (Exception exception) { logger.LogWarning( exception, "Could not apply Outlook meeting metadata to {MeetingNotePath}", - meetingNotePath); + run.MeetingNotePath); } finally { - gate.Release(); + try + { + await TransitionMeetingAsync( + run, + AssistantContextState.Transcribing, + CancellationToken.None); + } + catch (Exception exception) + { + logger.LogWarning( + exception, + "Could not update assistant context state to transcribing for {MeetingNotePath}", + run.MeetingNotePath); + } } } - private static void ApplyMeetingMetadata(MeetingNote meetingNote, MeetingMetadata metadata) + private async Task ApplyMeetingMetadataAsync( + MeetingNote meetingNote, + MeetingMetadata metadata, + CancellationToken cancellationToken) { if (!string.IsNullOrWhiteSpace(metadata.Title)) { @@ -446,7 +507,30 @@ public sealed class MeetingRecordingCoordinator if (metadata.Attendees.Count > 0) { - meetingNote.Frontmatter.Attendees = metadata.Attendees.ToList(); + meetingNote.Frontmatter.Attendees = await CanonicalizeAttendeesAsync(metadata.Attendees, cancellationToken); + } + } + + private async Task> CanonicalizeAttendeesAsync( + IReadOnlyList attendees, + CancellationToken cancellationToken) + { + try + { + return (await attendeeCanonicalizer.CanonicalizeAsync(attendees, cancellationToken)).ToList(); + } + catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) + { + throw; + } + catch (Exception exception) + { + logger.LogWarning(exception, "Could not canonicalize meeting attendees; writing raw attendee names"); + return attendees + .Select(NormalizeAttendeeName) + .Where(name => !string.IsNullOrWhiteSpace(name)) + .Distinct(StringComparer.OrdinalIgnoreCase) + .ToList(); } } @@ -503,14 +587,12 @@ public sealed class MeetingRecordingCoordinator } private async Task RewriteTranscriptWithFinishedSegmentsAsync( - TranscriptSession session, - ISpeechRecognitionPipeline pipeline, RecordingRun run, CancellationToken cancellationToken) { - var finishedSegments = await pipeline.ReadFinishedTranscriptAsync( + var finishedSegments = await run.Pipeline.ReadFinishedTranscriptAsync( run.RecordedAudio.AudioPath, - await BuildSpeechRecognitionPipelineOptionsAsync(cancellationToken), + await BuildSpeechRecognitionPipelineOptionsAsync(run.Options, run.MeetingNotePath, cancellationToken), cancellationToken); if (finishedSegments.Count == 0) { @@ -524,28 +606,43 @@ public sealed class MeetingRecordingCoordinator run.RecordedAudio.AudioPath, finishedSegments, run.GetSpeakerSamplesSnapshot(), + run.GetSpeakerMappingsSnapshot(), + run.MeetingNotePath, + run.Options, cancellationToken); - await transcriptStore.ReplaceAsync(session, finishedSegments, cancellationToken); + await transcriptStore.ReplaceAsync(run.Session, finishedSegments, cancellationToken); } private async Task> IdentifySpeakersAsync( string audioPath, IReadOnlyList finishedSegments, IReadOnlyList samples, + IReadOnlyDictionary knownSpeakerMappings, + string meetingNotePath, + MeetingAssistantOptions runOptions, CancellationToken cancellationToken) { - if (speakerIdentificationService is null || string.IsNullOrWhiteSpace(currentMeetingNote?.Path)) + if (speakerIdentificationService is null || string.IsNullOrWhiteSpace(meetingNotePath)) { return finishedSegments; } try { - var meetingNote = await meetingNoteStore.ReadAsync(currentMeetingNote.Path, cancellationToken); + var meetingNote = await meetingNoteStore.ReadAsync(meetingNotePath, cancellationToken); var result = await speakerIdentificationService.ProcessFinishedTranscriptAsync( - new SpeakerIdentificationRequest(audioPath, meetingNote, finishedSegments, samples), + new SpeakerIdentificationRequest( + audioPath, + meetingNote, + finishedSegments, + samples, + knownSpeakerMappings), + cancellationToken); + await AddIdentifiedSpeakersToMeetingAttendeesAsync( + result.AttendeeMatches, + meetingNotePath, + runOptions, cancellationToken); - await AddIdentifiedSpeakersToMeetingAttendeesAsync(result.AttendeeMatches, cancellationToken); return result.Segments; } catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) @@ -561,14 +658,16 @@ public sealed class MeetingRecordingCoordinator private async Task AddIdentifiedSpeakersToMeetingAttendeesAsync( IReadOnlyList? matches, + string meetingNotePath, + MeetingAssistantOptions runOptions, CancellationToken cancellationToken) { - if (matches is null || matches.Count == 0 || string.IsNullOrWhiteSpace(currentMeetingNote?.Path)) + if (matches is null || matches.Count == 0 || string.IsNullOrWhiteSpace(meetingNotePath)) { return; } - var meetingNote = await meetingNoteStore.ReadAsync(currentMeetingNote.Path, cancellationToken); + var meetingNote = await meetingNoteStore.ReadAsync(meetingNotePath, cancellationToken); var existingNames = meetingNote.Frontmatter.Attendees .Select(NormalizeAttendeeName) .Where(name => !string.IsNullOrWhiteSpace(name)) @@ -603,45 +702,56 @@ public sealed class MeetingRecordingCoordinator return; } - currentMeetingNote = await meetingNoteStore.SaveAsync(meetingNote, cancellationToken); + var savedMeetingNote = await meetingNoteStore.SaveAsync(meetingNote, runOptions, cancellationToken); + if (string.Equals(currentMeetingNote?.Path, savedMeetingNote.Path, StringComparison.OrdinalIgnoreCase)) + { + currentMeetingNote = savedMeetingNote; + } + logger.LogInformation( "Added identified speaker(s) to meeting note attendees for {MeetingNotePath}", - currentMeetingNote.Path); + savedMeetingNote.Path); } - private async Task CompleteMeetingNoteAsync(CancellationToken cancellationToken) + private async Task CompleteMeetingNoteAsync( + string meetingNotePath, + MeetingAssistantOptions runOptions, + CancellationToken cancellationToken) { - if (string.IsNullOrWhiteSpace(currentMeetingNote?.Path)) + if (string.IsNullOrWhiteSpace(meetingNotePath)) { return null; } - var meetingNote = await meetingNoteStore.ReadAsync(currentMeetingNote.Path, cancellationToken); + var meetingNote = await meetingNoteStore.ReadAsync(meetingNotePath, cancellationToken); meetingNote.Frontmatter.EndTime = DateTimeOffset.Now; - currentMeetingNote = await meetingNoteStore.SaveAsync(meetingNote, cancellationToken); - return currentMeetingNote; + var savedMeetingNote = await meetingNoteStore.SaveAsync(meetingNote, runOptions, cancellationToken); + if (string.Equals(currentMeetingNote?.Path, savedMeetingNote.Path, StringComparison.OrdinalIgnoreCase)) + { + currentMeetingNote = savedMeetingNote; + } + + return savedMeetingNote; } private static string NormalizeAttendeeName(string attendee) { - var trimmed = attendee.Trim(); - var emailStart = trimmed.IndexOf('<', StringComparison.Ordinal); - return emailStart > 0 ? trimmed[..emailStart].Trim() : trimmed; + return MeetingAttendeeNames.NormalizeDisplayName(attendee); } private async Task RunSummaryAsync( - MeetingSessionArtifacts artifacts, + RecordingRun run, CancellationToken cancellationToken) { try { - await meetingArtifactStore.UpdateAssistantContextStateAsync( - artifacts, + await TransitionMeetingAsync( + run, AssistantContextState.Summarizing, cancellationToken); - var result = await summaryPipeline.RunAsync(artifacts, cancellationToken); - await meetingArtifactStore.UpdateAssistantContextStateAsync( - artifacts, + var result = await summaryPipeline.RunAsync(run.Artifacts, run.Options, cancellationToken); + await TransitionMeetingAsync( + run, result.Succeeded ? AssistantContextState.Finished : AssistantContextState.Error, CancellationToken.None); } @@ -652,47 +762,82 @@ public sealed class MeetingRecordingCoordinator catch (Exception exception) { logger.LogError(exception, "Meeting summary pipeline failed unexpectedly"); - await meetingArtifactStore.UpdateAssistantContextStateAsync( - artifacts, + await TransitionMeetingAsync( + run, AssistantContextState.Error, CancellationToken.None); } } - private bool HasConfiguredFinalizer() + private async Task TransitionMeetingAsync( + RecordingRun run, + AssistantContextState state, + CancellationToken cancellationToken) { - return options.Recording.TranscriptionProvider switch + if (!run.TryTransitionTo(state)) { - "funasr" => options.FunAsr.Diarization.Enabled, - "whisper-local" => options.WhisperLocal.Diarization.Enabled, + return; + } + + await meetingArtifactStore.UpdateAssistantContextStateAsync( + run.Artifacts, + state, + cancellationToken); + } + + private bool HasConfiguredFinalizer(MeetingAssistantOptions runOptions) + { + return runOptions.Recording.TranscriptionProvider switch + { + "funasr" => runOptions.FunAsr.Diarization.Enabled, + "whisper-local" => runOptions.WhisperLocal.Diarization.Enabled, _ => false }; } private async Task BuildSpeechRecognitionPipelineOptionsAsync( + MeetingAssistantOptions runOptions, + string? meetingNotePath, CancellationToken cancellationToken) { - var dictationWords = await dictationWordStore.ReadWordsAsync(cancellationToken); - if (string.IsNullOrWhiteSpace(currentMeetingNote?.Path)) + var dictationWords = await dictationWordStore.ReadWordsAsync(runOptions, cancellationToken); + if (string.IsNullOrWhiteSpace(meetingNotePath)) { return new SpeechRecognitionPipelineOptions(DictationWords: dictationWords); } - var meetingNote = await meetingNoteStore.ReadAsync(currentMeetingNote.Path, cancellationToken); + var meetingNote = await meetingNoteStore.ReadAsync(meetingNotePath, cancellationToken); var attendeeCount = meetingNote.Frontmatter.Attendees.Count(attendee => !string.IsNullOrWhiteSpace(attendee)); return attendeeCount > 1 ? new SpeechRecognitionPipelineOptions(attendeeCount, dictationWords) : new SpeechRecognitionPipelineOptions(DictationWords: dictationWords); } - private string GetAssistantContextPath(DateTimeOffset startedAt) + private MeetingAssistantOptions ResolveOptions(string? launchProfileName) { - return GetMeetingArtifactPath(options.Vault, options.Vault.AssistantContextFolder, startedAt, "assistant-context"); + if (launchProfiles is not null) + { + return launchProfiles.GetRequiredProfile(launchProfileName).Options; + } + + if (string.IsNullOrWhiteSpace(launchProfileName) || + launchProfileName.Equals(ConfigurationLaunchProfileOptionsProvider.DefaultProfileName, StringComparison.OrdinalIgnoreCase)) + { + return options; + } + + throw new InvalidOperationException( + $"Launch profile '{launchProfileName}' was requested, but no launch profile provider is registered."); } - private string GetSummaryPath(DateTimeOffset startedAt) + private string GetAssistantContextPath(DateTimeOffset startedAt, MeetingAssistantOptions runOptions) { - return GetMeetingArtifactPath(options.Vault, options.Vault.SummariesFolder, startedAt, "summary"); + return GetMeetingArtifactPath(runOptions.Vault, runOptions.Vault.AssistantContextFolder, startedAt, "assistant-context"); + } + + private string GetSummaryPath(DateTimeOffset startedAt, MeetingAssistantOptions runOptions) + { + return GetMeetingArtifactPath(runOptions.Vault, runOptions.Vault.SummariesFolder, startedAt, "summary"); } private static string GetMeetingArtifactPath( @@ -702,7 +847,7 @@ public sealed class MeetingRecordingCoordinator string artifactName) { var folder = VaultPath.Resolve(vault, configuredFolder); - return Path.Combine(folder, $"{startedAt:yyyyMMdd-HHmmss}-{artifactName}.md"); + return Path.Combine(folder, $"{startedAt:yyyyMMdd-HHmmss-fffffff}-{artifactName}.md"); } private async Task CompleteRunAsync(RecordingRun run) @@ -718,6 +863,9 @@ public sealed class MeetingRecordingCoordinator if (ReferenceEquals(currentRun, run)) { currentRun = null; + currentSession = null; + currentMeetingNote = null; + currentArtifacts = null; } } finally @@ -730,6 +878,7 @@ public sealed class MeetingRecordingCoordinator private sealed class RecordingRun : IDisposable { private int completed; + private readonly object stateGate = new(); private readonly object liveSegmentsGate = new(); private readonly object liveIdentificationGate = new(); private readonly List liveSegments = []; @@ -740,18 +889,26 @@ public sealed class MeetingRecordingCoordinator public RecordingRun( CancellationTokenSource captureCancellation, CancellationTokenSource transcriptionCancellation, + TranscriptSession session, + string meetingNotePath, + MeetingSessionArtifacts artifacts, IRecordedAudioSink recordedAudio, ISpeechRecognitionPipeline pipeline, SpeechRecognitionPipelineOptions pipelineOptions, + MeetingAssistantOptions options, TimeSpan liveSampleBufferDuration, int maxSpeakerSamples) { CaptureCancellationSource = captureCancellation; TranscriptionCancellationSource = transcriptionCancellation; LiveIdentificationCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(transcriptionCancellation.Token); + Session = session; + MeetingNotePath = meetingNotePath; + Artifacts = artifacts; RecordedAudio = recordedAudio; Pipeline = pipeline; PipelineOptions = pipelineOptions; + Options = options; speakerSampleCollector = new SpeakerAudioSampleCollector(liveSampleBufferDuration, maxSpeakerSamples); } @@ -763,10 +920,18 @@ public sealed class MeetingRecordingCoordinator public IRecordedAudioSink RecordedAudio { get; } + public TranscriptSession Session { get; } + + public string MeetingNotePath { get; } + + public MeetingSessionArtifacts Artifacts { get; } + public ISpeechRecognitionPipeline Pipeline { get; } public SpeechRecognitionPipelineOptions PipelineOptions { get; } + public MeetingAssistantOptions Options { get; } + public CancellationToken CaptureCancellation => CaptureCancellationSource.Token; public CancellationToken TranscriptionCancellation => TranscriptionCancellationSource.Token; @@ -777,6 +942,8 @@ public sealed class MeetingRecordingCoordinator public bool IsCaptureStopping => CaptureCancellationSource.IsCancellationRequested; + public AssistantContextState ContextState { get; private set; } = AssistantContextState.CollectingMetadata; + public void StopCapture() { CaptureCancellationSource.Cancel(); @@ -792,6 +959,20 @@ public sealed class MeetingRecordingCoordinator LiveIdentificationCancellationSource.Cancel(); } + public bool TryTransitionTo(AssistantContextState state) + { + lock (stateGate) + { + if (StateRank(state) <= StateRank(ContextState)) + { + return false; + } + + ContextState = state; + return true; + } + } + public void AddLiveSegment(TranscriptionSegment segment) { lock (liveSegmentsGate) @@ -883,6 +1064,14 @@ public sealed class MeetingRecordingCoordinator } } + public IReadOnlyDictionary GetSpeakerMappingsSnapshot() + { + return speakerMappings.ToDictionary( + pair => pair.Key, + pair => pair.Value, + StringComparer.OrdinalIgnoreCase); + } + private IReadOnlyList GetUnmappedSampleSpeakers() { return GetSpeakerSamplesSnapshot() @@ -917,6 +1106,20 @@ public sealed class MeetingRecordingCoordinator LiveIdentificationCancellationSource.Dispose(); } + private static int StateRank(AssistantContextState state) + { + return state switch + { + AssistantContextState.CollectingMetadata => 0, + AssistantContextState.Transcribing => 1, + AssistantContextState.SpeakerRecognition => 2, + AssistantContextState.Summarizing => 3, + AssistantContextState.Finished => 4, + AssistantContextState.Error => 5, + _ => 5 + }; + } + public sealed record LiveIdentificationCheckpoint( IReadOnlyList Speakers, string AttendeeSignature) diff --git a/MeetingAssistant/Recording/TemporaryRecordedAudioStore.cs b/MeetingAssistant/Recording/TemporaryRecordedAudioStore.cs index b49cb28..8a2626d 100644 --- a/MeetingAssistant/Recording/TemporaryRecordedAudioStore.cs +++ b/MeetingAssistant/Recording/TemporaryRecordedAudioStore.cs @@ -18,7 +18,14 @@ public sealed class TemporaryRecordedAudioStore : IRecordedAudioStore public Task CreateSessionAsync(CancellationToken cancellationToken) { - var folder = GetTemporaryRecordingsFolder(); + return CreateSessionAsync(options, cancellationToken); + } + + public Task CreateSessionAsync( + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + var folder = GetTemporaryRecordingsFolder(options); Directory.CreateDirectory(folder); var path = Path.Combine(folder, $"{DateTimeOffset.Now:yyyyMMdd-HHmmss}-{Guid.NewGuid():N}-recording.wav"); @@ -30,7 +37,7 @@ public sealed class TemporaryRecordedAudioStore : IRecordedAudioStore public Task DeleteStaleRecordingsAsync(CancellationToken cancellationToken) { - var folder = GetTemporaryRecordingsFolder(); + var folder = GetTemporaryRecordingsFolder(options); if (!Directory.Exists(folder)) { return Task.CompletedTask; @@ -45,7 +52,7 @@ public sealed class TemporaryRecordedAudioStore : IRecordedAudioStore return Task.CompletedTask; } - private string GetTemporaryRecordingsFolder() + private static string GetTemporaryRecordingsFolder(MeetingAssistantOptions options) { return VaultPath.Resolve(options.Recording.TemporaryRecordingsFolder); } diff --git a/MeetingAssistant/Recording/VaultTranscriptStore.cs b/MeetingAssistant/Recording/VaultTranscriptStore.cs index df5a5b0..c4ab7d5 100644 --- a/MeetingAssistant/Recording/VaultTranscriptStore.cs +++ b/MeetingAssistant/Recording/VaultTranscriptStore.cs @@ -16,11 +16,18 @@ public sealed class VaultTranscriptStore : ITranscriptStore } public async Task CreateSessionAsync(CancellationToken cancellationToken) + { + return await CreateSessionAsync(options, cancellationToken); + } + + public async Task CreateSessionAsync( + MeetingAssistantOptions options, + CancellationToken cancellationToken) { var folder = VaultPath.Resolve(options.Vault, options.Vault.TranscriptsFolder); Directory.CreateDirectory(folder); - var fileName = $"{DateTimeOffset.Now:yyyyMMdd-HHmmss}-transcript.md"; + var fileName = $"{DateTimeOffset.Now:yyyyMMdd-HHmmss-fffffff}-transcript.md"; var path = Path.Combine(folder, fileName); await File.WriteAllTextAsync(path, $"# Meeting Transcript{Environment.NewLine}{Environment.NewLine}", cancellationToken); logger.LogInformation("Created meeting transcript file {TranscriptPath}", path); diff --git a/MeetingAssistant/Speakers/AzureSpeechSpeakerIdentityMatcher.cs b/MeetingAssistant/Speakers/AzureSpeechSpeakerIdentityMatcher.cs index fd282fb..4a19042 100644 --- a/MeetingAssistant/Speakers/AzureSpeechSpeakerIdentityMatcher.cs +++ b/MeetingAssistant/Speakers/AzureSpeechSpeakerIdentityMatcher.cs @@ -52,7 +52,15 @@ public sealed class AzureSpeechSpeakerIdentityMatcher : ISpeakerIdentityMatcher return null; } - var segments = await diarizationClient.DiarizeAsync(tempPath, cancellationToken); + var segments = await DiarizeWithTimeoutAsync(tempPath, cancellationToken); + if (segments.Count == 0) + { + logger.LogInformation( + "Speaker identity matching {DiarizedSpeaker} skipped because diarization returned no segments", + request.DiarizedSpeaker); + return null; + } + logger.LogInformation( "Speaker identity matching {DiarizedSpeaker} received {SegmentCount} diarized segment(s)", request.DiarizedSpeaker, @@ -95,6 +103,31 @@ public sealed class AzureSpeechSpeakerIdentityMatcher : ISpeakerIdentityMatcher } } + private async Task> DiarizeWithTimeoutAsync( + string wavPath, + CancellationToken cancellationToken) + { + var matchTimeout = options.MatchTimeout; + if (matchTimeout <= TimeSpan.Zero) + { + return await diarizationClient.DiarizeAsync(wavPath, cancellationToken); + } + + using var timeout = new CancellationTokenSource(matchTimeout); + using var linked = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeout.Token); + try + { + return await diarizationClient.DiarizeAsync(wavPath, linked.Token); + } + catch (OperationCanceledException) when (timeout.IsCancellationRequested && !cancellationToken.IsCancellationRequested) + { + logger.LogWarning( + "Speaker identity diarization timed out after {Timeout}", + matchTimeout); + return []; + } + } + private CompositeLayout WriteCompositeWav(string path, SpeakerIdentityMatchRequest request) { using var firstReader = OpenFirstReadableWave(request); diff --git a/MeetingAssistant/Speakers/SpeakerIdentificationModels.cs b/MeetingAssistant/Speakers/SpeakerIdentificationModels.cs index 887b2a2..fe933e6 100644 --- a/MeetingAssistant/Speakers/SpeakerIdentificationModels.cs +++ b/MeetingAssistant/Speakers/SpeakerIdentificationModels.cs @@ -7,7 +7,8 @@ public sealed record SpeakerIdentificationRequest( string AudioPath, MeetingNote MeetingNote, IReadOnlyList Segments, - IReadOnlyList? Samples = null); + IReadOnlyList? Samples = null, + IReadOnlyDictionary? KnownSpeakerMappings = null); public sealed record SpeakerAudioSample( string Speaker, @@ -32,7 +33,7 @@ public sealed record SpeakerIdentityMatchRequest( public sealed record SpeakerIdentityMatchCandidate( int IdentityId, string? CanonicalName, - int TranscriptionCount, + int ReferenceCount, IReadOnlyList Snippets); public sealed record SpeakerIdentityMatch(int IdentityId); diff --git a/MeetingAssistant/Speakers/SpeakerIdentity.cs b/MeetingAssistant/Speakers/SpeakerIdentity.cs index 27a0e47..85f3175 100644 --- a/MeetingAssistant/Speakers/SpeakerIdentity.cs +++ b/MeetingAssistant/Speakers/SpeakerIdentity.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations.Schema; namespace MeetingAssistant.Speakers; @@ -8,8 +9,6 @@ public sealed class SpeakerIdentity public string? CanonicalName { get; set; } - public int TranscriptionCount { get; set; } - public DateTimeOffset CreatedAt { get; set; } public DateTimeOffset UpdatedAt { get; set; } @@ -20,6 +19,11 @@ public sealed class SpeakerIdentity public List Snippets { get; set; } = []; + public List References { get; set; } = []; + + [NotMapped] + public int ReferenceCount => References.Count; + public string? GetDisplayName() { if (!string.IsNullOrWhiteSpace(CanonicalName)) @@ -35,6 +39,65 @@ public sealed class SpeakerIdentity } } +public sealed class SpeakerIdentityReference +{ + public int Id { get; set; } + + public int SpeakerIdentityId { get; set; } + + public SpeakerIdentity? SpeakerIdentity { get; set; } + + public string MeetingNotePath { get; set; } = ""; + + public string TranscriptPath { get; set; } = ""; + + public DateTimeOffset CreatedAt { get; set; } +} + +public static class SpeakerIdentityReferences +{ + public static SpeakerIdentityReference Create( + string meetingNotePath, + string transcriptPath, + DateTimeOffset createdAt) + { + return new SpeakerIdentityReference + { + MeetingNotePath = meetingNotePath, + TranscriptPath = transcriptPath, + CreatedAt = createdAt + }; + } + + public static void AddIfMissing( + SpeakerIdentity identity, + SpeakerIdentityReference reference, + DateTimeOffset? createdAt = null) + { + if (IsEmpty(reference) || identity.References.Any(existing => IsSame(existing, reference))) + { + return; + } + + identity.References.Add(Create( + reference.MeetingNotePath, + reference.TranscriptPath, + createdAt ?? reference.CreatedAt)); + } + + private static bool IsEmpty(SpeakerIdentityReference reference) + { + return string.IsNullOrWhiteSpace(reference.MeetingNotePath) && + string.IsNullOrWhiteSpace(reference.TranscriptPath); + } + + private static bool IsSame(SpeakerIdentityReference first, SpeakerIdentityReference second) + { + return string.Equals(first.MeetingNotePath, second.MeetingNotePath, StringComparison.OrdinalIgnoreCase) && + string.Equals(first.TranscriptPath, second.TranscriptPath, StringComparison.OrdinalIgnoreCase); + } +} + public sealed class SpeakerCandidateName { public int Id { get; set; } @@ -85,10 +148,15 @@ public sealed class SpeakerIdentityDbContext : DbContext public DbSet SpeakerSnippets => Set(); + public DbSet SpeakerIdentityReferences => Set(); + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { + entity.Property("TranscriptionCount") + .HasDefaultValue(0); + entity.HasMany(identity => identity.CandidateNames) .WithOne(candidate => candidate.SpeakerIdentity) .HasForeignKey(candidate => candidate.SpeakerIdentityId) @@ -103,6 +171,11 @@ public sealed class SpeakerIdentityDbContext : DbContext .WithOne(snippet => snippet.SpeakerIdentity) .HasForeignKey(snippet => snippet.SpeakerIdentityId) .OnDelete(DeleteBehavior.Cascade); + + entity.HasMany(identity => identity.References) + .WithOne(reference => reference.SpeakerIdentity) + .HasForeignKey(reference => reference.SpeakerIdentityId) + .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity() @@ -112,5 +185,9 @@ public sealed class SpeakerIdentityDbContext : DbContext modelBuilder.Entity() .HasIndex(alias => new { alias.SpeakerIdentityId, alias.Name }) .IsUnique(); + + modelBuilder.Entity() + .HasIndex(reference => new { reference.SpeakerIdentityId, reference.MeetingNotePath, reference.TranscriptPath }) + .IsUnique(); } } diff --git a/MeetingAssistant/Speakers/SpeakerIdentityAttendeeCanonicalizer.cs b/MeetingAssistant/Speakers/SpeakerIdentityAttendeeCanonicalizer.cs new file mode 100644 index 0000000..9ef932e --- /dev/null +++ b/MeetingAssistant/Speakers/SpeakerIdentityAttendeeCanonicalizer.cs @@ -0,0 +1,124 @@ +using Microsoft.EntityFrameworkCore; +using MeetingAssistant.MeetingNotes; + +namespace MeetingAssistant.Speakers; + +public interface ISpeakerIdentityAttendeeCanonicalizer +{ + Task> CanonicalizeAsync( + IReadOnlyList attendees, + CancellationToken cancellationToken); +} + +public sealed class SpeakerIdentityAttendeeCanonicalizer : ISpeakerIdentityAttendeeCanonicalizer +{ + private readonly IDbContextFactory dbContextFactory; + + public SpeakerIdentityAttendeeCanonicalizer(IDbContextFactory dbContextFactory) + { + this.dbContextFactory = dbContextFactory; + } + + public async Task> CanonicalizeAsync( + IReadOnlyList attendees, + CancellationToken cancellationToken) + { + var attendeeEntries = attendees + .Select(attendee => new + { + Raw = attendee.Trim(), + DisplayName = NormalizeName(attendee) + }) + .Where(entry => !string.IsNullOrWhiteSpace(entry.Raw) && !string.IsNullOrWhiteSpace(entry.DisplayName)) + .ToList(); + if (attendeeEntries.Count == 0) + { + return []; + } + + await using var context = await dbContextFactory.CreateDbContextAsync(cancellationToken); + await SpeakerIdentitySchema.EnsureCreatedOrUpdatedAsync(context, cancellationToken); + + var identities = await context.SpeakerIdentities + .Include(identity => identity.Aliases) + .Include(identity => identity.References) + .ToListAsync(cancellationToken); + var identitiesByAcceptedName = identities + .OrderBy(identity => string.IsNullOrWhiteSpace(identity.CanonicalName)) + .ThenByDescending(identity => identity.ReferenceCount) + .ThenByDescending(identity => identity.UpdatedAt) + .ThenBy(identity => identity.Id) + .SelectMany(identity => GetExactAcceptedNames(identity).Select(name => new { Name = name, Identity = identity })) + .GroupBy(entry => entry.Name, StringComparer.OrdinalIgnoreCase) + .ToDictionary(group => group.Key, group => group.First().Identity, StringComparer.OrdinalIgnoreCase); + + var result = new List(); + var seenNames = new HashSet(StringComparer.OrdinalIgnoreCase); + var seenIdentityIds = new HashSet(); + foreach (var attendee in attendeeEntries) + { + if (identitiesByAcceptedName.TryGetValue(attendee.DisplayName!, out var identity)) + { + var displayName = identity.GetDisplayName(); + if (string.IsNullOrWhiteSpace(displayName) || !seenIdentityIds.Add(identity.Id)) + { + continue; + } + + if (seenNames.Add(displayName)) + { + result.Add(displayName); + } + + continue; + } + + if (seenNames.Add(attendee.Raw)) + { + result.Add(attendee.Raw); + } + } + + return result; + } + + private static IEnumerable GetExactAcceptedNames(SpeakerIdentity identity) + { + return new[] { identity.CanonicalName } + .Concat(identity.Aliases.Select(alias => alias.Name)) + .Select(NormalizeName) + .Where(name => !string.IsNullOrWhiteSpace(name)) + .Select(name => name!); + } + + private static string? NormalizeName(string? name) + { + if (string.IsNullOrWhiteSpace(name)) + { + return null; + } + + return MeetingAttendeeNames.NormalizeDisplayName(name); + } +} + +public sealed class PassthroughSpeakerIdentityAttendeeCanonicalizer : ISpeakerIdentityAttendeeCanonicalizer +{ + public static PassthroughSpeakerIdentityAttendeeCanonicalizer Instance { get; } = new(); + + private PassthroughSpeakerIdentityAttendeeCanonicalizer() + { + } + + public Task> CanonicalizeAsync( + IReadOnlyList attendees, + CancellationToken cancellationToken) + { + var distinctAttendees = attendees + .Select(attendee => attendee.Trim()) + .Where(name => !string.IsNullOrWhiteSpace(name)) + .Distinct(StringComparer.OrdinalIgnoreCase) + .ToList(); + return Task.FromResult>(distinctAttendees); + } +} diff --git a/MeetingAssistant/Speakers/SpeakerIdentityMergeService.cs b/MeetingAssistant/Speakers/SpeakerIdentityMergeService.cs index 9d821d9..fab3c09 100644 --- a/MeetingAssistant/Speakers/SpeakerIdentityMergeService.cs +++ b/MeetingAssistant/Speakers/SpeakerIdentityMergeService.cs @@ -47,7 +47,8 @@ public sealed class SpeakerIdentityMergeService : ISpeakerIdentityMergeService .Include(identity => identity.Aliases) .Include(identity => identity.CandidateNames) .Include(identity => identity.Snippets) - .OrderByDescending(identity => identity.TranscriptionCount) + .Include(identity => identity.References) + .OrderByDescending(identity => identity.References.Count) .ThenBy(identity => identity.Id) .ToListAsync(cancellationToken); @@ -107,7 +108,14 @@ public sealed class SpeakerIdentityMergeService : ISpeakerIdentityMergeService continue; } + var targetName = target.GetDisplayName() ?? $"identity-{target.Id}"; + var sourceName = source.GetDisplayName() ?? $"identity-{source.Id}"; MergeIdentities(target, source); + await SpeakerIdentityTranscriptAudit.AppendMergedAsync( + target.References, + targetName, + sourceName, + cancellationToken); context.SpeakerIdentities.Remove(source); identities.Remove(source); mergedPairs++; @@ -138,7 +146,7 @@ public sealed class SpeakerIdentityMergeService : ISpeakerIdentityMergeService candidates.Select(identity => new SpeakerIdentityMatchCandidate( identity.Id, identity.GetDisplayName(), - identity.TranscriptionCount, + identity.ReferenceCount, identity.Snippets .OrderBy(snippet => snippet.CreatedAt) .Select(snippet => snippet.WavBytes) @@ -166,8 +174,12 @@ public sealed class SpeakerIdentityMergeService : ISpeakerIdentityMergeService AddAlias(target, candidate.Name); } - target.TranscriptionCount += source.TranscriptionCount; target.UpdatedAt = DateTimeOffset.UtcNow; + foreach (var reference in source.References) + { + SpeakerIdentityReferences.AddIfMissing(target, reference); + } + var retainedSnippets = target.Snippets .Concat(source.Snippets) .OrderBy(snippet => StableSnippetKey(snippet.WavBytes)) diff --git a/MeetingAssistant/Speakers/SpeakerIdentitySchema.cs b/MeetingAssistant/Speakers/SpeakerIdentitySchema.cs index de89a13..34d4e47 100644 --- a/MeetingAssistant/Speakers/SpeakerIdentitySchema.cs +++ b/MeetingAssistant/Speakers/SpeakerIdentitySchema.cs @@ -27,6 +27,25 @@ internal static class SpeakerIdentitySchema ON "SpeakerAliases" ("SpeakerIdentityId", "Name"); """, cancellationToken); + await context.Database.ExecuteSqlRawAsync( + """ + CREATE TABLE IF NOT EXISTS "SpeakerIdentityReferences" ( + "Id" INTEGER NOT NULL CONSTRAINT "PK_SpeakerIdentityReferences" PRIMARY KEY AUTOINCREMENT, + "SpeakerIdentityId" INTEGER NOT NULL, + "MeetingNotePath" TEXT NOT NULL, + "TranscriptPath" TEXT NOT NULL, + "CreatedAt" TEXT NOT NULL, + CONSTRAINT "FK_SpeakerIdentityReferences_SpeakerIdentities_SpeakerIdentityId" + FOREIGN KEY ("SpeakerIdentityId") REFERENCES "SpeakerIdentities" ("Id") ON DELETE CASCADE + ); + """, + cancellationToken); + await context.Database.ExecuteSqlRawAsync( + """ + CREATE UNIQUE INDEX IF NOT EXISTS "IX_SpeakerIdentityReferences_SpeakerIdentityId_MeetingNotePath_TranscriptPath" + ON "SpeakerIdentityReferences" ("SpeakerIdentityId", "MeetingNotePath", "TranscriptPath"); + """, + cancellationToken); } private static async Task EnsureSpeakerIdentityTimestampColumnsAsync( diff --git a/MeetingAssistant/Speakers/SpeakerIdentityService.cs b/MeetingAssistant/Speakers/SpeakerIdentityService.cs index 52d7f50..98854c8 100644 --- a/MeetingAssistant/Speakers/SpeakerIdentityService.cs +++ b/MeetingAssistant/Speakers/SpeakerIdentityService.cs @@ -1,3 +1,4 @@ +using MeetingAssistant.MeetingNotes; using MeetingAssistant.Transcription; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; @@ -54,9 +55,31 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService await SpeakerIdentitySchema.EnsureCreatedOrUpdatedAsync(context, cancellationToken); var attendees = NormalizeAttendees(request.MeetingNote.Frontmatter.Attendees); + var meetingReference = CreateReference(request.MeetingNote, DateTimeOffset.UtcNow); var speakerMappings = new Dictionary(StringComparer.OrdinalIgnoreCase); var attendeeMatches = new List(); + var knownSpeakerMappings = request.KnownSpeakerMappings ?? + new Dictionary(StringComparer.OrdinalIgnoreCase); + var knownDiarizedSpeakers = knownSpeakerMappings.Keys + .Where(speaker => !string.IsNullOrWhiteSpace(speaker)) + .ToHashSet(StringComparer.OrdinalIgnoreCase); + var alreadyIdentifiedNames = knownSpeakerMappings.Values + .Where(name => !string.IsNullOrWhiteSpace(name)) + .Select(name => name.Trim()) + .ToHashSet(StringComparer.OrdinalIgnoreCase); + foreach (var speaker in request.Segments + .Select(segment => segment.Speaker) + .Where(speaker => !string.IsNullOrWhiteSpace(speaker) && !IsDiarizedSpeakerLabel(speaker))) + { + alreadyIdentifiedNames.Add(speaker.Trim()); + } + var matchedAcceptedNames = new HashSet(StringComparer.OrdinalIgnoreCase); + foreach (var name in alreadyIdentifiedNames) + { + matchedAcceptedNames.Add(name); + } + var unmatchedSpeakers = new List<(string Speaker, byte[] Snippet)>(); var samplesBySpeaker = request.Samples? .Where(sample => !string.IsNullOrWhiteSpace(sample.Speaker) && sample.WavBytes.Length > 0) @@ -73,6 +96,11 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService .OrderBy(group => group.Min(segment => segment.Start))) { var speaker = group.Key; + if (knownDiarizedSpeakers.Contains(speaker) || alreadyIdentifiedNames.Contains(speaker)) + { + continue; + } + if (speakerMappings.ContainsKey(speaker)) { continue; @@ -90,7 +118,13 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService continue; } - var match = await FindMatchAsync(context, attendees, speaker, snippet, cancellationToken); + var match = await FindMatchAsync( + context, + attendees, + alreadyIdentifiedNames, + speaker, + snippet, + cancellationToken); if (match is null) { unmatchedSpeakers.Add((speaker, snippet)); @@ -106,7 +140,19 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService if (mode == SpeakerIdentityProcessingMode.Final) { + var previousCanonicalName = identity.CanonicalName; + AddMeetingReference(identity, meetingReference); UpdateMatchedIdentity(identity, attendees, snippet); + if (string.IsNullOrWhiteSpace(previousCanonicalName) && + !string.IsNullOrWhiteSpace(identity.CanonicalName)) + { + await SpeakerIdentityTranscriptAudit.AppendIdentifiedAsync( + identity.References, + speaker, + identity.CanonicalName, + cancellationToken); + } + foreach (var acceptedName in GetAcceptedNames(identity)) { matchedAcceptedNames.Add(acceptedName); @@ -117,6 +163,12 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService if (!string.IsNullOrWhiteSpace(speakerName)) { speakerMappings[speaker] = speakerName; + alreadyIdentifiedNames.Add(speakerName); + foreach (var acceptedName in GetAcceptedNames(identity)) + { + alreadyIdentifiedNames.Add(acceptedName); + } + attendeeMatches.Add(new SpeakerIdentityAttendeeMatch( speakerName, GetAcceptedNames(identity).ToList())); @@ -125,7 +177,13 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService if (mode == SpeakerIdentityProcessingMode.Final) { - await LearnUnmatchedSpeakersAsync(context, attendees, matchedAcceptedNames, unmatchedSpeakers, cancellationToken); + await LearnUnmatchedSpeakersAsync( + context, + attendees, + matchedAcceptedNames, + unmatchedSpeakers, + meetingReference, + cancellationToken); } await context.SaveChangesAsync(cancellationToken); @@ -141,6 +199,7 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService private async Task FindMatchAsync( SpeakerIdentityDbContext context, IReadOnlyList attendees, + IReadOnlySet alreadyIdentifiedNames, string speaker, byte[] snippet, CancellationToken cancellationToken) @@ -150,7 +209,8 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService var identities = await context.SpeakerIdentities .Include(identity => identity.Snippets) .Include(identity => identity.Aliases) - .OrderByDescending(identity => identity.TranscriptionCount) + .Include(identity => identity.References) + .OrderByDescending(identity => identity.References.Count) .ThenBy(identity => identity.Id) .ToListAsync(cancellationToken); identities = identities @@ -161,8 +221,9 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService IsActive = identity.UpdatedAt >= activeCutoff }) .Where(candidate => candidate.IsAttendee || candidate.IsActive) + .Where(candidate => !MatchesAcceptedNames(candidate.Identity, alreadyIdentifiedNames)) .OrderByDescending(candidate => candidate.IsAttendee) - .ThenByDescending(candidate => candidate.Identity.TranscriptionCount) + .ThenByDescending(candidate => candidate.Identity.ReferenceCount) .ThenBy(candidate => candidate.Identity.Id) .Take(maxCandidates) .Select(candidate => candidate.Identity) @@ -176,7 +237,7 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService batch.Select(identity => new SpeakerIdentityMatchCandidate( identity.Id, identity.CanonicalName, - identity.TranscriptionCount, + identity.ReferenceCount, identity.Snippets.Select(storedSnippet => storedSnippet.WavBytes).ToList())) .ToList()); var match = await matcher.MatchAsync(request, cancellationToken); @@ -189,6 +250,13 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService return null; } + private static bool MatchesAcceptedNames( + SpeakerIdentity identity, + IReadOnlySet names) + { + return GetAcceptedNames(identity).Any(names.Contains); + } + private static bool MatchesAttendees( SpeakerIdentity identity, IReadOnlyList attendees) @@ -206,6 +274,7 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService .Include(identity => identity.CandidateNames) .Include(identity => identity.Aliases) .Include(identity => identity.Snippets) + .Include(identity => identity.References) .SingleOrDefaultAsync(identity => identity.Id == identityId, cancellationToken); } @@ -214,7 +283,6 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService IReadOnlyList attendees, byte[] snippet) { - identity.TranscriptionCount++; identity.UpdatedAt = DateTimeOffset.UtcNow; if (string.IsNullOrWhiteSpace(identity.CanonicalName) && attendees.Count > 0) @@ -265,6 +333,7 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService IReadOnlyList attendees, IEnumerable matchedCanonicalNames, IReadOnlyList<(string Speaker, byte[] Snippet)> unmatchedSpeakers, + SpeakerIdentityReference meetingReference, CancellationToken cancellationToken) { var remainingCandidates = attendees @@ -276,11 +345,13 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService return; } - foreach (var (_, snippet) in unmatchedSpeakers.Where(speaker => speaker.Snippet.Length > 0)) + foreach (var (speaker, snippet) in unmatchedSpeakers.Where(speaker => speaker.Snippet.Length > 0)) { var now = DateTimeOffset.UtcNow; - context.SpeakerIdentities.Add(new SpeakerIdentity + var canonicalName = remainingCandidates.Count == 1 ? remainingCandidates[0] : null; + var identity = new SpeakerIdentity { + CanonicalName = canonicalName, CreatedAt = now, UpdatedAt = now, CandidateNames = remainingCandidates @@ -293,8 +364,24 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService WavBytes = snippet, CreatedAt = now } + ], + References = + [ + SpeakerIdentityReferences.Create( + meetingReference.MeetingNotePath, + meetingReference.TranscriptPath, + now) ] - }); + }; + context.SpeakerIdentities.Add(identity); + if (!string.IsNullOrWhiteSpace(canonicalName)) + { + await SpeakerIdentityTranscriptAudit.AppendIdentifiedAsync( + identity.References, + speaker, + canonicalName, + cancellationToken); + } } await Task.CompletedTask; @@ -366,9 +453,30 @@ public sealed class SpeakerIdentityService : ISpeakerIdentificationService private static string NormalizeAttendee(string attendee) { - var trimmed = attendee.Trim(); - var emailStart = trimmed.IndexOf('<', StringComparison.Ordinal); - return emailStart > 0 ? trimmed[..emailStart].Trim() : trimmed; + return MeetingAttendeeNames.NormalizeDisplayName(attendee); + } + + private static bool IsDiarizedSpeakerLabel(string speaker) + { + var normalized = speaker.Trim(); + return normalized.Equals("Unknown", StringComparison.OrdinalIgnoreCase) || + normalized.StartsWith("Guest", StringComparison.OrdinalIgnoreCase) || + normalized.StartsWith("Speaker", StringComparison.OrdinalIgnoreCase); + } + + private static SpeakerIdentityReference CreateReference(MeetingNote meetingNote, DateTimeOffset timestamp) + { + return SpeakerIdentityReferences.Create( + meetingNote.Path, + meetingNote.Frontmatter.Transcript, + timestamp); + } + + private static void AddMeetingReference( + SpeakerIdentity identity, + SpeakerIdentityReference reference) + { + SpeakerIdentityReferences.AddIfMissing(identity, reference, DateTimeOffset.UtcNow); } private enum SpeakerIdentityProcessingMode diff --git a/MeetingAssistant/Speakers/SpeakerIdentityTranscriptAudit.cs b/MeetingAssistant/Speakers/SpeakerIdentityTranscriptAudit.cs new file mode 100644 index 0000000..feb1ba4 --- /dev/null +++ b/MeetingAssistant/Speakers/SpeakerIdentityTranscriptAudit.cs @@ -0,0 +1,59 @@ +namespace MeetingAssistant.Speakers; + +internal static class SpeakerIdentityTranscriptAudit +{ + public static Task AppendIdentifiedAsync( + IEnumerable references, + string speakerLabel, + string name, + CancellationToken cancellationToken) + { + return AppendAsync( + references, + $"{DateTimeOffset.Now:yyyy-MM-dd} {speakerLabel} was identified as {name}", + cancellationToken); + } + + public static Task AppendMergedAsync( + IEnumerable references, + string name1, + string name2, + CancellationToken cancellationToken) + { + return AppendAsync( + references, + $"{DateTimeOffset.Now:yyyy-MM-dd} {name1} and {name2} were merged", + cancellationToken); + } + + private static async Task AppendAsync( + IEnumerable references, + string line, + CancellationToken cancellationToken) + { + foreach (var transcriptPath in references + .Select(reference => reference.TranscriptPath) + .Where(path => !string.IsNullOrWhiteSpace(path)) + .Distinct(StringComparer.OrdinalIgnoreCase)) + { + if (!File.Exists(transcriptPath)) + { + continue; + } + + var existing = await File.ReadAllTextAsync(transcriptPath, cancellationToken); + if (existing.Contains(line, StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + var separator = existing.EndsWith(Environment.NewLine, StringComparison.Ordinal) + ? "" + : Environment.NewLine; + await File.AppendAllTextAsync( + transcriptPath, + $"{separator}{line}{Environment.NewLine}", + cancellationToken); + } + } +} diff --git a/MeetingAssistant/Summary/BoundMeetingProjectResolver.cs b/MeetingAssistant/Summary/BoundMeetingProjectResolver.cs new file mode 100644 index 0000000..cf20dbc --- /dev/null +++ b/MeetingAssistant/Summary/BoundMeetingProjectResolver.cs @@ -0,0 +1,74 @@ +using MeetingAssistant.MeetingNotes; +using YamlDotNet.Serialization; + +namespace MeetingAssistant.Summary; + +public sealed record BoundMeetingProject(string Name, string Path); + +public sealed class BoundMeetingProjectResolver +{ + private static readonly IDeserializer YamlDeserializer = new DeserializerBuilder() + .IgnoreUnmatchedProperties() + .Build(); + + private readonly MeetingAssistantOptions options; + + public BoundMeetingProjectResolver(MeetingAssistantOptions options) + { + this.options = options; + } + + public string ProjectsRoot => VaultPath.Resolve(options.Vault, options.Vault.ProjectsFolder); + + public async Task> GetBoundProjectsAsync( + MeetingSessionArtifacts artifacts, + CancellationToken cancellationToken = default) + { + if (!Directory.Exists(ProjectsRoot)) + { + return []; + } + + var projectNames = await ReadMeetingProjectNamesAsync(artifacts.MeetingNotePath, cancellationToken); + if (projectNames.Count == 0) + { + return []; + } + + return Directory.EnumerateDirectories(ProjectsRoot) + .Select(path => new BoundMeetingProject(Path.GetFileName(path), path)) + .Where(project => projectNames.Contains(project.Name)) + .OrderBy(project => project.Name, StringComparer.OrdinalIgnoreCase) + .ToList(); + } + + private static async Task> ReadMeetingProjectNamesAsync( + string meetingNotePath, + CancellationToken cancellationToken) + { + if (!File.Exists(meetingNotePath)) + { + return []; + } + + var content = await File.ReadAllTextAsync(meetingNotePath, cancellationToken); + var document = MarkdownDocumentParser.SplitOptional(content); + if (!document.HasFrontmatter) + { + return []; + } + + var frontmatter = YamlDeserializer.Deserialize(document.Frontmatter) + ?? new ProjectFrontmatter(); + return (frontmatter.Projects ?? []) + .Where(project => !string.IsNullOrWhiteSpace(project)) + .Select(project => project.Trim()) + .ToHashSet(StringComparer.OrdinalIgnoreCase); + } + + private sealed class ProjectFrontmatter + { + [YamlMember(Alias = "projects")] + public List? Projects { get; set; } + } +} diff --git a/MeetingAssistant/Summary/IMeetingSummaryInstructionBuilder.cs b/MeetingAssistant/Summary/IMeetingSummaryInstructionBuilder.cs index 9c82378..607817e 100644 --- a/MeetingAssistant/Summary/IMeetingSummaryInstructionBuilder.cs +++ b/MeetingAssistant/Summary/IMeetingSummaryInstructionBuilder.cs @@ -7,4 +7,12 @@ public interface IMeetingSummaryInstructionBuilder Task BuildAsync( MeetingSessionArtifacts artifacts, CancellationToken cancellationToken); + + Task BuildAsync( + MeetingSessionArtifacts artifacts, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return BuildAsync(artifacts, cancellationToken); + } } diff --git a/MeetingAssistant/Summary/IMeetingSummaryPipeline.cs b/MeetingAssistant/Summary/IMeetingSummaryPipeline.cs index f83f935..30165d4 100644 --- a/MeetingAssistant/Summary/IMeetingSummaryPipeline.cs +++ b/MeetingAssistant/Summary/IMeetingSummaryPipeline.cs @@ -5,6 +5,14 @@ namespace MeetingAssistant.Summary; public interface IMeetingSummaryPipeline { Task RunAsync(MeetingSessionArtifacts artifacts, CancellationToken cancellationToken); + + Task RunAsync( + MeetingSessionArtifacts artifacts, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return RunAsync(artifacts, cancellationToken); + } } public sealed record MeetingSummaryRunResult( diff --git a/MeetingAssistant/Summary/MeetingSummaryArtifactResolver.cs b/MeetingAssistant/Summary/MeetingSummaryArtifactResolver.cs index 42117ef..5c4a510 100644 --- a/MeetingAssistant/Summary/MeetingSummaryArtifactResolver.cs +++ b/MeetingAssistant/Summary/MeetingSummaryArtifactResolver.cs @@ -8,6 +8,14 @@ public interface IMeetingSummaryArtifactResolver Task ResolveBySummaryPathAsync( string summaryPath, CancellationToken cancellationToken); + + Task ResolveBySummaryPathAsync( + string summaryPath, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return ResolveBySummaryPathAsync(summaryPath, cancellationToken); + } } public sealed class MeetingSummaryArtifactResolver : IMeetingSummaryArtifactResolver @@ -27,7 +35,15 @@ public sealed class MeetingSummaryArtifactResolver : IMeetingSummaryArtifactReso string summaryPath, CancellationToken cancellationToken) { - var requestedSummaryPath = ResolveRequestedSummaryPath(summaryPath); + return await ResolveBySummaryPathAsync(summaryPath, options, cancellationToken); + } + + public async Task ResolveBySummaryPathAsync( + string summaryPath, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + var requestedSummaryPath = ResolveRequestedSummaryPath(summaryPath, options); if (requestedSummaryPath is null) { return null; @@ -58,7 +74,9 @@ public sealed class MeetingSummaryArtifactResolver : IMeetingSummaryArtifactReso return null; } - private string? ResolveRequestedSummaryPath(string summaryPath) + private static string? ResolveRequestedSummaryPath( + string summaryPath, + MeetingAssistantOptions options) { if (string.IsNullOrWhiteSpace(summaryPath)) { diff --git a/MeetingAssistant/Summary/MeetingSummaryFailureWriter.cs b/MeetingAssistant/Summary/MeetingSummaryFailureWriter.cs index 5ff5bcd..1fd1c1c 100644 --- a/MeetingAssistant/Summary/MeetingSummaryFailureWriter.cs +++ b/MeetingAssistant/Summary/MeetingSummaryFailureWriter.cs @@ -10,6 +10,15 @@ public interface IMeetingSummaryFailureWriter MeetingSessionArtifacts artifacts, Exception exception, CancellationToken cancellationToken); + + Task WriteAsync( + MeetingSessionArtifacts artifacts, + Exception exception, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return WriteAsync(artifacts, exception, cancellationToken); + } } public sealed class MeetingSummaryFailureWriter : IMeetingSummaryFailureWriter @@ -29,6 +38,15 @@ public sealed class MeetingSummaryFailureWriter : IMeetingSummaryFailureWriter MeetingSessionArtifacts artifacts, Exception exception, CancellationToken cancellationToken) + { + return await WriteAsync(artifacts, exception, options, cancellationToken); + } + + public async Task WriteAsync( + MeetingSessionArtifacts artifacts, + Exception exception, + MeetingAssistantOptions options, + CancellationToken cancellationToken) { Directory.CreateDirectory(Path.GetDirectoryName(artifacts.SummaryPath)!); var meetingNote = File.Exists(artifacts.MeetingNotePath) @@ -43,7 +61,7 @@ public sealed class MeetingSummaryFailureWriter : IMeetingSummaryFailureWriter artifacts.SummaryPath, MeetingArtifactFrontmatterRenderer.Render( frontmatter, - RenderFailureMarkdown(artifacts, exception)), + RenderFailureMarkdown(artifacts, exception, options)), cancellationToken); return new MeetingSummaryRunResult( @@ -53,7 +71,10 @@ public sealed class MeetingSummaryFailureWriter : IMeetingSummaryFailureWriter Error: exception.Message); } - private string RenderFailureMarkdown(MeetingSessionArtifacts artifacts, Exception exception) + private static string RenderFailureMarkdown( + MeetingSessionArtifacts artifacts, + Exception exception, + MeetingAssistantOptions options) { var builder = new StringBuilder(); builder.AppendLine("# Meeting Summary"); diff --git a/MeetingAssistant/Summary/MeetingSummaryInstructionBuilder.cs b/MeetingAssistant/Summary/MeetingSummaryInstructionBuilder.cs index 047bebe..69b7894 100644 --- a/MeetingAssistant/Summary/MeetingSummaryInstructionBuilder.cs +++ b/MeetingAssistant/Summary/MeetingSummaryInstructionBuilder.cs @@ -1,6 +1,5 @@ using MeetingAssistant.MeetingNotes; using Microsoft.Extensions.Options; -using YamlDotNet.Serialization; namespace MeetingAssistant.Summary; @@ -21,25 +20,31 @@ public sealed class MeetingSummaryInstructionBuilder : IMeetingSummaryInstructio Keep the output grounded in the source material and explicitly say when a section has no known items. """; - private static readonly IDeserializer YamlDeserializer = new DeserializerBuilder() - .IgnoreUnmatchedProperties() - .Build(); - private readonly MeetingAssistantOptions options; + private readonly BoundMeetingProjectResolver projectResolver; public MeetingSummaryInstructionBuilder(IOptions options) { this.options = options.Value; + projectResolver = new BoundMeetingProjectResolver(this.options); } public async Task BuildAsync( MeetingSessionArtifacts artifacts, CancellationToken cancellationToken) + { + return await BuildAsync(artifacts, options, cancellationToken); + } + + public async Task BuildAsync( + MeetingSessionArtifacts artifacts, + MeetingAssistantOptions options, + CancellationToken cancellationToken) { var instructions = string.IsNullOrWhiteSpace(options.Agent.InitialPrompt) ? DefaultInitialPrompt : options.Agent.InitialPrompt.Trim(); - var projectInstructions = await BuildProjectInstructionsAsync(artifacts, cancellationToken); + var projectInstructions = await BuildProjectInstructionsAsync(artifacts, options, cancellationToken); return string.IsNullOrWhiteSpace(projectInstructions) ? instructions : instructions.TrimEnd() + "\n\n" + projectInstructions; @@ -47,9 +52,10 @@ public sealed class MeetingSummaryInstructionBuilder : IMeetingSummaryInstructio private async Task BuildProjectInstructionsAsync( MeetingSessionArtifacts artifacts, + MeetingAssistantOptions options, CancellationToken cancellationToken) { - var projects = await GetBoundProjectsWithInstructionsAsync(artifacts, cancellationToken); + var projects = await GetBoundProjectsWithInstructionsAsync(artifacts, options, cancellationToken); if (projects.Count == 0) { return ""; @@ -62,30 +68,16 @@ public sealed class MeetingSummaryInstructionBuilder : IMeetingSummaryInstructio private async Task> GetBoundProjectsWithInstructionsAsync( MeetingSessionArtifacts artifacts, + MeetingAssistantOptions options, CancellationToken cancellationToken) { - var projectNames = await ReadMeetingProjectNamesAsync(artifacts.MeetingNotePath, cancellationToken); - if (projectNames.Count == 0) - { - return []; - } - - var projectsRoot = VaultPath.Resolve(options.Vault, options.Vault.ProjectsFolder); - if (!Directory.Exists(projectsRoot)) - { - return []; - } - + var resolver = ReferenceEquals(options, this.options) + ? projectResolver + : new BoundMeetingProjectResolver(options); var projects = new List(); - foreach (var projectDirectory in Directory.EnumerateDirectories(projectsRoot).Order(StringComparer.OrdinalIgnoreCase)) + foreach (var project in await resolver.GetBoundProjectsAsync(artifacts, cancellationToken)) { - var projectName = Path.GetFileName(projectDirectory); - if (!projectNames.Contains(projectName)) - { - continue; - } - - var agentsPath = Path.Combine(projectDirectory, "AGENTS.md"); + var agentsPath = Path.Combine(project.Path, "AGENTS.md"); if (!File.Exists(agentsPath)) { continue; @@ -94,42 +86,12 @@ public sealed class MeetingSummaryInstructionBuilder : IMeetingSummaryInstructio var content = await File.ReadAllTextAsync(agentsPath, cancellationToken); if (!string.IsNullOrWhiteSpace(content)) { - projects.Add(new ProjectInstructions(projectName, content)); + projects.Add(new ProjectInstructions(project.Name, content)); } } return projects; } - private static async Task> ReadMeetingProjectNamesAsync( - string meetingNotePath, - CancellationToken cancellationToken) - { - if (!File.Exists(meetingNotePath)) - { - return []; - } - - var content = await File.ReadAllTextAsync(meetingNotePath, cancellationToken); - var document = MarkdownDocumentParser.SplitOptional(content); - if (!document.HasFrontmatter) - { - return []; - } - - var frontmatter = YamlDeserializer.Deserialize(document.Frontmatter) - ?? new ProjectFrontmatter(); - return (frontmatter.Projects ?? []) - .Where(project => !string.IsNullOrWhiteSpace(project)) - .Select(project => project.Trim()) - .ToHashSet(StringComparer.OrdinalIgnoreCase); - } - private sealed record ProjectInstructions(string Name, string Instructions); - - private sealed class ProjectFrontmatter - { - [YamlMember(Alias = "projects")] - public List? Projects { get; set; } - } } diff --git a/MeetingAssistant/Summary/MeetingSummaryTools.cs b/MeetingAssistant/Summary/MeetingSummaryTools.cs index 5a9bf3d..21db201 100644 --- a/MeetingAssistant/Summary/MeetingSummaryTools.cs +++ b/MeetingAssistant/Summary/MeetingSummaryTools.cs @@ -15,6 +15,8 @@ public sealed class MeetingSummaryTools private readonly MeetingSessionArtifacts artifacts; private readonly MeetingAssistantOptions options; private readonly IDictationWordStore? dictationWordStore; + private readonly SummaryAgentWriteAudit? writeAudit; + private readonly BoundMeetingProjectResolver projectResolver; public MeetingSummaryTools(MeetingSessionArtifacts artifacts) : this(artifacts, new MeetingAssistantOptions(), null) @@ -24,11 +26,14 @@ public sealed class MeetingSummaryTools public MeetingSummaryTools( MeetingSessionArtifacts artifacts, MeetingAssistantOptions options, - IDictationWordStore? dictationWordStore = null) + IDictationWordStore? dictationWordStore = null, + SummaryAgentWriteAudit? writeAudit = null) { this.artifacts = artifacts; this.options = options; this.dictationWordStore = dictationWordStore; + this.writeAudit = writeAudit; + projectResolver = new BoundMeetingProjectResolver(options); } public Task ReadTranscript(int? @from = null, int? to = null) @@ -76,7 +81,16 @@ public sealed class MeetingSummaryTools return "Refused: word must not be empty."; } - var words = await dictationWordStore.AddWordAsync(word, CancellationToken.None); + if (writeAudit is not null) + { + IReadOnlyList? capturedWords = null; + await writeAudit.CaptureFileWriteAsync( + VaultPath.Resolve(options.Vault, options.Vault.DictationWordsPath), + async () => capturedWords = await dictationWordStore.AddWordAsync(word, options, CancellationToken.None)); + return $"Added '{word.Trim()}'. Dictionary now contains {capturedWords?.Count ?? 0} word(s)."; + } + + var words = await dictationWordStore.AddWordAsync(word, options, CancellationToken.None); return $"Added '{word.Trim()}'. Dictionary now contains {words.Count} word(s)."; } @@ -176,7 +190,17 @@ public sealed class MeetingSummaryTools } Directory.CreateDirectory(Path.GetDirectoryName(target.Path)!); - await WriteProjectFileContentAsync(target.Path, content, editMode); + if (writeAudit is not null) + { + await writeAudit.CaptureFileWriteAsync( + target.Path, + () => WriteProjectFileContentAsync(target.Path, content, editMode)); + } + else + { + await WriteProjectFileContentAsync(target.Path, content, editMode); + } + return $"{target.Project.Name}/{ToToolPath(path)}"; } @@ -237,7 +261,7 @@ public sealed class MeetingSummaryTools return new MeetingNote(artifacts.MeetingNotePath, frontmatter, await ReadUserNotes()); } - private async Task> GetSearchProjectsAsync(string[]? projects) + private async Task> GetSearchProjectsAsync(string[]? projects) { var boundProjects = await GetBoundProjectsAsync(); if (projects is null || projects.Length == 0) @@ -253,7 +277,7 @@ public sealed class MeetingSummaryTools .ToList(); } - private async Task ResolveBoundProjectAsync(string project) + private async Task ResolveBoundProjectAsync(string project) { if (string.IsNullOrWhiteSpace(project)) { @@ -297,7 +321,7 @@ public sealed class MeetingSummaryTools } var projectFolder = Directory.EnumerateDirectories(projectsRoot) - .Select(candidate => new ProjectFolder(Path.GetFileName(candidate), candidate)) + .Select(candidate => new BoundMeetingProject(Path.GetFileName(candidate), candidate)) .FirstOrDefault(candidate => string.Equals(candidate.Name, project, StringComparison.OrdinalIgnoreCase)); if (projectFolder is null) { @@ -414,56 +438,19 @@ public sealed class MeetingSummaryTools return string.Join('\n', lines); } - private async Task> GetBoundProjectsAsync() + private Task> GetBoundProjectsAsync() { - var projectsRoot = GetProjectsRoot(); - if (!Directory.Exists(projectsRoot)) - { - return []; - } - - var projectNames = await ReadMeetingProjectNamesAsync(); - if (projectNames.Count == 0) - { - return []; - } - - return Directory.EnumerateDirectories(projectsRoot) - .Select(path => new ProjectFolder(Path.GetFileName(path), path)) - .Where(project => projectNames.Contains(project.Name)) - .OrderBy(project => project.Name, StringComparer.OrdinalIgnoreCase) - .ToList(); - } - - private async Task> ReadMeetingProjectNamesAsync() - { - if (!File.Exists(artifacts.MeetingNotePath)) - { - return []; - } - - var content = await File.ReadAllTextAsync(artifacts.MeetingNotePath); - var document = MarkdownDocumentParser.SplitOptional(content); - if (!document.HasFrontmatter) - { - return []; - } - - var note = YamlDeserializer.Deserialize(document.Frontmatter) ?? new ProjectFrontmatter(); - return (note.Projects ?? []) - .Where(project => !string.IsNullOrWhiteSpace(project)) - .Select(project => project.Trim()) - .ToHashSet(StringComparer.OrdinalIgnoreCase); + return projectResolver.GetBoundProjectsAsync(artifacts); } private string GetProjectsRoot() { - return VaultPath.Resolve(options.Vault, options.Vault.ProjectsFolder); + return projectResolver.ProjectsRoot; } private static async Task RunRipgrepAsync( string projectsRoot, - IReadOnlyList projects, + IReadOnlyList projects, string keywords) { try @@ -528,7 +515,7 @@ public sealed class MeetingSummaryTools return string.Join('\n', matches); } - private static string SearchWithRegexFallback(IReadOnlyList projects, string keywords, bool singleProject) + private static string SearchWithRegexFallback(IReadOnlyList projects, string keywords, bool singleProject) { try { @@ -584,9 +571,7 @@ public sealed class MeetingSummaryTools .Replace(Path.AltDirectorySeparatorChar.ToString(), "/", StringComparison.Ordinal); } - private sealed record ProjectFolder(string Name, string Path); - - private sealed record ProjectFileTarget(ProjectFolder Project, string Path); + private sealed record ProjectFileTarget(BoundMeetingProject Project, string Path); private sealed record FileLineEditMode( FileLineEditKind Kind, @@ -621,12 +606,6 @@ public sealed class MeetingSummaryTools Insert } - private sealed class ProjectFrontmatter - { - [YamlDotNet.Serialization.YamlMember(Alias = "projects")] - public List? Projects { get; set; } - } - private sealed class MeetingNoteFrontmatterYaml { [YamlDotNet.Serialization.YamlMember(Alias = "title")] diff --git a/MeetingAssistant/Summary/OpenAiMeetingSummaryAgentPipeline.cs b/MeetingAssistant/Summary/OpenAiMeetingSummaryAgentPipeline.cs index 23653a5..6b88fba 100644 --- a/MeetingAssistant/Summary/OpenAiMeetingSummaryAgentPipeline.cs +++ b/MeetingAssistant/Summary/OpenAiMeetingSummaryAgentPipeline.cs @@ -39,11 +39,20 @@ public sealed class OpenAiMeetingSummaryAgentPipeline : IMeetingSummaryPipeline public async Task RunAsync( MeetingSessionArtifacts artifacts, CancellationToken cancellationToken) + { + return await RunAsync(artifacts, options, cancellationToken); + } + + public async Task RunAsync( + MeetingSessionArtifacts artifacts, + MeetingAssistantOptions options, + CancellationToken cancellationToken) { var agentOptions = options.Agent; var key = ResolveApiKey(agentOptions); - var tools = CreateTools(new MeetingSummaryTools(artifacts, options, dictationWordStore)); - var instructions = await instructionBuilder.BuildAsync(artifacts, cancellationToken); + var writeAudit = new SummaryAgentWriteAudit(artifacts); + var tools = CreateTools(new MeetingSummaryTools(artifacts, options, dictationWordStore, writeAudit)); + var instructions = await instructionBuilder.BuildAsync(artifacts, options, cancellationToken); using var compactionSummaryClient = new LiteLlmResponsesChatClient( new Uri(agentOptions.Endpoint), key, @@ -85,6 +94,7 @@ public sealed class OpenAiMeetingSummaryAgentPipeline : IMeetingSummaryPipeline options: new ChatClientAgentRunOptions(CreateChatOptions(agentOptions)), cancellationToken: cancellationToken); + await writeAudit.AppendToAssistantContextAsync(cancellationToken); return new MeetingSummaryRunResult(artifacts.SummaryPath, response.Text); } catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) @@ -97,7 +107,9 @@ public sealed class OpenAiMeetingSummaryAgentPipeline : IMeetingSummaryPipeline exception, "Meeting summary generation failed for {SummaryPath}; writing failure summary", artifacts.SummaryPath); - return await failureWriter.WriteAsync(artifacts, exception, cancellationToken); + var result = await failureWriter.WriteAsync(artifacts, exception, options, cancellationToken); + await writeAudit.AppendToAssistantContextAsync(cancellationToken); + return result; } } diff --git a/MeetingAssistant/Summary/SummaryAgentWriteAudit.cs b/MeetingAssistant/Summary/SummaryAgentWriteAudit.cs new file mode 100644 index 0000000..79d0760 --- /dev/null +++ b/MeetingAssistant/Summary/SummaryAgentWriteAudit.cs @@ -0,0 +1,117 @@ +using DiffPlex.DiffBuilder; +using DiffPlex.DiffBuilder.Model; +using MeetingAssistant.MeetingNotes; +using System.Text; + +namespace MeetingAssistant.Summary; + +public sealed class SummaryAgentWriteAudit +{ + private readonly MeetingSessionArtifacts artifacts; + private readonly List changes = []; + + public SummaryAgentWriteAudit(MeetingSessionArtifacts artifacts) + { + this.artifacts = artifacts; + } + + public async Task CaptureFileWriteAsync( + string path, + Func writeOperation, + CancellationToken cancellationToken = default) + { + var fullPath = Path.GetFullPath(path); + var before = File.Exists(fullPath) + ? await File.ReadAllTextAsync(fullPath, cancellationToken) + : ""; + await writeOperation(); + var after = File.Exists(fullPath) + ? await File.ReadAllTextAsync(fullPath, cancellationToken) + : ""; + Capture(fullPath, before, after, cancellationToken); + } + + public void Capture( + string path, + string before, + string after, + CancellationToken cancellationToken = default) + { + cancellationToken.ThrowIfCancellationRequested(); + var fullPath = Path.GetFullPath(path); + if (IsOwnedArtifact(fullPath) || string.Equals(before, after, StringComparison.Ordinal)) + { + return; + } + + var diffLines = CreateDiffLines(before, after); + if (diffLines.Count == 0) + { + return; + } + + changes.Add(new FileChange(fullPath, diffLines)); + } + + public async Task AppendToAssistantContextAsync(CancellationToken cancellationToken) + { + if (changes.Count == 0) + { + return; + } + + Directory.CreateDirectory(Path.GetDirectoryName(artifacts.AssistantContextPath)!); + var existing = File.Exists(artifacts.AssistantContextPath) + ? await File.ReadAllTextAsync(artifacts.AssistantContextPath, cancellationToken) + : ""; + var builder = new StringBuilder(); + if (!string.IsNullOrEmpty(existing) && !existing.EndsWith(Environment.NewLine, StringComparison.Ordinal)) + { + builder.AppendLine(); + } + + builder.AppendLine(); + builder.AppendLine("## Summary Agent External File Changes"); + builder.AppendLine(); + foreach (var change in changes) + { + builder.AppendLine($"### {change.Path}"); + builder.AppendLine(); + builder.AppendLine("```diff"); + foreach (var line in change.DiffLines) + { + builder.AppendLine(line); + } + + builder.AppendLine("```"); + builder.AppendLine(); + } + + await File.AppendAllTextAsync(artifacts.AssistantContextPath, builder.ToString(), cancellationToken); + } + + private bool IsOwnedArtifact(string fullPath) + { + return IsSamePath(fullPath, artifacts.SummaryPath) || + IsSamePath(fullPath, artifacts.AssistantContextPath); + } + + private static bool IsSamePath(string first, string second) + { + return string.Equals( + Path.GetFullPath(first), + Path.GetFullPath(second), + StringComparison.OrdinalIgnoreCase); + } + + private static List CreateDiffLines(string before, string after) + { + var model = InlineDiffBuilder.Diff(before, after); + return model.Lines + .Where(line => line.Type is ChangeType.Deleted or ChangeType.Inserted) + .Select(line => $"{(line.Type == ChangeType.Inserted ? "+" : "-")} {line.Text}") + .ToList(); + } + + private sealed record FileChange(string Path, IReadOnlyList DiffLines); +} diff --git a/MeetingAssistant/Transcription/AsrDiagnosticService.cs b/MeetingAssistant/Transcription/AsrDiagnosticService.cs index 00864ce..2e5bb64 100644 --- a/MeetingAssistant/Transcription/AsrDiagnosticService.cs +++ b/MeetingAssistant/Transcription/AsrDiagnosticService.cs @@ -12,20 +12,18 @@ public sealed class AsrDiagnosticService this.pipelineFactory = pipelineFactory; } - public async Task TranscribeWavAsync(string path, CancellationToken cancellationToken) + public Task TranscribeWavAsync(string path, CancellationToken cancellationToken) { - if (string.IsNullOrWhiteSpace(path)) - { - throw new ArgumentException("A WAV file path is required.", nameof(path)); - } + return TranscribeWavAsync(path, launchProfileName: null, cancellationToken); + } - var fullPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(path)); - if (!File.Exists(fullPath)) - { - throw new FileNotFoundException($"WAV file was not found at '{fullPath}'.", fullPath); - } - - await using var pipeline = pipelineFactory.Create(); + public async Task TranscribeWavAsync( + string path, + string? launchProfileName, + CancellationToken cancellationToken) + { + var fullPath = ResolveExistingWavPath(path); + await using var pipeline = pipelineFactory.Create(launchProfileName); await pipeline.InitializeAsync(cancellationToken); var liveTranscriptTask = CollectLiveTranscriptAsync(pipeline, cancellationToken); await WriteWavToPipelineAsync(fullPath, pipeline, paceAudio: true, cancellationToken); @@ -39,7 +37,17 @@ public sealed class AsrDiagnosticService CancellationToken cancellationToken) { var fullPath = ResolveExistingWavPath(path); - await using var pipeline = pipelineFactory.Create(); + return await DiarizeWavAsync(fullPath, options, launchProfileName: null, cancellationToken); + } + + public async Task DiarizeWavAsync( + string path, + SpeechRecognitionPipelineOptions options, + string? launchProfileName, + CancellationToken cancellationToken) + { + var fullPath = ResolveExistingWavPath(path); + await using var pipeline = pipelineFactory.Create(launchProfileName); await pipeline.InitializeAsync(cancellationToken); var liveTranscriptTask = CollectLiveTranscriptAsync(pipeline, cancellationToken); await WriteWavToPipelineAsync(fullPath, pipeline, paceAudio: true, cancellationToken); @@ -99,7 +107,9 @@ public sealed class AsrDiagnosticService string path, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default) { - using var reader = new WaveFileReader(path); + var reader = new WaveFileReader(path); + try + { var format = reader.WaveFormat; if (format.Encoding != WaveFormatEncoding.Pcm || format.BitsPerSample != 16) { @@ -113,6 +123,18 @@ public sealed class AsrDiagnosticService { yield return new AudioChunk(buffer[..read], format.SampleRate, format.Channels); } + } + finally + { + try + { + reader.Dispose(); + } + catch (NotSupportedException) + { + // NAudio can throw while disposing reader streams from async iterators; diagnostics should not fail after reading all chunks. + } + } } } diff --git a/MeetingAssistant/Transcription/AzureSpeechRecognitionPipelineBuilder.cs b/MeetingAssistant/Transcription/AzureSpeechRecognitionPipelineBuilder.cs new file mode 100644 index 0000000..427f043 --- /dev/null +++ b/MeetingAssistant/Transcription/AzureSpeechRecognitionPipelineBuilder.cs @@ -0,0 +1,18 @@ +namespace MeetingAssistant.Transcription; + +public sealed class AzureSpeechRecognitionPipelineBuilder : + SpeechRecognitionPipelineBuilder, + ISpeechRecognitionPipelineBuilder +{ + public AzureSpeechRecognitionPipelineBuilder(IServiceProvider services) + : base(services) + { + } + + public string ProviderName => "azure-speech"; + + public ISpeechRecognitionPipeline Create(MeetingAssistantOptions options) + { + return new AzureSpeechRecognitionPipeline(CreateProfiled(options)); + } +} diff --git a/MeetingAssistant/Transcription/AzureSpeechStreamingTranscriptionProvider.cs b/MeetingAssistant/Transcription/AzureSpeechStreamingTranscriptionProvider.cs index 5bc66d2..9f9acb8 100644 --- a/MeetingAssistant/Transcription/AzureSpeechStreamingTranscriptionProvider.cs +++ b/MeetingAssistant/Transcription/AzureSpeechStreamingTranscriptionProvider.cs @@ -25,7 +25,9 @@ public sealed class AzureSpeechStreamingTranscriptionProvider : IStreamingTransc SpeechRecognitionPipelineOptions pipelineOptions, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken) { - await using var enumerator = audio.GetAsyncEnumerator(cancellationToken); + var enumerator = audio.GetAsyncEnumerator(cancellationToken); + try + { if (!await enumerator.MoveNextAsync()) { yield break; @@ -94,6 +96,18 @@ public sealed class AzureSpeechStreamingTranscriptionProvider : IStreamingTransc } await pumpTask.WaitAsync(cancellationToken); + } + finally + { + try + { + await enumerator.DisposeAsync(); + } + catch (NotSupportedException) + { + // Some diagnostic async enumerable sources expose DisposeAsync but throw after the stream has been read. + } + } } internal ConversationTranscriber CreateTranscriber(SpeechConfig speechConfig, AudioConfig audioConfig) @@ -150,7 +164,7 @@ public sealed class AzureSpeechStreamingTranscriptionProvider : IStreamingTransc $"Azure Speech key is not configured. Set AzureSpeech:Key or environment variable {azure.KeyEnv}."); } - var speechConfig = SpeechConfig.FromEndpoint(GetEndpoint(azure), key); + var speechConfig = CreateSpeechConfig(azure, key); var autoDetectLanguages = GetAutoDetectLanguages(azure); if (autoDetectLanguages.Count == 0) { @@ -167,6 +181,13 @@ public sealed class AzureSpeechStreamingTranscriptionProvider : IStreamingTransc speechConfig.SetProperty( PropertyId.SpeechServiceResponse_DiarizeIntermediateResults, azure.DiarizeIntermediateResults ? "true" : "false"); + if (!string.IsNullOrWhiteSpace(azure.PostProcessingOption)) + { + logger.LogWarning( + "Azure Speech post-processing option {PostProcessingOption} is configured but skipped because the live Azure backend uses ConversationTranscriber; Speech SDK post-processing is documented for SpeechRecognizer.", + azure.PostProcessingOption.Trim()); + } + return speechConfig; } @@ -185,10 +206,17 @@ public sealed class AzureSpeechStreamingTranscriptionProvider : IStreamingTransc } internal static Uri GetEndpoint(AzureSpeechOptions options) + { + return string.IsNullOrWhiteSpace(options.Endpoint) + ? throw new InvalidOperationException("Azure Speech endpoint must be configured.") + : new Uri(options.Endpoint); + } + + internal static SpeechConfig CreateSpeechConfig(AzureSpeechOptions options, string key) { if (!string.IsNullOrWhiteSpace(options.Endpoint)) { - return new Uri(options.Endpoint); + return SpeechConfig.FromEndpoint(GetEndpoint(options), key); } if (string.IsNullOrWhiteSpace(options.Region)) @@ -196,7 +224,7 @@ public sealed class AzureSpeechStreamingTranscriptionProvider : IStreamingTransc throw new InvalidOperationException("Azure Speech region or endpoint must be configured."); } - return new Uri($"wss://{options.Region}.stt.speech.microsoft.com/speech/universal/v2"); + return SpeechConfig.FromSubscription(key, options.Region.Trim()); } internal static string NormalizeLanguageIdMode(string? value) diff --git a/MeetingAssistant/Transcription/ConfiguredSpeechRecognitionPipelineFactory.cs b/MeetingAssistant/Transcription/ConfiguredSpeechRecognitionPipelineFactory.cs index 5984946..0f2e12f 100644 --- a/MeetingAssistant/Transcription/ConfiguredSpeechRecognitionPipelineFactory.cs +++ b/MeetingAssistant/Transcription/ConfiguredSpeechRecognitionPipelineFactory.cs @@ -1,29 +1,75 @@ +using MeetingAssistant.LaunchProfiles; using Microsoft.Extensions.Options; namespace MeetingAssistant.Transcription; public sealed class ConfiguredSpeechRecognitionPipelineFactory : ISpeechRecognitionPipelineFactory { - private readonly IServiceProvider services; + private readonly IReadOnlyDictionary builders; private readonly MeetingAssistantOptions options; + private readonly ILaunchProfileOptionsProvider? launchProfiles; public ConfiguredSpeechRecognitionPipelineFactory( - IServiceProvider services, + IEnumerable builders, IOptions options) + : this(builders, options, launchProfiles: null) + { + } + + public ConfiguredSpeechRecognitionPipelineFactory( + IEnumerable builders, + IOptions options, + ILaunchProfileOptionsProvider? launchProfiles) { - this.services = services; this.options = options.Value; + this.launchProfiles = launchProfiles; + this.builders = builders + .GroupBy(builder => builder.ProviderName, StringComparer.OrdinalIgnoreCase) + .ToDictionary( + group => group.Key, + group => group.Count() == 1 + ? group.Single() + : throw new InvalidOperationException( + $"Speech recognition pipeline provider '{group.Key}' is registered more than once."), + StringComparer.OrdinalIgnoreCase); + if (this.builders.Count == 0) + { + throw new InvalidOperationException("No speech recognition pipeline builders are registered."); + } } public ISpeechRecognitionPipeline Create() { - return options.Recording.TranscriptionProvider switch - { - "funasr" => ActivatorUtilities.CreateInstance(services), - "whisper-local" => ActivatorUtilities.CreateInstance(services), - "azure-speech" => ActivatorUtilities.CreateInstance(services), - _ => throw new InvalidOperationException( - $"Unsupported speech recognition pipeline '{options.Recording.TranscriptionProvider}'.") - }; + return Create(null); } + + public ISpeechRecognitionPipeline Create(string? launchProfileName) + { + var profileOptions = ResolveOptions(launchProfileName); + if (!builders.TryGetValue(profileOptions.Recording.TranscriptionProvider, out var builder)) + { + throw new InvalidOperationException( + $"Unsupported speech recognition pipeline '{profileOptions.Recording.TranscriptionProvider}'."); + } + + return builder.Create(profileOptions); + } + + private MeetingAssistantOptions ResolveOptions(string? launchProfileName) + { + if (launchProfiles is not null) + { + return launchProfiles.GetRequiredProfile(launchProfileName).Options; + } + + if (string.IsNullOrWhiteSpace(launchProfileName) || + launchProfileName.Equals(ConfigurationLaunchProfileOptionsProvider.DefaultProfileName, StringComparison.OrdinalIgnoreCase)) + { + return options; + } + + throw new InvalidOperationException( + $"Launch profile '{launchProfileName}' was requested, but no launch profile provider is registered."); + } + } diff --git a/MeetingAssistant/Transcription/FunAsrSpeechRecognitionPipelineBuilder.cs b/MeetingAssistant/Transcription/FunAsrSpeechRecognitionPipelineBuilder.cs new file mode 100644 index 0000000..7dac582 --- /dev/null +++ b/MeetingAssistant/Transcription/FunAsrSpeechRecognitionPipelineBuilder.cs @@ -0,0 +1,22 @@ +namespace MeetingAssistant.Transcription; + +public sealed class FunAsrSpeechRecognitionPipelineBuilder : + SpeechRecognitionPipelineBuilder, + ISpeechRecognitionPipelineBuilder +{ + public FunAsrSpeechRecognitionPipelineBuilder(IServiceProvider services) + : base(services) + { + } + + public string ProviderName => "funasr"; + + public ISpeechRecognitionPipeline Create(MeetingAssistantOptions options) + { + var backendLifecycle = GetRequiredService(); + return new FunAsrSpeechRecognitionPipeline( + CreateProfiled(options), + backendLifecycle, + CreateProfiled(options)); + } +} diff --git a/MeetingAssistant/Transcription/IDictationWordStore.cs b/MeetingAssistant/Transcription/IDictationWordStore.cs index cc2903c..50540a9 100644 --- a/MeetingAssistant/Transcription/IDictationWordStore.cs +++ b/MeetingAssistant/Transcription/IDictationWordStore.cs @@ -4,5 +4,20 @@ public interface IDictationWordStore { Task> ReadWordsAsync(CancellationToken cancellationToken); + Task> ReadWordsAsync( + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return ReadWordsAsync(cancellationToken); + } + Task> AddWordAsync(string word, CancellationToken cancellationToken); + + Task> AddWordAsync( + string word, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + return AddWordAsync(word, cancellationToken); + } } diff --git a/MeetingAssistant/Transcription/ISpeechRecognitionPipeline.cs b/MeetingAssistant/Transcription/ISpeechRecognitionPipeline.cs index fadc74d..1bd6b6a 100644 --- a/MeetingAssistant/Transcription/ISpeechRecognitionPipeline.cs +++ b/MeetingAssistant/Transcription/ISpeechRecognitionPipeline.cs @@ -27,6 +27,11 @@ public interface ISpeechRecognitionPipeline : IAsyncDisposable public interface ISpeechRecognitionPipelineFactory { ISpeechRecognitionPipeline Create(); + + ISpeechRecognitionPipeline Create(string? launchProfileName) + { + return Create(); + } } public sealed record SpeechRecognitionPipelineOptions( diff --git a/MeetingAssistant/Transcription/ISpeechRecognitionPipelineBuilder.cs b/MeetingAssistant/Transcription/ISpeechRecognitionPipelineBuilder.cs new file mode 100644 index 0000000..e9dc326 --- /dev/null +++ b/MeetingAssistant/Transcription/ISpeechRecognitionPipelineBuilder.cs @@ -0,0 +1,8 @@ +namespace MeetingAssistant.Transcription; + +public interface ISpeechRecognitionPipelineBuilder +{ + string ProviderName { get; } + + ISpeechRecognitionPipeline Create(MeetingAssistantOptions options); +} diff --git a/MeetingAssistant/Transcription/MarkdownDictationWordStore.cs b/MeetingAssistant/Transcription/MarkdownDictationWordStore.cs index 06537ac..723e89f 100644 --- a/MeetingAssistant/Transcription/MarkdownDictationWordStore.cs +++ b/MeetingAssistant/Transcription/MarkdownDictationWordStore.cs @@ -13,7 +13,14 @@ public sealed class MarkdownDictationWordStore : IDictationWordStore public async Task> ReadWordsAsync(CancellationToken cancellationToken) { - var path = GetPath(); + return await ReadWordsAsync(options, cancellationToken); + } + + public async Task> ReadWordsAsync( + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + var path = GetPath(options); if (!File.Exists(path)) { return []; @@ -25,7 +32,15 @@ public sealed class MarkdownDictationWordStore : IDictationWordStore public async Task> AddWordAsync(string word, CancellationToken cancellationToken) { - var path = GetPath(); + return await AddWordAsync(word, options, cancellationToken); + } + + public async Task> AddWordAsync( + string word, + MeetingAssistantOptions options, + CancellationToken cancellationToken) + { + var path = GetPath(options); Directory.CreateDirectory(Path.GetDirectoryName(path)!); var existing = File.Exists(path) ? await File.ReadAllLinesAsync(path, cancellationToken) @@ -39,7 +54,7 @@ public sealed class MarkdownDictationWordStore : IDictationWordStore return words; } - private string GetPath() + private static string GetPath(MeetingAssistantOptions options) { return VaultPath.Resolve(options.Vault, options.Vault.DictationWordsPath); } diff --git a/MeetingAssistant/Transcription/SpeechRecognitionPipelineBuilder.cs b/MeetingAssistant/Transcription/SpeechRecognitionPipelineBuilder.cs new file mode 100644 index 0000000..703323d --- /dev/null +++ b/MeetingAssistant/Transcription/SpeechRecognitionPipelineBuilder.cs @@ -0,0 +1,25 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; + +namespace MeetingAssistant.Transcription; + +public abstract class SpeechRecognitionPipelineBuilder +{ + private readonly IServiceProvider services; + + protected SpeechRecognitionPipelineBuilder(IServiceProvider services) + { + this.services = services; + } + + protected T CreateProfiled(MeetingAssistantOptions options) + { + return ActivatorUtilities.CreateInstance(services, Options.Create(options)); + } + + protected T GetRequiredService() + where T : notnull + { + return services.GetRequiredService(); + } +} diff --git a/MeetingAssistant/Transcription/WhisperLocalSpeechRecognitionPipelineBuilder.cs b/MeetingAssistant/Transcription/WhisperLocalSpeechRecognitionPipelineBuilder.cs new file mode 100644 index 0000000..c56d15d --- /dev/null +++ b/MeetingAssistant/Transcription/WhisperLocalSpeechRecognitionPipelineBuilder.cs @@ -0,0 +1,20 @@ +namespace MeetingAssistant.Transcription; + +public sealed class WhisperLocalSpeechRecognitionPipelineBuilder : + SpeechRecognitionPipelineBuilder, + ISpeechRecognitionPipelineBuilder +{ + public WhisperLocalSpeechRecognitionPipelineBuilder(IServiceProvider services) + : base(services) + { + } + + public string ProviderName => "whisper-local"; + + public ISpeechRecognitionPipeline Create(MeetingAssistantOptions options) + { + return new WhisperLocalSpeechRecognitionPipeline( + CreateProfiled(options), + CreateProfiled(options)); + } +} diff --git a/MeetingAssistant/appsettings.json b/MeetingAssistant/appsettings.json index 3e0984c..299df8a 100644 --- a/MeetingAssistant/appsettings.json +++ b/MeetingAssistant/appsettings.json @@ -80,16 +80,16 @@ } }, "AzureSpeech": { - "Endpoint": "wss://germanywestcentral.stt.speech.microsoft.com/speech/universal/v2", - "Region": "germanywestcentral", + "Endpoint": "", + "Region": "westeurope", "Language": "de-DE", "AutoDetectLanguages": [ "de-DE" ], - "LanguageIdMode": "Continuous", "KeyEnv": "AZURE_SPEECH_KEY", "RecognitionStopTimeout": "00:00:10", "DiarizeIntermediateResults": true, + "PostProcessingOption": "", "PhraseListWeight": 1.5 }, "SpeakerIdentification": { @@ -103,7 +103,8 @@ "MaxSnippetsPerSpeaker": 3, "SilenceBetweenSnippetsSeconds": 1, "LiveSampleBufferDuration": "00:10:00", - "MergeRecentIdentityAge": "14.00:00:00" + "MergeRecentIdentityAge": "14.00:00:00", + "MatchTimeout": "00:03:00" }, "Agent": { "Endpoint": "https://litellm.schweigert.cloud", @@ -122,6 +123,19 @@ }, "Api": { "PublicBaseUrl": "http://localhost:5090" + }, + "LaunchProfiles": { + "english": { + "Hotkey": { + "Toggle": "Ctrl+Alt+E" + }, + "AzureSpeech": { + "Language": "en-US", + "AutoDetectLanguages": [ + "en-US" + ] + } + } } }, "Logging": { diff --git a/README.md b/README.md index 760ad21..de5050e 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ Meeting notes link to separate transcript, assistant context, and summary markdo Meeting note, transcript, assistant context, and summary artifacts use frontmatter links so they backlink to each other. Meeting note frontmatter includes `start_time` when recording starts and `end_time` when transcription processing finishes. Transcript and summary frontmatter copy the meeting title, start time, and end time from the meeting note; if the meeting has no title, the summary agent can provide one when writing the summary. -Assistant context notes keep their artifact links in frontmatter and expose a lifecycle `state`: `transcribing`, `speaker recognition`, `summarizing`, `finished`, or `error`. Meeting Assistant updates this state as recording, final speaker recognition, and summary generation progress. +Assistant context notes keep their artifact links in frontmatter and expose a lifecycle `state`: `collecting metadata`, `transcribing`, `speaker recognition`, `summarizing`, `finished`, or `error`. Meeting Assistant updates this state as metadata lookup, recording, final speaker recognition, and summary generation progress. `ProjectsFolder` contains project knowledge. Each direct subfolder is treated as one project, and a meeting binds projects by listing those subfolder names in the meeting note `projects` frontmatter. diff --git a/openspec/changes/add-cross-platform-build-targets/tasks.md b/openspec/changes/add-cross-platform-build-targets/tasks.md deleted file mode 100644 index 9b7f3d8..0000000 --- a/openspec/changes/add-cross-platform-build-targets/tasks.md +++ /dev/null @@ -1,11 +0,0 @@ -## 1. Build Targets - -- [ ] 1.1 Add explicit macOS and Linux target framework/runtime build coverage. -- [ ] 1.2 Keep Windows-only implementations excluded from macOS and Linux builds. -- [ ] 1.3 Add platform service registration for unsupported or future macOS/Linux capture and hotkey implementations. - -## 2. Tests - -- [ ] 2.1 Split platform-specific tests by compilation target or runtime guard. -- [ ] 2.2 Add CI/build commands that verify Windows, macOS, and Linux compile targets. -- [ ] 2.3 Add at least one portable compile test that proves Windows-only packages are not required by non-Windows builds. diff --git a/openspec/changes/archive/2026-05-21-add-launch-profiles/proposal.md b/openspec/changes/archive/2026-05-21-add-launch-profiles/proposal.md new file mode 100644 index 0000000..91af058 --- /dev/null +++ b/openspec/changes/archive/2026-05-21-add-launch-profiles/proposal.md @@ -0,0 +1,15 @@ +## Why +Meeting Assistant currently has one global configuration, one hotkey, and one implicit ASR/runtime setup. In practice, the user needs to start meetings with different speech-recognition settings, such as German-only versus English-only recognition, without editing configuration and restarting between meetings. + +## What Changes +- Add named launch profiles to configuration. +- Treat the root `MeetingAssistant` configuration as the `default` launch profile. +- Resolve non-default launch profiles by copying the default settings and binding the named profile override onto that copy. +- Add profile-aware endpoint routes while preserving the existing default-profile URLs. +- Register one global hotkey per launch profile, requiring distinct hotkey definitions. +- Add an `english` launch profile that keeps the current default settings except for English Azure Speech recognition and its own hotkey. + +## Impact +- Existing URLs and the existing hotkey continue to operate the default profile. +- Named profiles are addressed through profile URLs, allowing diagnostics and recording commands to select the desired backend/language profile. +- Speech pipeline creation becomes profile-aware. diff --git a/openspec/changes/archive/2026-05-21-add-launch-profiles/specs/meeting-recording/spec.md b/openspec/changes/archive/2026-05-21-add-launch-profiles/specs/meeting-recording/spec.md new file mode 100644 index 0000000..c7649d2 --- /dev/null +++ b/openspec/changes/archive/2026-05-21-add-launch-profiles/specs/meeting-recording/spec.md @@ -0,0 +1,33 @@ +## ADDED Requirements + +### Requirement: Recording can be launched through named profiles +Meeting Assistant SHALL treat the root `MeetingAssistant` configuration as a launch profile named `default`. + +Meeting Assistant SHALL allow additional named launch profiles to be configured as overrides of the default profile. A named profile SHALL be resolved by binding the default profile first, then binding the named profile override onto the same option object. + +Meeting Assistant SHALL preserve existing recording endpoint URLs as default-profile URLs and SHALL provide equivalent named-profile URLs that include the profile name. + +Each launch profile SHALL have a distinct global hotkey. Pressing a profile hotkey SHALL toggle recording using that profile's resolved configuration. + +Meeting Assistant SHALL use the selected launch profile's vault and recording storage settings when it creates meeting notes, transcripts, assistant context notes, summary notes, temporary recordings, and dictation-word inputs for that meeting. + +Meeting Assistant SHALL use the selected launch profile's summary-agent settings when it runs the summary pipeline for that meeting. + +#### Scenario: Default profile keeps existing recording URL +- **WHEN** the user calls the existing recording start URL without a profile name +- **THEN** Meeting Assistant starts recording with the `default` launch profile + +#### Scenario: Named profile starts recording +- **WHEN** the user calls the named-profile recording start URL for profile `english` +- **THEN** Meeting Assistant starts recording using the resolved `english` launch profile configuration + +#### Scenario: Named profile stores meeting artifacts in profile folders +- **GIVEN** launch profile `english` overrides vault folders and summary-agent settings +- **WHEN** the user starts and stops a recording with launch profile `english` +- **THEN** Meeting Assistant creates the meeting note, transcript, assistant context note, and summary note using the resolved `english` vault folders +- **AND** Meeting Assistant runs the summary pipeline using the resolved `english` summary-agent settings + +#### Scenario: Profile hotkeys must be distinct +- **GIVEN** two launch profiles configure the same toggle hotkey +- **WHEN** Meeting Assistant resolves launch profiles +- **THEN** Meeting Assistant rejects the configuration before registering global hotkeys diff --git a/openspec/changes/archive/2026-05-21-add-launch-profiles/specs/meeting-transcription/spec.md b/openspec/changes/archive/2026-05-21-add-launch-profiles/specs/meeting-transcription/spec.md new file mode 100644 index 0000000..741ec44 --- /dev/null +++ b/openspec/changes/archive/2026-05-21-add-launch-profiles/specs/meeting-transcription/spec.md @@ -0,0 +1,16 @@ +## ADDED Requirements + +### Requirement: Speech recognition diagnostics are launch-profile aware +Meeting Assistant SHALL preserve existing ASR diagnostic endpoint URLs as default-profile URLs. + +Meeting Assistant SHALL provide equivalent named-profile ASR diagnostic endpoint URLs that include the profile name. + +When a named-profile ASR diagnostic endpoint is used, Meeting Assistant SHALL create the speech recognition pipeline from the resolved profile configuration. + +#### Scenario: Default ASR diagnostic URL uses default profile +- **WHEN** the user submits a WAV file to the existing ASR diagnostic endpoint URL +- **THEN** Meeting Assistant streams the WAV through the default launch profile's configured speech recognition pipeline + +#### Scenario: Named ASR diagnostic URL uses named profile +- **WHEN** the user submits a WAV file to the ASR diagnostic endpoint URL for profile `english` +- **THEN** Meeting Assistant streams the WAV through the resolved `english` launch profile's configured speech recognition pipeline diff --git a/openspec/changes/archive/2026-05-21-add-launch-profiles/tasks.md b/openspec/changes/archive/2026-05-21-add-launch-profiles/tasks.md new file mode 100644 index 0000000..ffc5a95 --- /dev/null +++ b/openspec/changes/archive/2026-05-21-add-launch-profiles/tasks.md @@ -0,0 +1,18 @@ +## 1. Specification +- [x] 1.1 Define launch profile requirements for recording control and endpoint routing. +- [x] 1.2 Define launch profile requirements for profile-aware ASR pipeline selection. + +## 2. Implementation +- [x] 2.1 Add launch profile option resolution with default-plus-override merge behavior. +- [x] 2.2 Preserve existing default endpoint URLs and add named profile URL variants. +- [x] 2.3 Pass selected launch profiles into recording and ASR diagnostics pipeline creation. +- [x] 2.4 Register distinct hotkeys for all launch profiles. +- [x] 2.5 Add an `english` launch profile override to appsettings. +- [x] 2.6 Use the selected launch profile for meeting artifact storage paths, dictation words, and summary-agent settings. + +## 3. Validation +- [x] 3.1 Add tests for default and named launch profile option resolution. +- [x] 3.2 Add tests for profile-aware diagnostic endpoint routing. +- [x] 3.3 Add tests for distinct profile hotkey planning. +- [x] 3.4 Add tests for profile-scoped meeting artifact paths and summary-agent settings. +- [x] 3.5 Run focused tests. diff --git a/openspec/changes/add-speaker-identity-learning/proposal.md b/openspec/changes/archive/2026-05-21-add-speaker-identity-learning/proposal.md similarity index 100% rename from openspec/changes/add-speaker-identity-learning/proposal.md rename to openspec/changes/archive/2026-05-21-add-speaker-identity-learning/proposal.md diff --git a/openspec/changes/add-speaker-identity-learning/specs/meeting-transcription/spec.md b/openspec/changes/archive/2026-05-21-add-speaker-identity-learning/specs/meeting-transcription/spec.md similarity index 95% rename from openspec/changes/add-speaker-identity-learning/specs/meeting-transcription/spec.md rename to openspec/changes/archive/2026-05-21-add-speaker-identity-learning/specs/meeting-transcription/spec.md index 0436bb7..af90450 100644 --- a/openspec/changes/add-speaker-identity-learning/specs/meeting-transcription/spec.md +++ b/openspec/changes/archive/2026-05-21-add-speaker-identity-learning/specs/meeting-transcription/spec.md @@ -83,6 +83,8 @@ When a match is confirmed and the identity has a canonical name, Meeting Assista When a match is confirmed and the matched speaker is not already listed in meeting note attendees by display name or alias, Meeting Assistant SHALL add the speaker display name to the attendee list. +When Meeting Assistant writes attendees from calendar metadata, it SHALL match attendee display names exactly against known identity canonical names and aliases, replace matches with the identity display name, and deduplicate attendees that map to the same identity. + #### Scenario: Finished transcript is relabeled after a confirmed match - **GIVEN** the speaker identity database contains canonical speaker `Chris` - **WHEN** a finished transcript has diarized speaker `Guest03` and the matching backend confirms it is `Chris` @@ -100,6 +102,11 @@ When a match is confirmed and the matched speaker is not already listed in meeti - **WHEN** live or final speaker matching confirms a diarized speaker is `Christopher` - **THEN** Meeting Assistant does not add another attendee for `Christopher` +#### Scenario: Calendar attendee aliases are deduplicated +- **GIVEN** the speaker identity database contains canonical speaker `Karl Berger` with alias `Berger, Karl` +- **WHEN** calendar metadata provides attendees `Karl Berger` and `Berger, Karl` +- **THEN** Meeting Assistant writes a single attendee `Karl Berger` to the meeting note + #### Scenario: Attendee identities are tried first - **GIVEN** the meeting attendees include names matching known identity display names or aliases - **WHEN** Meeting Assistant tries to identify a diarized speaker diff --git a/openspec/changes/add-speaker-identity-learning/tasks.md b/openspec/changes/archive/2026-05-21-add-speaker-identity-learning/tasks.md similarity index 91% rename from openspec/changes/add-speaker-identity-learning/tasks.md rename to openspec/changes/archive/2026-05-21-add-speaker-identity-learning/tasks.md index 2a9d540..864ee49 100644 --- a/openspec/changes/add-speaker-identity-learning/tasks.md +++ b/openspec/changes/archive/2026-05-21-add-speaker-identity-learning/tasks.md @@ -18,6 +18,7 @@ - [x] 2.13 Run live speaker identification incrementally when new unmapped speakers appear or attendees change. - [x] 2.14 Maintain speaker identity last-modified timestamps for active-age filtering. - [x] 2.15 Add identified speaker display names to meeting note attendees without duplicating display names or aliases. +- [x] 2.16 Canonicalize calendar attendee names through identity canonical names and aliases before writing meeting notes. ## 3. Validation - [x] 3.1 Add tests for candidate creation, elimination, canonical promotion, and reset on empty candidate intersection. @@ -31,4 +32,5 @@ - [x] 3.9 Add tests for incremental live speaker identification triggers. - [x] 3.10 Add tests for speaker identity last-modified timestamp creation, updates, and schema upgrade. - [x] 3.11 Add tests for adding matched speaker identities to meeting attendees and alias duplicate suppression. -- [x] 3.12 Run `dotnet test`. +- [x] 3.12 Add tests for calendar attendee canonicalization and alias duplicate suppression. +- [x] 3.13 Run `dotnet test`. diff --git a/openspec/changes/configure-summary-agent-instructions/proposal.md b/openspec/changes/archive/2026-05-21-configure-summary-agent-instructions/proposal.md similarity index 100% rename from openspec/changes/configure-summary-agent-instructions/proposal.md rename to openspec/changes/archive/2026-05-21-configure-summary-agent-instructions/proposal.md diff --git a/openspec/changes/configure-summary-agent-instructions/specs/meeting-summary/spec.md b/openspec/changes/archive/2026-05-21-configure-summary-agent-instructions/specs/meeting-summary/spec.md similarity index 100% rename from openspec/changes/configure-summary-agent-instructions/specs/meeting-summary/spec.md rename to openspec/changes/archive/2026-05-21-configure-summary-agent-instructions/specs/meeting-summary/spec.md diff --git a/openspec/changes/configure-summary-agent-instructions/tasks.md b/openspec/changes/archive/2026-05-21-configure-summary-agent-instructions/tasks.md similarity index 100% rename from openspec/changes/configure-summary-agent-instructions/tasks.md rename to openspec/changes/archive/2026-05-21-configure-summary-agent-instructions/tasks.md diff --git a/openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/proposal.md b/openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/proposal.md new file mode 100644 index 0000000..072d068 --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/proposal.md @@ -0,0 +1,12 @@ +## Why +Azure Speech post-stream refinement can improve final segment quality while preserving the existing low-latency streaming transcription flow. + +## What Changes +- Add an `AzureSpeech.PostProcessingOption` setting. +- Keep the default option unset while the live Azure backend uses `ConversationTranscriber`. +- Apply the configured option only for compatible Azure Speech SDK recognizer paths; skip it for `ConversationTranscriber` to preserve working live diarized transcription. +- Use a Speech resource region that supports post-stream refinement. + +## Impact +- Affected specs: `meeting-transcription` +- Affected code: Azure Speech options, Azure streaming transcription provider, appsettings, Azure provider tests diff --git a/openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/specs/meeting-transcription/spec.md b/openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/specs/meeting-transcription/spec.md new file mode 100644 index 0000000..6d6e2f6 --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/specs/meeting-transcription/spec.md @@ -0,0 +1,27 @@ +## ADDED Requirements + +### Requirement: Azure Speech post-stream refinement is configurable +Meeting Assistant SHALL allow the Azure Speech streaming transcription provider to configure the Speech SDK post-processing option. + +When configured for a compatible Azure Speech SDK recognizer, Meeting Assistant SHALL set `SpeechServiceResponse_PostProcessingOption` on the Azure Speech SDK `SpeechConfig`. + +The default application configuration SHALL keep `PostProcessingOption` empty while using live `ConversationTranscriber` and SHALL use a region that supports post-stream refinement for future compatible recognizer paths. + +Meeting Assistant SHALL keep using the existing Azure live streaming transcription flow rather than switching to batch or offline processing. + +When the Azure live streaming backend uses `ConversationTranscriber`, Meeting Assistant SHALL prefer working live diarized transcription over applying a post-processing option that is only documented for `SpeechRecognizer`. + +#### Scenario: Azure Speech post-refinement is configured +- **WHEN** `AzureSpeech.PostProcessingOption` is `PostRefinement` +- **AND** the configured Azure Speech recognizer supports SDK post-processing +- **THEN** Meeting Assistant sets `SpeechServiceResponse_PostProcessingOption` to `PostRefinement` on the Azure Speech SDK configuration + +#### Scenario: Azure live conversation transcription remains available +- **WHEN** `AzureSpeech.PostProcessingOption` is `PostRefinement` +- **AND** the Azure backend is using live `ConversationTranscriber` +- **THEN** Meeting Assistant skips the post-processing SDK property +- **AND** continues using live conversation transcription + +#### Scenario: Azure Speech post-processing is unset +- **WHEN** `AzureSpeech.PostProcessingOption` is empty +- **THEN** Meeting Assistant does not set a post-processing option on the Azure Speech SDK configuration diff --git a/openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/tasks.md b/openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/tasks.md new file mode 100644 index 0000000..053e5e0 --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-azure-speech-post-refinement/tasks.md @@ -0,0 +1,14 @@ +## 1. Specification +- [x] 1.1 Define Azure Speech post-stream refinement configuration behavior. + +## 2. Implementation +- [x] 2.1 Add configurable Azure Speech post-processing option. +- [x] 2.2 Apply the configured option only to compatible Azure Speech SDK recognizer paths and skip it for live `ConversationTranscriber`. +- [x] 2.3 Configure Azure Speech for a post-stream-refinement-supported region. +- [x] 2.4 Provision or reuse an Azure Speech resource and set the local key environment variable. + +## 3. Validation +- [x] 3.1 Add provider tests for the post-processing option. +- [x] 3.2 Run focused provider tests. +- [x] 3.3 Run full test suite. +- [x] 3.4 Run OpenSpec validation. diff --git a/openspec/changes/add-cross-platform-build-targets/proposal.md b/openspec/changes/archive/2026-05-22-add-cross-platform-build-targets/proposal.md similarity index 88% rename from openspec/changes/add-cross-platform-build-targets/proposal.md rename to openspec/changes/archive/2026-05-22-add-cross-platform-build-targets/proposal.md index 64fa60a..d38dcd9 100644 --- a/openspec/changes/add-cross-platform-build-targets/proposal.md +++ b/openspec/changes/archive/2026-05-22-add-cross-platform-build-targets/proposal.md @@ -2,6 +2,10 @@ Meeting Assistant currently focuses V1 runtime support on Windows capture and Outlook enrichment. We need a separate future change to define macOS and Linux build targets without expanding the V1 scope. +## Status + +Not planned for V1. This change is intentionally iced without implementation or spec updates. + ## What Changes - Define supported macOS and Linux build targets for Meeting Assistant. diff --git a/openspec/changes/add-cross-platform-build-targets/specs/build-targets/spec.md b/openspec/changes/archive/2026-05-22-add-cross-platform-build-targets/specs/build-targets/spec.md similarity index 100% rename from openspec/changes/add-cross-platform-build-targets/specs/build-targets/spec.md rename to openspec/changes/archive/2026-05-22-add-cross-platform-build-targets/specs/build-targets/spec.md diff --git a/openspec/changes/archive/2026-05-22-add-cross-platform-build-targets/tasks.md b/openspec/changes/archive/2026-05-22-add-cross-platform-build-targets/tasks.md new file mode 100644 index 0000000..79895f6 --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-cross-platform-build-targets/tasks.md @@ -0,0 +1,15 @@ +## Status + +Not planned for V1; archived without spec changes. + +## 1. Build Targets + +- [x] 1.1 Not planned for V1: add explicit macOS and Linux target framework/runtime build coverage. +- [x] 1.2 Not planned for V1: keep Windows-only implementations excluded from macOS and Linux builds. +- [x] 1.3 Not planned for V1: add platform service registration for unsupported or future macOS/Linux capture and hotkey implementations. + +## 2. Tests + +- [x] 2.1 Not planned for V1: split platform-specific tests by compilation target or runtime guard. +- [x] 2.2 Not planned for V1: add CI/build commands that verify Windows, macOS, and Linux compile targets. +- [x] 2.3 Not planned for V1: add at least one portable compile test that proves Windows-only packages are not required by non-Windows builds. diff --git a/openspec/changes/archive/2026-05-22-add-speaker-identity-references/proposal.md b/openspec/changes/archive/2026-05-22-add-speaker-identity-references/proposal.md new file mode 100644 index 0000000..19f1536 --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-speaker-identity-references/proposal.md @@ -0,0 +1,12 @@ +## Why +Speaker identity usage is currently tracked as a denormalized transcript count. That loses which meeting files caused the count and prevents Meeting Assistant from updating past transcript files when an identity is later named or merged. + +## What Changes +- Store speaker identity meeting participation as reference rows containing meeting note and transcript file addresses. +- Calculate identity usage counts from references when ordering matching candidates. +- Add transcript audit lines to referenced transcripts when an identity is named or two identities are merged. + +## Impact +- Speaker identity SQLite schema gains a references table. +- Matching, attendee canonicalization, and merge ordering use calculated reference counts instead of a persisted counter. +- Existing databases keep working; legacy transcript-count columns may remain unused. diff --git a/openspec/changes/archive/2026-05-22-add-speaker-identity-references/specs/meeting-transcription/spec.md b/openspec/changes/archive/2026-05-22-add-speaker-identity-references/specs/meeting-transcription/spec.md new file mode 100644 index 0000000..a129e1b --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-speaker-identity-references/specs/meeting-transcription/spec.md @@ -0,0 +1,107 @@ +## MODIFIED Requirements +### Requirement: Meeting Assistant learns speaker identities locally +Meeting Assistant SHALL maintain a local SQLite speaker identity database in the user's application data folder. + +The speaker identity database SHALL store speaker identities, optional canonical names, aliases, candidate names, meeting file references, and a bounded set of WAV snippets per identity. + +Meeting file references SHALL include the meeting note file address and the transcript file address. + +Meeting Assistant SHALL calculate speaker identity participation counts from meeting file references when needed instead of persisting a denormalized transcript count. + +Each speaker identity SHALL store a last-modified timestamp used by active-age filtering, and Meeting Assistant SHALL update it whenever the identity is created or modified by identification, candidate updates, snippet changes, reference changes, or merge operations. + +The configured maximum snippet count per identity SHALL prevent unbounded growth. + +#### Scenario: Unknown speaker is learned from meeting attendees +- **WHEN** a finished transcript contains an unmatched diarized speaker and the meeting note has attendees +- **THEN** Meeting Assistant stores a new unnamed speaker identity with candidate names from the attendees that were not already matched in that meeting +- **AND** stores a meeting file reference for that identity + +#### Scenario: Speaker snippets are bounded +- **WHEN** Meeting Assistant adds a snippet for an identity that already has the configured maximum number of snippets +- **THEN** Meeting Assistant does not store more snippets for that identity + +#### Scenario: Identity modification updates active-age timestamp +- **WHEN** Meeting Assistant creates, identifies, updates candidates for, stores snippets for, stores references for, or merges a speaker identity +- **THEN** Meeting Assistant updates that identity's last-modified timestamp + +### Requirement: Speaker candidates are eliminated across meetings +Meeting Assistant SHALL update candidate names for a matched unnamed identity using the intersection of its existing candidate names and the current meeting attendees. + +Meeting Assistant SHALL treat identity aliases as acceptable names during candidate elimination and when excluding already-matched attendees from new unmatched speaker candidates. + +When the candidate intersection leaves exactly one candidate, Meeting Assistant SHALL promote that candidate to the canonical speaker name. + +When an identity receives a canonical name, Meeting Assistant SHALL append an audit line to each referenced transcript in the form ` was identified as `. + +When the candidate intersection is empty, Meeting Assistant SHALL replace the oldest stored snippet for that identity and reset candidates from the current meeting attendees, because the previous snippet may have been dirty. + +#### Scenario: Candidate elimination promotes canonical name +- **GIVEN** an unnamed identity has candidate names `John` and `Mike` +- **WHEN** that identity matches a speaker in a later meeting with attendees `Jane`, `John`, and `Chris` +- **THEN** Meeting Assistant removes `Mike` from the identity candidates and promotes `John` as the canonical name +- **AND** appends the identity naming audit line to the identity's referenced transcripts + +#### Scenario: Alias participates in candidate elimination +- **GIVEN** an unnamed identity has candidate name `Michael` and alias `Mike` +- **WHEN** that identity matches a speaker in a later meeting with attendee `Mike` +- **THEN** Meeting Assistant treats `Mike` as matching `Michael` +- **AND** promotes `Michael` as the canonical name + +#### Scenario: Empty candidate intersection resets candidates +- **GIVEN** an unnamed identity has candidate names `John` and `Mike` +- **WHEN** that identity matches a speaker in a later meeting with attendees `Jane` and `Chris` +- **THEN** Meeting Assistant resets the identity candidates to `Jane` and `Chris` +- **AND** replaces the oldest stored snippet for that identity with the current speaker snippet + +### Requirement: Speaker identity matches relabel transcripts +Meeting Assistant SHALL attempt to match unknown diarized speaker snippets against known speaker identities ordered by calculated meeting reference count. + +Speaker identity matching SHALL use a dedicated Azure Speech diarization verifier component rather than the configured speech recognition pipeline. + +The matcher SHALL test at most the configured batch size of known people per diarization session and continue with later batches until a match is found or no candidates remain. + +The matcher SHALL prioritize identities whose canonical name or aliases match current meeting attendees. + +After attendee-matched identities, the matcher SHALL order identities by calculated meeting reference count, filter out non-attendee identities whose last update is older than the configured active age, and cap the candidate set at the configured maximum match candidate count. + +When a match is confirmed in final identity processing, Meeting Assistant SHALL store a meeting file reference for that identity. + +When a match is confirmed and the identity has a canonical name, Meeting Assistant SHALL rewrite finished transcript segments for that diarized speaker with the canonical name. + +When a match is confirmed and the matched speaker is not already listed in meeting note attendees by display name or alias, Meeting Assistant SHALL add the speaker display name to the attendee list. + +When Meeting Assistant writes attendees from calendar metadata, it SHALL match attendee display names exactly against known identity canonical names and aliases, replace matches with the identity display name, and deduplicate attendees that map to the same identity. + +#### Scenario: Finished transcript is relabeled after a confirmed match +- **GIVEN** the speaker identity database contains canonical speaker `Chris` +- **WHEN** a finished transcript has diarized speaker `Guest03` and the matching backend confirms it is `Chris` +- **THEN** Meeting Assistant rewrites `Guest03` segments in the transcript as `Chris` + +#### Scenario: Confirmed match stores meeting reference +- **GIVEN** the speaker identity database contains canonical speaker `Chris` +- **WHEN** a finished transcript has diarized speaker `Guest03` and the matching backend confirms it is `Chris` +- **THEN** Meeting Assistant stores the meeting note and transcript file addresses as a reference for `Chris` + +### Requirement: Speaker identities can be merged diagnostically +Meeting Assistant SHALL expose a diagnostic endpoint that merges duplicate speaker identities. + +The merge process SHALL compare recently-created identities, using a configurable recent age that defaults to two weeks, against all other identities in matcher batches bounded by the configured batch size. + +The merge process SHALL require a match and a second validation match using a different source sample before merging two identities. + +When identities are merged, Meeting Assistant SHALL retain one identity, move useful names from the merged identity into aliases, combine meeting file references, retain a bounded set of snippets from both identities, and append an audit line to each referenced transcript in the form ` and were merged`. + +#### Scenario: Recently-created duplicate identity is merged +- **GIVEN** a recently-created identity and an older identity have matching speaker snippets +- **WHEN** the diagnostic merge endpoint is triggered +- **THEN** Meeting Assistant validates the match twice with different source snippets +- **AND** merges the recent identity into the older identity +- **AND** stores the recent identity name as an alias on the retained identity +- **AND** keeps meeting file references from both identities +- **AND** appends the merge audit line to the referenced transcripts + +#### Scenario: Old identities are not used as merge sources +- **GIVEN** two identities older than the configured recent age +- **WHEN** the diagnostic merge endpoint is triggered +- **THEN** Meeting Assistant does not compare them as source identities diff --git a/openspec/changes/archive/2026-05-22-add-speaker-identity-references/tasks.md b/openspec/changes/archive/2026-05-22-add-speaker-identity-references/tasks.md new file mode 100644 index 0000000..b44615d --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-speaker-identity-references/tasks.md @@ -0,0 +1,10 @@ +## 1. Implementation +- [x] Add speaker identity reference storage and schema creation. +- [x] Replace transcript-count ordering and match candidate data with calculated reference counts. +- [x] Record meeting note/transcript references when final identity processing matches or creates an identity. +- [x] Append transcript audit lines when identities are named or merged. + +## 2. Verification +- [x] Add/adjust behavior tests for references, calculated counts, naming audit lines, and merge audit lines. +- [x] Run focused speaker identity tests. +- [x] Run `openspec validate add-speaker-identity-references --strict`. diff --git a/openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/proposal.md b/openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/proposal.md new file mode 100644 index 0000000..425fc3e --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/proposal.md @@ -0,0 +1,12 @@ +## Why +The summary agent can edit supporting files such as project notes or the dictation dictionary. Those writes are currently invisible after the run unless the user notices file changes manually. + +## What Changes +- Track in-memory diffs for summary-agent writes outside the summary and assistant context files. +- Use a real diff implementation so whole-file rewrites produce useful changed-line output. +- Append the collected diff audit to the assistant context when the summary agent finishes. + +## Impact +- Adds a .NET diff package dependency. +- Summary tool write paths gain audit capture for project files and dictation dictionary writes. +- Assistant context files receive an appended audit section for external files changed by the agent. diff --git a/openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/specs/meeting-summary/spec.md b/openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/specs/meeting-summary/spec.md new file mode 100644 index 0000000..c39be88 --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/specs/meeting-summary/spec.md @@ -0,0 +1,82 @@ +## MODIFIED Requirements +### Requirement: Meeting Assistant generates meeting outputs +Meeting Assistant SHALL generate a summary, decisions, and next steps from the meeting transcript, metadata, user notes, and assistant-discovered context. + +Meeting Assistant SHALL use a Microsoft Agent Framework pipeline for the first summary implementation. The pipeline SHALL use a configurable OpenAI-compatible endpoint, model, and API key source, including support for a direct key or an environment variable name. + +The summary pipeline SHALL retry transient model endpoint failures according to configurable reconnection attempts and delay settings. + +The summary pipeline SHALL track context-window usage for the configured model using response usage when available and request-size estimates otherwise. The context-window limit, maximum output reserve, compaction enablement, compaction threshold, and Responses compact endpoint path SHALL be configurable. + +When only the configured remaining context ratio is available, the summary pipeline SHALL try to compact the conversation through the configured OpenAI-compatible `POST /v1/responses/compact` endpoint. If that endpoint is unavailable or returns invalid data, the pipeline SHALL fall back to Microsoft Agent Framework compaction. + +Fallback compaction SHALL become increasingly aggressive: collapse old tool results, summarize older conversation spans, keep only the last four user turns, and drop oldest groups if still over budget. + +When summary generation fails after retries, Meeting Assistant SHALL write a markdown failure report to the configured summary note path. The failure report SHALL include a clickable retry link, error details, and the meeting artifact paths needed to diagnose or retry the run. + +After transcript processing finishes for a recording, Meeting Assistant SHALL automatically invoke the summary pipeline for that meeting. + +Meeting Assistant SHALL expose an API operation to retry summary generation for a given summary note path. The retry operation SHALL resolve the linked meeting artifacts from the meeting note frontmatter and SHALL overwrite the existing summary note with either the new summary or a new failure report. + +The summary pipeline SHALL expose tools scoped to the current meeting: + +- `read_meetingnote` +- `read_transcript` +- `read_context` +- `read_usernotes` +- `read_glossary` +- `write_summary` +- `write_context` +- `list_projects` +- `list_projectfiles` +- `read_projectfile` +- `write_projectfile` +- `search` + +All summary-agent read tools that return file-like content SHALL support either reading the whole file or reading a clamped inclusive 1-based line range when `from` and `to` are supplied. + +The summary pipeline SHALL write the summary note as a markdown artifact linked to the meeting note, transcript, and assistant context. + +The summary agent SHALL be able to read the meeting note, transcript, assistant context, glossary, and bound project files through tools. + +The summary agent SHALL be able to write the summary and assistant context files as its owned artifacts. + +For summary-agent writes to any file other than the summary file and assistant context file, Meeting Assistant SHALL record an in-memory diff containing removed and added lines. + +Meeting Assistant SHALL use a diff implementation that can reduce whole-file rewrites to changed lines instead of treating every rewrite as a full replacement. + +When the summary agent finishes, Meeting Assistant SHALL append the collected external write diffs to the assistant context file. + +After writing the meeting summary, the summary agent SHALL update existing project files when the meeting produced project-relevant knowledge. + +The assistant context note SHALL keep `title`, `start_time`, `end_time`, `meeting`, `transcript`, `summary`, `state`, and `agenda` in frontmatter. Meeting Assistant SHALL write `title` and `start_time` when the assistant context note is created, update `title` when later meeting metadata is discovered, and write `end_time` when transcript processing stops. When a Teams appointment is detected at recording start, the assistant context note SHALL also keep `scheduled_end` in frontmatter. The `state` value SHALL be one of `transcribing`, `speaker recognition`, `summarizing`, `finished`, or `error`. + +The summary note SHALL keep frontmatter links to meeting artifacts and SHALL copy `title`, `start_time`, and `end_time` from the meeting note when available. If the meeting note has no title, the summary agent SHALL be able to provide a title when writing the summary. + +The summary agent SHALL be able to read and write the assistant context body as its own notebook using overwrite, replace, and insert line modes. + +#### Scenario: Assistant context note is initialized +- **WHEN** Meeting Assistant starts a meeting session +- **THEN** it creates the assistant context note with frontmatter links to the meeting note, transcript note, and summary note +- **AND** the assistant context frontmatter state is `transcribing` +- **AND** the assistant context frontmatter includes `agenda`, empty when no agenda is known +- **AND** the assistant context frontmatter includes `scheduled_end` when Teams metadata supplied a scheduled end time + +#### Scenario: Assistant context state follows meeting processing +- **WHEN** transcription, final speaker recognition, and summary generation progress +- **THEN** Meeting Assistant updates assistant context frontmatter state to `transcribing`, `speaker recognition`, `summarizing`, `finished`, or `error` as appropriate +- **AND** preserves existing `agenda` and `scheduled_end` frontmatter values + +#### Scenario: External project write is audited +- **WHEN** the summary agent writes a bound project file +- **THEN** Meeting Assistant records the changed removed and added lines for that project file +- **AND** appends that diff to the assistant context after the agent finishes + +#### Scenario: Dictionary write is audited +- **WHEN** the summary agent adds a dictation word and the dictionary file changes +- **THEN** Meeting Assistant records the changed removed and added lines for the dictionary file +- **AND** appends that diff to the assistant context after the agent finishes + +#### Scenario: Owned artifact writes are not audited +- **WHEN** the summary agent writes the summary or assistant context file +- **THEN** Meeting Assistant does not include those writes in the external write diff audit diff --git a/openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/tasks.md b/openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/tasks.md new file mode 100644 index 0000000..14e3748 --- /dev/null +++ b/openspec/changes/archive/2026-05-22-add-summary-agent-write-diff-audit/tasks.md @@ -0,0 +1,9 @@ +## 1. Implementation +- [x] Add an in-memory summary-agent write audit component. +- [x] Capture project-file and dictation-dictionary diffs while excluding summary and assistant-context writes. +- [x] Append the collected audit to assistant context after the summary agent finishes. + +## 2. Verification +- [x] Add behavior tests for project-file diff capture, dictionary diff capture, and summary/context exclusion. +- [x] Run focused summary/project tool tests. +- [x] Run `openspec validate add-summary-agent-write-diff-audit --strict`. diff --git a/openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/proposal.md b/openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/proposal.md new file mode 100644 index 0000000..4380611 --- /dev/null +++ b/openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/proposal.md @@ -0,0 +1,11 @@ +## Why +Users can stop one meeting and immediately start the next while the previous meeting is still draining transcription, speaker recognition, or summarization. Per-run buffers and artifacts must remain isolated so old transcription output cannot be written to the new meeting. + +## What Changes +- Keep meeting note, transcript session, artifact paths, and run options bound to the run that created them. +- Allow a new recording to start after the previous capture has stopped even while the previous run continues final processing. +- Ensure rapidly-created artifact filenames are distinct. + +## Impact +- Recording coordinator finalization paths use immutable per-run state instead of mutable current-run fields. +- Transcript, meeting note, assistant context, and summary filenames include higher-resolution timestamps. diff --git a/openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/specs/meeting-recording/spec.md b/openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/specs/meeting-recording/spec.md new file mode 100644 index 0000000..c7b215e --- /dev/null +++ b/openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/specs/meeting-recording/spec.md @@ -0,0 +1,22 @@ +## MODIFIED Requirements +### Requirement: Stopping recording drains captured audio through transcription +Meeting Assistant SHALL stop capturing new audio when recording mode is stopped, but it SHALL allow already captured audio to finish running through the configured speech recognition pipeline before the recording session completes. + +When a recording is stopped, Meeting Assistant SHALL stop audio capture for that run and MAY continue draining transcription, speaker recognition, and summary generation for that stopped run. + +Meeting Assistant SHALL allow a new recording to start after the previous run's capture has stopped, even if the previous run is still draining transcription, speaker recognition, or summary generation. + +Each run SHALL keep its own transcript session, meeting note path, artifact paths, options, audio buffer, live transcript buffer, and speaker mappings isolated from later runs. + +Rapidly-created meeting note, transcript, assistant context, and summary artifact filenames SHALL be distinct. + +#### Scenario: Hotkey stops recording with buffered audio +- **WHEN** the user presses the hotkey to stop recording while captured audio is still buffered for transcription +- **THEN** Meeting Assistant stops capturing new audio and appends transcription output for the already captured audio before reporting the recording stopped + +#### Scenario: New capture starts while previous run is finalizing +- **GIVEN** a recording has been stopped and is still finalizing its transcript or summary +- **WHEN** the user starts another recording +- **THEN** Meeting Assistant starts the new capture +- **AND** final transcription and summary output from the stopped run use the stopped run's files +- **AND** live transcription buffers from the stopped run are not written to the new run diff --git a/openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/tasks.md b/openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/tasks.md new file mode 100644 index 0000000..6b8382a --- /dev/null +++ b/openspec/changes/archive/2026-05-22-allow-overlapping-meeting-finalization/tasks.md @@ -0,0 +1,8 @@ +## 1. Implementation +- [x] Add regression coverage for rapid stop/start while the first run is still finalizing. +- [x] Move finalization and summary reads/writes to per-run meeting note and artifact state. +- [x] Make rapidly-created artifact filenames distinct. + +## 2. Verification +- [x] Run focused recording coordinator tests. +- [x] Run `openspec validate allow-overlapping-meeting-finalization --strict`. diff --git a/openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/proposal.md b/openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/proposal.md new file mode 100644 index 0000000..26a0938 --- /dev/null +++ b/openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/proposal.md @@ -0,0 +1,11 @@ +## Why +Meeting artifact notes currently emit frontmatter properties that can point back to the same note. Self-references add noise and make backlinks less useful. + +## What Changes +- Meeting note frontmatter keeps links to transcript, assistant context, and summary. +- Transcript, assistant context, and summary notes keep links only to the other notes from the same run. +- The frontmatter property that would reference the note itself is omitted. + +## Impact +- Shared artifact frontmatter rendering changes for transcript, assistant context, and summary notes. +- Existing resolver behavior based on meeting note links is unchanged. diff --git a/openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/specs/meeting-session/spec.md b/openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/specs/meeting-session/spec.md new file mode 100644 index 0000000..689f3ed --- /dev/null +++ b/openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/specs/meeting-session/spec.md @@ -0,0 +1,16 @@ +## MODIFIED Requirements +### Requirement: Meeting note template is coded and round-trippable +Meeting Assistant SHALL link the note files generated for one meeting run through frontmatter. + +The meeting note frontmatter SHALL link to the transcript, assistant context, and summary notes. + +Generated artifact notes SHALL link only to the other notes from the same run and SHALL omit the frontmatter property that would reference themselves. + +#### Scenario: Meeting note links to generated artifacts +- **WHEN** Meeting Assistant creates a meeting note +- **THEN** the note frontmatter links to the configured transcript, assistant context, and summary note locations + +#### Scenario: Generated artifacts do not self-reference +- **WHEN** Meeting Assistant writes transcript, assistant context, or summary artifact frontmatter +- **THEN** the artifact frontmatter links to the other run notes +- **AND** the artifact frontmatter omits the property for the artifact's own note type diff --git a/openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/tasks.md b/openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/tasks.md new file mode 100644 index 0000000..3f798fa --- /dev/null +++ b/openspec/changes/archive/2026-05-22-remove-artifact-self-frontmatter-links/tasks.md @@ -0,0 +1,8 @@ +## 1. Implementation +- [x] Omit empty/self artifact link fields from rendered artifact frontmatter. +- [x] Ensure transcript, assistant context, and summary frontmatter include only other run artifacts. + +## 2. Verification +- [x] Add/update artifact frontmatter behavior tests. +- [x] Run focused artifact/summary tests. +- [x] Run `openspec validate remove-artifact-self-frontmatter-links --strict`. diff --git a/openspec/specs/meeting-recording/spec.md b/openspec/specs/meeting-recording/spec.md index 5a745ca..2bf9180 100644 --- a/openspec/specs/meeting-recording/spec.md +++ b/openspec/specs/meeting-recording/spec.md @@ -28,10 +28,25 @@ Meeting Assistant SHALL capture microphone input and computer output and combine ### Requirement: Stopping recording drains captured audio through transcription Meeting Assistant SHALL stop capturing new audio when recording mode is stopped, but it SHALL allow already captured audio to finish running through the configured speech recognition pipeline before the recording session completes. +When a recording is stopped, Meeting Assistant SHALL stop audio capture for that run and MAY continue draining transcription, speaker recognition, and summary generation for that stopped run. + +Meeting Assistant SHALL allow a new recording to start after the previous run's capture has stopped, even if the previous run is still draining transcription, speaker recognition, or summary generation. + +Each run SHALL keep its own transcript session, meeting note path, artifact paths, options, audio buffer, live transcript buffer, and speaker mappings isolated from later runs. + +Rapidly-created meeting note, transcript, assistant context, and summary artifact filenames SHALL be distinct. + #### Scenario: Hotkey stops recording with buffered audio - **WHEN** the user presses the hotkey to stop recording while captured audio is still buffered for transcription - **THEN** Meeting Assistant stops capturing new audio and appends transcription output for the already captured audio before reporting the recording stopped +#### Scenario: New capture starts while previous run is finalizing +- **GIVEN** a recording has been stopped and is still finalizing its transcript or summary +- **WHEN** the user starts another recording +- **THEN** Meeting Assistant starts the new capture +- **AND** final transcription and summary output from the stopped run use the stopped run's files +- **AND** live transcription buffers from the stopped run are not written to the new run + ### Requirement: Transcripts are written to the configured vault folder Meeting Assistant SHALL write live transcript text to a markdown file in the configured vault folder. @@ -43,3 +58,35 @@ Meeting Assistant SHALL write live transcript text to a markdown file in the con - **WHEN** the speech recognition pipeline emits a live transcript segment - **THEN** Meeting Assistant appends that segment to the active transcript text file +### Requirement: Recording can be launched through named profiles +Meeting Assistant SHALL treat the root `MeetingAssistant` configuration as a launch profile named `default`. + +Meeting Assistant SHALL allow additional named launch profiles to be configured as overrides of the default profile. A named profile SHALL be resolved by binding the default profile first, then binding the named profile override onto the same option object. + +Meeting Assistant SHALL preserve existing recording endpoint URLs as default-profile URLs and SHALL provide equivalent named-profile URLs that include the profile name. + +Each launch profile SHALL have a distinct global hotkey. Pressing a profile hotkey SHALL toggle recording using that profile's resolved configuration. + +Meeting Assistant SHALL use the selected launch profile's vault and recording storage settings when it creates meeting notes, transcripts, assistant context notes, summary notes, temporary recordings, and dictation-word inputs for that meeting. + +Meeting Assistant SHALL use the selected launch profile's summary-agent settings when it runs the summary pipeline for that meeting. + +#### Scenario: Default profile keeps existing recording URL +- **WHEN** the user calls the existing recording start URL without a profile name +- **THEN** Meeting Assistant starts recording with the `default` launch profile + +#### Scenario: Named profile starts recording +- **WHEN** the user calls the named-profile recording start URL for profile `english` +- **THEN** Meeting Assistant starts recording using the resolved `english` launch profile configuration + +#### Scenario: Named profile stores meeting artifacts in profile folders +- **GIVEN** launch profile `english` overrides vault folders and summary-agent settings +- **WHEN** the user starts and stops a recording with launch profile `english` +- **THEN** Meeting Assistant creates the meeting note, transcript, assistant context note, and summary note using the resolved `english` vault folders +- **AND** Meeting Assistant runs the summary pipeline using the resolved `english` summary-agent settings + +#### Scenario: Profile hotkeys must be distinct +- **GIVEN** two launch profiles configure the same toggle hotkey +- **WHEN** Meeting Assistant resolves launch profiles +- **THEN** Meeting Assistant rejects the configuration before registering global hotkeys + diff --git a/openspec/specs/meeting-session/spec.md b/openspec/specs/meeting-session/spec.md index 7015025..cffd007 100644 --- a/openspec/specs/meeting-session/spec.md +++ b/openspec/specs/meeting-session/spec.md @@ -34,45 +34,20 @@ The dictation words location SHALL point to a word-list artifact that speech rec - **THEN** Meeting Assistant can provide words from the configured dictation words path without changing the other vault locations ### Requirement: Meeting note template is coded and round-trippable -Meeting Assistant SHALL own a coded meeting note template and a store that can save and read meeting notes. +Meeting Assistant SHALL link the note files generated for one meeting run through frontmatter. -The meeting note frontmatter SHALL include: +The meeting note frontmatter SHALL link to the transcript, assistant context, and summary notes. -- `start_time` as the meeting recording start timestamp -- `end_time` as the timestamp when transcript processing stops, empty while the meeting is active -- `attendees` as an array of display strings, where email is optional and may use a format such as `Mike ` -- `projects` as an array because one meeting can cover multiple projects -- `transcript` as text containing a markdown link to the transcript note -- `assistant_context` as text containing a markdown link to the assistant context note -- `summary` as text containing a markdown link to the generated summary note once Meeting Assistant creates it +Generated artifact notes SHALL link only to the other notes from the same run and SHALL omit the frontmatter property that would reference themselves. -The user notes SHALL be the markdown body. Decisions and next steps SHALL NOT be required as frontmatter fields. - -#### Scenario: Meeting note is saved -- **WHEN** Meeting Assistant saves a meeting note -- **THEN** it writes the coded frontmatter template and the user notes body to a markdown file in the configured meeting notes folder - -#### Scenario: Meeting note links generated artifacts -- **WHEN** Meeting Assistant creates a meeting note for a new recording +#### Scenario: Meeting note links to generated artifacts +- **WHEN** Meeting Assistant creates a meeting note - **THEN** the note frontmatter links to the configured transcript, assistant context, and summary note locations -#### Scenario: Generated artifacts link back to each other -- **WHEN** Meeting Assistant creates transcript, assistant context, and summary artifacts -- **THEN** those artifacts use frontmatter links for the meeting note, transcript note, assistant context note, and summary note where applicable - -#### Scenario: Meeting note records session times -- **WHEN** Meeting Assistant creates a meeting note for a new recording -- **THEN** the note frontmatter contains `start_time` -- **AND** when transcript processing stops, Meeting Assistant writes `end_time` to the same note frontmatter -- **AND** transcript and summary frontmatter copy the meeting note title, `start_time`, and `end_time` - -#### Scenario: Meeting note is read -- **WHEN** Meeting Assistant reads a meeting note created from the coded template -- **THEN** it returns the frontmatter fields and user notes body without losing attendees, projects, transcript link, assistant context link, or summary - -#### Scenario: Meeting note frontmatter is updated -- **WHEN** Meeting Assistant reads a meeting note, changes frontmatter, and writes the note back -- **THEN** the existing user-authored markdown body remains unchanged +#### Scenario: Generated artifacts do not self-reference +- **WHEN** Meeting Assistant writes transcript, assistant context, or summary artifact frontmatter +- **THEN** the artifact frontmatter links to the other run notes +- **AND** the artifact frontmatter omits the property for the artifact's own note type ### Requirement: Meeting notes preserve user-authored content Meeting Assistant SHALL preserve user-authored meeting notes and include them as input when generating summaries, decisions, and next steps. diff --git a/openspec/specs/meeting-summary/spec.md b/openspec/specs/meeting-summary/spec.md index 8666536..6ba7274 100644 --- a/openspec/specs/meeting-summary/spec.md +++ b/openspec/specs/meeting-summary/spec.md @@ -39,9 +39,21 @@ The summary pipeline SHALL expose tools scoped to the current meeting: All summary-agent read tools that return file-like content SHALL support either reading the whole file or reading a clamped inclusive 1-based line range when `from` and `to` are supplied. +The summary pipeline SHALL write the summary note as a markdown artifact linked to the meeting note, transcript, and assistant context. + +The summary agent SHALL be able to read the meeting note, transcript, assistant context, glossary, and bound project files through tools. + +The summary agent SHALL be able to write the summary and assistant context files as its owned artifacts. + +For summary-agent writes to any file other than the summary file and assistant context file, Meeting Assistant SHALL record an in-memory diff containing removed and added lines. + +Meeting Assistant SHALL use a diff implementation that can reduce whole-file rewrites to changed lines instead of treating every rewrite as a full replacement. + +When the summary agent finishes, Meeting Assistant SHALL append the collected external write diffs to the assistant context file. + After writing the meeting summary, the summary agent SHALL update existing project files when the meeting produced project-relevant knowledge. -The assistant context note SHALL keep `meeting`, `transcript`, `summary`, `state`, and `agenda` in frontmatter. When a Teams appointment is detected at recording start, the assistant context note SHALL also keep `scheduled_end` in frontmatter. The `state` value SHALL be one of `transcribing`, `speaker recognition`, `summarizing`, `finished`, or `error`. +The assistant context note SHALL keep `title`, `start_time`, `end_time`, `meeting`, `transcript`, `summary`, `state`, and `agenda` in frontmatter. Meeting Assistant SHALL write `title` and `start_time` when the assistant context note is created, update `title` when later meeting metadata is discovered, and write `end_time` when transcript processing stops. When a Teams appointment is detected at recording start, the assistant context note SHALL also keep `scheduled_end` in frontmatter. The `state` value SHALL be one of `collecting metadata`, `transcribing`, `speaker recognition`, `summarizing`, `finished`, or `error`. The summary note SHALL keep frontmatter links to meeting artifacts and SHALL copy `title`, `start_time`, and `end_time` from the meeting note when available. If the meeting note has no title, the summary agent SHALL be able to provide a title when writing the summary. @@ -50,12 +62,57 @@ The summary agent SHALL be able to read and write the assistant context body as #### Scenario: Assistant context note is initialized - **WHEN** Meeting Assistant starts a meeting session - **THEN** it creates the assistant context note with frontmatter links to the meeting note, transcript note, and summary note -- **AND** the assistant context frontmatter state is `transcribing` +- **AND** the assistant context frontmatter state is `collecting metadata` - **AND** the assistant context frontmatter includes `agenda`, empty when no agenda is known - **AND** the assistant context frontmatter includes `scheduled_end` when Teams metadata supplied a scheduled end time #### Scenario: Assistant context state follows meeting processing - **WHEN** transcription, final speaker recognition, and summary generation progress -- **THEN** Meeting Assistant updates assistant context frontmatter state to `transcribing`, `speaker recognition`, `summarizing`, `finished`, or `error` as appropriate +- **THEN** Meeting Assistant updates assistant context frontmatter state to `collecting metadata`, `transcribing`, `speaker recognition`, `summarizing`, `finished`, or `error` as appropriate - **AND** preserves existing `agenda` and `scheduled_end` frontmatter values +#### Scenario: External project write is audited +- **WHEN** the summary agent writes a bound project file +- **THEN** Meeting Assistant records the changed removed and added lines for that project file +- **AND** appends that diff to the assistant context after the agent finishes + +#### Scenario: Dictionary write is audited +- **WHEN** the summary agent adds a dictation word and the dictionary file changes +- **THEN** Meeting Assistant records the changed removed and added lines for the dictionary file +- **AND** appends that diff to the assistant context after the agent finishes + +#### Scenario: Owned artifact writes are not audited +- **WHEN** the summary agent writes the summary or assistant context file +- **THEN** Meeting Assistant does not include those writes in the external write diff audit + +### Requirement: Summary agent instructions are configurable +Meeting Assistant SHALL allow the summary agent initial prompt to be configured through application settings. + +When no configured initial prompt is supplied, Meeting Assistant SHALL use the built-in default prompt. + +#### Scenario: Configured initial prompt is used +- **WHEN** `MeetingAssistant:Agent:InitialPrompt` is configured with non-empty content +- **THEN** the summary agent uses that configured prompt as its base instructions + +#### Scenario: Empty initial prompt falls back to built-in default +- **WHEN** `MeetingAssistant:Agent:InitialPrompt` is missing or blank +- **THEN** the summary agent uses the built-in default instructions + +### Requirement: Summary agent receives bound project instructions +Meeting Assistant SHALL append project instructions to the summary agent instructions for projects bound to the meeting note frontmatter. + +For each bound project folder under the configured projects folder, when an `AGENTS.md` file exists directly in that project folder, Meeting Assistant SHALL append the project name and the `AGENTS.md` content under a project instructions section. + +When no bound projects have `AGENTS.md`, Meeting Assistant SHALL not append the project instructions section. + +#### Scenario: Project AGENTS files are appended +- **GIVEN** the meeting note frontmatter lists projects `Alpha` and `Beta` +- **AND** both configured project folders contain `AGENTS.md` +- **WHEN** the summary agent is created +- **THEN** its instructions include `---`, `projects:`, `# Alpha`, Alpha's `AGENTS.md`, `# Beta`, and Beta's `AGENTS.md` + +#### Scenario: Projects without AGENTS files are skipped +- **GIVEN** the meeting note frontmatter lists project `Alpha` +- **AND** the configured project folder does not contain `AGENTS.md` +- **WHEN** the summary agent is created +- **THEN** no empty project instruction entry is appended for `Alpha` diff --git a/openspec/specs/meeting-transcription/spec.md b/openspec/specs/meeting-transcription/spec.md index 1f4bad6..9055a76 100644 --- a/openspec/specs/meeting-transcription/spec.md +++ b/openspec/specs/meeting-transcription/spec.md @@ -188,3 +188,197 @@ When configured, Meeting Assistant SHALL manage a local FunASR backend lifecycle - **WHEN** Meeting Assistant stops after starting a managed FunASR backend - **THEN** Meeting Assistant stops the managed backend process or container +### Requirement: Meeting Assistant learns speaker identities locally +Meeting Assistant SHALL maintain a local SQLite speaker identity database in the user's application data folder. + +The speaker identity database SHALL store speaker identities, optional canonical names, aliases, candidate names, meeting file references, and a bounded set of WAV snippets per identity. + +Meeting file references SHALL include the meeting note file address and the transcript file address. + +Meeting Assistant SHALL calculate speaker identity participation counts from meeting file references when needed instead of persisting a denormalized transcript count. + +Each speaker identity SHALL store a last-modified timestamp used by active-age filtering, and Meeting Assistant SHALL update it whenever the identity is created or modified by identification, candidate updates, snippet changes, reference changes, or merge operations. + +The configured maximum snippet count per identity SHALL prevent unbounded growth. + +#### Scenario: Unknown speaker is learned from meeting attendees +- **WHEN** a finished transcript contains an unmatched diarized speaker and the meeting note has attendees +- **THEN** Meeting Assistant stores a new unnamed speaker identity with candidate names from the attendees that were not already matched in that meeting +- **AND** stores a meeting file reference for that identity + +#### Scenario: Speaker snippets are bounded +- **WHEN** Meeting Assistant adds a snippet for an identity that already has the configured maximum number of snippets +- **THEN** Meeting Assistant does not store more snippets for that identity + +#### Scenario: Identity modification updates active-age timestamp +- **WHEN** Meeting Assistant creates, identifies, updates candidates for, stores snippets for, stores references for, or merges a speaker identity +- **THEN** Meeting Assistant updates that identity's last-modified timestamp + +### Requirement: Speaker identities can be merged diagnostically +Meeting Assistant SHALL expose a diagnostic endpoint that merges duplicate speaker identities. + +The merge process SHALL compare recently-created identities, using a configurable recent age that defaults to two weeks, against all other identities in matcher batches bounded by the configured batch size. + +The merge process SHALL require a match and a second validation match using a different source sample before merging two identities. + +When identities are merged, Meeting Assistant SHALL retain one identity, move useful names from the merged identity into aliases, combine meeting file references, retain a bounded set of snippets from both identities, and append an audit line to each referenced transcript in the form ` and were merged`. + +#### Scenario: Recently-created duplicate identity is merged +- **GIVEN** a recently-created identity and an older identity have matching speaker snippets +- **WHEN** the diagnostic merge endpoint is triggered +- **THEN** Meeting Assistant validates the match twice with different source snippets +- **AND** merges the recent identity into the older identity +- **AND** stores the recent identity name as an alias on the retained identity +- **AND** keeps meeting file references from both identities +- **AND** appends the merge audit line to the referenced transcripts + +#### Scenario: Old identities are not used as merge sources +- **GIVEN** two identities older than the configured recent age +- **WHEN** the diagnostic merge endpoint is triggered +- **THEN** Meeting Assistant does not compare them as source identities + +### Requirement: Speaker candidates are eliminated across meetings +Meeting Assistant SHALL update candidate names for a matched unnamed identity using the intersection of its existing candidate names and the current meeting attendees. + +Meeting Assistant SHALL treat identity aliases as acceptable names during candidate elimination and when excluding already-matched attendees from new unmatched speaker candidates. + +When the candidate intersection leaves exactly one candidate, Meeting Assistant SHALL promote that candidate to the canonical speaker name. + +When an identity receives a canonical name, Meeting Assistant SHALL append an audit line to each referenced transcript in the form ` was identified as `. + +When the candidate intersection is empty, Meeting Assistant SHALL replace the oldest stored snippet for that identity and reset candidates from the current meeting attendees, because the previous snippet may have been dirty. + +#### Scenario: Candidate elimination promotes canonical name +- **GIVEN** an unnamed identity has candidate names `John` and `Mike` +- **WHEN** that identity matches a speaker in a later meeting with attendees `Jane`, `John`, and `Chris` +- **THEN** Meeting Assistant removes `Mike` from the identity candidates and promotes `John` as the canonical name +- **AND** appends the identity naming audit line to the identity's referenced transcripts + +#### Scenario: Alias participates in candidate elimination +- **GIVEN** an unnamed identity has candidate name `Michael` and alias `Mike` +- **WHEN** that identity matches a speaker in a later meeting with attendee `Mike` +- **THEN** Meeting Assistant treats `Mike` as matching `Michael` +- **AND** promotes `Michael` as the canonical name + +#### Scenario: Empty candidate intersection resets candidates +- **GIVEN** an unnamed identity has candidate names `John` and `Mike` +- **WHEN** that identity matches a speaker in a later meeting with attendees `Jane` and `Chris` +- **THEN** Meeting Assistant resets the identity candidates to `Jane` and `Chris` +- **AND** replaces the oldest stored snippet for that identity with the current speaker snippet + +### Requirement: Speaker identity matches relabel transcripts +Meeting Assistant SHALL attempt to match unknown diarized speaker snippets against known speaker identities ordered by calculated meeting reference count. + +Speaker identity matching SHALL use a dedicated Azure Speech diarization verifier component rather than the configured speech recognition pipeline. + +The matcher SHALL test at most the configured batch size of known people per diarization session and continue with later batches until a match is found or no candidates remain. + +The matcher SHALL prioritize identities whose canonical name or aliases match current meeting attendees. + +After attendee-matched identities, the matcher SHALL order identities by calculated meeting reference count, filter out non-attendee identities whose last update is older than the configured active age, and cap the candidate set at the configured maximum match candidate count. + +When a match is confirmed in final identity processing, Meeting Assistant SHALL store a meeting file reference for that identity. + +When a match is confirmed and the identity has a canonical name, Meeting Assistant SHALL rewrite finished transcript segments for that diarized speaker with the canonical name. + +When a match is confirmed and the matched speaker is not already listed in meeting note attendees by display name or alias, Meeting Assistant SHALL add the speaker display name to the attendee list. + +When Meeting Assistant writes attendees from calendar metadata, it SHALL match attendee display names exactly against known identity canonical names and aliases, replace matches with the identity display name, and deduplicate attendees that map to the same identity. + +#### Scenario: Finished transcript is relabeled after a confirmed match +- **GIVEN** the speaker identity database contains canonical speaker `Chris` +- **WHEN** a finished transcript has diarized speaker `Guest03` and the matching backend confirms it is `Chris` +- **THEN** Meeting Assistant rewrites `Guest03` segments in the transcript as `Chris` + +#### Scenario: Confirmed match stores meeting reference +- **GIVEN** the speaker identity database contains canonical speaker `Chris` +- **WHEN** a finished transcript has diarized speaker `Guest03` and the matching backend confirms it is `Chris` +- **THEN** Meeting Assistant stores the meeting note and transcript file addresses as a reference for `Chris` + +### Requirement: Speaker matching runs during active transcription +Meeting Assistant SHALL start speaker identity matching only after the configured initial transcription duration has elapsed. + +For backends that emit live diarized transcript segments, Meeting Assistant SHALL keep a bounded in-memory sliding audio buffer with chunk timestamps and extract candidate WAV snippets from that buffer when live diarized segments arrive. + +Meeting Assistant SHALL keep only the configured best candidate snippets per diarized speaker in memory. Better snippets SHALL be preferred when the segment looks like a continuous medium-length sentence. + +Meeting Assistant SHALL periodically match unresolved diarized speaker samples while transcription is active and attempt to match them against the local identity database. + +Meeting Assistant SHALL run live matching incrementally at the configured interval only when at least one new unmapped diarized speaker sample appears or the meeting note attendee frontmatter changes while unmapped speaker samples still exist. + +When a speaker is matched during transcription, Meeting Assistant SHALL rewrite already-written live transcript segments for that diarized speaker and write future transcript segments using the canonical name. + +Live speaker matching SHALL be read-only with respect to the speaker identity database. Candidate elimination, canonical promotion, transcription counters, stored snippet updates, and new unmatched identity creation SHALL happen only after transcription is finished, using the latest meeting note frontmatter. + +For backends that only provide diarization after finalization, Meeting Assistant SHALL defer speaker identity matching until finished diarization is available, extract candidate snippets from the completed temporary recording, complete identity matching, and only then allow summary generation to start. + +#### Scenario: Matching waits for useful speech duration +- **WHEN** transcription has been active for less than the configured speaker identification initial delay +- **THEN** Meeting Assistant does not run speaker identity matching yet + +#### Scenario: Live matching uses in-memory speaker samples +- **WHEN** a live diarized transcript segment identifies an unresolved speaker +- **THEN** Meeting Assistant extracts a WAV snippet for that segment from the in-memory sliding audio buffer +- **AND** uses retained speaker samples for live identity matching without reading the temporary recording file + +#### Scenario: Live match rewrites current and future transcript writes +- **WHEN** periodic matching confirms that diarized speaker `Guest03` is canonical speaker `Chris` +- **THEN** already-written live transcript segments for `Guest03` are rewritten as `Chris` +- **AND** later live transcript segments for `Guest03` are written as `Chris` + +#### Scenario: New live speaker triggers another identification round +- **GIVEN** live matching already checked the current unresolved speaker samples +- **WHEN** a new unmapped diarized speaker sample appears +- **THEN** Meeting Assistant runs another live matching round at the next configured interval + +#### Scenario: Attendee changes trigger another identification round +- **GIVEN** live matching already checked unresolved speaker samples +- **WHEN** the meeting note attendee frontmatter changes +- **THEN** Meeting Assistant runs another live matching round at the next configured interval using the latest attendees + +#### Scenario: Live matching does not make final identity decisions +- **WHEN** live matching finds a possible speaker identity during transcription +- **THEN** Meeting Assistant does not change candidate names, promote canonical names, increment counters, store snippets, or create unmatched identities +- **AND** the final speaker identity pass uses the latest meeting note attendees after transcription finishes + +### Requirement: Speech recognition diagnostics are launch-profile aware +Meeting Assistant SHALL preserve existing ASR diagnostic endpoint URLs as default-profile URLs. + +Meeting Assistant SHALL provide equivalent named-profile ASR diagnostic endpoint URLs that include the profile name. + +When a named-profile ASR diagnostic endpoint is used, Meeting Assistant SHALL create the speech recognition pipeline from the resolved profile configuration. + +#### Scenario: Default ASR diagnostic URL uses default profile +- **WHEN** the user submits a WAV file to the existing ASR diagnostic endpoint URL +- **THEN** Meeting Assistant streams the WAV through the default launch profile's configured speech recognition pipeline + +#### Scenario: Named ASR diagnostic URL uses named profile +- **WHEN** the user submits a WAV file to the ASR diagnostic endpoint URL for profile `english` +- **THEN** Meeting Assistant streams the WAV through the resolved `english` launch profile's configured speech recognition pipeline + +### Requirement: Azure Speech post-stream refinement is configurable +Meeting Assistant SHALL allow the Azure Speech streaming transcription provider to configure the Speech SDK post-processing option. + +When configured for a compatible Azure Speech SDK recognizer, Meeting Assistant SHALL set `SpeechServiceResponse_PostProcessingOption` on the Azure Speech SDK `SpeechConfig`. + +The default application configuration SHALL keep `PostProcessingOption` empty while using live `ConversationTranscriber` and SHALL use a region that supports post-stream refinement for future compatible recognizer paths. + +Meeting Assistant SHALL keep using the existing Azure live streaming transcription flow rather than switching to batch or offline processing. + +When the Azure live streaming backend uses `ConversationTranscriber`, Meeting Assistant SHALL prefer working live diarized transcription over applying a post-processing option that is only documented for `SpeechRecognizer`. + +#### Scenario: Azure Speech post-refinement is configured +- **WHEN** `AzureSpeech.PostProcessingOption` is `PostRefinement` +- **AND** the configured Azure Speech recognizer supports SDK post-processing +- **THEN** Meeting Assistant sets `SpeechServiceResponse_PostProcessingOption` to `PostRefinement` on the Azure Speech SDK configuration + +#### Scenario: Azure live conversation transcription remains available +- **WHEN** `AzureSpeech.PostProcessingOption` is `PostRefinement` +- **AND** the Azure backend is using live `ConversationTranscriber` +- **THEN** Meeting Assistant skips the post-processing SDK property +- **AND** continues using live conversation transcription + +#### Scenario: Azure Speech post-processing is unset +- **WHEN** `AzureSpeech.PostProcessingOption` is empty +- **THEN** Meeting Assistant does not set a post-processing option on the Azure Speech SDK configuration +