Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ All notable changes to MandoCode will be documented in this file.

## [Unreleased]

**External agents with clearer session controls and tool activity.** Run coding agents through ACP, including Codex through its tested adapter. See the connected agent, model, and mode at startup, change the session mode with `/agent-acp-mode`, and expand individual tool calls to inspect their details. The CLI also includes RazorConsole 0.7.0's upstream focus fix and retains MandoCode's startup rendering safeguard.
**External agents, clearer session controls, and smoother workspace switching.** Run coding agents through ACP, including Codex through its tested adapter. See the connected agent, model, and mode at startup, change the session mode with `/agent-acp-mode`, and expand individual tool calls to inspect their details. Reduce visible top-to-bottom repainting when switching workspaces, including from multiple agent panes to a blank conversation. The CLI also includes RazorConsole 0.7.0's upstream focus fix and retains MandoCode's startup rendering safeguard.

**Highlights**

- Run Codex through the existing ACP client, with documented setup and authentication handled by Codex.
- Choose the external agent's permission and behavior mode without starting another conversation.
- Follow ACP tool calls through compact, expandable rows that update in place.
- Switch agents and workspaces with fewer unnecessary redraws and completed terminal frames delivered together.
- 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.
Expand Down Expand Up @@ -38,15 +39,22 @@ All notable changes to MandoCode will be documented in this file.

### Fixed

- Batch synchronized terminal frames into one output write, reducing fragmented row-by-row delivery during large workspace transitions. Preserve terminal size and encoding, pass non-frame output through, bound buffering, and release interrupted frames at shutdown.
- Enable synchronized terminal frames to reduce visible top-to-bottom repainting on terminals supporting synchronized output. Publish one completed workspace-switch notification instead of three intermediate redraw requests, preserving pane focus and background sessions.
- Reuse unchanged conversation snapshots and transcript groups during focus, scrolling, and status updates. Avoid copying and regrouping the full history on these refreshes while keeping streamed output, tool expansion, late agent replies, and cleared conversations current.
- Reduce unnecessary multi-agent redraws: selecting an agent no longer re-focuses the previous pane when the workspace picker is already closed. Poll top-level status only when visible indicators or tips change, let the root forward workspace and resize updates once, and avoid rebuilding pane content for unchanged Git status. Preserve background streaming, focus safeguards, and inactive-pane dimming.
- Refresh the prompt after submission so the clipboard attachment message clears reliably.

### Test coverage

- Verify frame batching through the actual RazorConsole live canvas: a large-to-blank transition produces identical ANSI output in one underlying writer call. Cover fragmented frame markers, interrupted-frame shutdown, bounded buffering, and output restoration. All 59 selected rendering, workspace, and routing checks pass on both net8.0 and net10.0.
- Cover reuse of long conversation snapshots, updated streaming status, cleared history, retained expansion, and late agent replies. During this rendering work, a full-suite run passed 1,924 tests with one skip on net10.0; net8.0 passed 1,923 with one skip and hit the previously observed ACP command-notification timeout. The final frame-batching change was validated with the targeted checks above. The user also confirmed that batching resolved the visible workspace repaint sweep in their terminal.
- Add rendering regressions for no-op picker closure, one focus transition per agent-tab selection, quiet idle polling, one body repaint per pane on focus changes, and continued awaiting-input updates. A two-pane test that previously rebuilt agent bodies six extra times over 750 ms now performs no extra idle rebuilds.
- 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.
- The RazorConsole upgrade passed its then-current suite of 1,248 tests on net10.0 and net8.0, plus startup, typing, resizing, and CLI packaging checks.
- Add coverage for ACP mode selection, sparse and interleaved tool updates, permission decisions, cancellation and interruption, reused call ids, bounded output, attached diffs, and expansion that stays open during updates. The 95 targeted activity, permission, transcript, and export checks pass on both supported frameworks.
- Final full-suite validation passes on net10.0 and net8.0: 1,919 tests passed and one existing symlink-creation test skipped on each framework. Verify Codex adapter initialization, session creation, a streamed reply, and a session-scoped mode change on Windows.
- The earlier Codex ACP full-suite validation passed on net10.0 and net8.0: 1,919 tests passed and one existing symlink-creation test skipped on each framework. Verify Codex adapter initialization, session creation, a streamed reply, and a session-scoped mode change on Windows.

## [0.16.2] - 2026-11-11

