SubmuxHQ/CodeDecay
GitHub: SubmuxHQ/CodeDecay
一款本地优先的开源 PR 分析工具,专门用于在合并前发现 AI 编程代理可能遗漏的代码缺陷、测试不足和可维护性衰退等问题。
Stars: 3 | Forks: 1
# CodeDecay
CodeDecay 是一款开源的、本地优先的 PR 安全防护工具,专为 AI 辅助开发设计。
它可以帮助使用 Codex、Claude Code、Cursor、桌面代理或其他 AI 辅助工作流的团队,在合并前发现编程代理可能遗漏的问题:受影响的文件、路由、API、模块,缺失的测试,薄弱的验证,重复的逻辑,复杂度的增加,脆弱的抽象以及可维护性的衰退。
它不是一款通用的 AI 代码审查工具。CodeDecay 可以分析任何 pull request,并特别关注 AI 生成或 AI 辅助代码中常见的风险:
- 这个 PR 可能会破坏什么?
- 哪些文件、路由和模块会受到影响?
- 可能缺少哪些测试?
- 这些测试是否真正验证了实际的 API、UI、数据库或下游路径?
- 这个 PR 是否加剧了可维护性的衰退?
- 这个 PR 是应该合并、仔细审查,还是被阻止?
CodeDecay 是确定性的、本地优先的,并且无需云服务即可使用。它不需要遥测、API key、LLM 或模型调用。可选的 agent 和 LLM 集成必须由用户拥有并明确授权。
## 安装
```
npm install -D @submux/codedecay
```
本地安装完成后,可以通过 `npx codedecay` 运行 CLI,或者将 `codedecay` 添加到 npm script 中。
在本仓库进行本地开发:
```
pnpm install
pnpm build
pnpm test
```
## CLI
```
npx codedecay analyze --base main --head HEAD --format markdown
npx codedecay analyze --format json
npx codedecay analyze --format sarif --output codedecay.sarif
npx codedecay analyze --cwd ../my-repo --format markdown
npx codedecay analyze --fail-on high
npx codedecay config --format markdown
npx codedecay execute --format markdown
npx codedecay differential --base main --head HEAD --format markdown
npx codedecay redteam --base main --head HEAD --format markdown
npx codedecay agent --base main --head HEAD --format markdown
npx codedecay agent --profile codex --format markdown
```
选项:
- `--base `: 用于对比的 base git ref。
- `--head `: 对比至该 head git ref。
- `--cwd `: 要分析的仓库工作目录。
- `--format json|markdown|sarif`: 报告格式。
- `--profile generic|codex|claude-code|cursor|desktop`: `codedecay agent` 的 agent 交接配置。
- `--output `: 将报告写入文件而不是输出到 stdout。
- `--fail-on low|medium|high`: 当 PR 达到该风险等级或更高时,以非零状态退出。
如果省略 `--base`,CodeDecay 将分析当前工作树的 diff。
## 输出示例
对于一个修改了 API、auth、database/schema、config 和 UI 文件且附近没有测试的 PR,CodeDecay 会生成如下报告:
```
## CodeDecay 报告
**Overall risk:** High
| Score | Value |
| --- | ---: |
| Merge risk | 100/100 |
| Decay risk | 62/100 |
| Findings | Count |
| --- | ---: |
| High | 5 |
| Medium | 4 |
| Low | 0 |
### 可能受影响的区域
- High **API surface** (api): `src/api/users.ts`
- High **Authentication and authorization** (auth): `src/auth/session.ts`
- High **Database and schema** (database): `prisma/schema.prisma`
- Medium **Build and runtime configuration** (config): `vite.config.ts`
### 可能受影响的路由和 API
- Medium `/dashboard` (Next.js UI route): `app/dashboard/page.tsx`
### 高风险发现
- **Risky source changes without changed tests**
- **Api area changed**
- **Auth area changed**
- **Database area changed**
- **Potential silent failure path**
### 推荐的检查
- `Add or run tests covering src/api/users.ts`
- `Add or run tests covering src/auth/session.ts`
```
建议按以下顺序阅读报告:整体风险、可能受影响的区域、可能受影响的路由/API、高风险发现,以及推荐的检查是否证明了实际的行为路径。完整的 Markdown、JSON 和 SARIF 示例可在[示例报告](docs/sample-reports/README.md)中查看。
## GitHub Action
```
name: CodeDecay
on:
pull_request:
jobs:
codedecay:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: SubmuxHQ/CodeDecay/packages/github-action@v0
with:
base: ${{ github.event.pull_request.base.sha }}
head: ${{ github.event.pull_request.head.sha }}
format: markdown
fail-on: high
```
## 风险等级
- `0-39`: 低
- `40-69`: 中
- `70-100`: 高
## 仓库
公开仓库:
```
git@github.com:SubmuxHQ/CodeDecay.git
```
## 文档
- [快速入门](docs/getting-started.md)
- [配置](docs/configuration.md)
- [开发环境配置](DEVELOPMENT.md)
- [本地仓库记忆](docs/memory.md)
- [Agent 技能](docs/skills.md)
- [测试验证审计](docs/test-audit.md)
- [工具适配器](docs/tool-adapters.md)
- [执行探针](docs/execution.md)
- [差异行为检查](docs/differential.md)
- [红队报告](docs/redteam.md)
- [Agent 任务包](docs/agent.md)
- [LLM 提供商](docs/llm-providers.md)
- [MCP 服务器](docs/mcp.md)
- [GitHub Action](docs/github-action.md)
- [GitHub App](docs/github-app.md)
- [示例报告](docs/sample-reports/README.md)
- [评分模型](docs/scoring.md)
- [感知框架的影响范围映射提案](docs/proposals/framework-aware-impact-map.md)
- [Agent 无关的红队测试工具 RFC](docs/rfcs/0001-agent-agnostic-redteam-harness.md)
- [研究基础](docs/research.md)
- [发布](docs/releasing.md)
- [贡献](CONTRIBUTING.md)
标签:AI辅助编程, MITM代理, SOC Prime, 云安全监控, 代码质量审查, 开发工具, 暗色界面, 自动化攻击, 静态分析