From 75f720fa92a695710df98bbe658ac6103bce3f69 Mon Sep 17 00:00:00 2001 From: DevMando Date: Wed, 11 Nov 2026 20:27:18 -0800 Subject: [PATCH 1/2] Upgrade CLI to RazorConsole 0.7.0 and retain deferred focus safeguard --- docs/CHANGELOG.md | 25 ++++++++ .../Components/Input/PromptInput.razor | 1 + src/MandoCode/MandoCode.csproj | 6 +- .../Services/Input/PromptEmojiAliases.cs | 2 +- .../Services/Rendering/AnsiTranscriptText.cs | 4 +- .../Services/Rendering/DeferredFocus.cs | 4 +- .../Services/Rendering/PaneColors.cs | 4 +- .../Services/Sessions/AgentArchiveStore.cs | 2 +- .../Services/Sessions/TranscriptExport.cs | 4 +- .../PromptStartupRenderingTests.cs | 63 +++++++++++++++++++ 10 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 tests/MandoCode.Tests/PromptStartupRenderingTests.cs diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bad7d29..956b088 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,31 @@ All notable changes to MandoCode will be documented in this file. +## [Unreleased] + +**Updated terminal rendering with RazorConsole 0.7.0.** The CLI now includes RazorConsole's upstream fix for focus events raised while the interface is being drawn. MandoCode keeps the deferred focus safeguard introduced in v0.16.2, which prevents the repeated prompt borders seen on some launches. + +**Highlights** + +- Upgrade the terminal UI framework while preserving the startup rendering fix. +- Keep transcript formatting, hyperlinks, and emoji shortcuts compatible with the updated rendering dependencies. +- Clear the clipboard attachment message reliably after sending a prompt. + +### Changed + +- Upgrade RazorConsole.Core from 0.6.0 to 0.7.0. Retain `DeferredFocus` for startup and panels so focus requests made from `OnAfterRenderAsync` continue to wait until their render batch completes. +- Adapt transcript rendering, saved-agent history, HTML exports, and emoji expansion to the updated Spectre.Console APIs. Hyperlinks now use the separate link API, and styles use the new value type. +- Update Markdig to 1.5.1 and Microsoft.Extensions.FileSystemGlobbing to 10.0.14 to satisfy the new dependency requirements on both supported .NET targets. + +### Fixed + +- Refresh the prompt after submission so the clipboard attachment message clears reliably. + +### Test coverage + +- Add a component check that focusing and redrawing the prompt repeatedly leaves one prompt in the render tree and keeps keyboard focus on it. +- All 1,248 tests pass on net10.0 and net8.0. Verify startup, typing, and resizing in a real pseudo-terminal on both builds, with no reported rendering errors. Confirm the CLI tool package builds successfully. + ## [0.16.2] - 2026-11-11 **The startup screen no longer fills with repeated prompt borders.** On some launches the first agent drew its prompt as rows of bottom borders and could not take input; the workaround was to open a second agent and close the first. The 0.16.1 startup change did not address this. RazorConsole remains at 0.6.0. A screenshot of the failure is in [#138](https://github.com/DevMando/MandoCode/pull/138). diff --git a/src/MandoCode/Components/Input/PromptInput.razor b/src/MandoCode/Components/Input/PromptInput.razor index 4287111..b878a1f 100644 --- a/src/MandoCode/Components/Input/PromptInput.razor +++ b/src/MandoCode/Components/Input/PromptInput.razor @@ -384,6 +384,7 @@ _composer.SetText(""); _clipboardStatus = ""; await OnSubmit.InvokeAsync(value); + StateHasChanged(); } public void SetValue(string value) { _composer.SetText(value); StateHasChanged(); } } diff --git a/src/MandoCode/MandoCode.csproj b/src/MandoCode/MandoCode.csproj index 72d1bcf..fdccfcd 100644 --- a/src/MandoCode/MandoCode.csproj +++ b/src/MandoCode/MandoCode.csproj @@ -28,8 +28,8 @@ - - + + @@ -53,7 +53,7 @@ - + diff --git a/src/MandoCode/Services/Input/PromptEmojiAliases.cs b/src/MandoCode/Services/Input/PromptEmojiAliases.cs index 86fe6bd..6be9088 100644 --- a/src/MandoCode/Services/Input/PromptEmojiAliases.cs +++ b/src/MandoCode/Services/Input/PromptEmojiAliases.cs @@ -89,7 +89,7 @@ public static bool Expand(TextSelectionState buffer) "cool" => "😎", "brain" => "🧠", "llama" => "🦙", - _ => Emoji.Replace(alias.AsSpan()) + _ => Emoji.Replace(alias) }; if (emoji == alias) return false; buffer.SetText(text[..start] + emoji + text[cursor..]); diff --git a/src/MandoCode/Services/Rendering/AnsiTranscriptText.cs b/src/MandoCode/Services/Rendering/AnsiTranscriptText.cs index e3cf03a..afcd233 100644 --- a/src/MandoCode/Services/Rendering/AnsiTranscriptText.cs +++ b/src/MandoCode/Services/Rendering/AnsiTranscriptText.cs @@ -16,7 +16,7 @@ public static Paragraph Parse(string input) for (var index = 0; index < input.Length; index++) { if (input[index] != '\u001b') continue; - if (index > start) output.Append(input[start..index], new Style(foreground, background, decoration, link)); + if (index > start) output.Append(input[start..index], new Style(foreground, background, decoration), link is null ? null : new Link(link)); if (index + 1 < input.Length && input[index + 1] == '[') { var end = index + 2; @@ -70,7 +70,7 @@ public static Paragraph Parse(string input) else index = Math.Min(index + 1, input.Length - 1); start = index + 1; } - if (start < input.Length) output.Append(input[start..], new Style(foreground, background, decoration, link)); + if (start < input.Length) output.Append(input[start..], new Style(foreground, background, decoration), link is null ? null : new Link(link)); return output; } } diff --git a/src/MandoCode/Services/Rendering/DeferredFocus.cs b/src/MandoCode/Services/Rendering/DeferredFocus.cs index b8402de..2d7970c 100644 --- a/src/MandoCode/Services/Rendering/DeferredFocus.cs +++ b/src/MandoCode/Services/Rendering/DeferredFocus.cs @@ -7,7 +7,7 @@ namespace MandoCode.Services; /// Keeps focus requests made from OnAfterRender out of the render batch that raised them. /// /// -/// FocusManager.FocusAsync dispatches focusin/focusout as soon as the key is a known focus +/// In RazorConsole 0.6, FocusManager.FocusAsync dispatched focusin/focusout as soon as the key was a known focus /// target. OnAfterRender runs while the renderer is still inside its batch, so that dispatch /// starts the event's own render pass before the batch has been cleared. The renderer then hands /// the same edits to the display a second time and every component the batch created is inserted @@ -15,6 +15,8 @@ namespace MandoCode.Services; /// bottom borders and could not take input. Whether the key was already a known target depended /// on a thread-pool observer, which made the failure intermittent. /// Event handlers are not affected: they run outside a batch and may call FocusAsync directly. +/// RazorConsole 0.7 also defers reentrant dispatch upstream. Keep this lifecycle safeguard +/// so MandoCode's after-render focus requests explicitly run after their batch completes. /// public static class DeferredFocus { diff --git a/src/MandoCode/Services/Rendering/PaneColors.cs b/src/MandoCode/Services/Rendering/PaneColors.cs index 08ad7c4..7b6ab23 100644 --- a/src/MandoCode/Services/Rendering/PaneColors.cs +++ b/src/MandoCode/Services/Rendering/PaneColors.cs @@ -32,12 +32,12 @@ public IEnumerable Render(RenderOptions options, int maxWidth) yield return segment; continue; } - var foreground = segment.Style?.Foreground ?? Color.Default; + var foreground = segment.Style.Foreground; // Error and warning colors remain noticeable in background transcripts. if (foreground == Color.Red || foreground == Color.Red1 || foreground == Color.Yellow) yield return segment; else - yield return new Segment(segment.Text, new Style(Color.Grey62, Color.Default, segment.Style?.Decoration ?? Decoration.None)); + yield return new Segment(segment.Text, new Style(Color.Grey62, Color.Default, segment.Style.Decoration)); } } } diff --git a/src/MandoCode/Services/Sessions/AgentArchiveStore.cs b/src/MandoCode/Services/Sessions/AgentArchiveStore.cs index cc3359b..1a70edd 100644 --- a/src/MandoCode/Services/Sessions/AgentArchiveStore.cs +++ b/src/MandoCode/Services/Sessions/AgentArchiveStore.cs @@ -185,7 +185,7 @@ public static List Capture(TuiSession session) foreach (var entry in entries.Skip(start)) { var spans = entry.Content.Render(options, 120).Where(s => !s.IsControlCode) - .Select(s => new ArchivedSpan(s.Text, s.Style?.ToMarkup() ?? "")).ToList(); + .Select(s => new ArchivedSpan(s.Text, s.Style.ToMarkup())).ToList(); blocks.Add(new(spans, entry.UserPrompt, entry.SpaceAfter) { ToolGroup = entry.ToolActivity is not null ? entry.Id : entry.ToolOutput is { } output ? groups.GetValueOrDefault(output) : null, diff --git a/src/MandoCode/Services/Sessions/TranscriptExport.cs b/src/MandoCode/Services/Sessions/TranscriptExport.cs index 2779ddb..fd624dd 100644 --- a/src/MandoCode/Services/Sessions/TranscriptExport.cs +++ b/src/MandoCode/Services/Sessions/TranscriptExport.cs @@ -28,7 +28,7 @@ public static string BuildHtml(TuiSession session, string agent, string project, foreach (var span in block.Spans) { var css = new StringBuilder(); - if (Style.TryParse(span.Style, out var style) && style is not null) { + if (Style.TryParse(span.Style, out var style)) { if (style.Foreground != Color.Default) css.Append($"color:#{style.Foreground.R:x2}{style.Foreground.G:x2}{style.Foreground.B:x2};"); if (style.Background != Color.Default) css.Append($"background:#{style.Background.R:x2}{style.Background.G:x2}{style.Background.B:x2};"); if (style.Decoration.HasFlag(Decoration.Bold)) css.Append("font-weight:bold;"); @@ -63,4 +63,4 @@ public static async Task SaveAsync(TuiSession session, string agent, str } private static bool IsSaveCommand(string text) => text.Trim().Equals("/transcript-save", StringComparison.OrdinalIgnoreCase) || text.TrimStart().StartsWith("/transcript-save ", StringComparison.OrdinalIgnoreCase); private static string E(string text) => WebUtility.HtmlEncode(text); -} \ No newline at end of file +} diff --git a/tests/MandoCode.Tests/PromptStartupRenderingTests.cs b/tests/MandoCode.Tests/PromptStartupRenderingTests.cs new file mode 100644 index 0000000..5aa10a4 --- /dev/null +++ b/tests/MandoCode.Tests/PromptStartupRenderingTests.cs @@ -0,0 +1,63 @@ +using System.Reflection; +using MandoCode.Components; +using MandoCode.Services; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Rendering; +using Microsoft.Extensions.DependencyInjection; +using RazorConsole.Core; +using RazorConsole.Core.Focus; +using Xunit; + +namespace MandoCode.Tests; + +[Trait("Category", "Component")] +public sealed class PromptStartupRenderingTests +{ + [Fact] + public async Task FocusAndRefocusKeepOnePromptInTheRenderTree() + { + var registrations = new ServiceCollection().AddLogging(); + registrations.AddRazorConsoleServices(); + registrations.AddSingleton(new InputStateMachine(new Dictionary(), null)); + await using var services = registrations.BuildServiceProvider(); + PromptInput input = null!; + await using var renderer = await WidgetRendererHarness.MountAsync(services, new() + { + [nameof(Host.Capture)] = (Action)(value => input = value) + }); + var hook = (string)typeof(PromptInput).GetField("_hook", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(input)!; + var focus = services.GetRequiredService(); + // The test renderer has no console host to deliver snapshots to the focus observer. + await renderer.Dispatcher.InvokeAsync(async () => + { + typeof(FocusManager).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) + .Single(method => method.Name.EndsWith("OnNext")).Invoke(focus, [renderer.Snapshot()]); + await input.FocusPromptAsync(); + }); + for (var iteration = 0; iteration < 5; iteration++) + { + await renderer.Dispatcher.InvokeAsync(async () => + { + input.SetValue($"Prompt {iteration}"); + await input.FocusPromptAsync(); + }); + await renderer.Dispatcher.InvokeAsync(() => + { + var nodes = WidgetRendererHarness.Flatten(WidgetRendererHarness.Root(renderer.Snapshot())); + Assert.Single(nodes, node => node.Attributes.TryGetValue("data-focus-key", out var key) && key == hook); + Assert.True(focus.IsFocused(hook)); + }); + } + } + + public sealed class Host : ComponentBase + { + [Parameter] public Action Capture { get; set; } = default!; + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.OpenComponent(0); + builder.AddComponentReferenceCapture(1, value => Capture((PromptInput)value)); + builder.CloseComponent(); + } + } +} From 481826c326ecbbb4bcf4838b56c157530b41bb2c Mon Sep 17 00:00:00 2001 From: DevMando Date: Wed, 11 Nov 2026 20:35:23 -0800 Subject: [PATCH 2/2] Make hyperlink rendering tests independent of CI terminal detection --- docs/CHANGELOG.md | 1 + tests/MandoCode.Tests/MarkdownHtmlRendererTests.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 956b088..8d681aa 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -24,6 +24,7 @@ All notable changes to MandoCode will be documented in this file. ### Test coverage +- Explicitly enable hyperlink support in Markdown rendering tests so their clickable-link assertions run consistently in local terminals and CI. - Add a component check that focusing and redrawing the prompt repeatedly leaves one prompt in the render tree and keeps keyboard focus on it. - All 1,248 tests pass on net10.0 and net8.0. Verify startup, typing, and resizing in a real pseudo-terminal on both builds, with no reported rendering errors. Confirm the CLI tool package builds successfully. diff --git a/tests/MandoCode.Tests/MarkdownHtmlRendererTests.cs b/tests/MandoCode.Tests/MarkdownHtmlRendererTests.cs index 9e51e5f..db21da8 100644 --- a/tests/MandoCode.Tests/MarkdownHtmlRendererTests.cs +++ b/tests/MandoCode.Tests/MarkdownHtmlRendererTests.cs @@ -202,6 +202,8 @@ private static string RenderToString(IRenderable renderable) ColorSystem = ColorSystemSupport.TrueColor, Out = new AnsiConsoleOutput(writer), }); + // Exercise hyperlink rendering regardless of the host terminal or CI detection. + console.Profile.Capabilities.Links = true; console.Write(renderable); return writer.ToString(); }