Skip to content

CLI 配置详解

MyDeskBot CLI 提供了灵活的配置系统,让您可以根据需要定制工具的行为。

配置文件结构

全局配置文件

位置:~/.bytebuddy/config.json

json
{
  "version": "1.0.0",
  "defaultModel": "gpt-4",
  "workspace": "/home/user/projects",
  "logLevel": "info",
  "providers": {
    "openai": {
      "apiKey": "${OPENAI_API_KEY}",
      "baseURL": "https://api.openai.com/v1",
      "timeout": 30000
    }
  },
  "plugins": ["@mydeskbot/plugin-react", "@mydeskbot/plugin-eslint"],
  "rules": ["typescript-best-practices", "react-hooks-rules"],
  "tools": {
    "fileManager": {
      "enabled": true,
      "maxFileSize": "10MB"
    },
    "codeGenerator": {
      "enabled": true,
      "templateDir": "./templates"
    }
  }
}

项目配置文件

位置:./.bytebuddy/config.json

json
{
  "name": "my-project",
  "type": "react",
  "model": "gpt-3.5-turbo",
  "context": {
    "include": ["src/**/*"],
    "exclude": ["node_modules/**", "dist/**"]
  },
  "rules": {
    "project": "react-specific-rules",
    "coding": "eslint-rules"
  },
  "hooks": {
    "beforeGenerate": "npm run lint",
    "afterGenerate": "npm run format"
  }
}

配置命令

查看配置

bash
# 显示当前配置
mydeskbot config show

# 显示特定配置项
mydeskbot config get model.default
mydeskbot config get providers.openai.apiKey

# 显示配置文件路径
mydeskbot config path

设置配置

bash
# 设置默认模型
mydeskbot config set model.default=gpt-4

# 设置 API 密钥
mydeskbot config set providers.openai.apiKey=your_api_key

# 设置工作空间
mydeskbot config set workspace=/path/to/workspace

# 设置日志级别
mydeskbot config set logLevel=debug

删除配置

bash
# 删除配置项
mydeskbot config delete model.default

# 重置为默认值
mydeskbot config reset

# 重置特定部分
mydeskbot config reset providers

模型配置

模型提供商配置

OpenAI

json
{
  "providers": {
    "openai": {
      "apiKey": "${OPENAI_API_KEY}",
      "baseURL": "https://api.openai.com/v1",
      "organization": "org-your-org-id",
      "timeout": 30000,
      "maxRetries": 3,
      "models": {
        "chat": ["gpt-4", "gpt-3.5-turbo"],
        "completion": ["text-davinci-003"],
        "embedding": ["text-embedding-ada-002"]
      }
    }
  }
}

Anthropic Claude

json
{
  "providers": {
    "anthropic": {
      "apiKey": "${ANTHROPIC_API_KEY}",
      "baseURL": "https://api.anthropic.com",
      "timeout": 60000,
      "models": {
        "chat": ["claude-3-opus-20240229", "claude-3-sonnet-20240229"]
      }
    }
  }
}

本地模型 (Ollama)

json
{
  "providers": {
    "ollama": {
      "baseURL": "http://localhost:11434",
      "timeout": 120000,
      "models": {
        "chat": ["llama2", "codellama", "mistral"]
      }
    }
  }
}

模型选择策略

json
{
  "modelSelection": {
    "strategy": "cost-optimized",
    "fallback": true,
    "rules": [
      {
        "condition": "task.type === 'code-generation'",
        "model": "gpt-4"
      },
      {
        "condition": "task.type === 'simple-question'",
        "model": "gpt-3.5-turbo"
      }
    ]
  }
}

工作空间配置

工作空间管理

json
{
  "workspace": {
    "default": "/home/user/projects",
    "autoCreate": true,
    "template": "react-typescript",
    "structure": {
      "src": "src",
      "docs": "docs",
      "tests": "__tests__"
    }
  }
}

项目类型配置

json
{
  "projectTypes": {
    "react": {
      "template": "react-typescript",
      "dependencies": ["react", "react-dom", "typescript"],
      "devDependencies": ["@types/react", "@types/react-dom"],
      "rules": ["react-hooks", "react-typescript"],
      "tools": ["eslint", "prettier"]
    },
    "node": {
      "template": "node-express",
      "dependencies": ["express", "cors"],
      "rules": ["node-best-practices"],
      "tools": ["nodemon", "jest"]
    }
  }
}

插件配置

插件管理

json
{
  "plugins": {
    "enabled": ["@mydeskbot/plugin-react", "@mydeskbot/plugin-typescript"],
    "disabled": ["@mydeskbot/plugin-python"],
    "config": {
      "@mydeskbot/plugin-react": {
        "componentTemplate": "functional",
        "styledComponents": true
      },
      "@mydeskbot/plugin-typescript": {
        "strictMode": true,
        "target": "ES2020"
      }
    }
  }
}

插件开发配置

json
{
  "plugins": {
    "development": {
      "watch": true,
      "hotReload": true,
      "debug": true,
      "sourceMap": true
    },
    "registry": "https://registry.bytebuddy.com",
    "localPath": "./plugins"
  }
}

规则配置

代码质量规则

