# CodeFree CLI

**CodeFree CLI** 是一个基于AI的智能命令行工具，专为开发者设计。该项目从Qwen Code CLI适配而来，针对中国电信研发云平台进行了深度优化和定制。

**核心定位**：为中国电信研发云开发者提供增强开发工作流程的智能命令行工具，支持高级代码理解、自动化任务和智能辅助功能。

## 功能特性

### 主要功能

- **代码理解与编辑**：查询和编辑大型代码库，自动压缩上下文，突破传统上下文窗口限制

- **工作流自动化**：自动化操作任务，如处理拉取请求和复杂rebase操作

- **增强解析器**：专门为CodeFree模型优化的解析器

- **子代理系统**：支持文件配置的专业化AI助手子系统

- **任务管理**：内置todo_write工具用于任务规划和进度跟踪

- **预置研发云MCP服务**

### 会话管理

- 支持会话压缩、清除和历史统计命令

## 安装使用

### 系统要求

- Node.js版本22或更高

### 安装方式

1. **NPM安装**

```bash
npm install -g @srdcloud/codefree-cli
```

1. **快速开始**

```bash
# 启动CodeFree CLI
codefree

# 示例命令
> Explain this codebase structure
> Help me refactor this function
> Generate unit tests for this module
> Plan and implement a new feature
```

## 使用示例

### 🔍 代码库探索

```bash
cd your-project/
codefree

# 架构分析
> Describe the main pieces of this system's architecture
> 描述这个系统架构的主要组成部分
> What are the key dependencies and how do they interact?
> 关键依赖项有哪些？它们如何交互？
> Find all API endpoints and their authentication methods
> 查找所有API端点及其认证方法
```

### 💻 代码开发

```bash
# 重构
> Refactor this function to improve readability and performance
> 重构这个函数以提高可读性和性能
> Convert this class to use dependency injection
> 将这个类转换为使用依赖注入
> Split this large module into smaller, focused components
> 将这个大型模块拆分为更小、专注的组件

# 代码生成
> Create a REST API endpoint for user management
> 为用户管理创建一个REST API端点
> Generate unit tests for the authentication module
> 为认证模块生成单元测试
> Add error handling to all database operations
> 为所有数据库操作添加错误处理
```

### 🔄 工作流自动化

```bash
# Git自动化
> Analyze git commits from the last 7 days, grouped by feature
> 分析过去7天的git提交，按功能分组
> Create a changelog from recent commits
> 根据最近的提交创建变更日志
> Find all TODO comments and create GitHub issues
> 查找所有TODO注释并创建GitHub issue

# 文件操作
> Convert all images in this directory to PNG format
> 将此目录中的所有图像转换为PNG格式
> Rename all test files to follow the *.test.ts pattern
> 重命名所有测试文件以遵循*.test.ts模式
> Find and remove all console.log statements
> 查找并删除所有console.log语句
```

### 🐛 调试与分析

```bash
# 性能分析
> Identify performance bottlenecks in this React component
> 识别此React组件中的性能瓶颈
> Find all N+1 query problems in the codebase
> 在代码库中查找所有N+1查询问题

# 安全审计
> Check for potential SQL injection vulnerabilities
> 检查潜在的SQL注入漏洞
> Find all hardcoded credentials or API keys
> 查找所有硬编码的凭据或API密钥
```

### 📚 常用任务

**理解新代码库**

> What are the core business logic components?
> 核心业务逻辑组件有哪些？
> What security mechanisms are in place?
> 实施了哪些安全机制？
> How does the data flow through the system?
> 数据如何在系统中流动？
> What are the main design patterns used?
> 使用了哪些主要的设计模式？
> Generate a dependency graph for this module
> 为此模块生成依赖关系图
> **代码重构与优化**

> What parts of this module can be optimized?
> 这个模块的哪些部分可以优化？
> Help me refactor this class to follow SOLID principles
> 帮助我重构这个类以遵循SOLID原则
> Add proper error handling and logging
> 添加适当的错误处理和日志记录
> Convert callbacks to async/await pattern
> 将回调转换为async/await模式
> Implement caching for expensive operations
> 为昂贵的操作实现缓存
> **文档与测试**

> Generate comprehensive JSDoc comments for all public APIs
> 为所有公共API生成全面的JSDoc注释
> Write unit tests with edge cases for this component
> 为此组件编写包含边界情况的单元测试
> Create API documentation in OpenAPI format
> 以OpenAPI格式创建API文档
> Add inline comments explaining complex algorithms
> 添加内联注释解释复杂算法
> Generate a README for this module
> 为此模块生成README文档
> **开发加速**

> Set up a new Express server with authentication
> 设置一个带认证的新Express服务器
> Create a React component with TypeScript and tests
> 创建一个带有TypeScript和测试的React组件
> Implement a rate limiter middleware
> 实现一个速率限制器中间件
> Add database migrations for new schema
> 为新模式添加数据库迁移
> Configure CI/CD pipeline for this project
> 为此项目配置CI/CD流水线

## 命令和快捷键

### 会话命令

- `/help` - 显示可用命令

- `/clear` - 清除对话历史

- `/compress` - 压缩历史以节省令牌

- `/init` - 初始化项目上下文（当上下文文件存在时会有确认提示）

更多命令请参考帮助文档：https://www.srdcloud.cn/helpcenter/content?id=1443286119281876992

### 键盘快捷键

- `Ctrl+C` - 取消当前操作

- `Ctrl+D` - 退出（在空行时）

- `Ctrl+J` - 换行

- 上下箭头 - 导航命令历史
