第十一章:配置与部署
⚙️ 本章详细介绍 MiniClaw 的配置系统和部署方式。
11.1 项目配置
11.1.1 package.json 配置详解
┌─────────────────────────────────────────────────────────────────────┐
│ package.json 配置 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ { │
│ "name": "miniclaw", │
│ "version": "0.5.0", │
│ "description": "Micro-Kernel Agent - A nervous system for AI", │
│ "type": "module", │
│ "main": "dist/index.js", │
│ "bin": { │
│ "miniclaw": "dist/index.js" │
│ }, │
│ "files": [ │
│ "dist", │
│ "templates" │
│ ], │
│ "scripts": { │
│ "build": "tsc", │
│ "start": "node dist/index.js" │
│ }, │
│ "dependencies": { │
│ "@modelcontextprotocol/sdk": "^1.0.0", │
│ "node-cron": "^3.0.0", │
│ "zod": "^3.22.0" │
│ }, │
│ "devDependencies": { │
│ "@types/node": "^20.0.0", │
│ "@types/node-cron": "^3.0.0", │
│ "typescript": "^5.0.0" │
│ } │
│ } │
│ │
└─────────────────────────────────────────────────────────────────────┘
配置字段说明
┌─────────────────────────────────────────────────────────────────────┐
│ package.json 字段说明 │
├─────────────────┬───────────────────────────────────────────────────┤
│ 字段 │ 说明 │
├─────────────────┼───────────────────────────────────────────────────┤
│ name │ 包名称,用于 npm 发布和安装 │
├─────────────────┼───────────────────────────────────────────────────┤
│ version │ 版本号,遵循语义化版本 │
├─────────────────┼───────────────────────────────────────────────────┤
│ description │ 项目描述,显示在 npm 搜索结果中 │
├─────────────────┼───────────────────────────────────────────────────┤
│ type │ 模块类型,"module" 表示 ES Module │
├─────────────────┼───────────────────────────────────────────────────┤
│ main │ 主入口文件,npm 包的默认入口 │
├─────────────────┼───────────────────────────────────────────────────┤
│ bin │ 二进制命令映射,使包可全局执行 │
├─────────────────┼───────────────────────────────────────────────────┤
│ files │ 发布时包含的文件/目录 │
├─────────────────┼───────────────────────────────────────────────────┤
│ scripts │ npm 脚本命令 │
├─────────────────┼───────────────────────────────────────────────────┤
│ dependencies │ 运行时依赖 │
├─────────────────┼───────────────────────────────────────────────────┤
│ devDependencies│ 开发时依赖 │
└─────────────────┴───────────────────────────────────────────────────┘
11.1.2 tsconfig.json 配置详解
┌─────────────────────────────────────────────────────────────────────┐
│ tsconfig.json 配置 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ { │
│ "compilerOptions": { │
│ "target": "ES2022", // 编译目标版本 │
│ "module": "NodeNext", // 模块系统 │
│ "moduleResolution": "NodeNext", // 模块解析策略 │
│ "outDir": "./dist", // 输出目录 │
│ "rootDir": "./src", // 源码目录 │
│ "strict": true, // 严格模式 │
│ "esModuleInterop": true, // ES 模块互操作 │
│ "skipLibCheck": true, // 跳过库检查 │
│ "forceConsistentCasingInFileNames": true │
│ }, │
│ "include": ["src/**/*"], │
│ "exclude": ["node_modules", "dist"] │
│ } │
│ │
└─────────────────────────────────────────────────────────────────────┘
编译选项说明
┌─────────────────────────────────────────────────────────────────────┐
│ TypeScript 编译选项说明 │
├─────────────────────┬───────────────────────────────────────────────┤
│ 选项 │ 说明 │
├─────────────────────┼───────────────────────────────────────────────┤
│ target: ES2022 │ 编译到 ES2022,支持最新特性 │
├─────────────────────┼───────────────────────────────────────────────┤
│ module: NodeNext │ 使用 Node.js 原生 ES Module 支持 │
├─────────────────────┼───────────────────────────────────────────────┤
│ strict: true │ 启用所有严格类型检查选项 │
├─────────────────────┼───────────────────────────────────────────────┤
│ esModuleInterop │ 允许 CommonJS 模块默认导入 │
├─────────────────────┼───────────────────────────────────────────────┤
│ outDir: ./dist │ 编译输出到 dist 目录 │
├─────────────────────┼───────────────────────────────────────────────┤
│ rootDir: ./src │ 源码位于 src 目录 │
└─────────────────────┴───────────────────────────────────────────────┘
11.1.3 plugin.json 配置详解
┌─────────────────────────────────────────────────────────────────────┐
│ plugin.json 配置 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ { │
│ "mcp": { │
│ "servers": { │
│ "miniclaw": { │
│ "command": "npx", │
│ "args": ["-y", "miniclaw"], │
│ "env": {} │
│ } │
│ } │
│ } │
│ } │
│ │
│ 说明:plugin.json 用于某些 MCP 客户端的插件配置 │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.2 环境变量
11.2.1 支持的环境变量
┌─────────────────────────────────────────────────────────────────────┐
│ 环境变量配置 │
├─────────────────────────┬───────────────────────────────────────────┤
│ 变量名 │ 说明 │
├─────────────────────────┼───────────────────────────────────────────┤
│ MINICLAW_TOKEN_BUDGET │ Token 预算,默认 8000 │
│ │ 示例:MINICLAW_TOKEN_BUDGET=12000 │
├─────────────────────────┼───────────────────────────────────────────┤
│ HOME │ 用户主目录,用于定位 ~/.miniclaw/ │
│ │ 通常由系统自动设置 │
└─────────────────────────┴───────────────────────────────────────────┘
11.2.2 环境变量使用示例
┌─────────────────────────────────────────────────────────────────────┐
│ 环境变量配置示例 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ MCP 客户端配置 (claude_desktop_config.json) │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ { │ │
│ │ "mcpServers": { │ │
│ │ "miniclaw": { │ │
│ │ "command": "npx", │ │
│ │ "args": ["-y", "github:8421bit/miniclaw"], │ │
│ │ "env": { │ │
│ │ "MINICLAW_TOKEN_BUDGET": "12000" │ │
│ │ } │ │
│ │ } │ │
│ │ } │ │
│ │ } │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ 命令行方式 │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ MINICLAW_TOKEN_BUDGET=12000 npx -y miniclaw │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.3 安装方式
11.3.1 零安装方式(推荐)
┌─────────────────────────────────────────────────────────────────────┐
│ 零安装方式 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ 使用 npx 直接运行,无需预先安装 │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ npx -y github:8421bit/miniclaw │ │
│ │ │ │
│ │ 参数说明: │ │
│ │ • -y → 自动确认,跳过安装确认 │ │
│ │ • github:... → 直接从 GitHub 仓库安装 │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ 优势: │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ ✅ 无需全局安装 │ │
│ │ ✅ 始终使用最新版本 │ │
│ │ ✅ 不占用本地存储 │ │
│ │ ✅ 配置简单 │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.3.2 手动安装方式
┌─────────────────────────────────────────────────────────────────────┐
│ 手动安装方式 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ 方式一:从 npm 安装 │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ npm install -g miniclaw │ │
│ │ │ │
│ │ # 或使用 pnpm │ │
│ │ pnpm add -g miniclaw │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ 方式二:从源码构建 │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ # 克隆仓库 │ │
│ │ git clone https://github.com/8421bit/miniclaw.git │ │
│ │ cd miniclaw │ │
│ │ │ │
│ │ # 安装依赖 │ │
│ │ npm install │ │
│ │ │ │
│ │ # 编译 TypeScript │ │
│ │ npm run build │ │
│ │ │ │
│ │ # 全局链接 │ │
│ │ npm link │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.3.3 安装脚本分析
┌─────────────────────────────────────────────────────────────────────┐
│ install.sh 脚本分析 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ #!/bin/bash │
│ │
│ # 设置颜色输出 │
│ RED='\033[0;31m' │
│ GREEN='\033[0;32m' │
│ NC='\033[0m' │
│ │
│ echo -e "${GREEN}Installing MiniClaw...${NC}" │
│ │
│ # 检查 Node.js │
│ if ! command -v node &> /dev/null; then │
│ echo -e "${RED}Node.js is required${NC}" │
│ exit 1 │
│ fi │
│ │
│ # 创建运行时目录 │
│ mkdir -p ~/.miniclaw/memory │
│ mkdir -p ~/.miniclaw/skills │
│ │
│ # 复制模板文件 │
│ cp -r templates/* ~/.miniclaw/ │
│ │
│ echo -e "${GREEN}MiniClaw installed successfully!${NC}" │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.4 客户端配置
11.4.1 Claude Code 配置
┌─────────────────────────────────────────────────────────────────────┐
│ Claude Code 配置 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ 配置文件位置:~/.claude/claude_desktop_config.json │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ { │ │
│ │ "mcpServers": { │ │
│ │ "miniclaw": { │ │
│ │ "command": "npx", │ │
│ │ "args": ["-y", "github:8421bit/miniclaw"], │ │
│ │ "env": { │ │
│ │ "MINICLAW_TOKEN_BUDGET": "12000" │ │
│ │ } │ │
│ │ } │ │
│ │ } │ │
│ │ } │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.4.2 Claude Desktop 配置
┌─────────────────────────────────────────────────────────────────────┐
│ Claude Desktop 配置 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ macOS 配置文件位置: │
│ ~/Library/Application Support/Claude/claude_desktop_config.json │
│ │
│ Windows 配置文件位置: │
│ %APPDATA%\Claude\claude_desktop_config.json │
│ │
│ 配置内容与 Claude Code 相同 │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.4.3 Cursor 配置
┌─────────────────────────────────────────────────────────────────────┐
│ Cursor 配置 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ 配置文件位置:项目根目录 .cursor/mcp.json │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ { │ │
│ │ "mcpServers": { │ │
│ │ "miniclaw": { │ │
│ │ "command": "npx", │ │
│ │ "args": ["-y", "github:8421bit/miniclaw"] │ │
│ │ } │ │
│ │ } │ │
│ │ } │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.4.4 Windsurf 配置
┌─────────────────────────────────────────────────────────────────────┐
│ Windsurf 配置 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ 配置文件位置:~/.windsurf/mcp.json │
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ { │ │
│ │ "mcpServers": { │ │
│ │ "miniclaw": { │ │
│ │ "command": "npx", │ │
│ │ "args": ["-y", "miniclaw"] │ │
│ │ } │ │
│ │ } │ │
│ │ } │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.4.5 其他客户端配置
┌─────────────────────────────────────────────────────────────────────┐
│ 其他 MCP 客户端配置 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ Antigravity │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ 配置文件:~/.antigravity/mcp.json │ │
│ │ 格式与上述客户端相同 │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ Qoder/千问 │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ 配置文件:~/.qoder/mcp.json │ │
│ │ 格式与上述客户端相同 │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ 通用配置模式 │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ 1. 找到客户端的 MCP 配置文件 │ │
│ │ 2. 添加 miniclaw 服务器配置 │ │
│ │ 3. 重启客户端 │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.5 部署架构
11.5.1 单机部署架构
┌─────────────────────────────────────────────────────────────────────┐
│ 单机部署架构 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ 用户机器 │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ MCP 客户端 │────►│ MiniClaw │────►│ ~/.miniclaw/│ │ │
│ │ │ (Claude等) │ │ (MCP Server)│ │ (数据存储) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ │ │ │ │ │ │
│ │ │ │ │ │ │
│ │ ▼ ▼ ▼ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ AI 模型 API │ │ 本地命令 │ │ 文件系统 │ │ │
│ │ │ (Claude等) │ │ (安全执行) │ │ (读写) │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ 特点: │
│ • 所有组件运行在同一台机器上 │
│ • 数据完全本地化,隐私安全 │
│ • 无需网络配置 │
│ │
└─────────────────────────────────────────────────────────────────────┘
11.5.2 数据流向
┌─────────────────────────────────────────────────────────────────────┐
│ 数据流向 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ 用户输入 │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ MCP 客户端 │ │
│ │ • 接收用户输入 │ │
│ │ • 调用 MCP 工具/提示词 │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │ │
│ │ MCP 协议 (JSON-RPC) │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ MiniClaw (MCP Server) │ │
│ │ • 编译上下文 │ │
│ │ • 执行工具 │ │
│ │ • 管理记忆 │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │ │
│ ├──────────────────┬──────────────────┐ │
│ ▼ ▼ ▼ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │文件系统 │ │命令执行 │ │AI 模型 │ │
│ │(读写) │ │(安全) │ │(API) │ │
│ └─────────┘ └─────────┘ └─────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
本章小结
┌─────────────────────────────────────────────────────────────────────┐
│ 第十一章 核心要点 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ⚙️ 项目配置 │
│ • package.json:包配置、依赖、脚本 │
│ • tsconfig.json:TypeScript 编译配置 │
│ • plugin.json:MCP 插件配置 │
│ │
│ 🌍 环境变量 │
│ • MINICLAW_TOKEN_BUDGET:Token 预算 │
│ • HOME:用户主目录 │
│ │
│ 📦 安装方式 │
│ • 零安装:npx -y github:8421bit/miniclaw(推荐) │
│ • 手动安装:npm install -g miniclaw │
│ │
│ 🔌 客户端配置 │
│ • Claude Code / Claude Desktop │
│ • Cursor / Windsurf │
│ • 其他 MCP 客户端 │
│ │
│ 🏗️ 部署架构 │
│ • 单机部署,数据本地化 │
│ │
└─────────────────────────────────────────────────────────────────────┘
下一章:测试与验证 →