json
{
  "rules": {
    "coding": {
      "enabled": ["eslint", "prettier", "typescript-compiler"],
      "config": {
        "eslint": {
          "extends": ["@typescript-eslint/recommended"],
          "rules": {
            "no-console": "warn",
            "prefer-const": "error"
          }
        }
      }
    },
    "security": {
      "enabled": ["security-scan", "dependency-check"],
      "config": {
        "securityScan": {
          "level": "high",
          "ignore": ["node_modules/**"]
        }
      }
    },
    "performance": {
      "enabled": ["bundle-analyzer", "lighthouse"],
      "config": {
        "bundleAnalyzer": {
          "maxSize": "1MB",
          "reportFormat": "json"
        }
      }
    }
  }
}

自定义规则

json
{
  "rules": {
    "custom": [
      {
        "name": "naming-convention",
        "type": "style",
        "pattern": "^[A-Z][a-zA-Z0-9]*$",
        "message": "组件名必须使用 PascalCase"
      },
      {
        "name": "no-hardcoded-secrets",
        "type": "security",
        "pattern": "(password|secret|key|token)\\s*[:=]\\s*['\"][^'\"]+['\"]",
        "severity": "error"
      }
    ]
  }
}

工具配置

文件管理工具

json
{
  "tools": {
    "fileManager": {
      "enabled": true,
      "maxFileSize": "10MB",
      "allowedExtensions": [".js", ".ts", ".jsx", ".tsx", ".json", ".md"],
      "excludedPatterns": ["node_modules/**", "dist/**", ".git/**"],
      "watchMode": true
    }
  }
}

代码生成工具

json
{
  "tools": {
    "codeGenerator": {
      "enabled": true,
      "templateDirectory": "./templates",
      "outputDirectory": "./src/generated",
      "variables": {
        "author": "Your Name",
        "license": "MIT",
        "year": "2024"
      }
    }
  }
}

测试工具

json
{
  "tools": {
    "testing": {
      "framework": "jest",
      "coverage": {
        "enabled": true,
        "threshold": 80,
        "outputDirectory": "./coverage"
      },
      "watchMode": true,
      "testMatch": ["**/__tests__/**/*.(ts|tsx|js)"]
    }
  }
}

性能配置

并发控制

json
{
  "performance": {
    "concurrency": {
      "maxConcurrentRequests": 5,
      "maxConcurrentGenerations": 2,
      "queueSize": 100
    },
    "cache": {
      "enabled": true,
      "maxSize": "100MB",
      "ttl": 3600,
      "directory": "./.cache"
    },
    "memory": {
      "maxHeapSize": "2GB",
      "gcInterval": 30000
    }
  }
}

网络配置

json
{
  "network": {
    "timeout": {
      "connect": 10000,
      "read": 30000,
      "write": 30000
    },
    "retry": {
      "maxRetries": 3,
      "backoffFactor": 2,
      "maxDelay": 60000
    },
    "proxy": {
      "http": "${HTTP_PROXY}",
      "https": "${HTTPS_PROXY}",
      "noProxy": "localhost,127.0.0.1"
    }
  }
}

日志配置

日志级别和输出

json
{
  "logging": {
    "level": "info",
    "format": "json",
    "outputs": [
      {
        "type": "console",
        "colorize": true
      },
      {
        "type": "file",
        "path": "./logs/mydeskbot.log",
        "rotation": "daily",
        "maxSize": "100MB"
      }
    ],
    "categories": {
      "http": "debug",
      "ai": "info",
      "plugin": "warn"
    }
  }
}

调试配置

json
{
  "debug": {
    "enabled": false,
    "breakpoints": true,
    "profiler": true,
    "trace": {
      "enabled": true,
      "level": "verbose",
      "output": "./debug/trace.log"
    }
  }
}

环境配置

环境变量

bash
# .env 文件
BYTEBUDDY_CONFIG_PATH=./custom-config.json
BYTEBUDDY_LOG_LEVEL=debug
BYTEBUDDY_WORKSPACE=/path/to/workspace

# API 密钥
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key

# 代理设置
HTTP_PROXY=http://proxy.example.com:8080
HTTPS_PROXY=http://proxy.example.com:8080

环境特定配置

json
{
  "environments": {
    "development": {
      "logLevel": "debug",
      "cacheEnabled": false,
      "hotReload": true
    },
    "production": {
      "logLevel": "warn",
      "cacheEnabled": true,
      "minify": true
    },
    "test": {
      "logLevel": "error",
      "mockMode": true,
      "testDataPath": "./test/fixtures"
    }
  }
}

配置验证

验证命令

bash
# 验证配置文件
mydeskbot config validate

# 验证特定配置部分
mydeskbot config validate --section=models
mydeskbot config validate --section=providers

# 详细验证报告
mydeskbot config validate --verbose

配置模板

bash
# 生成配置模板
mydeskbot config template --type=basic
mydeskbot config template --type=advanced
mydeskbot config template --type=production

# 从模板初始化
mydeskbot config init --template=typescript-react

最佳实践

配置管理

  1. 版本控制: 将 .bytebuddy/config.json 纳入版本控制
  2. 环境隔离: 为不同环境创建不同配置
  3. 密钥管理: 使用环境变量存储敏感信息
  4. 文档化: 为团队配置编写文档

性能优化

  1. 缓存策略: 合理配置缓存大小和过期时间
  2. 并发控制: 根据硬件资源调整并发设置
  3. 网络优化: 配置合适的超时和重试策略

安全考虑

  1. 密钥保护: 绝不在配置文件中硬编码密钥
  2. 权限控制: 限制配置文件的访问权限
  3. 审计日志: 启用关键操作的审计日志

通过合理配置,您可以让 MyDeskBot CLI 更好地适应您的工作流程和项目需求。