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
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,20 @@ slash commands appear with the connected agent's name. Alt+V attaches an image w
Changing folders restarts only that ACP pane and keeps the transcript. MandoCode attempts to continue its session;
if the adapter starts fresh, choose whether to carry recent text context. A project-change note tells the agent to
re-read files before the next request. `/clear` starts a fresh ACP conversation and discards pending context.
`/agent-acp <name> --resume` requests the remembered session for this folder; `/agent-acp sessions` lists available
sessions when supported. Agent memory and session continuation depend on the adapter.
`/acp-agent <name> --resume` lists this folder's sessions and lets you choose which conversation to continue.
One session is selected directly; Escape cancels without replacing the current agent. A dedicated panel shows up to
100 sessions with readable titles and local update times. Use arrows or Page Up/Down to browse and Enter to continue;
IDs stay out of the picker. Workspace and agent bars are hidden while choosing; navigation controls sit at the lower
right. Use `/acp-agent <name> --resume <session-id>` to continue an explicit id, optionally with `--new-panel`; quote
ids containing spaces. `/acp-agent sessions` remains a plain list
with full ids. The `/agent-acp` spelling also works.

When supported, MandoCode loads the session and restores user/agent messages, completed tool activity, and plans
between history separators. The display keeps up to 40 recent turns and 240 entries, with long text shortened and
an overall text budget; this does not trim the agent's own memory. Replay does not run tools or ask for permissions,
and prompts typed while history loads wait for it to finish. Agents without history loading can resume their context
without displaying earlier messages. Agents without session listing use the last remembered id for this folder;
when no session is available, a new conversation starts. Agent memory and continuation depend on the adapter.

