KevinRabun/judges

GitHub: KevinRabun/judges

基于 MCP 协议的 39 维度 AI 代码评审服务器,结合模式匹配与 AST 分析实现即时离线审查,并可触发 LLM 深度分析。

Stars: 5 | Forks: 0

# 评委团 (Judges Panel) 一个 MCP (Model Context Protocol) 服务器,提供由 **39 位专业评委** 组成的评审团,用于评估 AI 生成的代码——无论审查哪个项目,都作为一个独立的质量关卡。结合了 **确定性模式匹配与 AST 分析**(即时、离线、零 LLM 调用)以及 **LLM 驱动的深度审查提示**,让你的 AI 助手在所有 39 个领域执行专家级角色分析。 **亮点:** - 包含 **应用构建器工作流 (3 步)** 演示,用于发布决策、通俗语言风险摘要和优先级修复——请参阅 [试用演示](#2-try-the-demo)。 - 包含 **V2 上下文感知评估**,具备策略配置文件、证据校准、专业反馈、置信度评分和不确定性报告。 - 包含 **公共仓库 URL 报告**,可克隆仓库、运行完整评审团并输出合并的 Markdown 报告。 [![CI](https://github.com/KevinRabun/judges/actions/workflows/ci.yml/badge.svg)](https://github.com/KevinRabun/judges/actions/workflows/ci.yml) [![npm](https://img.shields.io/npm/v/@kevinrabun/judges)](https://www.npmjs.com/package/@kevinrabun/judges) [![npm downloads](https://img.shields.io/npm/dw/@kevinrabun/judges)](https://www.npmjs.com/package/@kevinrabun/judges) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Tests](https://img.shields.io/badge/tests-1666-brightgreen)](https://github.com/KevinRabun/judges/actions) ## 为什么选择 Judges? AI 代码生成器(Copilot、Cursor、Claude、ChatGPT 等)编写代码速度很快——但它们经常产生 **不安全的默认设置、缺失认证、硬编码机密和糟糕的错误处理**。人工审查者可以发现其中一些问题,但没有人能始终如一地审查 39 个维度。 | | ESLint / Biome | SonarQube | Semgrep / CodeQL | **Judges** | |---|---|---|---|---| | **范围** | 风格 + 部分错误 | 错误 + 代码异味 | 安全模式 | **39 个领域**:安全、成本、合规、无障碍 (a11y)、API 设计、云、用户体验 (UX) 等 | | **AI 生成代码重点** | 否 | 否 | 部分 | **专为** AI 输出失效模式**构建** | | **设置** | 每个项目配置 | 服务器 + 扫描器 | 云端或本地 | **一条命令**:`npx @kevinrabun/judges eval file.ts` | | **自动修复补丁** | 部分 | 否 | 否 | **114 个确定性补丁** —— 即时、离线 | | **非技术性输出** | 否 | 仪表板 | 否 | **通俗语言发现**,包含 问题/原因/下一步 | | **MCP 原生** | 否 | 否 | 否 | **是** —— 在 Copilot、Claude、Cursor 内部工作 | | **SARIF 输出** | 否 | 是 | 是 | **是** —— 上传至 GitHub Code Scanning | | **成本** | 免费 | $$$$ | 免费/付费 | **免费 / MIT** | **Judges 不能替代 Linter**——它覆盖了 Linter 未覆盖的维度:认证策略、数据主权、成本模式、无障碍性、框架特定的反模式以及跨多个文件的架构问题。

Judges — Terminal Output