Expand Down
5 changes: 5 additions & 0 deletions src/MandoCode/Components/Conversation/ConversationView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
private int _offset;
private bool _following = true;
private TuiEntry[] _visibleEntries = [];
private IReadOnlyList<TuiEntry>? _partitionedEntries;
private IReadOnlyDictionary<AgentExchange, TuiEntry[]> _details = new Dictionary<AgentExchange, TuiEntry[]>();
protected override void OnParametersSet()
{
// Session snapshots reuse their entries until an entry is added or cleared.
// Focus, scrolling, and live activity still render, without regrouping history.
if (ReferenceEquals(_partitionedEntries, Entries)) return;
_partitionedEntries = Entries;
_visibleEntries = Entries.Where(e => e.AgentOutput is null).ToArray();
_details = Entries.Where(e => e.AgentOutput is not null).GroupBy(e => e.AgentOutput!).ToDictionary(g => g.Key, g => g.ToArray());
}
Expand Down
4 changes: 3 additions & 1 deletion src/MandoCode/Components/Workspaces/AgentPaneContent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
if (_shutdown.IsCancellationRequested) break;
await InvokeAsync(() =>
{
_git = root == rootAccessor.ProjectRoot ? status : null;
var next = root == rootAccessor.ProjectRoot ? status : null;
if (_git == next) return;
_git = next;
StateHasChanged();
});
} while (await timer.WaitForNextTickAsync(_shutdown.Token));
Expand Down
9 changes: 7 additions & 2 deletions src/MandoCode/Components/Workspaces/AgentWorkspaceView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
[Parameter] public RenderFragment<AgentPane>? AgentBody { get; set; }
[Parameter] public AgentWorkspace Workspace { get; set; } = default!;
[Parameter] public int ReservedHeight { get; set; }
// TerminalWorkspaceView already forwards registry and resize changes through parameters.
[Parameter] public bool ObserveChanges { get; set; } = true;
private int AvailableHeight => Math.Max(1, Viewport.Height - ReservedHeight);
private int RowWidth => SplitRowsSideBySide ? Viewport.Width : PaneWidth;
private long _lastFocusVersion = -1;
Expand All @@ -24,8 +26,11 @@
protected override void OnInitialized()
{
Workspace ??= DefaultWorkspace;
Workspace.Changed += Changed;
Viewport.OnResized += Changed;
if (ObserveChanges)
{
Workspace.Changed += Changed;
Viewport.OnResized += Changed;
}
if (Workspace.Panes.Count == 0) Workspace.Add();
UpdateSizes();
}
Expand Down
19 changes: 17 additions & 2 deletions src/MandoCode/Components/Workspaces/TerminalWorkspaceView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
private readonly WorkspaceTabWindow _tabs = new();
private AgentWorkspace[] _openWorkspaces = [];
private bool _pickerWasOpen;
private (int Awaiting, bool Explorer, bool AgentTips, string Tip) _lastStatus;
private string ExplorerTip => Registry.Active.SelectedPane?.IsHistoryOpen?.Invoke() == true
? "Tab switches list/conversation · Up/Down or Page Up/Page Down navigates · Home/End jumps · Type to search the list · Left/Right selects actions · Enter activates · Esc closes."
: Registry.Active.SelectedPane?.IsGitChangesOpen?.Invoke() == true
Expand Down Expand Up @@ -109,6 +110,7 @@
Viewport.OnResized += Changed;
if (Registry.Active.Panes.Count == 0) Registry.Active.Add();
UpdateTabs();
_lastStatus = CaptureStatus();
_ = RefreshStatusAsync();
}
private void UpdateTabs()
Expand All @@ -118,7 +120,20 @@
_openWorkspaces = Registry.Workspaces.ToArray();
_tabs.Update(_openWorkspaces, Registry.Active, Viewport.Width - LabelWidth - ArrowWidth - ActionsWidth);
}
private void Changed() => _ = InvokeAsync(() => { UpdateTabs(); _revision++; StateHasChanged(); });
private void Changed() => _ = InvokeAsync(() => { UpdateTabs(); _lastStatus = CaptureStatus(); _revision++; StateHasChanged(); });
private (int Awaiting, bool Explorer, bool AgentTips, string Tip) CaptureStatus()
{
var awaiting = 0;
var panes = Registry.Active.Panes;
for (var index = 0; index < panes.Count; index++)
if (panes[index].IsAwaitingInput?.Invoke() == true) awaiting |= 1 << index;
var explorer = ShowExplorerTip;
return (awaiting, explorer, ShowAgentTips, explorer ? ExplorerTip : "");
}
private void PollStatus()
{
if (CaptureStatus() != _lastStatus) Changed();
}
private void ScrollTabs(int direction) { _tabs.Scroll(direction, _openWorkspaces.Length); Changed(); }
private void ClosePicker()
{
Expand All @@ -129,7 +144,7 @@
private async Task RefreshStatusAsync()
{
using var timer = new PeriodicTimer(TimeSpan.FromMilliseconds(300));
try { while (await timer.WaitForNextTickAsync(_shutdown.Token)) Changed(); }
try { while (await timer.WaitForNextTickAsync(_shutdown.Token)) await InvokeAsync(PollStatus); }
catch (OperationCanceledException) when (_shutdown.IsCancellationRequested) { }
}
public void Dispose() { Registry.Changed -= Changed; Viewport.OnResized -= Changed; Registry.IsWorkspacePickerOpen = false; _shutdown.Cancel(); _shutdown.Dispose(); }
Expand Down
2 changes: 1 addition & 1 deletion src/MandoCode/Components/Workspaces/WorkspaceSurface.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
@* grid selects the renderer's Spectre fallback, which emits zero cells when hidden. *@
<div class="@(Workspace.IsVisible ? "workspace-surface" : "grid")" data-workspace-hidden="@(!Workspace.IsVisible ? "true" : "false")">
<AgentWorkspaceView Workspace="Workspace" ReservedHeight="ReservedHeight" AgentBody="AgentBody" />
<AgentWorkspaceView Workspace="Workspace" ReservedHeight="ReservedHeight" AgentBody="AgentBody" ObserveChanges="false" />
</div>
}
@code {
Expand Down
3 changes: 3 additions & 0 deletions src/MandoCode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ static async Task Main(string[] args)
options.RenderingPipeline = RazorConsoleRenderingPipeline.WidgetLayout;
options.ConsoleLiveDisplayOptions.UseAlternateScreenBuffer = true;
options.ConsoleLiveDisplayOptions.EnableMouseEvents = true;
// Present a complete frame together on terminals supporting mode 2026.
options.ConsoleLiveDisplayOptions.EnableSynchronizedUpdates = true;
options.EnableTerminalResizing = true;
});

Expand Down Expand Up @@ -104,6 +106,7 @@ static async Task Main(string[] args)

using (var host = hostBuilder.Build())
using (var outputScope = host.Services.CreateScope())
using (var frames = FrameBufferedOutput.Attach(Spectre.Console.AnsiConsole.Console))
using (var tuiOutput = TuiConsole.Begin(outputScope.ServiceProvider.GetRequiredService<TuiSession>()))
await host.RunAsync();
try { toolUpdate.Launch(); }
Expand Down
121 changes: 121 additions & 0 deletions src/MandoCode/Services/Rendering/FrameBufferedOutput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System.Text;
using Spectre.Console;

namespace MandoCode.Services;

/// <summary>Delivers synchronized frames in one write while retaining terminal capabilities.</summary>
internal sealed class FrameBufferedOutput(IAnsiConsoleOutput inner) : IAnsiConsoleOutput, IDisposable
{
private readonly FrameWriter _writer = new(inner.Writer);
public TextWriter Writer => _writer;
public bool IsTerminal => inner.IsTerminal;
public int Width => inner.Width;
public int Height => inner.Height;
public void SetEncoding(Encoding encoding) => inner.SetEncoding(encoding);
public void Dispose() => _writer.Dispose();

internal sealed class FrameWriter(TextWriter inner) : TextWriter
{
internal const string Begin = "\u001b[?2026h";
internal const string End = "\u001b[?2026l";
private const int MaximumBufferedCharacters = 1024 * 1024;
private readonly object _sync = new();
private readonly StringBuilder _frame = new();
private string _pending = "";
private bool _inFrame;
public override Encoding Encoding => inner.Encoding;
public override void Write(char value) => Write(value.ToString());
public override void Write(char[] buffer, int index, int count) => Write(new string(buffer, index, count));
public override void Write(ReadOnlySpan<char> buffer) => Write(buffer.ToString());
public override void Write(string? value)
{
if (string.IsNullOrEmpty(value)) return;
lock (_sync)
{
_pending += value;
while (_pending.Length > 0)
{
var marker = _inFrame ? End : Begin;
var index = _pending.IndexOf(marker, StringComparison.Ordinal);
if (index >= 0)
{
Emit(_pending[..index]);
_pending = _pending[(index + marker.Length)..];
if (_inFrame)
{
_frame.Append(End);
DeliverFrame();
_inFrame = false;
}
else
{
_inFrame = true;
_frame.Append(Begin);
}
continue;
}
// A marker can be split across Spectre writes, including char writes.
var keep = Math.Min(marker.Length - 1, _pending.Length);
while (keep > 0 && !_pending.EndsWith(marker[..keep], StringComparison.Ordinal)) keep--;
Emit(_pending[..(_pending.Length - keep)]);
_pending = keep == 0 ? "" : _pending[^keep..];
break;
}
}
}
private void Emit(string text)
{
if (text.Length == 0) return;
if (!_inFrame) inner.Write(text);
else
{
_frame.Append(text);
// Bound memory even if a producer fails to finish its frame.
if (_frame.Length >= MaximumBufferedCharacters) DeliverFrame();
}
}
private void DeliverFrame()
{
if (_frame.Length == 0) return;
inner.Write(_frame.ToString());
_frame.Clear();
inner.Flush();
}
public override void Flush()
{
lock (_sync) { if (!_inFrame) inner.Flush(); }
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
lock (_sync)
{
Emit(_pending);
_pending = "";
if (_inFrame) _frame.Append(End);
DeliverFrame();
_inFrame = false;
inner.Flush();
}
}
base.Dispose(disposing);
}
}