ACP agents receive a built-in `mandocode` MCP server for the open-agent directory, collaboration, and saved
conversation snapshots. Type `@`, then Tab to select another agent. Try `Ask @Ares what it found and let me know
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to MandoCode will be documented in this file.

**Highlights**

- Choose an earlier ACP conversation with `--resume`, or continue a specific session id, and restore its recent messages and completed activity when the adapter supports history loading.

- Run ACP builds, tests, and scripts through MandoCode-managed terminals, with live output and lifecycle cleanup via ACP v1 or the built-in MCP bridge.

- Collaborate between ACP and native Ollama agents with agent mentions, questions, background tasks, messages, and progress tracking.
Expand All @@ -25,6 +27,8 @@ All notable changes to MandoCode will be documented in this file.

### Added

- Add a folder-scoped ACP session picker before switching agents, with direct session IDs and `--new-panel` support. Show choices in a dedicated panel with readable titles, local update times, keyboard paging, and clear continue/cancel controls at the lower right. Hide workspace/agent chrome while the picker is open and restore it without remounting the conversation; keep full IDs in the plain session list. Keep the current pane on cancellation, follow bounded session-list pagination, and fall back to the last remembered session for agents without listing support. Prefer history loading over resume, restore bounded messages, completed tool calls and plans, suppress replay-time permission prompts, and queue new input until loading finishes.

- Run non-interactive commands in host-managed ACP terminals through the five ACP v1 `terminal/*` methods or the built-in MCP terminal tools. Stream bounded stdout/stderr into persistent command rows, report exit status, preserve displayed output after release, and isolate IDs by session. Cancel command trees on Escape and clean up on session clear, crash, restart, folder change, and closure. Apply configured ACP environment rules, validate working directories, and cap command duration, output, and terminal counts. Disable both routes per agent with `clientTerminals: false`; the reusable process backend does not require ACP v2.

- Offer a source-agent recap when switching between native and ACP agents, with opt-out and cancellation before changing runtimes.
Expand Down Expand Up @@ -80,6 +84,8 @@ All notable changes to MandoCode will be documented in this file.

### Test coverage

- The ACP session picker/history update passed 2,069 tests with one existing skip on .NET 10 Release. Coverage includes read-only discovery against the mock adapter, folder filtering and duplicate IDs, picker cancellation for current/new panes, direct IDs without local persistence, history-load preference and resume-only fallback, bounded text/tool/plan replay, repeated pagination cursors, suppression of replay permissions, reused tool IDs across turns, queued input delivered once after history, local date conversion, panel placement, hidden IDs, and keyboard selection/paging at narrow sizes. A further 71 focused workspace and layout checks passed after the fullscreen refinement, including real terminal footer placement and chrome restoration without disposing the conversation.

- The ACP terminal update passed 2,038 tests with one existing skip on .NET 10 Release. Coverage includes all five ACP terminal methods, real MCP terminal calls, capability opt-out, active-session validation, literal arguments/environment, stdout/stderr and non-newline streaming, bounded UTF-8 tail output under a large flood, exit status, cancellation with child processes, per-pane isolation, and cleanup on clear, crash, and disposal. Terminal DTOs are checked against the vendored official v1 schema.

- The final ACP collaboration update passed 1,990 tests with one existing skip on .NET 10 Release. Real stdio MCP checks cover tool discovery, owning-pane identity, active-turn restrictions, call-loop prevention, cancellation, snapshot operations, skill precedence/disabled files, resource boundaries, and connection revocation. Component checks cover snapshots without Ollama, import retries and images, optional source-agent handoffs, compatible command spellings, and compact exchange rendering. A regression deliberately announces a command before the session/new response. Final focused checks and user testing also passed.
Expand Down
8 changes: 5 additions & 3 deletions src/MandoCode.Acp/Client/AcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public async Task<IReadOnlyList<SessionInfo>> ListSessionsAsync(

var result = new List<SessionInfo>();
string? cursor = null;
var seen = new HashSet<string>(StringComparer.Ordinal);
for (var page = 0; page < maxPages; page++)
{
var response = await WithTimeoutAsync("session/list", cancellationToken, token =>
Expand All @@ -220,9 +221,9 @@ public async Task<IReadOnlyList<SessionInfo>> ListSessionsAsync(
AcpJsonContext.Default.ListSessionsRequest, AcpJsonContext.Default.ListSessionsResponse, token))
.ConfigureAwait(false);

result.AddRange(response.Sessions);
result.AddRange(response.Sessions.Take(1000 - result.Count));
cursor = response.NextCursor;
if (string.IsNullOrEmpty(cursor))
if (result.Count >= 1000 || string.IsNullOrEmpty(cursor) || !seen.Add(cursor))
break;
}

Expand Down Expand Up @@ -347,7 +348,8 @@ private async ValueTask<RequestPermissionResponse> HandlePermissionAsync(Request
{
var cancelled = new RequestPermissionResponse { Outcome = new CancelledPermissionOutcome() };

if (!_sessions.TryGetValue(request.SessionId, out var session))
// Loading an earlier conversation is display-only: never interrupt replay with an approval prompt.
if (!_sessions.TryGetValue(request.SessionId, out var session) || session.HistorySink is not null)
return cancelled;

// A cancel is already under way: do not bother the user with a prompt for a turn being abandoned.
Expand Down
119 changes: 119 additions & 0 deletions src/MandoCode/Components/Sessions/AcpSessionPickerPanel.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
@namespace MandoCode.Components
@using MandoCode.Services.Acp
@using Microsoft.AspNetCore.Components.Web
@using RazorConsole.Core.Renderables
@using Spectre.Console
@inject RazorConsole.Core.Rendering.ITerminalViewport Viewport
@inject RazorConsole.Core.Focus.FocusManager Focus
@implements IDisposable

<Flex Direction="FlexDirection.Column" FillWidth="true" FillHeight="true">
<Box FillWidth="true" FillHeight="true">
<Box Width="@PanelWidth" Height="@BoxHeight" Border="BoxBorder.Rounded" Title="@Title" BorderColor="@PaneColors.For(Pane, Color.DeepSkyBlue1)">
<div @key="_focusKey" data-focusable="@((Pane is null || Pane.Active) ? "true" : "false")" data-focus-key="@_focusKey" data-input-managed="true" data-manage-tab="true" @onkeydown="Key">
<Rows>
@if (ShowContext) { <Markup Content="@Escape(Context)" Foreground="@PaneColors.For(Pane, Color.Grey70)" /> }
@if (ShowSeparator) { <Markup Content="@(new string('─', RowWidth))" Foreground="Color.Grey50" /> }
@for (var i = _start; i < Math.Min(State.Choices.Count, _start + PageSize); i++)
{
var index = i; var choice = State.Choices[index]; var selected = index == _selected;
<div @key="choice.Label" data-focusable="false" @onclick="@(() => Select(index))">
<Rows>
<Markup Content="@Escape((selected ? "› " : " ") + (choice.Caption ?? "Untitled conversation"))"
Foreground="@(selected ? Color.Black : PaneColors.For(Pane, Color.Grey85))"
Background="@(selected ? PaneColors.For(Pane, Color.DeepSkyBlue1) : Color.Default)" />
@if (ShowDates) { <Markup Content="@Escape(" " + choice.Description)" Foreground="@PaneColors.For(Pane, Color.Grey70)" /> }
</Rows>
</div>
}
</Rows>
</div>
</Box>
</Box>
<Box Height="1" FillWidth="true">
<RazorConsole.Components.Align Horizontal="HorizontalAlignment.Right">
<Markup Content="@Spectre.Console.Markup.Escape(WorkspaceTabWindow.Fit(Footer, AvailableWidth))" Foreground="@PaneColors.For(Pane, Color.Grey70)" />
</RazorConsole.Components.Align>
</Box>
</Flex>

@code {
[CascadingParameter] public AgentPane? Pane { get; set; }
[Parameter, EditorRequired] public AcpSessionPickerState State { get; set; } = default!;
[Parameter] public int InitialIndex { get; set; }
[Parameter] public int? Width { get; set; }
[Parameter] public int? Height { get; set; }
[Parameter] public EventCallback<string> OnSelect { get; set; }
[Parameter] public EventCallback OnClose { get; set; }
private readonly string _focusKey = "acp-sessions-" + Guid.NewGuid().ToString("N");
private AcpSessionPickerState? _previous;
private int _selected, _start;
private bool _requestFocus = true;
private sealed record Draft(AcpSessionPickerState State, int Selected);
private int AvailableWidth => Math.Max(12, Width ?? Pane?.Width ?? Viewport.Width);
private int PanelWidth => Math.Min(AvailableWidth, 96);
private int PanelHeight => Math.Max(5, Height ?? Pane?.Height ?? Viewport.Height);
private int BoxHeight => Math.Min(PanelHeight - 1, State.Choices.Count * 2 + 5);
private int RowWidth => Math.Max(1, PanelWidth - 4);
private bool ShowDates => BoxHeight >= 7;
private bool ShowContext => BoxHeight >= 6;
private bool ShowSeparator => BoxHeight >= 8;
private int PageSize => Math.Max(1, (BoxHeight - 2 - (ShowContext ? 1 : 0) - (ShowSeparator ? 1 : 0)) / (ShowDates ? 2 : 1));
private string Title => Spectre.Console.Markup.Escape("Continue with " + (State.AgentName.Length > 0 ? char.ToUpperInvariant(State.AgentName[0]) + State.AgentName[1..] : "ACP agent"));
private string ProjectName => Path.GetFileName(Path.TrimEndingDirectorySeparator(State.Folder)) is { Length: > 0 } name ? name : State.Folder;
private string Context => ProjectName + " · " + State.Choices.Count + " conversations · Local time";
private string Footer => AvailableWidth >= 60
? $"↑↓ Select · Enter Continue · Esc Cancel {_selected + 1}/{State.Choices.Count}"
: AvailableWidth >= 35 ? $"↑↓ Select · Enter Open · Esc Cancel" : "↑↓ · Enter · Esc";
private string Escape(string text) => Spectre.Console.Markup.Escape(WorkspaceTabWindow.Fit(text, RowWidth));
protected override void OnParametersSet()
{
if (!ReferenceEquals(State, _previous))
{
_previous = State;
var saved = Pane?.PresentationState.GetValueOrDefault("acp-session-selection") as Draft;
_selected = Math.Clamp(saved is not null && ReferenceEquals(saved.State, State) ? saved.Selected : InitialIndex, 0, Math.Max(0, State.Choices.Count - 1));
Reveal(); _requestFocus = true;
}
Reveal();
}
private void Reveal() => _start = Math.Clamp(_selected - PageSize + 1, 0, Math.Max(0, State.Choices.Count - PageSize));
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (Pane is not null && !Pane.Active) return;
if (Pane is not null) Pane.FocusKey = _focusKey;
if (firstRender || _requestFocus || !Focus.IsFocused(_focusKey))
{
await Focus.FocusDeferredAsync(_focusKey);
_requestFocus = !Focus.IsFocused(_focusKey);
}
}
private async Task Select(int index)
{
_selected = index; Reveal(); _requestFocus = true;
await Focus.FocusDeferredAsync(_focusKey);
}
private async Task Key(KeyboardEventArgs key)
{
if (Pane is not null && !Pane.Active) return;
if (Pane?.Workspace.Key(Pane, key) == true) return;
switch (key.Key)
{
case "Escape": await OnClose.InvokeAsync(); return;
case "Enter": case "Return":
if (State.Choices.Count > 0) await OnSelect.InvokeAsync(State.Choices[_selected].Label);
return;
case "ArrowUp": case "UpArrow": _selected--; break;
case "ArrowDown": case "DownArrow": _selected++; break;
case "PageUp": _selected -= PageSize; break;
case "PageDown": _selected += PageSize; break;
case "Home": _selected = 0; break;
case "End": _selected = State.Choices.Count - 1; break;
}
_selected = Math.Clamp(_selected, 0, Math.Max(0, State.Choices.Count - 1)); Reveal();
}
public void Dispose()
{
if (Pane is not null) Pane.PresentationState["acp-session-selection"] = new Draft(State, _selected);
}
}
Loading