SergUdo/ai-slop-gate

GitHub: SergUdo/ai-slop-gate

结合静态分析与多LLM审查的CI/CD质量门禁工具,用于检测AI生成代码的质量问题和安全风险。

Stars: 2 | Forks: 1

# ai-slop-gate **ai-slop-gate** — 开源 **CI/CD** 工具,结合 **静态分析** 和 **多 LLM**(`Groq`、`Gemini`、`Ollama`)代码审查,以检测低意图 AI 生成的代码。实现对 LLM 输出(严重性、置信度、信号)的确定性归一化,用于对审计友好的自动化质量门禁,并内置 **DevSecOps** 检查:`SBOM` 生成、`License` 审计和 `CVE` 扫描。 [![Docker Publish](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/b3ceb6bd8b042521.svg)](https://github.com/SergUdo/ai-slop-gate/actions/workflows/docker-publish.yml) [![Tests](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/eea18f26b3042522.svg)](https://github.com/SergUdo/ai-slop-gate/actions/workflows/tests.yml) [![Code Analysis](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/2b932506ac042523.svg)](https://github.com/SergUdo/ai-slop-gate/actions/workflows/analyze.yml) [![Release](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/42b2d58c57042524.svg)](https://github.com/SergUdo/ai-slop-gate/actions/workflows/release.yml) [![Documentation](https://readthedocs.org/projects/ai-slop-gate/badge/?version=latest)](https://ai-slop-gate.readthedocs.io/en/latest/?badge=latest) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![GitHub release](https://img.shields.io/github/v/release/SergUdo/ai-slop-gate?sort=semver)](https://github.com/SergUdo/ai-slop-gate/releases/latest) [![Docker](https://img.shields.io/badge/docker-GHCR-2496ED?logo=docker&logoColor=white)](https://github.com/SergUdo/ai-slop-gate/pkgs/container/ai-slop-gate) [![Cosign](https://img.shields.io/badge/cosign-signed-success?logo=sigstore&logoColor=white)](https://github.com/SergUdo/ai-slop-gate/releases) [![SBOM](https://img.shields.io/badge/SBOM-included-blue)](https://github.com/SergUdo/ai-slop-gate/releases) [![GitHub stars](https://img.shields.io/github/stars/SergUdo/ai-slop-gate?style=social)](https://github.com/SergUdo/ai-slop-gate/stargazers) ## 文档 完整文档:**[ai-slop-gate.readthedocs.io](https://ai-slop-gate.readthedocs.io/)** ### 快速链接 - [快速入门指南](docs/source/quick-start.rst) - [架构概览](docs/source/ARCHITECTURE.md) - [CLI 参考](docs/source/CLI_REFERENCE.md) - [缓存指南](docs/source/CACHE.md) - [Docker 设置](docs/source/DOCKER.md) - [CI/CD 集成](docs/source/INTEGRATIONS.md) - [安全策略](docs/source/SECURITY.md) ## 主要特性 ### 供应链安全 - 检测禁止的许可证(GPL、AGPL) - 识别 AI 幻觉或可疑的包名称 - 通过 Syft 生成 SBOM(SPDX-JSON) - 通过 Trivy 进行 CVE 扫描 - 支持 NIS2 - 协助在技术上符合 **[EU Cyber Resilience Act](https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32024R1689)** 和 **[DORA](https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32022R2554)** 供应链安全要求。 ### GDPR/DSGVO 合规性 - 强制 AI 处理仅限欧盟数据驻留 - 防止不符合合规要求的 LLM 路由 - 生成可供审计的合规报告 ### 企业策略即代码 - 集中的 `policy.yml` 定义风险偏好和 `include_paths` - 对 CI/CD 门禁进行确定性评估 - 跨团队和仓库的一致治理 ### 多模型智能 - **Groq (Llama 3.3)** — 极速,提供免费层 - **Google Gemini** — 提供免费层 - **本地 LLM (Ollama)** — 100% 私有,无 API 成本 ### CI/CD 就绪 - 通过 GitHub API 自动进行 PR 评论 - GitLab Merge Request 集成 - `--enforcement advisory/blocking/never` 用于渐进式推出 ## ai-slop-gate 的功能 ### 目标 - **检测 AI Slop:** 识别混乱、重复或无上下文的 AI 生成代码 - **混合分析:** 结合静态分析与深度 LLM 洞察 - **左移审查:** 在推送到生产环境之前在本地审计代码 - **建议性反馈:** 直接在 Pull Request 中提供可操作的见解 ### 非目标 ai-slop-gate **不是**: - 人工代码审查的替代品 - 正式的安全扫描仪或合规认证工具 - AI 生成代码正确或安全的保证 **免责声明:** 此工具支持合规工作流,但不保证符合 `EU Cyber Resilience Act` 或 `DORA` 法规的法律合规性。 ## 支持的语言与基础设施 - **语言:** Python, JavaScript/TypeScript, Ruby, Java, C++, C# - **基础设施:** Docker, Kubernetes, Terraform ## 供应链与安全 当运行静态分析提供者(`--provider static`)或 **CI/CD 集成**时,门禁会自动生成行业标准的安全构件:有关即用型配置,请参阅 [GitHub Actions 静态分析示例](docs/source/examples/example_workflow_static.yml): | 构件 | 格式 | 描述 | |----------|--------|-------------| | `sbom.json` | Syft Native | 所有依赖项的完整清单 | | `sbom-spdx.json` | SPDX 2.3 | 符合 EU CRA / NTIA 的合规格式 | | `sbom-cyclonedx.json` | CycloneDX 1.6 | 用于自动化流水线的现代 SBOM | | `sbom-cyclonedx-vex.json` | CycloneDX + VEX | 与组件关联的漏洞报告 | 这些文件保存在扫描目录中,并可以作为 CI/CD 构件上传。 ## 入门指南 ### 安装 ``` git clone https://github.com/SergUdo/ai-slop-gate.git cd ai-slop-gate python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate pip install -e . ``` ### 初始化配置 ``` python -m ai_slop_gate.cli init ``` 在当前目录创建默认的 `policy.yml`。 ### 设置环境变量 ``` # .env 文件 GITHUB_TOKEN=your_github_personal_access_token GEMINI_API_KEY=your_google_gemini_api_key GROQ_API_KEY=your_groq_api_key AI_SLOP_GATE_TOKEN=your_gitlab_token # For GitLab integration ``` ## 分析示例与报告 真实执行日志和示例: - [LLM 分析 (Gemini)](docs/source/example_gemini_report.md) - 使用 Gemini 进行 AI slop 检测 - [LLM 分析 (Groq)](docs/source/example_groq_report.md) - 使用 Groq 进行 AI slop 检测 - [LLM 分析 (Ollama)](docs/source/example_ollama_report.md) - 本地 AI slop 检测 - [静态分析](docs/source/example_static_pipeline_report.md) - 安全与质量门禁 - [合规审计](docs/source/example_compliance_report.md) - 法律和监管检查 ## 策略文件 — 必需 每个 `run` 命令都 **需要** `--policy`。`policy.yml` 通过 `include_paths` 控制哪些目录 发送给提供者。如果没有它,LLM 提供者将接收整个 仓库并因 token 限制错误而失败。 当扫描仓库拥有自己的策略时的 **策略发现顺序**: 1. `--policy <显式路径>` — 始终优先 2. `<--path>/policy.yml` — 扫描仓库内的策略(自动发现) 3. `./policy.yml` — 当前工作目录 4. 打包的默认配置(宽松,不推荐用于 LLM 使用) ### 策略配置 **ai-slop-gate** 专为速度和灵活性而设计。您可以从零配置开始,也可以针对复杂的合规需求进行微调。 ### 选项 1:零配置启动(推荐) 还没有策略?门禁默认使用 **强大的内置安全策略**。它预配置为检测常见的 AI 生成反模式和基本安全缺陷。 只需运行 Docker 容器或 CLI;首次扫描无需配置文件。 ### 选项 2:自定义策略控制 要使门禁适应您项目的特定标准(例如,自定义严重级别或特定 GDPR 规则),请在您的仓库根目录放置 `policy.yml`。门禁将自动发现它。 * **自动发现:** 在根目录中将文件命名为 `policy.yml`。 * **手动路径:** 使用 `--policy ./my-custom-rules.yml` 标志。 [📄 查看最小策略模板](docs/source/examples/example_policy_minimal.yml) ## 运行您的第一次分析 ``` # Clone the repository git clone https://github.com/SergUdo/ai-slop-gate.git cd ai-slop-gate # Create and activate virtual environment python -m venv .venv source .venv/bin/activate pip install -e . # Install Node.js dependencies (Required for static analysis tools) npm install npm install -g ts-prune # Create .env file with your API key(s) touch .env # Example content: # SLOPE_GATE_GROQ=your_key_here # GEMINI_API_KEY=your_key_here # GITHUB_TOKEN=your_token_here # AI_SLOP_GATE_TOKEN=your_gitlab_token # iF you using GitLab integration # Static analysis (fast, no API key required) python -m ai_slop_gate.cli run --provider static --policy policy.yml --path /your/project # LLM Groq analysis on local files python -m ai_slop_gate.cli run --provider groq --llm-local --policy policy.yml --path /your/project # LLM Gemini analysis on local files python -m ai_slop_gate.cli run --provider gemini --llm-local --policy policy.yml --path /your/project # Compliance check only python -m ai_slop_gate.cli run --compliance --policy policy.yml --path /your/project # Advisory mode — findings shown, CI never blocked python -m ai_slop_gate.cli run --provider static --policy policy.yml --enforcement advisory --path /your/project # Analyze a GitHub Pull Request (PR #2 from SergUdo/slop_test) python -m ai_slop_gate.cli run --provider gemini --llm-local --policy policy.yml --github-repo SergUdo/slop_test --pr-id 2 ``` ## 执行级别 | 模式 | 行为 | 使用场景 | |---|---|---| | `advisory` | 报告发现,CI 始终通过 | 首次推出,基线调整 | | `blocking` | 违规时 CI 失败 | 生产门禁 | | `never` | 仅报告,退出代码始终为 0 | 演练 / 调试 | ``` # Override policy enforcement from CLI python -m ai_slop_gate.cli run --provider static --policy policy.yml --enforcement advisory --path /your/project ``` ## 敏感文件排除 LLM 提供者自动从 API 调用中排除以下内容(无论策略如何): - `.env`, `.env.*`, `.env.example` - `policy.yml` - `docs/`, `scripts/`, `.ai-slop-cache/` - 锁文件:`package-lock.json`, `poetry.lock`, `yarn.lock` 等。 - 压缩包:`*.min.js` 仅发送源代码扩展名:`.py`, `.js`, `.ts`, `.rb`, `.cs`, `.yml`(仅应用配置)等。 ## 缓存系统 LLM 响应会自动缓存以节省 token 并加速重复运行: | 运行 | 时间 | API 调用 | |---|---|---| | 首次运行 | ~15s | 是 | | 缓存运行 | ~0.5s | 否 | | 节省 | — | ~67% 的 token | ``` # Cache enabled by default python -m ai_slop_gate.cli run --provider groq --llm-local --policy policy.yml --path /your/project # Disable cache (for debugging prompt changes only) python -m ai_slop_gate.cli run --provider groq --llm-local --policy policy.yml --no-cache --path /your/project # Custom cache directory python -m ai_slop_gate.cli run --provider groq --llm-local --policy policy.yml --cache-dir /tmp/cache --path /your/project ``` ## Docker 支持 ``` docker pull ghcr.io/sergudo/ai-slop-gate:latest docker run --rm -v $(pwd):/src \ ghcr.io/sergudo/ai-slop-gate:latest \ run --provider static --policy /src/policy.yml --path /src ``` 本地构建并运行: ``` docker build --no-cache -t ai-slop-gate:latest . docker run --rm \ -v /path_your_local_test_repo:/data \ ai-slop-gate:latest \ run --provider static --policy policy.yml --path /data ``` 完整 Docker 文档:[docs/source/DOCKER.md](docs/source/DOCKER.md) ## CI/CD 集成 ### GitHub Actions 示例工作流: - [静态分析示例工作流](docs/source/examples/example_workflow_static.yml) - [Gemini 分析示例工作流](docs/source/examples/example_workflow_gemini.yml) - [Groq 分析示例工作流](docs/source/examples/example_workflow_groq.yml) - [合规性分析示例工作流](docs/source/examples/example_workflow_compliance.yml) ### GitLab CI/CD 示例工作流: - [Gitlab CI 示例工作流](docs/source/examples/.gitlab-ci.yml) 完整集成指南:[docs/source/INTEGRATIONS.md](docs/source/INTEGRATIONS.md) **实时示例:** 查看 [此 PR](https://github.com/SergUdo/slop_test/pull/2),ai-slop-gate 在违规处自动发表了评论。 ## 测试 ``` # Run all tests python -m pytest ai_slop_gate/tests -v # With coverage python -m pytest ai_slop_gate/tests \ --cov=ai_slop_gate \ --cov-report=term-missing \ --cov-report=html ``` ## 验证镜像签名 **获取公钥** 公钥 `cosign.pub` 位于此仓库的根目录中。如果您尚未克隆仓库,可以手动下载密钥: `curl -O https://raw.githubusercontent.com/sergudo/ai-slop-gate/main/cosign.pub` **运行验证** 使用以下命令验证特定版本(例如 `1.2.2`)的签名。 ``` # Verify the image using the local cosign.pub file cosign verify --key cosign.pub ghcr.io/sergudo/ai-slop-gate:1.2.2 ``` **预期输出** 成功的验证将返回一个包含关键身份和签名详细信息的 JSON 对象,确认: 镜像摘要与签名匹配。 签名是使用受信任的私钥创建的。 ## 贡献 - [架构概览](docs/source/ARCHITECTURE.md) - [贡献指南](docs/source/CONTRIBUTING.md) ## 许可证 MIT License © 2025 Vira Udovychenko。参见 [LICENSE](LICENSE)。 ## 支持 - [文档](https://ai-slop-gate.readthedocs.io/) - [Issue Tracker](https://github.com/SergUdo/ai-slop-gate/issues)
标签:AI生成代码, AI风险缓解, CI/CD工具, Claude, CVE检测, DevSecOps, DLL 劫持, Docker容器, Gemini, LLM评估, Ollama, SBOM生成, 上游代理, 云安全监控, 人工智能辅助, 代码安全, 代码审查, 大语言模型, 攻击面发现, 漏洞枚举, 自动化门禁, 许可证审计, 请求拦截, 逆向工具, 静态分析