public static IDisposable Attach(IAnsiConsole console)
{
var original = console.Profile.Out;
var buffered = new FrameBufferedOutput(original);
console.Profile.Out = buffered;
return new OutputScope(() =>
{
try { buffered.Dispose(); }
finally { console.Profile.Out = original; }
});
}
private sealed class OutputScope(Action restore) : IDisposable
{
public void Dispose() => restore();
}
}
6 changes: 4 additions & 2 deletions src/MandoCode/Services/Rendering/TuiSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public sealed class TuiSession(TimeProvider? timeProvider = null)
{
private readonly object _sync = new();
private readonly List<TuiEntry> _entries = new();
private TuiEntry[]? _entrySnapshot;
private readonly Dictionary<long, IRenderable> _entryContent = new();
private readonly Dictionary<long, IRenderable> _registered = new();
private static long _nextId;
Expand Down Expand Up @@ -100,7 +101,7 @@ private sealed class OutputScope(Action close) : IDisposable { public void Dispo
public long Revision => Interlocked.Read(ref _revision);
public TuiSnapshot Snapshot()
{
lock (_sync) return new(_entries.ToArray(), _running, _activity, _preview) { Spinner = _spinner, LoadingMessage = _loadingMessage, Elapsed = _elapsed };
lock (_sync) return new(_entrySnapshot ??= _entries.ToArray(), _running, _activity, _preview) { Spinner = _spinner, LoadingMessage = _loadingMessage, Elapsed = _elapsed };
}
public void Append(IRenderable content)
{
Expand Down Expand Up @@ -156,6 +157,7 @@ public void AppendRestored(IRenderable content, string? userPrompt, bool spaceAf
private void AddEntry(TuiEntry entry)
{
_entries.Add(entry);
_entrySnapshot = null;
_entryContent[entry.Id] = entry.Content;
}
public long Register(IRenderable content)
Expand All @@ -165,7 +167,7 @@ public long Register(IRenderable content)
public void Unregister(long id) { lock (_sync) _registered.Remove(id); }
public void Clear()
{
lock (_sync) { _entries.Clear(); _entryContent.Clear(); _exchanges.Clear(); Interlocked.Increment(ref _revision); }
lock (_sync) { _entries.Clear(); _entrySnapshot = null; _entryContent.Clear(); _exchanges.Clear(); Interlocked.Increment(ref _revision); }
}
private bool _fixedLoadingMessage;
public void SetRunning(bool running, string? activity = null, string? message = null)
Expand Down
22 changes: 16 additions & 6 deletions src/MandoCode/Services/Rendering/WorkspaceRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,21 @@ public AgentWorkspace Add(string? name = null)
public void Switch(AgentWorkspace workspace)
{
if (workspace.IsClosed || !_entries.Contains(workspace)) return;
IsWorkspacePickerOpen = false;
var previous = Active;
Active = workspace;
previous.Refresh();
if (workspace.SelectedPane is { } pane) workspace.Focus(pane);
Notify();
var alreadyChanging = _changing;
_changing = true;
try
{
IsWorkspacePickerOpen = false;
var previous = Active;
Active = workspace;
previous.Refresh();
if (workspace.SelectedPane is { } pane) workspace.Focus(pane);
}
finally
{
_changing = alreadyChanging;
Notify();
}
}
public void Cycle(int direction)
{
Expand All @@ -86,6 +95,7 @@ public void OpenPicker()
}
public void ClosePicker()
{
if (!IsWorkspacePickerOpen) return;
IsWorkspacePickerOpen = false;
if (Active.SelectedPane is { } pane) Active.Focus(pane);
else Notify();
Expand Down
Loading
Loading