# Agent Console **把终端里的 Agent CLI 搬进 magpie 窗口,直接对话使用。** 作者 qingnian108,源码在 [qingnian108/magpie-agent-console](https://github.com/qingnian108/magpie-agent-console),欢迎提问题和建议。 支持 Claude Code、Codex、Cursor 等,直接用你电脑上已安装的 CLI。左边是项目和对话,中间聊天,右边看改动、文件和终端。 **Use your terminal Agent CLIs right inside magpie, by chat.** By qingnian108. Source: [qingnian108/magpie-agent-console](https://github.com/qingnian108/magpie-agent-console). Issues welcome. Works with Claude Code, Codex, Cursor and more, using the CLIs you already have. --- A Magpie page plugin that drives real local Agent CLIs (Claude Code, Codex, Cursor, Copilot, OpenCode, Pi, Devin, dsh). Each conversation is a **persistent Agent session** on a standalone Node daemon. Close or refresh the page — the Agent keeps running while Magpie is open. Reopen the page and you pick up where you left off. When Magpie quits, the daemon and its Agents stop; threads are persisted and can be resumed next time. ## Install Requires [Magpie](https://usemagpie.ai) ≥ 0.1.1340 and Node.js ≥ 20. ```bash magpie plugin add @magpie-community/page-agent-console ``` Or in Magpie: **Settings → Plugins → Add plugin**, enter `@magpie-community/page-agent-console` (or find **Agent Console** in Discover). After install, **Agent Console** appears in the sidebar plugin group. Install the Agent CLIs you want to use (for example `claude` or `codex`). Missing CLIs show an install hint in Settings. A cold install is about **46 MB** of `node_modules`, mostly `node-pty`'s native terminal module (~26 MB). Claude Code is **not** bundled: to use the Claude Code Agent, install the `claude` CLI yourself (`npm i -g @anthropic-ai/claude-code` or Anthropic's native installer). / 冷安装约占 **46 MB** 的 `node_modules`,主要是 `node-pty` 原生终端模块(约 26 MB)。插件**不**附带 Claude Code:要用 Claude Code Agent,请自行安装 `claude` CLI(`npm i -g @anthropic-ai/claude-code` 或 Anthropic 的原生安装器)。 --- This is not a gateway chat box. The daemon talks to the real CLIs through `claude -p --input-format stream-json --output-format stream-json` (the user's own `claude`, with its control messages for permissions, interrupt, model and mode), `codex app-server`, and ACP, normalizes a structured event stream (tool calls, thinking, permission requests, usage), and pushes it to the React page over WebSocket. UI principle: **obvious at a glance, nothing extra**. Three columns — sidebar (projects × threads), conversation timeline, and a right panel (changes / files / terminal). ## Features - **Persistent sessions**: each thread binds to a long-lived Agent process; after a daemon restart, running threads are marked closed and can be resumed (`--resume` / `thread/resume`) - **Multiple Agents**: Claude Code, Codex, Cursor, Copilot, OpenCode, Pi, Devin, dsh; missing CLIs show an install hint - **Model / permission / thinking**: per-thread; four permission modes and five thinking levels (what each Agent actually supports) - **全部自动同意 / Auto-approve all (1.3)**: a permission mode for every Agent; the default stays 每次询问 / Always Ask. While a conversation is in it, a one-line strip above the composer (全部自动同意已开启 on the left, whose tooltip says what it does for this Agent, and a 改回每次询问 link on the right) and a warning-coloured mode chip stay on screen, at any width and in light and dark. What it does per Agent, as the menu hint says: | Agent | What 全部自动同意 turns on | | --- | --- | | Codex | `approvalPolicy: never` + `sandbox: danger-full-access`: **the sandbox is off**, nothing asks | | Claude Code | `--permission-mode bypassPermissions` (started with `--allow-dangerously-skip-permissions`): **skips all permission checks** | | Copilot | its Allow All (`allow_all` on, agent mode) | | Devin CLI | its Bypass Permissions mode | | Cursor, OpenCode, dsh | no switch over ACP: Agent / Build mode, and the daemon answers each approval request with its **allow once** option | | Pi | Pi never asks before its tools anyway (its extensions' own dialogs still ask you) | The daemon only ever answers with the option for that one request (allow once / accept), never allow-always, so no lasting rule is written into the Agent's own config; when a request offers nothing narrower, the card stays for you. Plan approvals and questions are never answered for you. Every approval it gives is saved in the conversation (`permission_request` + `permission_resolved`, both `auto: true`) and shown as a quiet row after its tool calls, 已自动同意 3 项 · npm test · git status, that opens to each request's title, command or file and the answer. Turning the mode on also approves a card that is already waiting. Only the page (with its token) can switch it on. **Upgrading from 1.2.** 1.2's 全部放行 (`bypassPermissions`) did nothing for Cursor and OpenCode (they had no such mode, so it fell back to 每次询问) and dsh still asked; from 1.3 the same setting would really auto-approve for them. It is not escalated silently: on the first 1.3 start, Cursor / OpenCode / dsh conversations saved in that mode go back to 每次询问 with a notice in the conversation, and if your default permission mode was 全部放行, new Cursor / OpenCode / dsh conversations keep starting in 每次询问; the first one shows a notice that the new mode exists, with a button to turn it on there. Claude Code, Codex, Copilot and Devin keep the mode, which already meant the same in 1.2. Choosing the default permission mode again in Settings ends this. - **Structured timeline**: user message → thinking (expandable) → tool calls (read / edit / command, with line-level diffs) → todos → usage and duration; answer permission requests (tools / plan / questions) on the card. Since 1.3 every tool call is one compact row: a type icon, the command or path (monospace, relative to the project, never wrapping), `+N -M` for an edit and the status on the right; click a row for its output or diff, and a failed step opens by itself. A run of more than 6 tool calls (with the short thinking between them) folds into one summary row (改动 2 · 运行 3 · 读取 4 · 搜索 1 · 1 失败) that expands to the same rows; while it runs, one line shows the current step (正在运行:npm test…). The Agent's step list (Claude Code TodoWrite, Codex plan updates, an ACP agent's plan) is a checklist with N/M, and while it has open items an "N/M 个任务" pill above the composer jumps to it. Each reply ends with 复制 · model · time · duration (plus tokens / cost when the Agent reports them). Code blocks have a language label, line numbers, a wrap toggle and a copy button (the copy is the raw code). A block written without a language is detected by highlight.js (`highlightAuto`), coloured and labelled with what it found; while a reply streams, that happens as soon as the block's closing fence arrives (an open block stays plain "text" so its colours and label don't flip with every token), and results are cached so a closed block isn't detected again on every frame (1.3.7). Since 1.3.7 code blocks are drawn in the same pass as the Markdown, so a streaming reply no longer flickers; the Agent's Markdown is sanitized by DOMPurify with the HTML profile only (an `` the Agent writes is dropped), and the code block icons are added after sanitizing. The look is grayscale and was inspired by [Better Paseo](https://github.com/RoundRedDot/better-paseo) (MIT); no code was copied - **Instant send (1.3)**: your message shows in the timeline the moment you click 发送 and the composer switches to working at once. The daemon saves and pushes the message before it starts the Agent (spawn + ACP `initialize` / `session/new`, seconds on Windows) instead of after; the page draws it right away and swaps in the daemon's copy by a client message id, so it neither doubles nor jumps. A send that fails stays in place marked 发送失败 with 重试 / 移除. A message sent while a turn runs still goes to the queue list - **Steer and queue**: steer while running, queue the next message, interrupt - **Changes panel**: git status refresh every 3s, unified per-file diffs; discarded untracked files go to trash instead of a hard delete - **Files panel**: lazy directory tree (respects `.gitignore`), syntax-highlighted preview - **Terminal panel**: real PTY via node-pty (pwsh / powershell); reconnects after reopening the page; degrades if PTY is unavailable - **Images**: attach or paste images (and text files). Only PNG, JPEG, GIF and WebP are sent as images. Claude Code and Codex take them natively; Claude Code gets a text file (up to 1 MB) as a plain-text document, Codex gets its path; any other file (SVG, binaries, images over Claude's 5 MB limit) goes by path, with a notice. An ACP Agent (Cursor, Copilot, OpenCode, Pi, Devin CLI, dsh) gets image blocks when its ACP `initialize` advertises `promptCapabilities.image`; otherwise it gets each image's file path (as text and a `resource_link`), so it can open it with its file tools, and the timeline says it can't see the image itself. The composer says so before you send once the Agent has been asked. dsh answers `initialize` for the route its ACP starts on (its `acp` config row, which ships as a model dsh's catalog doesn't have) and refuses image blocks otherwise, so Agent Console starts dsh with a `--patch` overlay that puts that row on the conversation's model: on a model that sees images (Magpie writes those as `input: [text, image]`) dsh then takes image blocks; after a switch to another model in the same chat, images go by path and dsh opens them with its `read_image` tool. Checked on 2026-10-31 with the real CLIs, a throwaway HOME, no sign-in and a local stand-in for the model API (`npm run test:real`, see `test/real/`): the image reaches the model request from Claude Code 2.1.316 (stream-json), Codex 0.165.0, Copilot 1.0.105 (BYOK), OpenCode 1.19.5, Pi (pi-acp 0.0.34 + pi 1.4.0) and dsh 0.2.1-rc.5; Devin CLI 3000.11.234 and Cursor 2026.10.22 advertise images and Devin gets the image block, but both need a sign-in to run a model. Inline media is capped at 10 MB per file and 16 MB per message (an ACP SDK peer refuses messages over 32 MB); larger images go by path - **Import history**: import matching sessions from `~/.claude/projects` and `~/.codex/sessions` as new threads (resumable) - **Thread management**: search (Ctrl+K), pin, rename, archive, delete (trash), export Markdown, thread info (usage / cost / session ID) - **Preview tab** (1.2): a small browser in the right panel for local dev servers (`localhost`, `127.0.0.1`, `[::1]`, `*.localhost`, `0.0.0.0`): address bar, back / forward, reload, open in the system browser, widen the panel. The address is remembered per conversation. Pages load through the daemon's local preview proxy (see the security model), so module scripts, `fetch` and HMR WebSockets work inside Magpie's sandboxed frame. Limits: popups, `alert` and native form posts don't run in the sandbox; `localStorage` / `sessionStorage` / `document.cookie` are in-memory and reset on reload, and cookies are not passed (use 用浏览器打开 / Open in browser for logins) - **Links in chat** (1.2): local addresses in agent text, rendered Markdown and tool output (`localhost:5173`, `http://127.0.0.1:8080/x`, …) become links that open in the Preview tab; Ctrl/⌘+click, and any other `http(s)` link, opens the system browser through the daemon (`app.openExternal`: http/https only, re-serialized, run with `execFile` and no shell: `rundll32 url.dll,FileProtocolHandler` on Windows, `open` on macOS, `xdg-open` on Linux; if that fails the link is copied). The terminal is not linkified - **File chips** (1.2): drag a row from the Files tab into the composer, or right-click → 插入到聊天 / Add to chat, to attach a path chip. Chips are sent as project-relative paths, checked by the daemon (inside the project, no `..`, no symlink escape, must exist, at most 50), and reach the Agent as a "Referenced files" section with absolute paths after your text (plus `resource_link` blocks for ACP Agents). Dropping files from the OS file manager still uploads them as attachments - **Layout settings** (1.2): content width (narrow 640 / default 720 / wide 880 / full) and chat font size (12–18 px, default 13; timeline, composer, tool cards, diffs and the file viewer scale together, code 1 px smaller; the sidebar, top bar, panel tabs, menus and dialogs stay on the fixed 13 px UI scale); the sidebar collapses with the panel button at its top-left or Ctrl/⌘+B (collapses automatically in narrow windows); all persisted - **Follows Magpie live** (1.2): light/dark, Magpie's neutral colours and its language follow Magpie while the page is open (and after a reconnect); the accent stays neutral grey - **Mock Agent**: `AGENT_CONSOLE_MOCK=1` registers a demo Agent with 11 scripts (`default` / `perm` / `plan` / `ask` / `slow` / `error` / `long` / `exit` / `serve` / `tools` / `bashhint`) so UI work does not burn tokens ## Architecture ``` Magpie window └─ page/index.html (sandbox="allow-scripts" iframe, served by Magpie from /_magpie/plugin//) │ reads page/session.js {port, key} (gate key only, written by the plugin host) │ navigates itself to http://127.0.0.1:/open?k=&theme=… ▼ Magpie plugin host (Bun) ── index.mjs + lib/gate.mjs "gate" on 127.0.0.1: (default 3488) │ first /open: spawns the daemon as a child process (node, --port 0, stdin lifeline, --parent-pid) │ 302 → http://127.0.0.1:/app?theme=…#t=&p= (1.3: the gate's wrapper page, lib/wrapper.mjs) │ └─