AvixoSec/codesight

GitHub: AvixoSec/codesight

一款基于多提供商大模型的命令行代码分析工具,提供代码审查、Bug 检测、安全审计、文档生成和重构建议,并支持 SARIF 输出与 CI/CD 集成。

Stars: 3 | Forks: 0

# CodeSight **代码分析 CLI - 在您的终端中完成代码审查、Bug 检测、文档生成和重构。** CodeSight 将您的代码发送给 LLM(OpenAI、Anthropic、Google Vertex AI、Ollama 或任何 OpenAI 兼容的端点),并结合结构化的提示词进行代码审查、Bug 检测、安全分析、文档生成和重构。支持多提供商、可配置,适用于任何编程语言。 [![PyPI](https://img.shields.io/pypi/v/codesight?color=8b5cf6)](https://pypi.org/project/codesight/) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/9e05b6668a030201.svg)](https://github.com/AvixoSec/codesight/actions) ![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue) [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE) [![Docs](https://img.shields.io/badge/docs-codesight.is--a.dev-c084fc)](https://codesight.is-a.dev) [![Downloads](https://img.shields.io/pypi/dm/codesight?color=blue)](https://pypi.org/project/codesight/) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) ## 功能说明 - **`codesight review`** - 代码审查,附带严重性级别标签的 Issue(crit/warn/info) - **`codesight bugs`** - 查找逻辑错误、竞态条件、资源泄漏 - **`codesight security`** - 安全审计,附带 CWE ID 和 OWASP 映射 - **`codesight scan .`** - 带进度条扫描整个目录 - **`codesight docs`** - 自动生成 docstring 和模块文档 - **`codesight explain`** - 用通俗语言解析复杂代码 - **`codesight refactor`** - 重构建议,提供修改前后的 diff 对比 ## 演示

CodeSight terminal demo

## 快速入门 ``` # 安装 pip install codesight # 配置你的 provider codesight config # 运行 review codesight review src/main.py # 检测 bugs codesight bugs lib/parser.py # 扫描整个项目 codesight scan . --task review codesight scan src/ --ext .py .js # 生成 docs codesight docs utils/helpers.py ``` ## 支持的提供商 | 提供商 | 模型 | 配置 | |----------|--------|-------| | **OpenAI** | GPT-5.4, GPT-5.3-Codex | `OPENAI_API_KEY` | | **Anthropic** | Claude Opus 4.6, Claude Sonnet 4.6 | `ANTHROPIC_API_KEY` | | **Google Vertex AI** | Gemini 3.1 Pro, Gemini 3.1 Flash | `GOOGLE_CLOUD_PROJECT` + ADC | | **Ollama (本地)** | Llama 3, CodeLlama, Mistral 等 | 只需运行 `ollama serve` | | **自定义 (OpenAI 兼容)** | OpenRouter, Groq, Together AI, Mistral, xAI (Grok), Fireworks, DeepSeek, Perplexity, Cerebras, Cohere, Azure AI Foundry 或任何 OpenAI 兼容的 URL | 通过 `codesight config` -> Custom 进行设置,或在 `~/.codesight/config.json` 中配置 `base_url` + API 密钥 | ## 配置 CodeSight 将配置存储在 `~/.codesight/config.json` 中。您可以通过交互式方式进行配置: ``` codesight config ``` 或者设置环境变量: ``` export OPENAI_API_KEY="sk-..." export CODESIGHT_MODEL="gpt-5.4" codesight review my_file.py ``` 随时切换提供商: ``` codesight review my_file.py --provider anthropic codesight bugs my_file.py --provider google codesight explain my_file.py --provider openai codesight review my_file.py --provider ollama # fully offline, no data leaves your machine codesight review my_file.py --provider openrouter # any OpenAI-compatible endpoint you saved in config ``` 自定义 OpenAI 兼容的提供商(OpenRouter、Groq、Together、Mistral、xAI、Fireworks、DeepSeek、Perplexity、Cerebras、Cohere、Azure AI Foundry)可通过向导进行设置: ``` codesight config # 选择:Custom (OpenRouter / Groq / Together / 任何 OpenAI-compat) # 选择一个预设或输入自定义 base URL,保存在一个 label 下(例如 "openrouter") codesight review my_file.py --provider openrouter ``` ## 架构 ``` codesight/ ├── cli.py # CLI entry point (argparse) ├── analyzer.py # Core analysis engine ├── config.py # Config management (~/.codesight/) ├── compression.py # Context compression / code maps ├── streaming.py # Streaming output (OpenAI, Anthropic, Ollama) ├── templates.py # Custom prompt templates ├── pipeline.py # Multi-model triage → verify pipeline ├── sarif.py # SARIF output for CI/CD ├── benchmark.py # LLM benchmark runner ├── cost.py # Token cost tracking └── providers/ ├── base.py ├── factory.py ├── openai_provider.py ├── anthropic_provider.py ├── google_provider.py ├── ollama_provider.py └── custom_provider.py # OpenAI-compatible adapter (OpenRouter, Groq, Azure, etc.) ``` ## 开发 ``` git clone https://github.com/AvixoSec/codesight.git cd codesight pip install -e ".[dev]" pytest tests/ -v ruff check codesight/ ``` ## 路线图 - [x] `codesight scan .` - 分析整个目录 - [x] Ollama 支持 - 使用本地模型进行完全离线分析 - [x] `codesight security` - 专属安全审计,附带 CWE ID 和 OWASP 映射 - [x] `codesight diff` - 仅审查 git 修改过的文件 - [x] SARIF 输出 - 用于 GitHub Security 标签页的标准格式 - [x] 用于 CI/CD 的退出代码(0 = 干净,1 = 警告,2 = 严重) - [x] GitHub Action - 自动扫描 PR 并上传 SARIF - [x] 多模型管道 - 快速分诊 + 深度验证 - [x] 按查询进行成本追踪 - [x] `codesight benchmark` - 在有漏洞的代码库上测试 LLM - [x] 上下文压缩 - 通过代码映射减少 token 使用量 - [x] 大文件的流式输出 - [x] 自定义 prompt 模板 - [x] OpenAI 兼容提供商(OpenRouter、Groq、Azure 等 10 多种预设) - [x] 发布至 PyPI - [x] VS Code 扩展(脚手架) - [ ] 发布至 VS Code Marketplace - [ ] Web 仪表板 - [ ] Pre-commit hook 集成 - [ ] `.codesight.yml` 项目级配置 ## 许可证 MIT - 详见 [LICENSE](LICENSE)。
标签:AI, AI编程, AI风险缓解, Anthropic, Bug检测, CIS基准, DevSecOps, DLL 劫持, DNS 反向解析, Google Vertex AI, LLM评估, Ollama, OpenAI, Petitpotam, Python, SARIF, Spyse API, 上游代理, 代码安全, 代码审查, 代码重构, 内存规避, 大语言模型, 文档生成, 无后门, 漏洞枚举, 研发效能, 终端工具, 自动化代码审查, 逆向工具, 错误基检测, 静态代码分析