# 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) - **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 - **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) - **Mock Agent**: `AGENT_CONSOLE_MOCK=1` registers a demo Agent with 8 scripts (`default` / `perm` / `plan` / `ask` / `slow` / `error` / `long` / `exit`) 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:/?theme=…#t= ▼ daemon (Node, daemon/dist/main.js) ── HTTP + WebSocket on an ephemeral 127.0.0.1 port └─ React app (app/) reads the token from location.hash, sends it as the x-agent-console header and in the WebSocket hello ``` ## Security model The daemon can run Agents with full access to your machine, so the token that unlocks it must never be readable by another web page. - **Two secrets per plugin-host run.** Each run generates two independent random 256-bit values: a **gate key** and the **daemon token**. Only the gate key is ever written to a file. - **Why `session.js` holds only the gate key.** Magpie serves the page folder at `/_magpie/plugin//`, where the id is an HMAC that changes every time Magpie starts and is handed out only to Magpie's own window. Magpie does not check `Origin`, `Host`, `Sec-Fetch-*` or a cookie on these files, and sends no `Cross-Origin-Resource-Policy`, so the unguessable path is their only protection. A classic `