diff --git a/MandoCode.sln b/MandoCode.sln index 76489c3..30be3dd 100644 --- a/MandoCode.sln +++ b/MandoCode.sln @@ -11,6 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MandoCode.Tests", "tests\MandoCode.Tests\MandoCode.Tests.csproj", "{D407041F-0C3B-4215-9F92-38C01435E015}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MandoCode.Acp", "src\MandoCode.Acp\MandoCode.Acp.csproj", "{4AD6649A-5B01-4BE5-A335-534B80F80C5C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MandoCode.Acp.MockAgent", "tests\MandoCode.Acp.MockAgent\MandoCode.Acp.MockAgent.csproj", "{987F2544-BD32-4447-B850-BA91D1AF8FE8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +49,30 @@ Global {D407041F-0C3B-4215-9F92-38C01435E015}.Release|x64.Build.0 = Release|Any CPU {D407041F-0C3B-4215-9F92-38C01435E015}.Release|x86.ActiveCfg = Release|Any CPU {D407041F-0C3B-4215-9F92-38C01435E015}.Release|x86.Build.0 = Release|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Debug|x64.ActiveCfg = Debug|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Debug|x64.Build.0 = Debug|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Debug|x86.ActiveCfg = Debug|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Debug|x86.Build.0 = Debug|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Release|Any CPU.Build.0 = Release|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Release|x64.ActiveCfg = Release|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Release|x64.Build.0 = Release|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Release|x86.ActiveCfg = Release|Any CPU + {4AD6649A-5B01-4BE5-A335-534B80F80C5C}.Release|x86.Build.0 = Release|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Debug|x64.ActiveCfg = Debug|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Debug|x64.Build.0 = Debug|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Debug|x86.ActiveCfg = Debug|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Debug|x86.Build.0 = Debug|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Release|Any CPU.Build.0 = Release|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Release|x64.ActiveCfg = Release|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Release|x64.Build.0 = Release|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Release|x86.ActiveCfg = Release|Any CPU + {987F2544-BD32-4447-B850-BA91D1AF8FE8}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -52,6 +80,8 @@ Global GlobalSection(NestedProjects) = preSolution {3C5A3128-B243-5A70-788F-6B3C2B163656} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} {D407041F-0C3B-4215-9F92-38C01435E015} = {0AB3BF05-4346-4AA6-1389-037BE0695223} + {4AD6649A-5B01-4BE5-A335-534B80F80C5C} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B} + {987F2544-BD32-4447-B850-BA91D1AF8FE8} = {0AB3BF05-4346-4AA6-1389-037BE0695223} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B33BAE4E-D6AD-429A-971D-8A9E6D5A4F16} diff --git a/README.md b/README.md index 13b3162..ed0ea69 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ With **`/skills` (Alt+K)**, install skills from Git, ZIP files, or local folders | **Workspace** | Independent agents | Up to four agents per workspace, with separate models, conversations, settings, and approvals | | **Workspace** | Named workspaces | Organize projects and switch workspaces while background agents keep working | | **AI** | Agent collaboration | Tag agents with `@` to ask questions, request reviews, and hand off independent tasks | +| **Agents** | External ACP agents | Run an Agent Client Protocol agent (for example Claude Code through an ACP adapter) in its own pane, with tool calls, diffs and permission prompts in the transcript. Opt-in; see [docs/acp.md](docs/acp.md) | | **Memory** | Context snapshots | Save a conversation summary and import it into another agent | | **Memory** | Agent history | Search, preview, and restore closed agents with their conversation context | | **Tools** | File Explorer and Git review | Browse files, attach references, change directories, and inspect project diffs | @@ -254,6 +255,7 @@ Type `/` to see the autocomplete dropdown, or `!` to run a shell command. | `/agent-new` | Open an independent agent pane (Alt+N) | | `/agent-focus` | Switch agents; optional left/right (Alt+Left/Right) | | `/agent-close` | Close the current idle agent | +| `/agent-acp ` | Switch this pane to an external ACP agent (such as Claude Code through an adapter); `--new-panel` opens it in a new pane. Also `stop`, `list`, `status`, `restart`, `add`, `test`, `remove`, `enable`, `disable` ([details](docs/acp.md)) | | `/agent-rename ` | Rename this agent | | `/agent-settings` | Edit this agent's model, behavior, and integrations (Alt+S) | | `/agent-file-explorer` | Browse this agent's files and folders (Alt+E) | @@ -374,6 +376,7 @@ Skills use the same enable/disable convention as Desktop (`SKILL.md` / `SKILL.md ```bash mandocode --continue # resume this folder's most recent conversation (alias: -c) mandocode --doctor # preflight check: .NET runtime, Ollama status, models, sign-in +mandocode --acp-probe # start a configured ACP agent, run initialize + session/new, report, exit mandocode --config show # print current config mandocode --config init # create a default config file mandocode --config set # set a single value (e.g. set model qwen3:8b) @@ -487,6 +490,27 @@ MandoCode validates model compatibility on startup. Run `/learn` for a detailed

Configuration Reference

+### External agents (ACP) + +An optional `acpAgents` section in `~/.mandocode/config.json` (read only from that file, never from a project) lets +`/agent-acp ` run an external agent over the [Agent Client Protocol](https://agentclientprotocol.com): + +```json +"acpAgents": { + "claude": { + "command": "node", + "args": ["C:\\tools\\claude-agent-acp\\dist\\index.js"] + } +} +``` + +The agent runs without a shell, from a real executable (`.exe`/ELF, never `.cmd`, `npx` or a shell), and MandoCode +asks you to confirm the full command before the first start and again whenever it changes. Install the adapter yourself, +at a pinned version; MandoCode never downloads anything. The agent signs in with its own tooling, and +`ANTHROPIC_API_KEY` is not passed to it unless you opt in. See [docs/acp.md](docs/acp.md) for setup, trust, permissions, +file access, the debug trace and what is not supported yet. MandoCode does not sandbox the agent: permission +questions are relayed, and the agent applies the answers itself. + ### Config File Located at `~/.mandocode/config.json` diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8d681aa..5b2af77 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -12,6 +12,16 @@ All notable changes to MandoCode will be documented in this file. - Keep transcript formatting, hyperlinks, and emoji shortcuts compatible with the updated rendering dependencies. - Clear the clipboard attachment message reliably after sending a prompt. +### Added + +- External agents over the Agent Client Protocol (ACP v1, stdio), phases 1–2 of the ACP client. `/agent-acp ` 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 ` 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. +- ACP panes have a clear boundary to native behaviour: one restriction set hides and blocks what does not apply (`/mcp`, `/skills`, `/history`, `/plan*`, Alt+S/C/K/M/H/V, the `@` picker's Agents group). `/clear` starts a new ACP conversation in the same agent process and folder (the native conversation is untouched), `/copy` and `/copy-code` use the pane's own last reply, `/model` picks from the agent's model option, `/compact` sends the agent's own compact command, and a folder change restarts the agent after confirmation. `@file` mentions use the shared parser (quoted paths with spaces work) and the same project-folder guard. +- `/agent-acp --resume` continues the last session of the folder (`session/resume`, or `session/load` with the history replayed) and `/agent-acp sessions` lists the agent's sessions; MandoCode remembers only session ids in `~/.mandocode/acp-sessions.json`. +- Optional message trace for debugging an agent (`"trace": true` on the entry or `MANDOCODE_ACP_TRACE=1`): direction, method, id and size per message, never content. +- `ApprovalSelectCoordinator.Cancel()` and an opt-in Escape for approval menus (native menus are unchanged). + ### 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. diff --git a/docs/acp.md b/docs/acp.md new file mode 100644 index 0000000..bb03bdf --- /dev/null +++ b/docs/acp.md @@ -0,0 +1,386 @@ +# ACP agents (Agent Client Protocol) + +MandoCode can run an external coding agent as a child process and talk to it over the +[Agent Client Protocol](https://agentclientprotocol.com) (ACP v1, JSON-RPC 2.0 over stdio, NDJSON). +Authentication is the agent's own business; MandoCode never handles agent tokens. + +The protocol layer lives in `src/MandoCode.Acp` (no UI dependencies, no third-party ACP libraries). +Schema: pinned to the release tag `v1.16.0` of `agentclientprotocol/agent-client-protocol` (checked to exist), vendored in +`tests/MandoCode.Tests/Acp/schema/schema.v1.json`. The tag is the schema release; the protocol version is still 1 +(`protocolVersion: 1` in `initialize`). + +## Quick start + +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`. +3. Check it: `/agent-acp test claude` (or `mandocode --acp-probe claude`). You are asked to confirm the command first. +4. Use it: `/agent-acp claude` switches the current pane to the agent (`--new-panel` opens it in a new pane instead). + Sign in to the agent with its own tooling beforehand (`claude auth login`). `/agent-acp stop` returns the pane to + MandoCode's own agent. + +Status of this first version: phases 1–2, plus switching a pane in place (originally planned for a later phase, and +without passing context: see "Deviations"). Not included: `terminal/*`, images, resuming sessions, handing a +conversation between the native agent and an ACP agent, asking an ACP agent with `@`, a settings tab for agents. +Open questions are marked **pending** below. + +**Security model in one paragraph.** MandoCode does not sandbox the agent. It decides what program runs (no shell, +real executables only, confirmed by hash, configured only in the user's own config) and what environment it gets +(no `ANTHROPIC_API_KEY` by default), and it relays the agent's permission questions; the agent applies the answers +itself. Treat an ACP agent as a program with your user's rights. + +## Launch rules + +An agent command is code that runs with your permissions, so launching is deliberately strict: + +- No shell: `ProcessStartInfo` with `UseShellExecute = false` and `ArgumentList`. + `cmd.exe`, `powershell`, `sh -c` and friends are refused. +- The command must resolve (through `PATH`, or as an absolute path) to a real executable: + `.exe` on Windows, ELF/Mach-O on Unix. `.cmd`, `.bat`, `.ps1` and `#!` scripts are refused: + *specify the path to an .exe or run the adapter as `node