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
14 changes: 12 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ 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.
**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.

**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.
- 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.

### Added

- `/agent-acp-mode` opens a picker for the connected agent's permission and behavior modes, including the current selection and agent-provided descriptions. Select a mode directly with `/agent-acp-mode <name>`. Changes preserve the current conversation, apply only to the ACP session, and are refused during active work. Agents without advertised modes receive an explanation.
- Codex ACP setup guidance through `/agent-acp add codex`, using the pinned `@agentclientprotocol/codex-acp` 2.6.0 adapter and the existing ACP pane implementation. Document installation, external authentication, command boundaries, and the verified connection and streamed reply on Windows. Setup guidance does not install software or change configuration automatically.
- External agents over the Agent Client Protocol (ACP v1, stdio), phases 1–2 of the ACP client. `/agent-acp <name>` switches the current pane to an agent (for example Claude Code through an ACP adapter; `--new-panel` opens a new pane, `stop` returns to the native agent, and the native session stays alive underneath without sharing context); `/agent-acp list|status|restart|add|test|remove|enable|disable` manage the `acpAgents` entries of `~/.mandocode/config.json`, and `mandocode --acp-probe <name>` checks a connection. The protocol layer is the new `MandoCode.Acp` library (own thin implementation, no third-party ACP package).
- Agents are started without a shell from a real executable (`.exe`/ELF; `.cmd`, `npx` and shells are refused), after confirming the full command; the confirmation is remembered per command hash and asked again when the entry changes. `acpAgents` is read only from the user config, and `ANTHROPIC_API_KEY` is not passed to the agent by default.
- The ACP pane streams the reply, shows tool calls, plans and diffs, and relays the agent's permission questions as a menu (Escape cancels). It serves `fs/read_text_file` and `fs/write_text_file` inside the project folder, refusing symlinks and junctions that lead outside it, with atomic writes. Escape cancels a turn; an agent that ignores the cancel is shut down with its whole process tree.
Expand All @@ -24,6 +29,9 @@ All notable changes to MandoCode will be documented in this file.

### Changed

- Show ACP tool calls as persistent, expandable activity rows with status updates in place, concise summaries, and bounded command/output details. Attach completed diffs to their call and show terminal-output limitations only inside the details. Preserve permission denial and mark unfinished calls honestly when a turn ends or is interrupted. Native tool groups retain their existing behavior.
- Present successful ACP connections in a compact card with the agent's display name, selected model, current mode and its advertised description, session origin, and commands to change mode or return to the native conversation.
- Simplify ACP pane headers to the agent's human-readable title, selected model when advertised, and an ACP indicator. Keep adapter versions in diagnostics, and leave the project folder and approval mode out of the header to match native pane presentation.
- 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.
Expand All @@ -36,7 +44,9 @@ All notable changes to MandoCode will be documented in this file.

- 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.
- 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.

## [0.16.2] - 2026-11-11

Expand Down
84 changes: 84 additions & 0 deletions docs/acp-codex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Codex in an ACP pane

MandoCode can use the maintained [Codex ACP adapter](https://github.com/agentclientprotocol/codex-acp)
through the existing ACP client. Codex owns model execution, its tools, and authentication.
MandoCode displays the conversation and relays permissions through the same pane integration used for other ACP agents.

## Setup on Windows

Install Node.js and sign in to Codex separately with `codex login`. MandoCode does not perform
the adapter's authentication flow or collect credentials. An existing compatible Codex login
can be reused; if authentication is required, finish it with Codex before reconnecting.

Install a pinned adapter into a folder you control. For example, in PowerShell:

```powershell
$adapterFolder = Join-Path $env:USERPROFILE '.mandocode\acp\codex'
npm install --prefix "$adapterFolder" --save-exact @agentclientprotocol/codex-acp@2.6.0
Join-Path $adapterFolder 'node_modules\@agentclientprotocol\codex-acp\dist\index.js'
```

Copy the absolute path printed by the last command. In MandoCode, register it with:

```text
/agent-acp add codex node "C:\Users\YOUR_NAME\.mandocode\acp\codex\node_modules\@agentclientprotocol\codex-acp\dist\index.js"
/agent-acp test codex
/agent-acp codex --new-panel
```

Replace `YOUR_NAME` with your Windows user folder. If Node is not on PATH, use the absolute
path to `node.exe`. The adapter's package includes a compatible Codex dependency; a separately
installed Codex executable can be selected using `CODEX_PATH` in the entry's environment.
Keep the installation's lock file to preserve the resolved dependency versions.

`/agent-acp add codex` prints this setup guidance. It does not install an adapter or save a
configuration automatically. The normal launch confirmation still applies. MandoCode runs
Node directly, without `npx`, an npm shim, or a shell at launch time.

Other operating systems can use the same npm package and register its absolute JavaScript
entry path with `node`. The live validation below was performed on Windows only.

## Commands and boundaries

- `/agent-acp-mode` opens the agent's mode picker, with its descriptions and current selection. For example, Codex can offer Read-only, Workspace access, Auto review, and Full access. These are agent-defined permission and behavior modes, not MandoCode's native approval settings.
- `/agent-acp-mode read-only` selects an advertised mode directly. Changes keep the conversation and are refused while the pane has active work. The selection applies to this session; it does not rewrite global Codex configuration.
- `/model` uses the adapter's advertised model configuration. Available models depend on the account and adapter.
- `/compact` appears when the adapter advertises that command.
- `/clear` starts another ACP conversation and preserves the native MandoCode conversation.
- `/copy` and `/copy-code` read the ACP conversation's last reply.
- `/agent-acp stop` returns to the native conversation.
- Folder changes follow the normal ACP restart and confirmation flow.

Capability handling remains shared with other ACP agents. This setup does not add native
agent mentions, image paste, context handoff, or the proposed MandoCode MCP bridge.
The generic ACP restrictions still apply even if Codex itself advertises additional features.

The adapter also supports API-key authentication. Existing `OPENAI_API_KEY` and `CODEX_API_KEY`
environment variables are not filtered by MandoCode. Check your Codex authentication setup
if you specifically intend to use an existing ChatGPT login instead of API billing.

## Validation

Validated on Windows with `@agentclientprotocol/codex-acp` 2.6.0:

- ACP v1 initialization and session creation using existing login state, with API-key variables removed from the test process.
- MandoCode's actual `AcpClient` and process transport connected to the adapter and parsed its configuration options.
- Selected read-only mode, received a short streamed text reply, and closed the session and client successfully.
- The adapter accepted a `session/set_config_option` change for its `mode` option to `read-only`, then closed the session. The mode picker and its routing have automated coverage; its full interactive flow still needs a manual terminal check.
- Command tests cover setup guidance without saving an entry and explicit executable registration.

This verifies the core connection and text path. Interactive permission menus, cancellation,
model changes, compaction, session restoration, and folder restarts need manual validation
with Codex before claiming those flows have been tested against this adapter.

### Automated test results

- Final full-suite validation: 1,919 passed, one skipped, and zero failed on each of net8.0 and net10.0. The skip is the existing symlink-creation test on this Windows machine; the junction guard has separate coverage.
- All 95 targeted activity, permission, transcript, and export checks pass on both frameworks, including expansion across live updates and tool-call identity across turns and panes.
- All 64 agent-command tests pass on both net8.0 and net10.0, including the two new Codex tests.
- The first full run had 1,893 passes, one skip, and one failure on each target: a Windows
file-access error in the concurrent config-save test on net8.0, and a command-notification
timeout on net10.0. These are not Codex-specific tests; their cause remains unresolved.
- The notification test passed in isolation. Unchanged main passed its config-save tests and
its complete net10.0 suite (1,892 passes, one skip). The final branch run above is clean;
the earlier failures are retained here as validation history rather than attributed to a known fix.
22 changes: 15 additions & 7 deletions docs/acp.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Schema: pinned to the release tag `v1.16.0` of `agentclientprotocol/agent-client

## Quick start

For Codex, see [Codex adapter setup and validation](acp-codex.md), or run `/agent-acp add codex` for setup guidance.

1. Install an ACP adapter yourself, at a pinned version, for example for Claude Code the adapter validated below. No `npx`.
2. Add it (your own paths): `/agent-acp add claude node "C:\path\to\adapter\dist\index.js"`, or edit `acpAgents` in
`~/.mandocode/config.json`.
Expand Down Expand Up @@ -107,6 +109,8 @@ failure it prints the exit code and the stderr tail. Exit codes: `0` ok, `1` fai

## The ACP pane

Use `/agent-acp-mode` to pick from the connected agent's advertised permission and behavior modes, or `/agent-acp-mode <name>` to select one directly. The menu marks the current mode and shows descriptions when supplied. It prefers the agent's mode configuration option and falls back to `session/set_mode` for agents exposing session modes only. Changing modes keeps the conversation and is refused during active work. Unsupported agents receive an explanation; MandoCode does not invent modes or enforce the external agent's permissions.

`/agent-acp <name>` switches the current pane to the agent; `/agent-acp <name> --new-panel` opens it in a new pane
instead (the other panes are unchanged; at most four panes exist, and a fifth is refused with a message). A pane that
runs an ACP agent does not touch Ollama, models or MCP: it runs the trust question, starts the agent, runs `initialize`
Expand Down Expand Up @@ -212,9 +216,12 @@ When the agent advertises the capabilities, MandoCode remembers the last session

### Tool calls, plans and diffs

- `tool_call` / `tool_call_update`: one line per call (`<icon by kind> <title> · <path>:<line>`) and one line for the
final status (`completed`, or `failed` with the first line of the agent's message). State is kept by `toolCallId`, so
an update that carries only a status works. `terminal` content is shown as "terminal output not supported".
- `tool_call` / `tool_call_update`: one expandable row per call, identified by `toolCallId` within the pane and turn.
Its current status updates in place. Click the row, or focus it and press Enter/Space, to inspect the full title,
bounded input and available text output, and completed diffs. Expansion remains open as the same call updates.
Long row summaries are clipped to fit the pane. Reused ids in later turns create separate rows.
- Terminal references cannot be resolved to terminal output yet. When present, expanded details say
"Terminal output unavailable in this client." This does not override the agent-reported completion status.
- `plan`: the whole checklist is replaced on every update; the current one is printed when the turn ends, and the
activity line shows `Plan done/total` meanwhile.
- Diffs (`diff` content of a tool call, and files written through `fs/write_text_file`) go through the same renderer as
Expand All @@ -224,10 +231,11 @@ When the agent advertises the capabilities, MandoCode remembers the last session

### Writes that are not decided yet

A call that changes things (edit, delete, move, execute) shows `Awaiting permission…` while it is `pending` and
`Writing…` / `Running…` while it is `in_progress`. The proposed diff is shown only when the call completes; a call that
fails, or that you refuse, never shows a write. A refusal is shown at once as `permission denied`. The detail after
`failed:` is the first real line of the agent's message (code fences around it are dropped); with none, only `failed`.
Calls show Pending or Running from the agent's updates. Awaiting approval is shown only when a real permission
question opens. A refusal is shown immediately as Permission denied and cannot be overwritten by a late completion.
Proposed diffs are shown in expanded details only after the call completes; failed or refused calls do not show
their proposals as completed writes. Failed calls retain the available agent output in their details.
When a turn ends, still-active rows become Cancelled, Interrupted, or Unfinished rather than claiming success.

### Permissions

Expand Down
Binary file added docs/images/codex-acp-connection-card.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/MandoCode.Acp/Protocol/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public abstract record AcpObject
public sealed record Implementation : AcpObject
{
[JsonPropertyName("name")] public string Name { get; set; } = "";
[JsonPropertyName("title")] public string? Title { get; set; }
[JsonPropertyName("version")] public string Version { get; set; } = "";
}

Expand Down
73 changes: 73 additions & 0 deletions src/MandoCode/Components/Conversation/AcpToolActivityView.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@namespace MandoCode.Components
@using MandoCode.Services.Acp
@using RazorConsole.Core.Input
@using Spectre.Console
@inject RazorConsole.Core.Rendering.ITerminalViewport Viewport

<WorkspaceButton Parts="@Parts" OnClick="Toggle" />
@if (_expanded)
{
<ConversationEntry Entry="Entry" />
}

@code {
[Parameter, EditorRequired] public AcpToolActivity Activity { get; set; } = default!;
[Parameter, EditorRequired] public TuiEntry Entry { get; set; } = default!;
[CascadingParameter] public AgentPane? Pane { get; set; }
private bool _expanded;

private IReadOnlyList<ButtonTextPart> Parts
{
get
{
var snapshot = Activity.Snapshot;
var action = snapshot.Kind switch
{
"execute" => "Run command", "read" => "Read file", "edit" => "Edit file",
"search" => "Search", "delete" => "Delete file", "move" => "Move file",
"fetch" => "Fetch", _ => "Tool call"
};
var statusColor = snapshot.Status switch
{
"Completed" => Color.Green,
"Failed" => Color.Red,
"Awaiting approval" or "Permission denied" or "Cancelled" or "Interrupted" or "Unfinished" => Color.Gold1,
_ => Color.Grey
};
var title = snapshot.Title.Replace('\r', ' ').Replace('\n', ' ').Trim();
var summary = action + (title == "Tool call" || title == action ? "" : " · " + title);
var width = Math.Max(12, (Pane?.Width ?? Viewport.Width) - 4);
var status = width < 40 ? snapshot.Status switch
{
"Awaiting approval" => "Approval",
"Permission denied" => "Denied",
_ => snapshot.Status
} : snapshot.Status;
var budget = Math.Max(1, width - TextSelectionState.CellWidth(status) - 8);
return [new((_expanded ? "▾ " : "▸ ") + AcpTranscriptAdapter.IconFor(snapshot.Kind) + " ", Color.Grey),
new(Clip(summary, budget), Color.Grey85), new(" · " + status, statusColor)];
}
}

private static string Clip(string text, int width)
{
if (TextSelectionState.CellWidth(text) <= width) return text;
var result = new System.Text.StringBuilder();
var elements = System.Globalization.StringInfo.GetTextElementEnumerator(text);
var cells = 0;
while (elements.MoveNext())
{
var element = elements.GetTextElement();
cells += TextSelectionState.CellWidth(element);
if (cells > width - 1) break;
result.Append(element);
}
return result.Append('…').ToString();
}

private void Toggle()
{
if (Pane is not null && !Pane.Active) Pane.Workspace.Focus(Pane);
_expanded = !_expanded;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
@foreach (var entry in Entries)
{
<Rows @key="entry.Id">
@if (entry.AgentActivity is { } exchange)
@if (entry.AcpTool is { } acpTool)
{
<AcpToolActivityView @key="entry.Id" Activity="acpTool" Entry="entry" />
}
else if (entry.AgentActivity is { } exchange)
{
<WorkspaceButton @key="entry.Id" Parts="@ExchangeParts(exchange)" OnClick="@(() => OnAgentToggle.InvokeAsync(exchange))" />
@if (exchange.Expanded && Details.TryGetValue(exchange, out var details))
Expand Down
Loading
Loading