代码助手CLI
🚀 一个TypeScript CLI工具,通过MCP(模型上下文协议)连接到代码RAG系统,以提供智能代码探索和帮助。
✨ 特性
- 🔍 语义代码搜索:使用自然语言查询查找相关代码
- 💬 交互式聊天:在人工智能的帮助下询问有关代码库的问题
- 📊 存储库统计信息:查看索引统计信息和存储库信息
- 🔄 库管理:触发摄取和更新
- 🎨 美丽的输出:格式化、彩色终端输出
- ⚡ MCP协议:直接连接到Code RAG服务器,实现低延迟
🛠 安装
# Install dependencies
npm install
# Build the project
npm run build
# Test the CLI
node dist/index.js --help🚀 快速开始
先决条件:确保您的Code RAG MCP服务器正在运行:
cd ../windsurf-project
python -m src.mcp_server然后使用CLI:
🔍 搜索代码
# Basic search
node dist/index.js search "authentication middleware"
# Search with filters
node dist/index.js search "database connection" --repos backend-service --languages python
# Limit results
node dist/index.js search "error handling" --top-k 3💬 与AI聊天
# Single question
node dist/index.js chat "How does user authentication work?"
# Interactive chat mode
node dist/index.js chat --interactive
# Chat with specific context
node dist/index.js chat "Explain the API structure" --context 10📊 存储库统计信息
# View stats
node dist/index.js stats🔄 库管理
# Ingest specific repository
node dist/index.js ingest my-backend-repo
# Force full re-indexing
node dist/index.js ingest my-backend-repo --force配置
创建一个 .env 文件(复制自 .env.example):
# Path to the Code RAG MCP server
MCP_SERVER_PATH=../windsurf-project
# Default model for chat
DEFAULT_MODEL=claude-sonnet-4-5
# Default number of search results
DEFAULT_TOP_K=5
# Default context chunks for chat
DEFAULT_MAX_CONTEXT=5命令
search
使用语义相似性搜索代码。
选项:
-r, --repos-按存储库名称筛选-l, --languages-按编程语言筛选-k, --top-k-要返回的结果数(默认值:5)- `-s, --server-path
` -MCP服务器的路径(默认:../wundsurf项目)
chat [message]
与AI讨论你的代码库。
选项:
-r, --repos-按存储库名称筛选-l, --languages-按编程语言筛选-c, --context-最大上下文块数(默认值:5)-m, --model-要使用的模型(默认:claude-sonnet-4-5)-i, --interactive-启动交互式聊天模式- `-s, --server-path
` -MCP服务器的路径
stats
显示存储库统计信息。
选项:
- `-s, --server-path
` -MCP服务器的路径
ingest [repo-name]
触发存储库摄取。
选项:
-f, --force-强制完全重新索引- `-s, --server-path
` -MCP服务器的路径
例子
搜索示例
# Find authentication code
code-assistant search "user login authentication"
# Find database queries in specific repo
code-assistant search "SELECT FROM users" --repos user-service
# Find Python error handling
code-assistant search "try catch exception" --languages python聊天示例
# Ask about architecture
code-assistant chat "What is the overall architecture of this project?"
# Get help with debugging
code-assistant chat "How do I debug authentication issues?"
# Interactive exploration
code-assistant chat -i发展
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build
npm run build
# Watch mode
npm run watch建筑
┌─────────────────┐ MCP ┌─────────────────┐
│ CLI Assistant │ ◄─────────► │ Code RAG │
│ (TypeScript) │ Protocol │ MCP Server │
└─────────────────┘ └─────────────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Commands │ │ Vector Store │
│ • search │ │ • ChromaDB │
│ • chat │ │ • Embeddings │
│ • stats │ │ • Code Chunks │
│ • ingest │ └─────────────────┘
└─────────────────┘需求
- Node.js 18+
- TypeScript 5+
- 运行代码RAG MCP服务器
- 访问代码RAG系统
故障排除
连接问题
# Check if MCP server is running
cd ../windsurf-project
python -m src.mcp_server
# Verify server path
code-assistant stats --server-path /path/to/windsurf-project构建问题
# Clean and rebuild
rm -rf dist node_modules
npm install
npm run build许可证
MIT许可证-有关详细信息,请参阅许可证文件。
