haruki0104/pair_programing

GitHub: haruki0104/pair_programing

这是一个用于C/C++项目的结对编程代理,结合多种静态分析工具和大语言模型来审查代码,以发现bug、安全漏洞和架构问题。

Stars: 0 | Forks: 0

# Pair Agent — C/C++ 代码审查代理 一个用于 C 和 C++ 项目的**结对编程代理**,它结合了静态分析工具、安全扫描器和 LLM 驱动的代码审查,以发现错误、安全漏洞、架构问题和代码质量问题。 ## 功能 - **多工具静态分析** — cppcheck、clang-tidy、Clang Static Analyzer - **安全扫描** — FlawFinder、CodeQL(可用时) - **动态分析** — Valgrind、sanitizers(可用时) - **LLM 驱动的审查** — OpenAI GPT 分析架构适配性、逻辑错误和设计问题 - **三种输出格式** — 终端(彩色编码)、JSON、SARIF - **VS Code 集成** — LSP 服务器 + 内联诊断扩展 - **监视模式** — 文件更改时重新分析 - **可配置** — 基于项目的 `pair_agent.toml` ## 安装 ``` # 从源代码安装 git clone && cd pair_programming_agent_ws pip install -e ".[dev]" # 安装静态分析工具 (Ubuntu/Debian) sudo apt install cppcheck clang-tidy clang # 安装安全工具 pip install flawfinder # CodeQL: https://github.com/github/codeql-cli-binaries/releases ``` 为 LLM 驱动的审查设置你的 OpenAI API 密钥: ``` export OPENAI_API_KEY="sk-..." # 或添加到 pair_agent.toml 的 [llm] 部分 ``` ## 使用方法 ``` # 扫描项目 pair-agent scan path/to/project # 完整代码审查 pair-agent review path/to/project # 针对新功能进行架构分析审查 pair-agent review path/to/project --feature "Add WebSocket support" # 结构化输出 pair-agent review path/to/project --format json pair-agent review path/to/project --format sarif # 生成配置文件 pair-agent init path/to/project ``` ## 配置 在项目根目录创建一个 `pair_agent.toml` 文件: ``` [project] c_standard = "c17" cpp_standard = "c++20" [analyzers] enable = ["static", "security", "architecture", "quality"] [analyzers.static] tools = ["cppcheck", "clang-tidy", "clang-analyzer"] [analyzers.security] tools = ["flawfinder", "codeql"] [llm] provider = "openai" model = "gpt-4o" # 设置 OPENAI_API_KEY 环境变量或在此处添加 api_key [report] format = "terminal" # terminal, json, sarif severity_threshold = "warning" # info, warning, error, critical ``` ## VS Code 扩展 ``` cd extensions/vscode npm install npm run compile ``` 然后在 VS Code 中按 `F5` 启动扩展开发主机。命令: - `Pair Agent: 审查当前文件` - `Pair Agent: 审查整个项目` - `Pair Agent: 审查架构...` 诊断信息会在文件保存时以内联方式显示。 ## 架构 ``` CLI / VS Code Extension │ ▼ ┌─────────────────┐ │ Analyzer Pipeline │ │ (parallel via │ │ ThreadPool) │ ├──────────────────┤ │ ┌──────────────┐ │ │ │ cppcheck │ │ │ │ clang-tidy │ │ │ │ clang-analyze│ │ │ │ FlawFinder │ │ │ │ CodeQL │ │ │ │ Valgrind │ │ │ │ LLM (GPT) │ │ │ └──────────────┘ │ └────────┬─────────┘ ▼ ┌─────────────────┐ │ Dedup + Filter │ │ by severity │ └────────┬─────────┘ ▼ ┌─────────────────┐ │ Formatter │ │ Terminal / JSON │ │ / SARIF │ └─────────────────┘ ``` ## 工具 | 工具 | 可检测问题 | 需要 | |---|---|---| | cppcheck | 未使用的变量、死代码、风格问题 | `apt install cppcheck` | | clang-tidy | 安全问题(CWE-119)、现代 C++ 建议、错误 | `apt install clang-tidy` | | Clang Static Analyzer | 路径敏感错误、空指针解引用 | `apt install clang` | | FlawFinder | 缓冲区溢出、禁用的函数(CWE-120) | `pip install flawfinder` | | CodeQL | 深入的语义安全分析 | CodeQL CLI | | Valgrind | 内存泄漏、未定义行为 | `apt install valgrind` | | LLM (GPT) | 架构适配性、逻辑错误、设计问题 | OpenAI API 密钥 | ## 开发 ``` # 安装开发依赖 pip install -e ".[dev]" # 运行测试 PYTHONPATH="" pytest tests/ -v ``` ## 许可证 MIT
标签:API安全, bug检测, C/C++开发, clang-tidy, CodeQL, cppcheck, JSON输出, Linux安全, LLM驱动分析, LSP服务器, OpenAI GPT, Petitpotam, Python安全, SARIF, SOC Prime, Subfinder, Valgrind, VS Code集成, 云安全监控, 代码审查工具, 合规性检查, 安全扫描, 安全漏洞, 安全评估工具, 实时更新, 开发工具, 数据管道, 时序注入, 架构分析, 自动化审查, 软件工程, 输出格式, 逆向工具, 配对编程, 静态分析