Skip to content

Miasakiii/codebase-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codebase Agent

AI 驱动的代码协作 Agent — 需求拆解、代码生成、Bug 修复、测试验证。

核心特性

  • 四 Agent 协作管道:Planner → Developer → Tester → Reviewer
  • 自我修正循环:测试失败时自动反馈给 Developer 修正代码,最多重试 N 轮
  • 多 LLM 支持:OpenAI / Anthropic / Mock(无 API Key 时自动降级为 Mock 模式)
  • 仓库扫描:自动分析代码目录结构和文件内容,为 Agent 提供上下文
  • Markdown 报告:输出完整的分析和审查报告

架构

用户任务
   │
   ▼
┌──────────┐
│ Scanner  │  扫描仓库,生成代码快照
└────┬─────┘
     ▼
┌──────────┐
│ Planner  │  分析需求、拆解任务、识别影响范围
└────┬─────┘
     ▼
┌──────────┐     ┌──────────┐
│Developer │◄────│ Tester   │  自我修正循环
└────┬─────┘     └────┬─────┘
     │     测试通过    │
     ▼                │
┌──────────┐          │
│ Reviewer │◄─────────┘
└────┬─────┘
     ▼
  Markdown 报告

快速开始

安装

pip install -e ".[dev]"

使用 Mock 模式(无需 API Key)

python main.py --task "为 calculator.py 的 divide 函数添加除零保护" --repo sample_repo

使用 OpenAI

export OPENAI_API_KEY="sk-..."
python main.py --task "添加输入验证" --repo ./your-project --test-cmd "pytest"

使用 Anthropic

export ANTHROPIC_API_KEY="sk-ant-..."
python main.py --task "重构认证模块" --repo ./your-project --provider anthropic

CLI 参数

参数 说明 默认值
--repo, -r 代码仓库路径 .
--task, -t 任务描述(必填) -
--test-cmd 测试执行命令
--max-files 扫描最大文件数 30
--max-iterations 自我修正最大轮数 3
--provider LLM 提供商(openai/anthropic/mock) 自动检测
--output, -o 报告输出文件路径 stdout

运行测试

pytest tests/ -v

项目结构

codex/
├── src/codebase_agent/
│   ├── __init__.py        # 包初始化
│   ├── __main__.py        # python -m 入口
│   ├── agents.py          # Agent 定义(Planner/Developer/Tester/Reviewer)
│   ├── cli.py             # CLI 参数解析
│   ├── llm.py             # LLM 抽象层(OpenAI/Anthropic/Mock)
│   ├── repo_scanner.py    # 代码仓库扫描器
│   └── workflow.py        # 工作流编排(含自我修正循环)
├── tests/                 # 测试用例
├── sample_repo/           # 示例仓库(用于演示)
├── main.py                # 快速入口
├── pyproject.toml         # 项目配置
└── requirements.txt       # 依赖

About

codex

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages