# LemonACP Claude Code ACP 调用内核。通过 ACP 协议驱动本地 Claude CLI 进程,支持单 Agent 执行和 Master → Sub-Agent 多轮编排。 ## 架构 ``` packages/ acp-core/ 协议层 — Protocol / Transport / Launcher 抽象 agent-core/ Agent 运行时 — 目录驱动的 Agent、AgentBus、Registry server/ src/core/ 编排引擎 — Orchestrator、MasterSession、AgentManager、SessionPool src/engine/ 进程层 — CommandQueue、ProcessGuard、IdleTimer、RunRegistry src/tools/ Master 工具 — call-agent、tool-registry routes/ HTTP API — /api/master (SSE)、/api/config services/ 会话日志、文件解析、Agent 记忆 ``` ## 快速启动 ```bash npm install cp .env.example .env node server/index.js # 端口 3010 ``` ## API | 端点 | 方法 | 说明 | |------|------|------| | `/api/master/chat` | POST | Master Agent 多轮对话(SSE 流式) | | `/api/master/upload` | POST | 文件上传(注入对话上下文) | | `/api/master/sessions` | GET | 列出活跃 session | | `/api/master/sessions/:id` | DELETE | 关闭 session | | `/api/config/items` | GET | 列出配置项 | | `/api/config/items/:key` | GET / PUT | 读写配置文件 | | `/api/health` | GET | 健康检查 | ### Master Chat 示例 ```bash curl -X POST http://localhost:3010/api/master/chat \ -H "Content-Type: application/json" \ -d '{"message": "帮我写一个斐波那契函数", "sessionId": "my-session"}' \ --no-buffer ``` SSE 事件类型:`session` | `progress` | `agent_output` | `tool_call` | `result` | `error` ## 配置 **`server/config/backends.json`** — 定义 ACP Launcher / Client: ```json { "launchers": { "claude-local": { "command": "claude", "args": ["--dangerously-skip-permissions"], "protocol": "claude-cli" } } } ``` **`server/config/agents.json`**(可选)— 静态 Agent 定义: ```json { "coder": { "type": "executor", "client": "claude-local", "description": "编写代码" } } ``` **`.env`** — 端口与 CORS: ``` PORT=3010 CORS_ORIGINS=http://localhost:5173 ``` ## 编程调用 ```js const { runMasterSession, runOrchestration, runSingleAgent } = require('./server/src/standalone-entry'); // 单次 Master 会话 const result = await runMasterSession('实现一个 BMI 计算器'); // 多 Agent 编排 const result = await runOrchestration('开发一个 REST API', { workDir: '/my/project' }); // 单个 Agent const result = await runSingleAgent('coder', '写斐波那契函数'); ``` ## ACP 协议层 `packages/acp-core` 可独立使用: ```js const { createConnection, ClaudeCliProtocol } = require('@mas/acp-core'); // 通过 claude-cli 协议直连 const protocol = new ClaudeCliProtocol({ command: 'claude', args: ['--dangerously-skip-permissions'] }); await protocol.connect(); const session = await protocol.newSession(); await protocol.sendPrompt(session.id, '你好'); ``` ## License MIT