## 快速开始 ### 立即试用(无需克隆) ``` # 全局安装 npm install -g @kevinrabun/judges # 评估任意文件 judges eval src/app.ts # 从 stdin 管道输入 cat api.py | judges eval --language python # 单一 judge judges eval --judge cybersecurity server.ts # 面向 CI 的 SARIF 输出 judges eval --file app.ts --format sarif > results.sarif # 包含严重性过滤器和深色/浅色主题的 HTML 报告 judges eval --file app.ts --format html > report.html # 基于发现结果中断 CI (exit code 1) judges eval --fail-on-findings src/api.ts # 通过 baseline 抑制已知发现 judges eval --baseline baseline.json src/api.ts # 使用命名 preset judges eval --preset security-only src/api.ts # 使用配置文件 judges eval --config .judgesrc.json src/api.ts # 设置最低分数阈值 (若低于则 exit 1) judges eval --min-score 80 src/api.ts # 用于脚本的摘要 judges eval --summary src/api.ts # 列出所有 39 个 judges judges list ``` ### 其他 CLI 命令 ``` # 交互式项目设置向导 judges init # 预览自动修复补丁 (dry run) judges fix src/app.ts # 直接应用补丁 judges fix src/app.ts --apply # Watch 模式 — 文件保存时重新评估 judges watch src/ # 项目级报告 (本地目录) judges report . --format html --output report.html # 评估 unified diff (从 git diff 管道输入) git diff HEAD~1 | judges diff # 分析依赖项的供应链风险 judges deps --path . --format json # 创建 baseline 文件以抑制已知发现 judges baseline create --file src/api.ts -o baseline.json # 生成 CI 模板文件 judges ci-templates --provider github judges ci-templates --provider gitlab judges ci-templates --provider azure judges ci-templates --provider bitbucket # 生成每个 judge 的规则文档 judges docs judges docs --judge cybersecurity judges docs --output docs/ # 安装 shell completions judges completions bash # eval "$(judges completions bash)" judges completions zsh judges completions fish judges completions powershell # 安装 pre-commit hook judges hook install # 卸载 pre-commit hook judges hook uninstall ``` ### 在 GitHub Actions 中使用 零配置将 Judges 添加到你的 CI 流水线: ``` # .github/workflows/judges.yml name: Judges Code Review on: [pull_request] jobs: judges: runs-on: ubuntu-latest permissions: contents: read security-events: write # only if using upload-sarif steps: - uses: actions/checkout@v4 - uses: KevinRabun/judges@main with: path: src/api.ts # file or directory format: text # text | json | sarif | markdown upload-sarif: true # upload to GitHub Code Scanning fail-on-findings: true # fail CI on critical/high findings ``` 可供下游步骤使用的 **输出**:`verdict`、`score`、`findings`、`critical`、`high`、`sarif-file`。 ### 使用 Docker(无需 Node.js) ``` # 构建镜像 docker build -t judges . # 评估本地文件 docker run --rm -v $(pwd):/code judges eval --file /code/app.ts # 从 stdin 管道输入 cat api.py | docker run --rm -i judges eval --language python # 列出 judges docker run --rm judges list ``` ### 或者用作 MCP 服务器 ### 1. 安装并构建 ``` git clone https://github.com/KevinRabun/judges.git cd judges npm install npm run build ``` ### 2. 试用演示 运行包含的演示,查看所有 39 位评委评估一个故意充满漏洞的 API 服务器: ``` npm run demo ``` 这将评估 [`examples/sample-vulnerable-api.ts`](examples/sample-vulnerable-api.ts) —— 一个故意包含安全漏洞、性能反模式和代码质量问题的文件 —— 并打印完整的裁决,包含每位评委的评分和发现。 该演示现在还包含一个 **应用构建器工作流 (3 步)** 部分。在单次运行中,你可以同时获得评审团输出和工作流输出: - 发布决策 (`Ship now` / `Ship with caution` / `Do not ship`) - 主要风险的通俗语言摘要 - 优先级修复任务和 AI 可修复的 `P0/P1` 项目 **示例工作流输出(已截断):** ``` ╔══════════════════════════════════════════════════════════════╗ ║ App Builder Workflow Demo (3-Step) ║ ╚══════════════════════════════════════════════════════════════╝ Decision : Do not ship Verdict : FAIL (47/100) Risk Counts : Critical 24 | High 27 | Medium 55 Step 2 — Plain-Language Findings: - [CRITICAL] DATA-001: Hardcoded password detected What: ... Why : ... Next: ... Step 3 — Prioritized Tasks: - P0 | DEVELOPER | Effort L | DATA-001 Task: ... Done: ... AI-Fixable Now (P0/P1): - P0 DATA-001: ... ``` **示例评审团输出(已截断):** ``` ╔══════════════════════════════════════════════════════════════╗ ║ Judges Panel — Full Tribunal Demo ║ ╚══════════════════════════════════════════════════════════════╝ Overall Verdict : FAIL Overall Score : 43/100 Critical Issues : 15 High Issues : 17 Total Findings : 83 Judges Run : 33 Per-Judge Breakdown: ──────────────────────────────────────────────────────────────── ❌ Judge Data Security 0/100 7 finding(s) ❌ Judge Cybersecurity 0/100 7 finding(s) ❌ Judge Cost Effectiveness 52/100 5 finding(s) ⚠️ Judge Scalability 65/100 4 finding(s) ❌ Judge Cloud Readiness 61/100 4 finding(s) ❌ Judge Software Practices 45/100 6 finding(s) ❌ Judge Accessibility 0/100 8 finding(s) ❌ Judge API Design 0/100 9 finding(s) ❌ Judge Reliability 54/100 3 finding(s) ❌ Judge Observability 45/100 5 finding(s) ❌ Judge Performance 27/100 5 finding(s) ❌ Judge Compliance 0/100 4 finding(s) ⚠️ Judge Testing 90/100 1 finding(s) ⚠️ Judge Documentation 70/100 4 finding(s) ⚠️ Judge Internationalization 65/100 4 finding(s) ⚠️ Judge Dependency Health 90/100 1 finding(s) ❌ Judge Concurrency 44/100 4 finding(s) ❌ Judge Ethics & Bias 65/100 2 finding(s) ❌ Judge Maintainability 52/100 4 finding(s) ❌ Judge Error Handling 27/100 3 finding(s) ❌ Judge Authentication 0/100 4 finding(s) ❌ Judge Database 0/100 5 finding(s) ❌ Judge Caching 62/100 3 finding(s) ❌ Judge Configuration Mgmt 0/100 3 finding(s) ⚠️ Judge Backwards Compat 80/100 2 finding(s) ⚠️ Judge Portability 72/100 2 finding(s) ❌ Judge UX 52/100 4 finding(s) ❌ Judge Logging Privacy 0/100 4 finding(s) ❌ Judge Rate Limiting 27/100 4 finding(s) ⚠️ Judge CI/CD 80/100 2 finding(s) ``` ### 3. 运行测试 ``` npm test ``` 运行覆盖所有评委、AST 解析器、Markdown 格式化程序和边缘情况的自动化测试。 ### 4. 连接到你的编辑器 #### VS Code(推荐——零配置) 从市场安装 **[Judges Panel](https://marketplace.visualstudio.com/items?itemName=kevinrabun.judges-panel)** 扩展。它提供: - 每次文件保存时的 **内联诊断与快速修复** - **`@judges` 聊天参与者** —— 在 Copilot Chat 中输入 `@judges`,或直接请求 "judges panel review",Copilot 会自动路由 - **自动配置的 MCP 服务器** —— 所有 39 个专家角色提示对 Copilot 可用,零设置 ``` code --install-extension kevinrabun.judges-panel ``` #### VS Code —— 手动 MCP 配置 如果你更喜欢显式的工作区配置(或者希望没有扩展的队友也能受益),创建 `.vscode/mcp.json`: ``` { "servers": { "judges": { "command": "npx", "args": ["-y", "@kevinrabun/judges"] } } } ``` #### Claude Desktop 添加到 `claude_desktop_config.json`: ``` { "mcpServers": { "judges": { "command": "npx", "args": ["-y", "@kevinrabun/judges"] } } } ``` #### Cursor / 其他 MCP 客户端 对任何兼容 MCP 的客户端使用相同的 `npx` 命令: ``` { "command": "npx", "args": ["-y", "@kevinrabun/judges"] } ``` ### 5. 在 GitHub Copilot PR 审查中使用 Judges 是的——用户可以将 Judges 作为基于 GitHub 的审查工作流的一部分,但有一个重要的注意事项: - GitHub 上托管的 `copilot-pull-request-reviewer` 目前不允许像 VS Code 那样直接附加任意本地 MCP 服务器。 - 实用的模式是在 CI 中针对每个 PR 运行 Judges,发布报告/检查,并让 Copilot + 人工审查者在审查期间使用该输出。 #### 选项 A(推荐):PR 工作流检查 + 报告工件 创建 `.github/workflows/judges-pr-review.yml`: ``` name: Judges PR Review on: pull_request: types: [opened, synchronize, reopened] jobs: judges: runs-on: ubuntu-latest permissions: contents: read pull-requests: write steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 cache: npm - name: Install run: npm ci - name: Generate Judges report run: | npx tsx -e "import { generateRepoReportFromLocalPath } from './src/reports/public-repo-report.ts'; const result = generateRepoReportFromLocalPath({ repoPath: process.cwd(), outputPath: 'judges-pr-report.md', maxFiles: 600, maxFindingsInReport: 150, }); console.log('Overall:', result.overallVerdict, result.averageScore);" - name: Upload report artifact uses: actions/upload-artifact@v4 with: name: judges-pr-report path: judges-pr-report.md ``` 这为每个 PR 提供了你的团队(和 Copilot)可以引用的可复现 Judges 输出。 #### 选项 B:在仓库中添加 Copilot 自定义指令 添加 `.github/instructions/judges.instructions.md`,包含如下指导: ``` When reviewing pull requests: 1. Read the latest Judges report artifact/check output first. 2. Prioritize CRITICAL and HIGH findings in remediation guidance. 3. If findings conflict, defer to security/compliance-related Judges. 4. Include rule IDs (e.g., DATA-001, CYBER-004) in suggested fixes. ``` 这有助于保持 Copilot 反馈与 Judges 发现的一致性。 ## CLI 参考 所有命令都支持 `--help` 以获取用法详情。 ### `judges eval` 使用所有 39 位评委或单个评委评估文件。 | 标志 | 描述 | |------|-------------| | `--file ` / 位置参数 | 要评估的文件 | | `--judge ` / `-j ` | 单评委模式 | | `--language ` / `-l ` | 语言提示(根据扩展名自动检测) | | `--format ` / `-f ` | 输出格式:`text`、`json`、`sarif`、`markdown`、`html`、`junit`、`codeclimate` | | `--output ` / `-o ` | 将输出写入文件 | | `--fail-on-findings` | 如果裁决为 FAIL 则以代码 1 退出 | | `--baseline ` / `-b ` | JSON 基线文件 —— 抑制已知发现 | | `--summary` | 打印单行摘要(适用于脚本) | | `--config ` | 加载 `.judgesrc` / `.judgesrc.json` 配置文件 | | `--preset ` | 使用命名预设:`strict`、`lenient`、`security-only`、`startup`、`compliance`、`performance` | | `--min-score ` | 如果总分低于此阈值则以代码 1 退出 | | `--verbose` | 打印计时和调试信息 | | `--quiet` | 抑制非必要输出 | | `--no-color` | 禁用 ANSI 颜色 | ### `judges init` 生成项目配置的交互式向导: - `.judgesrc.json` —— 规则自定义、禁用的评委、严重性阈值 - `.github/workflows/judges.yml` —— GitHub Actions CI 工作流 - `.gitlab-ci.judges.yml` —— GitLab CI 流水线(可选) - `azure-pipelines.judges.yml` —— Azure Pipelines(可选) ### `judges fix` 预览或应用来自确定性发现的自动修复补丁。 | 标志 | 描述 | |------|-------------| | 位置参数 | 要修复的文件 | | `--apply` | 将补丁写入磁盘(默认:dry run) | | `--judge ` | 限制为单个评委的发现 | ### `judges watch` 保存时持续重新评估文件。 | 标志 | 描述 | |------|-------------| | 位置参数 | 要监视的文件或目录(默认:`.`) | | `--judge ` | 单评委模式 | | `--fail-on-findings` | 如果任何评估失败则非零退出 | ### `judges report` 在本地目录上运行完整的项目级评审团。 | 标志 | 描述 | |------|-------------| | 位置参数 | 目录路径(默认:`.`) | | `--format ` | 输出格式:`text`、`json`、`html`、`markdown` | | `--output ` | 将报告写入文件 | | `--max-files ` | 最大分析文件数(默认:600) | | `--max-file-bytes ` | 跳过大于此大小的文件(默认:300000) | ### `judges hook` 管理在暂存文件上运行 Judges 的 Git pre-commit hook。 ``` judges hook install # add pre-commit hook judges hook uninstall # remove pre-commit hook ``` 检测 Husky (`.husky/pre-commit`) 并回退到 `.git/hooks/pre-commit`。使用基于标记的注入,因此不会破坏现有的 hooks。 ### `judges diff` 仅评估统一 diff(例如 `git diff` 输出)中的更改行。 | 标志 | 描述 | |------|-------------| | `--file ` | 从文件而非 stdin 读取 diff | | `--format ` | 输出格式:`text`、`json`、`sarif`、`junit`、`codeclimate` | | `--output ` | 将输出写入文件 | ``` git diff HEAD~1 | judges diff judges diff --file changes.patch --format sarif ``` ### `judges deps` 分析项目依赖项的供应链风险。 | 标志 | 描述 | |------|-------------| | `--path ` | 要扫描的项目根目录(默认:`.`) | | `--format ` | 输出格式:`text`、`json` | ``` judges deps --path . judges deps --path ./backend --format json ``` ### `judges baseline` 创建一个基线文件以在未来的评估中抑制已知发现。 ``` judges baseline create --file src/api.ts judges baseline create --file src/api.ts -o .judges-baseline.json ``` ### `judges ci-templates` 为流行提供商生成 CI/CD 配置模板。 ``` judges ci-templates --provider github # .github/workflows/judges.yml judges ci-templates --provider gitlab # .gitlab-ci.judges.yml judges ci-templates --provider azure # azure-pipelines.judges.yml judges ci-templates --provider bitbucket # bitbucket-pipelines.yml (snippet) ``` ### `judges docs` 以 Markdown 格式生成每位评委的规则文档。 | 标志 | 描述 | |------|-------------| | `--judge ` | 为单个评委生成文档 | | `--output ` | 为每位评委写入单独的 `.md` 文件 | ``` judges docs # all judges to stdout judges docs --judge cybersecurity # single judge judges docs --output docs/judges/ # write files to directory ``` ### `judges completions` 生成 Shell 补全脚本。 ``` eval "$(judges completions bash)" # Bash eval "$(judges completions zsh)" # Zsh judges completions fish | source # Fish judges completions powershell # PowerShell (Register-ArgumentCompleter) ``` ### 命名预设 使用 `--preset` 应用预配置的评估设置: | 预设 | 描述 | |--------|-------------| | `strict` | 所有严重性、所有评委 —— 最大彻底性 | | `lenient` | 仅高和严重发现 —— 快速且专注 | | `security-only` | 仅安全评委 —— cybersecurity、data-security、authentication、logging-privacy | | `startup` | 跳过 compliance、sovereignty、i18n 评委 —— 快速行动 | | `compliance` | 仅 compliance、data-sovereignty、authentication —— 监管重点 | | `performance` | 仅 performance、scalability、caching、cost-effectiveness | ``` judges eval --preset security-only src/api.ts judges eval --preset strict --format sarif src/app.ts > results.sarif ``` ### CI 输出格式 #### JUnit XML 为 Jenkins、Azure DevOps、GitHub Actions 或 GitLab 测试结果查看器生成 JUnit XML: ``` judges eval --format junit src/api.ts > results.xml ``` 每位评委映射到一个 ``,每个发现成为一个 ``,严重/高严重性的带有 ``。 #### CodeClimate / GitLab Code Quality 为 GitLab Code Quality 或类似工具生成 CodeClimate JSON: ``` judges eval --format codeclimate src/api.ts > codequality.json ``` #### 分数徽章 为你的 README 生成 SVG 或徽章: ``` import { generateBadgeSvg, generateBadgeText } from "@kevinrabun/judges/badge"; const svg = generateBadgeSvg(85); // shields.io-style SVG const text = generateBadgeText(85); // "✓ judges 85/100" const svg2 = generateBadgeSvg(75, "quality"); // custom label ``` ## 评委组 | 评委 | 领域 | 规则前缀 | 评估内容 | |-------|--------|-------------|-------------------| | **Data Security** | 数据安全与隐私 | `DATA-` | 加密、PII 处理、机密管理、访问控制 | | **Cybersecurity** | 网络安全与威胁防御 | `CYBER-` | 注入攻击、XSS、CSRF、认证缺陷、OWASP Top 10 | | **Cost Effectiveness** | 成本优化 | `COST-` | 算法效率、N+1 查询、内存浪费、缓存策略 | | **Scalability** | 可扩展性与性能 | `SCALE-` | 无状态性、水平扩展、并发、瓶颈 | | **Cloud Readiness** | 云原生与 DevOps | `CLOUD-` | 12-Factor 合规性、容器化、优雅关闭、IaC | | **Software Practices** | 工程最佳实践 | `SWDEV-` | SOLID 原则、类型安全、错误处理、输入验证 | | **Accessibility** | 无障碍 (a11y) | `A11Y-` | WCAG 合规性、屏幕阅读器支持、键盘导航、ARIA | | **API Design** | API 设计与契约 | `API-` | REST 约定、版本控制、分页、错误响应 | | **Reliability** | 可靠性与弹性 | `REL-` | 错误处理、超时、重试、熔断器 | | **Observability** | 可观测性与监控 | `OBS-` | 结构化日志、健康检查、指标、追踪 | | **Performance** | 性能与效率 | `PERF-` | N+1 查询、同步 I/O、缓存、内存泄漏 | | **Compliance** | 监管合规 | `COMP-` | GDPR/CCPA、PII 保护、同意、数据保留、审计追踪 | | **Data Sovereignty** | 数据、技术与运营主权 | `SOV-` | 数据驻留、跨境传输、供应商密钥管理、AI 模型可移植性、身份联合、熔断器、审计追踪、数据导出 | | **Testing** | 测试与质量保证 | `TEST-` | 测试覆盖率、断言、测试隔离、命名 | | **Documentation** | 文档与可读性 | `DOC-` | JSDoc/docstrings、魔法数字、TODOs、代码注释 | | **Internationalization** | 国际化 (i18n) | `I18N-` | 硬编码字符串、区域设置处理、货币格式化 | | **Dependency Health** | 依赖管理 | `DEPS-` | 版本固定、已弃用的包、供应链 | | **Concurrency** | 并发与异步安全 | `CONC-` | 竞争条件、无限制并行、缺失 await | | **Ethics & Bias** | 伦理与偏见 | `ETHICS-` | 人口统计逻辑、暗模式、包容性语言 | | **Maintainability** | 代码可维护性与技术债务 | `MAINT-` | Any 类型、魔法数字、深层嵌套、死代码、文件长度 | | **Error Handling** | 错误处理与容错 | `ERR-` | 空 catch 块、缺失错误处理器、吞掉错误 | | **Authentication** | 认证与授权 | `AUTH-` | 硬编码凭据、缺失认证中间件、查询参数中的 token | | **Database** | 数据库设计与查询效率 | `DB-` | SQL 注入、N+1 查询、连接池、事务 | | **Caching** | 缓存策略与数据新鲜度 | `CACHE-` | 无限制缓存、缺失 TTL、无 HTTP 缓存头 | | **Configuration Mgmt** | 配置与机密管理 | `CFG-` | 硬编码机密、缺失环境变量、配置验证 | | **Backwards Compat** | 向后兼容性与版本控制 | `COMPAT-` | API 版本控制、破坏性变更、响应一致性 | | **Portability** | 平台可移植性与供应商独立性 | `PORTA-` | 操作系统特定路径、供应商锁定、硬编码主机 | | **UX** | 用户体验与界面质量 | `UX-` | 加载状态、错误消息、分页、破坏性操作 | | **Logging Privacy** | 日志隐私与数据脱敏 | `LOGPRIV-` | 日志中的 PII、token 日志、结构化日志、脱敏 | | **Rate Limiting** | 速率限制与节流 | `RATE-` | 缺失速率限制、无限制查询、退避策略 | | **CI/CD** | CI/CD 流水线与部署安全 | `CICD-` | 测试基础设施、Lint 配置、Docker 标签、构建脚本 | | **Code Structure** | 结构分析 (AST) | `STRUCT-` | 圈复杂度、嵌套深度、函数长度、死代码、类型安全 | | **Agent Instructions** | Agent 指令 Markdown 质量与安全 | `AGENT-` | 指令层级、冲突检测、不安全覆盖、作用域、验证、策略指导 | | **AI Code Safety** | AI 生成代码安全 | `AICS-` | 提示注入、不安全的 LLM 输出处理、调试默认值、缺失验证、AI 响应的不安全反序列化 | | **Framework Safety** | 框架特定安全 | `FW-` | React hooks 排序、Express 中间件链、Next.js SSR/SSG 陷阱、Angular/Vue 生命周期模式、框架特定反模式 | | **IaC Security** | 基础设施即代码 | `IAC-` | Terraform、Bicep、ARM 模板配置错误、硬编码机密、缺失加密、过于宽松的网络/IAM 规则 | | **False-Positive Review** | 误报检测与发现准确性 | `FPR-` | 审查基于模式的发现是否有误报的元评委:字符串字面量上下文、注释/docstring 匹配、测试脚手架、IaC 模板门控 | ## 工作原理 评审团在三个层面上运作: 1. **基于模式的分析** —— 所有工具(`evaluate_code`、`evaluate_code_single_judge`、`evaluate_project`、`evaluate_diff`)使用正则表达式模式匹配进行启发式分析,以捕获常见的反模式。这一层是即时的、确定性的,并且完全离线运行,无需外部 API 调用。 2. **基于 AST 的结构分析** —— 代码结构评委(`STRUCT-*` 规则)使用真正的抽象语法树解析来测量圈复杂度、嵌套深度、函数长度、参数计数、死代码和类型安全,其精度是正则表达式无法达到的。所有支持的语言 —— **TypeScript、JavaScript、Python、Rust、Go、Java、C# 和 C++** —— 都通过 **tree-sitter WASM 文法** 进行解析(编译为 WebAssembly 的真正语法树,进程内,零原生依赖)。当 WASM 文法不可用时,保留范围跟踪结构解析器作为回退。不需要外部 AST 服务器。 3. **LLM 驱动的深度分析(提示)** —— 服务器公开 MCP 提示(例如 `judge-data-security`、`full-tribunal`),将每位评委的专家角色作为系统提示提供。当基于 LLM 的客户端(Copilot、Claude、Cursor 等)使用时,宿主 LLM 执行更深层次的、上下文感知的概率分析,超越静态模式所能检测的范围。这就是每位评委的 `systemPrompt` 活跃起来的地方——Judges 本身不进行 LLM 调用,但它提供专家标准,以便你的 AI 助手可以充当 39 位专业审查者。 ## 设计上的可组合性 Judges Panel 是一个 **双层** 审查系统:用于模式和 AST 分析的即时 **确定性工具**(离线,无 API 密钥),加上 **39 个专家角色 MCP 提示**,在连接到 AI 客户端时解锁 LLM 驱动的深度分析。它不试图成为 CVE 扫描器或 Linter。这些能力属于专用的 MCP 服务器,AI Agent 可以与 Judges 一起编排。 ### 内置 AST 分析 (v2.0.0+) 与推荐单独 AST MCP 服务器的早期版本不同,Judges Panel 现在开箱即用地包含 **真正的基于 AST 的结构分析**: - **TypeScript、JavaScript、Python、Rust、Go、Java、C#、C++** —— 全部通过 **统一的 tree-sitter WASM 引擎** 解析,进行完整的语法树分析(函数、复杂度、嵌套、死代码、类型安全)。当 WASM 文法不可用时回退到范围跟踪结构解析器 代码结构评委(`STRUCT-*`)使用这些解析器准确测量: | 规则 | 指标 | 阈值 | |------|--------|-----------| | `STRUCT-001` | 圈复杂度 | 每个函数 > 10(高) | | `STRUCT-002` | 嵌套深度 | > 4 层(中) | | `STRUCT-003` | 函数长度 | > 50 行(中) | | `STRUCT-004` | 参数计数 | > 5 个参数(中) | | `STRUCT-005` | 死代码 | 不可达语句(低) | | `STRUCT-006` | 弱类型 | `any`、`dynamic`、`Object`、`interface{}`、`unsafe`(中) | | `STRUCT-007` | 文件复杂度 | 总圈复杂度 > 40(高) | | `STRUCT-008` | 极端复杂度 | 每个函数 > 20(严重) | | `STRUCT-009` | 极端参数 | > 8 个参数(高) | | `STRUCT-010` | 极端函数长度 | > 150 行(高) | ### 推荐的 MCP 技术栈 当你的 AI 编码助手连接到多个 MCP 服务器时,每个服务器贡献其专业能力: ``` ┌─────────────────────────────────────────────────────────┐ │ AI Coding Assistant │ │ (Claude, Copilot, Cursor, etc.) │ └──────┬──────────────────┬──────────┬───────────────────┘ │ │ │ ▼ ▼ ▼ ┌──────────────┐ ┌────────┐ ┌────────┐ │ Judges │ │ CVE / │ │ Linter │ │ Panel │ │ SBOM │ │ Server │ │ ─────────────│ └────────┘ └────────┘ │ 36 Heuristic │ Vuln DB Style & │ judges │ scanning correctness │ + AST judge │ └──────────────┘ Patterns + structural analysis ``` | 层 | 作用 | 示例服务器 | |-------|-------------|-----------------| | **Judges Panel** | 39 位评委质量关卡 —— 安全模式、AST 分析、成本、可扩展性、a11y、合规、主权、伦理、依赖健康、Agent 指令治理、AI 代码安全、框架安全 | 本服务器 | | **CVE / SBOM** | 针对实时数据库的漏洞扫描 —— 已知 CVE、许可证风险、供应链 | OSV、Snyk、Trivy、Grype MCP 服务器 | | **Linting** | 特定语言的风格和正确性规则 | ESLint、Ruff、Clippy MCP 服务器 | | **Runtime Profiling** | 运行代码的内存、CPU、延迟测量 | 自定义 profiling MCP 服务器 | ### 实际意义 当你问 AI 助手 *"这段代码准备好投入生产了吗?"*,Agent 可以: 1. **Judges Panel** → 扫描硬编码机密、缺失错误处理、N+1 查询、无障碍差距、合规问题,**并** 通过 AST 分析圈复杂度、检测死代码并标记深层嵌套函数 2. **CVE Server** → 根据 `package.json` 中的已知漏洞检查每个依赖项 3. **Linter Server** → 强制执行团队风格规则,捕获特定语言的陷阱 每个服务器返回结构化的发现。AI 将所有内容综合成一个可操作的审查——没有单个服务器需要包办一切。 ## MCP 工具 ### `evaluate_v2` 运行 **V2 上下文感知评审团评估**,旨在将反馈质量提升至首席工程师/架构师级别的审查: - 策略配置文件校准(`default`、`startup`、`regulated`、`healthcare`、`fintech`、`public-sector`) - 上下文摄取(架构说明、约束、标准、已知风险、数据边界模型) - 运行时证据挂钩(测试、覆盖率、延迟、错误率、漏洞计数) - 按评委/领域聚合的专业反馈 - 置信度评分和显式不确定性报告 支持: - **代码模式**:`code` + `language` - **项目模式**:`files[]` | 参数 | 类型 | 必需 | 描述 | |-----------|------|----------|-------------| | `code` | string | 条件性 | 单文件模式的源代码 | | `language` | string | 条件性 | 单文件模式的编程语言 | | `files` | array | 条件性 | 项目模式的 `{ path, content, language }[]` | | `context` | string | 否 | 高层审查上下文 | | `includeAstFindings` | boolean | 否 | 包含 AST/代码结构发现(默认:true) | | `minConfidence` | number | 否 | 要包含的最小发现置信度(0-1,默认:0) | | `policyProfile` | enum | 否 | `default`、`startup`、`regulated`、`healthcare`、`fintech`、`public-sector | | `evaluationContext` | object | 否 | 结构化架构/约束上下文 | | `evidence` | object | 否 | 用于置信度校准的运行时/运营证据 | ### `evaluate_app_builder_flow` 为技术和非技术利益相关者运行 **3 步应用构建器工作流**: 1. 评审团审查(代码/项目/diff) 2. 主要风险的通俗语言翻译 3. 包含 AI 可修复 P0/P1 提取的优先级修复任务 支持: - **代码模式**:`code` + `language` - **项目模式**:`files[]` - **Diff 模式**:`code` + `language` + `changedLines[]` | 参数 | 类型 | 必需 | 描述 | |-----------|------|----------|-------------| | `code` | string | 条件性 | 完整源内容(代码/diff 模式) | | `language` | string | 条件性 | 编程语言(代码/diff 模式) | | `files` | array | 条件性 | 项目模式的 `{ path, content, language }[]` | | `changedLines` | number[] | 否 | Diff 模式的 1 起始更改行 | | `context` | string | 否 | 可选的业务/技术上下文 | | `maxFindings` | number | 否 | 最大翻译顶级发现数(默认:10) | | `maxTasks` | number | 否 | 最大生成任务数(默认:20) | | `includeAstFindings` | boolean | 否 | 包含 AST/代码结构发现(默认:true) | | `minConfidence` | number | 否 | 要包含的最小发现置信度(0-1,默认:0) | ### `evaluate_public_repo_report` 克隆 **公共仓库 URL**,在符合条件的源文件上运行完整评委组,并生成合并的 Markdown 报告。 | 参数 | 类型 | 必需 | 描述 | |-----------|------|----------|-------------| | `repoUrl` | string | 是 | 公共仓库 URL(`https://...`) | | `branch` | string | 否 | 可选分支名称 | | `outputPath` | string | 否 | 写入报告 Markdown 的可选路径 | | `maxFiles` | number | 否 | 最大分析文件数(默认:600) | | `maxFileBytes` | number | 否 | 最大文件大小(字节)(默认:300000) | | `maxFindingsInReport` | number | 否 | 输出中最大详细发现数(默认:150) | | `credentialMode` | string | 否 | 凭据检测模式:`standard`(默认)或 `strict` | | `includeAstFindings` | boolean | 否 | 包含 AST/代码结构发现(默认:true) | | `minConfidence` | number | 否 | 要包含的最小发现置信度(0-1,默认:0) | | `enableMustFixGate` | boolean | 否 | 启用高置信度危险发现的必须修复关卡摘要(默认:false) | | `mustFixMinConfidence` | number | 否 | 必须修复关卡触发的置信度阈值(0-1,默认:0.85) | | `mustFixDangerousRulePrefixes` | string[] | 否 | 用于关卡匹配的可选危险规则前缀(例如 `AUTH`、`CYBER`、`DATA`) | | `keepClone` | boolean | 否 | 保留克隆的仓库在磁盘上以供检查 | **快速示例** 从 CLI 生成报告: ``` npm run report:public-repo -- --repoUrl https://github.com/microsoft/vscode --output reports/vscode-judges-report.md # 更严格的 credential-signal 模式(可选) npm run report:public-repo -- --repoUrl https://github.com/openclaw/openclaw --credentialMode strict --output reports/openclaw-judges-report-strict.md # 仅显示 judge 发现(排除 AST/代码结构发现) npm run report:public-repo -- --repoUrl https://github.com/openclaw/openclaw --includeAstFindings false --output reports/openclaw-judges-report-no-ast.md # 仅显示置信度 80%+ 的发现 npm run report:public-repo -- --repoUrl https://github.com/openclaw/openclaw --minConfidence 0.8 --output reports/openclaw-judges-report-high-confidence.md # 在生成的报告中包含 must-fix 门禁摘要 npm run report:public-repo -- --repoUrl https://github.com/openclaw/openclaw --enableMustFixGate true --mustFixMinConfidence 0.9 --mustFixDangerousPrefix AUTH --mustFixDangerousPrefix CYBER --output reports/openclaw-judges-report-mustfix.md # opinionated quick-start 模式(推荐首次运行) npm run report:quickstart -- --repoUrl https://github.com/openclaw/openclaw --output reports/openclaw-quickstart.md ``` 从 MCP 客户端调用: ``` { "tool": "evaluate_public_repo_report", "arguments": { "repoUrl": "https://github.com/microsoft/vscode", "branch": "main", "maxFiles": 400, "maxFindingsInReport": 120, "credentialMode": "strict", "includeAstFindings": false, "minConfidence": 0.8, "enableMustFixGate": true, "mustFixMinConfidence": 0.9, "mustFixDangerousRulePrefixes": ["AUTH", "CYBER", "DATA"], "outputPath": "reports/vscode-judges-report.md" } } ``` 典型响应摘要包括: - 总体裁决和平均分 - 分析的文件数和总发现数 - 每位评委的评分表 - 最高风险的发现和得分最低的文件 示例报告片段: ``` # 公共仓库完整 Judges 报告 Generated from https://github.com/microsoft/vscode on 2026-02-21T12:00:00.000Z. ## 执行摘要 - Overall verdict: WARNING - Average file score: 78/100 - Total findings: 412 (critical 3, high 29, medium 114, low 185, info 81) ``` ### `get_judges` 列出所有可用的评委及其领域和描述。 ### `evaluate_code` 将代码提交给 **完整评委组**。所有 39 位评委独立评估并返回合并的裁决。 | 参数 | 类型 | 必需 | 描述 | |-----------|------|----------|-------------| | `code` | string | 是 | 要评估的源代码 | | `language` | string | 是 | 编程语言(例如 `typescript`、`python`) | | `context` | string | 否 | 关于代码的附加上下文 | | `includeAstFindings` | boolean | 否 | 包含 AST/代码结构发现(默认:true) | | `minConfidence` | number | 否 | 要包含的最小发现置信度(0-1,默认:0) | | `config` | object | 否 | 内联配置(见 [配置](#configuration)) | ### `evaluate_code_single_judge` 将代码提交给 **特定评委** 进行针对性审查。 | 参数 | 类型 | 必需 | 描述 | |-----------|------|----------|-------------| | `code` | string | 是 | 要评估的源代码 | | `language` | string | 是 | 编程语言 | | `judgeId` | string | 是 | 见下方 [评委 ID](#judge-ids) | | `context` | string | 否 | 附加上下文 | | `minConfidence` | number | 否 | 要包含的最小发现置信度(0-1,默认:0) | | `config` | object | 否 | 内联配置(见 [配置](#configuration)) | ### `evaluate_project` 提交多个文件进行 **项目级分析**。所有 39 位评委评估每个文件,加上跨文件架构分析检测代码重复、不一致的错误处理和依赖循环。 | 参数 | 类型 | 必需 | 描述 | |-----------|------|----------|-------------| | `files` | array | 是 | `{ path, content, language }` 对象数组 | | `context` | string | 否 | 可选项目上下文 | | `includeAstFindings` | boolean | 否 | 包含 AST/代码结构发现(默认:true) | | `minConfidence` | number | 否 | 要包含的最小发现置信度(0-1,默认:0) | | `config` | object | 否 | 内联配置(见 [配置](#configuration)) | ### `evaluate_diff` 仅评估代码 diff 中的 **更改行**。在完整文件上运行所有 39 位评委,但将发现过滤到你指定的行。非常适合 PR 审查和增量分析。 | 参数 | 类型 | 必需 | 描述 | |-----------|------|----------|-------------| | `code` | string | 是 | 完整文件内容(更改后) | | `language` | string | 是 | 编程语言 | | `changedLines` | number[] | 是 | 已更改的 1 起始行号 | | `context` | string | 否 | 关于更改的可选上下文 | | `includeAstFindings` | boolean | 否 | 包含 AST/代码结构发现(默认:true) | | `minConfidence` | number | 否 | 要包含的最小发现置信度(0-1,默认:0) | | `config` | object | 否 | 内联配置(见 [配置](#configuration)) | ### `analyze_dependencies` 分析依赖清单文件的供应链风险、版本固定问题、typosquatting 指标和依赖项健康状况。支持 `package.json`、`requirements.txt`、`Cargo.toml`、`go.mod`、`pom.xml` 和 `.csproj` 文件。 | 参数 | 类型 | 必需 | 描述 | |-----------|------|----------|-------------| | `manifest` | string | 是 | 依赖清单文件的内容 | | `manifestType` | string | 是 | 文件类型:`package.json`、`requirements.txt` 等 | | `context` | string | 否 | 可选上下文 | #### 评委 ID `data-security` · `cybersecurity` · `cost-effectiveness` · `scalability` · `cloud-readiness` · `software-practices` · `accessibility` · `api-design` · `reliability` · `observability` · `performance` · `compliance` · `data-sovereignty` · `testing` · `documentation` · `internationalization` · `dependency-health` · `concurrency` · `ethics-bias` · `maintainability` · `error-handling` · `authentication` · `database` · `caching` · `configuration-management` · `backwards-compatibility` · `portability` · `ux` · `logging-privacy` · `rate-limiting` · `ci-cd` · `code-structure` · `agent-instructions` · `ai-code-safety` · `framework-safety` · `iac-security` · `false-positive-review` ## MCP 提示 每位评委都有一个用于 LLM 驱动深度分析的对应提示: | 提示 | 描述 | |--------|-------------| | `judge-data-security` | 深度数据安全审查 | | `judge-cybersecurity` | 深度网络安全审查 | | `judge-cost-effectiveness` | 深度成本优化审查 | | `judge-scalability` | 深度可扩展性审查 | | `judge-cloud-readiness` | 深度云就绪审查 | | `judge-software-practices` | 深度软件实践审查 | | `judge-accessibility` | 深度无障碍/WCAG 审查 | | `judge-api-design` | 深度 API 设计审查 | | `judge-reliability` | 深度可靠性与弹性审查 | | `judge-observability` | 深度可观测性与监控审查 | | `judge-performance` | 深度性能优化审查 | | `judge-compliance` | 深度监管合规审查 | | `judge-data-sovereignty` | 深度数据、技术与运营主权审查 | | `judge-testing` | 深度测试质量审查 | | `judge-documentation` | 深度文档质量审查 | | `judge-internationalization` | 深度 i18n 审查 | | `judge-dependency-health` | 深度依赖健康审查 | | `judge-concurrency` | 深度并发与异步安全审查 | | `judge-ethics-bias` | 深度伦理与偏见审查 | | `judge-maintainability` | 深度可维护性与技术债务审查 | | `judge-error-handling` | 深度错误处理审查 | | `judge-authentication` | 深度认证与授权审查 | | `judge-database` | 深度数据库设计与查询审查 | | `judge-caching` | 深度缓存策略审查 | | `judge-configuration-management` | 深度配置与机密审查 | | `judge-backwards-compatibility` | 深度向后兼容性审查 | | `judge-portability` | 深度平台可移植性审查 | | `judge-ux` | 深度用户体验审查 | | `judge-logging-privacy` | 深度日志隐私审查 | | `judge-rate-limiting` | 深度速率限制审查 | | `judge-ci-cd` | 深度 CI/CD 流水线审查 | | `judge-code-structure` | 深度基于 AST 的结构分析审查 | | `judge-agent-instructions` | 深度审查 Agent 指令 Markdown 质量和安全性 | | `judge-ai-code-safety` | 深度审查 AI 生成代码风险:提示注入、不安全的 LLM 输出处理、调试默认值、缺失验证 | | `judge-framework-safety` | 深度审查框架特定安全:React hooks、Express 中间件、Next.js SSR/SSG、Angular/Vue 模式 | | `judge-iac-security` | 深度审查基础设施即代码安全:Terraform、Bicep、ARM 模板配置错误 | | `judge-false-positive-review` | 审查基于模式的发现以检测误报和准确性的元评委审查 | | `full-tribunal` | 单个提示中的所有 39 位评委 | ## 配置 在项目根目录下创建 `.judgesrc.json`(或 `.judgesrc`)文件以自定义评估行为。请参阅 [`.judgesrc.example.json`](.judgesrc.example.json) 获取可复制粘贴的模板,或参考 [JSON Schema](judgesrc.schema.json) 获取完整的 IDE 自动补全。 ``` { "$schema": "https://github.com/KevinRabun/judges/blob/main/judgesrc.schema.json", "preset": "strict", "minSeverity": "medium", "disabledRules": ["COST-*", "I18N-001"], "disabledJudges": ["accessibility", "ethics-bias"], "ruleOverrides": { "SEC-003": { "severity": "critical" }, "DOC-*": { "disabled": true } }, "languages": ["typescript", "python"], "format": "text", "failOnFindings": false, "baseline": "" } ``` | 字段 | 类型 | 默认值 | 描述 | |-------|------|---------|-------------| | `$schema` | `string` | — | 用于 IDE 验证的 JSON Schema URL | | `preset` | `string` | — | 命名预设:`strict`、`lenient`、`security-only`、`startup`、`compliance`、`performance` | | `minSeverity` | `string` | `"info"` | 报告的最小严重性:`critical` · `high` · `medium` · `low` · `info` | | `disabledRules` | `string[]` | `[]` | 要抑制的规则 ID 或前缀通配符(例如 `"COST-*"`、`"SEC-003"`) | | `disabledJudges` | `string[]` | `[]` | 要跳过的评委 ID(例如 `"cost-effectiveness"`) | | `ruleOverrides` | `object` | `{}` | 按规则 ID 或通配符键控的按规则覆盖 —— `{ disabled?: boolean, severity?: string }` | | `languages` | `string[]` | `[]` | 将分析限制为特定语言(空 = 全部) | | `format` | `string` | `"text"` | 默认输出格式:`text` · `json` · `sarif` · `markdown` · `html` · `junit` · `codeclimate` | | `failOnFindings` | `boolean` | `false` | 当裁决为 `fail` 时退出代码 1 —— 对 CI 关卡有用 | | `baseline` | `string` | `""` | 基线 JSON 文件的路径 —— 匹配的发现被抑制 | 所有评估工具(CLI 和 MCP)都通过 `--config ` 或内联 `config` 参数接受相同的配置字段。 ## 高级功能 ### 内联抑制 使用注释指令直接在源代码中抑制特定发现: ``` const x = eval(input); // judges-ignore SEC-001 // judges-ignore-next-line CYBER-002 const y = dangerousOperation(); // judges-file-ignore DOC-* ← suppress globally for this file ``` 支持的注释样式:`//`、`#`、`/* */`。支持逗号分隔的规则 ID 和通配符(`*`、`SEC-*`)。 ### 自动修复补丁 某些发现包含 `patch` 字段中可由机器应用的补丁: | 模式 | 自动修复 | |---------|----------| | `new Buffer(x)` | → `Buffer.from(x)` | | `http://` URL(非 localhost) | → `https://` | | `Math.random()` | → `crypto.randomUUID()` | 补丁包含 `oldText`、`newText`、`startLine` 和 `endLine` 用于自动应用。 ### 跨评估器去重 当多位评委标记同一问题时(例如 Data Security 和 Cybersecurity 都在第 15 行检测到 SQL 注入),发现会自动去重。严重性最高的发现胜出,描述中会注释交叉引用(例如 *"Also identified by: CYBER-003"*)。 ### 污点流分析 引擎执行过程间污点跟踪,以跟踪数据从用户控制的源(例如 `req.body`、`process.env`)通过转换到安全敏感汇(例如 `eval()`、`exec()`、SQL 查询)。污点流用于提高真阳性发现的置信度,并在检测到清理时抑制误报。 ### 正向信号检测 展示良好实践的代码获得分数奖励(上限 +15): | 信号 | 奖励 | |--------|-------| | 参数化查询 | +3 | | 安全头 | +3 | | 认证中间件(passport 等) | +3 | | 正确的错误处理 | +2 | | 输入验证库(zod、joi 等) | +2 | | 速率限制 | +2 | | 结构化日志(pino、winston) | +2 | | CORS 配置 | +1 | | 严格模式 / strictNullChecks | +1 | | 测试模式 | +1 | ### 框架感知规则 Judges 包含针对 Express、Django、Flask、FastAPI、Spring、ASP.NET、Rails 等的框架特定检测。框架中间件(例如 `helmet()`、`express-rate-limit`、`passport.authenticate()`)被识别为缓解措施,减少误报。 ### 跨文件导入解析 在项目级分析中,导入在文件之间解析。如果一个文件从项目中的另一个文件导入安全中间件模块,关于缺失安全控制的发现会自动调整并降低置信度。 ## 评分 每位评委对代码进行 **0 到 100** 的评分: | 严重性 | 扣分 | |----------|----------------| | Critical | −30 分 | | High | −18 分 | | Medium | −10 分 | | Low | −5 分 | | Info | −2 分 | **裁决逻辑:** - **FAIL** —— 任何严重发现,或分数 < 60 - **WARNING** —— 任何高发现、任何中发现,或分数 < 80 - **PASS** —— 分数 ≥ 80 且无严重、高或中发现 **总体评审团分数** 是所有 39 位评委的平均值。如果 **任何** 评委失败,总体裁决失败。 ## 项目结构 ``` judges/ ├── src/ │ ├── index.ts # MCP server entry point — tools, prompts, transport │ ├── api.ts # Programmatic API entry point │ ├── cli.ts # CLI argument parser and command router │ ├── types.ts # TypeScript interfaces (Finding, JudgeEvaluation, etc.) │ ├── config.ts # .judgesrc configuration parser and validation │ ├── errors.ts # Custom error types (ConfigError, EvaluationError, ParseError) │ ├── language-patterns.ts # Multi-language regex pattern constants and helpers │ ├── plugins.ts # Plugin system for custom rules │ ├── scoring.ts # Confidence scoring and calibration │ ├── dedup.ts # Finding deduplication engine │ ├── fingerprint.ts # Finding fingerprint generation │ ├── comparison.ts # Tool comparison benchmark data │ ├── cache.ts # Evaluation result caching │ ├── calibration.ts # Confidence calibration from feedback data │ ├── fix-history.ts # Auto-fix application history tracking │ ├── ast/ # AST analysis engine (built-in, no external deps) │ │ ├── index.ts # analyzeStructure() — routes to correct parser │ │ ├── types.ts # FunctionInfo, CodeStructure interfaces │ │ ├── tree-sitter-ast.ts # Tree-sitter WASM parser (all 8 languages) │ │ ├── structural-parser.ts # Fallback scope-tracking parser │ │ ├── cross-file-taint.ts # Cross-file taint propagation analysis │ │ └── taint-tracker.ts # Single-file taint flow tracking │ ├── evaluators/ # Analysis engine for each judge │ │ ├── index.ts # evaluateWithJudge(), evaluateWithTribunal(), evaluateProject(), etc. │ │ ├── shared.ts # Scoring, verdict logic, markdown formatters │ │ └── *.ts # One analyzer per judge (39 files) │ ├── formatters/ # Output formatters │ │ ├── sarif.ts # SARIF 2.1.0 output │ │ ├── html.ts # Self-contained HTML report (dark/light theme, filters) │ │ ├── junit.ts # JUnit XML output (Jenkins, Azure DevOps, GitHub Actions) │ │ ├── codeclimate.ts # CodeClimate/GitLab Code Quality JSON │ │ ├── diagnostics.ts # Diagnostics formatter │ │ └── badge.ts # SVG and text badge generator │ ├── commands/ # CLI subcommands │ │ ├── init.ts # Interactive project setup wizard │ │ ├── fix.ts # Auto-fix patch preview and application │ │ ├── watch.ts # Watch mode — re-evaluate on save │ │ ├── report.ts # Project-level local report │ │ ├── hook.ts # Pre-commit hook install/uninstall │ │ ├── ci-templates.ts # GitLab, Azure, Bitbucket CI templates │ │ ├── diff.ts # Evaluate unified diff (git diff) │ │ ├── deps.ts # Dependency supply-chain analysis │ │ ├── baseline.ts # Create baseline for finding suppression │ │ ├── completions.ts # Shell completions (bash/zsh/fish/PowerShell) │ │ ├── docs.ts # Per-judge rule documentation generator │ │ ├── feedback.ts # False-positive tracking & finding feedback │ │ ├── benchmark.ts # Detection accuracy benchmark suite │ │ ├── rule.ts # Custom rule authoring wizard │ │ ├── language-packs.ts # Language-specific rule pack presets │ │ └── config-share.ts # Shareable team/org configuration │ ├── presets.ts # Named evaluation presets (strict, lenient, security-only, …) │ ├── patches/ │ │ └── index.ts # 53 deterministic auto-fix patch rules │ ├── tools/ # MCP tool registrations │ │ ├── register.ts # Tool registration orchestrator │ │ ├── register-evaluation.ts # Evaluation tools (evaluate_code, etc.) │ │ ├── register-workflow.ts # Workflow tools (app builder, reports, etc.) │ │ ├── prompts.ts # MCP prompt registrations (per-judge + full-tribunal) │ │ └── schemas.ts # Zod schemas for tool parameters │ ├── reports/ │ │ └── public-repo-report.ts # Public repo clone + full tribunal report generation │ └── judges/ # Judge definitions (id, name, domain, system prompt) │ ├── index.ts # JUDGES array, getJudge(), getJudgeSummaries() │ └── *.ts # One definition per judge (39 files) ├── scripts/ │ ├── generate-public-repo-report.ts # Run: npm run report:public-repo -- --repoUrl │ ├── daily-popular-repo-autofix.ts # Run: npm run automation:daily-popular │ └── debug-fp.ts # Debug false-positive findings ├── examples/ │ ├── sample-vulnerable-api.ts # Intentionally flawed code (triggers all judges) │ ├── demo.ts # Run: npm run demo │ └── quickstart.ts # Quick-start evaluation example ├── tests/ │ ├── judges.test.ts # Core judge evaluation tests │ ├── negative.test.ts # Negative / FP-avoidance tests │ ├── subsystems.test.ts # Subsystem integration tests │ ├── extension-logic.test.ts # VS Code extension logic tests │ └── tool-routing.test.ts # MCP tool routing tests ├── grammars/ # Tree-sitter WASM grammar files │ ├── tree-sitter-typescript.wasm │ ├── tree-sitter-cpp.wasm │ ├── tree-sitter-python.wasm │ ├── tree-sitter-go.wasm │ ├── tree-sitter-rust.wasm │ ├── tree-sitter-java.wasm │ └── tree-sitter-c_sharp.wasm ├── judgesrc.schema.json # JSON Schema for .judgesrc config files ├── server.json # MCP Registry manifest ├── package.json ├── tsconfig.json └── README.md ``` ## 脚本 | 命令 | 描述 | |---------|-------------| | `npm run build` | 将 TypeScript 编译到 `dist/` | | `npm run dev` | 监视模式 —— 保存时重新编译 | | `npm test` | 运行完整测试套件 | | `npm run demo` | 运行示例评审团演示 | | `npm run report:public-repo -- --repoUrl ` | 为公共仓库 URL 生成完整评审团报告 | | `npm run report:quickstart -- --repoUrl ` | 运行有主见的高信号报告默认值以快速采用 | | `npm run automation:daily-popular` | 每天分析多达 10 个轮换的热门仓库,并每个仓库打开多达 5 个修复 PR | | `npm start` | 启动 MCP 服务器 | | `npm run clean` | 删除 `dist/` | | `judges init` | 交互式项目设置向导 | | `judges fix ` | 预览自动修复补丁(添加 `--apply` 以写入) | | `judges watch ` | 监视模式 —— 文件保存时重新评估 | | `judges report ` | 本地目录上的完整评审团报告 | | `judges hook install` | 安装 Git pre-commit hook | | `judges diff` | 评估统一 diff 中的更改行 | | `judges deps` | 分析依赖项的供应链风险 | | `judges baseline create` | 创建用于发现抑制的基线 | | `judges ci-templates` | 生成 CI 流水线模板 | | `judges docs` | 生成每位评委的规则文档 | | `judges completions ` | Shell 补全脚本 | | `judges feedback submit` | 将发现标记为真阳性、假阳性或 won't fix | | `judges feedback stats` | 显示假阳性率统计 | | `judges benchmark run` | 运行检测准确性基准套件 | | `judges rule create` | 交互式自定义规则创建向导 | | `judges rule list` | 列出自定义评估规则 | | `judges pack list` | 列出可用的语言包 | | `judges config export` | 将配置导出为可共享包 | | `judges config import ` | 导入共享配置 | | `judges compare` | 将 Judges 与其他代码审查工具进行比较 | | `judges list` | 列出所有 39 位评委及其领域和描述 | ## 每日热门仓库自动化 此仓库包含位于 `.github/workflows/daily-popular-repo-autofix.yml` 的计划工作流,它: - 每天从 100+ 个热门仓库的默认池(或手动提供的目标)中选择多达 10 个仓库, - 在支持的源语言上运行完整的 Judges 评估, - 仅应用减少匹配发现计数的、保守的单行修复, - 为每个仓库打开多达 5 个 PR,并归属于 Judges 和目标仓库, - 除非仓库是公开的且可以使用现有的 GitHub 认证创建 PR(无额外认证流程),否则跳过仓库。 - 强制执行每个仓库每天 10 个仓库和 5 个 PR 的硬性运行时上限。 每次运行都会写入 `daily-autofix-summary.json`(或 `SUMMARY_PATH`),包含每个仓库的遥测数据,包括: - `runAggregate` —— 紧凑的运行级总数和跨仓库顶级优先规则, - `runAggregate.totalCandidatesDiscovered` 和 `runAggregate.totalCandidatesAfterLocationDedupe` —— 表示在尝试修复之前消除了多少重叠, - `runAggregate.totalCandidatesAfterPriorityThreshold` —— 应用最低优先级分数后保留的候选者, - `runAggregate.dedupeReductionPercent` —— 位置去重带来的百分比减少,用于快速运行时效率跟踪, - `runAggregate.priorityThresholdReductionPercent` —— 去重后最低优先级过滤带来的百分比减少, - `priorityRulePrefixesUsed` —— 优先级期间使用的危险规则前缀, - `minPriorityScoreUsed` —— 用于候选者包含的最低 `candidatePriorityScore`, - `candidatesDiscovered`、`candidatesAfterLocationDedupe` 和 `candidatesAfterPriorityThreshold` —— 每个过滤阶段后的每个仓库候选者计数, - `topPrioritizedRuleCounts` —— 排名候选者中最常见的规则 ID, - `topPrioritizedCandidates` —— 排名靠前的候选者样本(规则、严重性、置信度、文件、行、优先级分数)。 可选运行时控制: - `AUTOFIX_MIN_PRIORITY_SCORE` —— 去重后所需的最低候选者优先级分数(默认:`0`,禁用)。 必需的密钥: - `JUDGES_AUTOFIX_GH_TOKEN` —— 具有分叉/推送/为目标仓库创建 PR 权限的 GitHub token。 手动运行: ``` gh workflow run "Judges Daily Full-Run Autofix PRs" -f targetRepoUrl=https://github.com/owner/repo ``` ## 编程 API Judges 可以作为库使用(不仅仅通过 MCP)。从 `@kevinrabun/judges/api` 导入: ``` import { evaluateCode, evaluateProject, evaluateCodeSingleJudge, getJudge, JUDGES, findingsToSarif, } from "@kevinrabun/judges/api"; // Full tribunal evaluation const verdict = evaluateCode("const x = eval(input);", "typescript"); console.log(verdict.overallScore, verdict.overallVerdict); // Single judge const result = evaluateCodeSingleJudge("cybersecurity", code, "typescript"); // SARIF output for CI integration const sarif = findingsToSarif(verdict.evaluations.flatMap(e => e.findings)); ``` ### 包导出 | 入口点 | 描述 | |---|---| | `@kevinrabun/judges/api` | 编程 API(默认) | | `@kevinrabun/judges/server` | MCP 服务器入口点 | | `@kevinrabun/judges/sarif` | SARIF 2.1.0 格式化程序 | | `@kevinrabun/judges/junit` | JUnit XML 格式化程序 | | `@kevinrabun/judges/codeclimate` | CodeClimate/GitLab Code Quality JSON | | `@kevinrabun/judges/badge` | SVG 和文本徽章生成器 | | `@kevinrabun/judges/diagnostics` | 诊断格式化程序 | | `@kevinrabun/judges/plugins` | 插件系统 API | | `@kevinrabun/judges/fingerprint` | 发现指纹实用程序 | | `@kevinrabun/judges/comparison` | 工具比较基准 | ### SARIF 输出 将发现转换为 [SARIF 2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html),用于 GitHub Code Scanning、Azure DevOps 和其他 CI/CD 工具: ``` import { findingsToSarif, evaluationToSarif, verdictToSarif } from "@kevinrabun/judges/sarif"; const sarif = verdictToSarif(verdict, "src/app.ts"); fs.writeFileSync("results.sarif", JSON.stringify(sarif, null, 2)); ``` ## 自定义错误类型 所有抛出的错误都扩展自 `JudgesError`,带有一个机器可读的 `code` 属性: | 错误类 | 代码 | 何时 | |---|---|---| | `ConfigError` | `JUDGES_CONFIG_INVALID` | 格式错误的 `.judgesrc` 或无效的内联配置 | | `EvaluationError` | `JUDGES_EVALUATION_FAILED` | 未知的评委、分析器崩溃 | | `ParseError` | `JUDGES_PARSE_FAILED` | 无法解析的源代码或输入数据 | ``` import { ConfigError, EvaluationError } from "@kevinrabun/judges/api"; try { evaluateCode(code, "typescript"); } catch (e) { if (e instanceof ConfigError) console.error("Config issue:", e.code); } ``` ## 许可证 MIT
标签:AI代码审查, AI生成代码, Claude插件, DevSecOps, DLL 劫持, DNS 反向解析, LLM应用开发, LNA, MCP服务器, MITM代理, Model Context Protocol, NPM包, OSV-Scalibr, SonarQube替代, 上游代理, 云原生就绪, 代码合规性, 代码嗅觉检测, 代码安全, 代码质量门禁, 反取证, 可扩展性分析, 大语言模型, 威胁情报, 安全评估, 开发者工具, 成本优化, 暗色界面, 最佳实践检查, 漏洞枚举, 自动化攻击, 错误基检测, 静态代码分析