natureco-official/codedna
GitHub: natureco-official/codedna
一款 Git 原生的 Python CLI 工具,用于检测代码中 AI 生成的比例并量化评估团队对代码库的真实理解程度。
Stars: 1 | Forks: 0
# 🧬 CodeDNA — AI 代码透明度工具
**了解你提交的每一行代码。它到底是你写的,还是 AI 写的?**
检测哪些代码是由 AI 编写的,衡量开发者对其提交内容的实际理解程度,并绘制出整个团队的“理解债务”地图。
[](https://pypi.org/project/codedna/)
[](https://opensource.org/licenses/MIT)
[](https://www.python.org/downloads/)
[](https://github.com/natureco-official/codedna/stargazers)
[**快速开始**](#-quick-start) • [**功能**](#-features) • [**命令**](#-commands) • [**价格**](#-pricing) • [**文档**](#-documentation)
## 🎯 问题所在
在 2026 年,开发者 **78% 的代码是在 AI 的帮助下编写的**(Copilot、Cursor、ChatGPT、Claude)。结果如何?
- 😰 **“理解债务”** — 代码虽然提交了,但没人真正知道它是怎么运行的
- 🚌 **Bus Factor = 1** — 大家都在用同样的 AI,却没人理解代码库
- 💰 **技术债务爆炸** — 没有人工审查,AI 生成的代码衰退得很快
- 🐛 **Bug 倍增** — 3 个月后:“这是谁写的?我甚至都不知道它是干什么的”
**CodeDNA 解决了这个问题。** 每一次提交都会被评分。每一位开发者都会被衡量。每一个团队都能获得可见性。
## ✨ 功能
### 🔍 AI 检测(4 项指标指纹)
CodeDNA 使用 4 种启发式方法来检测 AI 生成的代码:
| 指标 | AI 特征 | 分数 |
|--------|--------------|-------|
| `comment_ratio > 0.3` | AI 会对其代码过度注释 | +0.20 |
| `avg_function_length > 50` | AI 会生成庞大的单体代码块 | +0.15 |
| `single_commit_ratio > 0.7` | 批量粘贴的提交是 AI 的危险信号 | +0.30 |
| 高复杂度 + 单次提交 | AI 特征 → +0.25 |
**总分 > 0.50 → 疑似 AI。** 结合 Tree-sitter AST 分析,准确率可达 80% 以上。
### 👤 开发者理解评分
- **基于访谈** — 每次提交后进行结构化的问答
- **AI 驱动** — 针对你刚刚提交的代码生成问题
- **长期跟踪** — 查看你的理解曲线
### 🚌 Bus Factor 分析
- **所有权追踪** — 谁拥有哪个文件?
- **风险识别** — 单点故障
- **重构建议** — “将 X 和 Y 分配到模块 Z 上”
### 💰 技术债务估算
- **以美元计算的成本** — 修复它需要多少钱?
- **随时间变化的趋势** — 债务在增加吗?
- **优先级划分** — 先修复什么?
### 🏃 Sprint 健康
- **速度跟踪** — 真实提交 vs. AI 辅助
- **代码审查负载** — 谁在审查什么?
- **质量指标** — 每个 Sprint 的评分
### 🤖 AI 工具比较(企业版)
- **Copilot vs. Cursor vs. ChatGPT** — 哪个工具会产生更多债务?
- **按开发者细分** — 谁在使用什么?
- **生产力与质量对比** — 真实指标
### 🎯 访谈工具(企业版)
- **自动生成问题** — “这个函数是做什么的?为什么?”
- **记录回复** — 用于 HR 和合规审查
- **可导出报告** — PDF/CSV
### 🚀 开发者入职
- **提升曲线** — 达到生产力需要多长时间?
- **导师匹配** — AI 建议配对
- **首次 PR 分析** — 他们交付了什么?
### 🛡️ 受保护模块
- **标记关键文件** — “AI 不得触碰 auth/、payment/、security/”
- **Pre-commit hook** — 阻止向受保护区域进行 AI 生成的提交
- **覆盖工作流** — 需带审批
### 📊 Web 仪表板
- **实时指标** — 实时提交流
- **图表** — 时间序列、细分、比较
- **多仓库视图** — 将你的所有项目集中在一个地方
- **团队分析** — 谁在成长,谁在停滞
### 💬 多渠道支持
- **Telegram bot** — 在手机上使用 `/codedna scan`
- **WhatsApp** — 斜杠前缀命令
- **iMessage** — 直接的 Mac 集成
- **Discord/Slack** — Webhook 支持
## 🚀 快速开始
### 安装
```
# 来自 PyPI
pip install codedna
# 或使用 uv(更快)
uv pip install codedna
# 或从开发环境
git clone https://github.com/natureco-official/codedna.git
cd codedna
pip install -e .
```
### 首次使用(60 秒)
```
# 1. 进入 Git repo
cd your-awesome-project
# 2. 启动 CodeDNA(创建 git hook + DB)
codedna init
# 3. 扫描 repo
codedna scan
# 4. 查看最新 commit 得分
codedna status
# 5. 查看历史 commit
codedna history
```
**就是这样。** 从现在起,每一次提交都会被自动分析。
### 运行仪表板(可选)
```
# Web dashboard (port 3000) + REST API (port 8000)
codedna dashboard
# 然后打开 http://localhost:3000
# 使用您的账号登录或注册新账号
```
## 📋 命令(共 25 个)
### 📊 分析与报告
```
codedna init # Git hook + DB olustur
codedna scan # Repoyu tara
codedna status # Son commit skoru
codedna history # Gecmis commit'ler
codedna report # HTML rapor olustur
codedna ai-compare # AI arac karsilastirmasi (Enterprise)
```
### 🛡️ 保护与策略
```
codedna protect-add
# Korunan modul ekle
codedna protect-remove # Korumayi kaldir
codedna protect-list # Korunan modulleri listele
codedna protect-check # Dosya korunuyor mu?
```
### 👥 团队与流程
```
codedna onboarding # Gelistirici ramp-up (Team+)
codedna interview-start # Mulakat baslat (Enterprise)
codedna interview-list # Mulakatlari listele
codedna interview-score # Mulakat skorla
codedna bus-factor # Sahiplik analizi (Team+)
codedna debt # Teknik borc (Team+)
codedna sprint-olustur # Sprint olustur
codedna sprint-sagligi # Sprint sagligi
codedna sprint-gecmisi # Sprint gecmisi
```
### 🌐 基础设施
```
codedna serve # FastAPI REST (port 8000)
codedna dashboard # Web dashboard (port 3000)
codedna pr-comment # GitHub PR yorumu
codedna plan # Plan/lisans yonetimi
codedna plan demo pro # 7 gunluk demo Pro lisans
codedna natureco # NatureCo CLI entegrasyonu (Pro+)
codedna uninstall # Hook kaldir
```
### 🔧 实用工具
```
codedna doctor # Sistem saglik kontrolu
codedna reset # Sifirla (DANGEROUS)
```
## 💎 价格
| 计划 | 价格 | 仓库 | 文件/扫描 | 历史 | 仪表板 | 功能 |
|------|-------|-------|------------|---------|-----------|----------|
| **Free** | $0 | 1 | 50 | 7 天 | ❌ | AI 检测,仅限本地 |
| **Pro** | ₺400/月 | ∞ | ∞ | 90 天 | ✅ | + GitHub Actions, NatureCo CLI |
| **Team** | ₺800/月 | ∞ | ∞ | 365 天 | ✅ | + Bus Factor, Sprint, 入职 |
| **Enterprise** | ₺1,650/月 | ∞ | ∞ | ∞ | ✅ | + AI 比较, 访谈工具, SSO |
**从 `codedna plan demo pro` 开始**,免费测试 7 天 Pro 功能。
通过 [Lemon Squeezy](https://www.lemonsqueezy.com) 付款 — 土耳其市场以 TRY 定价,全球市场以 USD 定价。
## 🔌 集成
### CI/CD
- **GitHub Actions** — 在 PR 上自动评论
- **GitLab CI** — Pipeline 集成
- **Bitbucket Pipelines** — 代码片段
### 问题追踪器
- **Jira** — Story → 提交映射
- **Linear** — 问题追踪
- **GitHub Issues** — 自动关联
### 通知
- **Slack** — 实时警报
- **Discord** — Webhook 支持
- **Telegram** — Bot 命令
- **电子邮件** — 每日摘要
### AI 工具
- **GitHub Copilot** — 检测
- **Cursor** — 检测
- **ChatGPT/Claude** — 检测
- **Codeium** — 检测
## 🛠️ 架构
```
┌─────────────────────────────────────────────────────────┐
│ CLI (Python 7,000+ LOC) │
│ ├── Typer framework │
│ ├── Tree-sitter parsers (Python, JS, TS, JSX, TSX) │
│ ├── GitPython (commit analysis) │
│ ├── SQLite (local DB) │
│ └── JWT (auth) │
└─────────────────────────────────────────────────────────┘
│
↓ HTTP
┌─────────────────────────────────────────────────────────┐
│ REST API (FastAPI) │
│ ├── /auth (register, login, me) │
│ ├── /billing (checkout, webhook, subscription) │
│ ├── /commits (list, scores) │
│ ├── /files (analysis) │
│ └── /repo (bus-factor, debt, sprint) │
└─────────────────────────────────────────────────────────┘
│
↓ HTTP
┌─────────────────────────────────────────────────────────┐
│ Web Dashboard (Next.js) │
│ ├── /dashboard (metrics) │
│ ├── /files (file list) │
│ ├── /commits (commit history) │
│ ├── /bus-factor (ownership) │
│ ├── /debt (technical debt) │
│ ├── /sprints (sprint health) │
│ ├── /ai-compare (tool comparison) │
│ ├── /onboarding (developer ramp-up) │
│ ├── /protected (module list) │
│ ├── /interview (Q&A tool) │
│ ├── /settings/integrations │
│ └── /pricing (plan comparison) │
└─────────────────────────────────────────────────────────┘
```
### 3 层技术栈
1. **CLI** — 终端优先的开发者
2. **REST API** — 用于仪表板和集成的后端
3. **Web 仪表板** — 经理/CTO 视图
## 🏗️ 技术栈
### 后端
- **Python 3.10+** — 核心语言
- **Typer** — 现代 CLI 框架
- **FastAPI** — 高性能 REST API
- **Tree-sitter** — 增量解析
- **GitPython** — Git 仓库访问
- **SQLite** — 本地数据库
- **bcrypt** — 密码哈希
- **PyJWT** — Token 管理
- **Pydantic** — 数据验证
- **uv** — 快速的 Python 包管理器
### 前端
- **Next.js 14+** — React 框架
- **TypeScript** — 类型安全
- **Tailwind CSS** — 样式设计
- **i18n** — 多语言 (EN/TR)
### 计费
- **Lemon Squeezy** — 记录商户
- **HMAC-SHA256** — Webhook 签名验证
### DevOps
- **GitHub Actions** — CI/CD
- **CodeQL** — 安全扫描
- **Dependabot** — 依赖项更新
- **uv** — Python 打包
## 🔒 安全
- ✅ **HMAC-SHA256** webhook 签名验证
- ✅ **bcrypt** 密码哈希(开销因子为 12)
- ✅ **JWT token** 7 天过期时间
- ✅ **httpOnly + secure + sameSite** cookies
- ✅ **CORS 保护**
- ✅ **SQL 注入** 保护(参数化查询)
- ✅ **Pydantic** 输入验证
- ✅ **速率限制**(FastAPI 中间件)
- ✅ 生产环境中**仅限 HTTPS**
- ✅ **无遥测** — 你的代码始终归你所有
## 🌍 支持的语言
CodeDNA 的 Tree-sitter 解析器支持:
- ✅ **Python** (`.py`)
- ✅ **JavaScript** (`.js`)
- ✅ **TypeScript** (`.ts`)
- ✅ **JSX** (`.jsx`)
- ✅ **TSX** (`.tsx`)
即将推出:Go、Rust、Java、C#、Ruby、PHP
## 📦 项目结构
```
codedna/
├── cli.py # 25 CLI commands
├── api.py # FastAPI REST endpoints
├── auth.py # JWT authentication
├── plan.py # License/plan management
├── db.py # SQLite database
├── scorer.py # AI risk scoring
├── analyzer.py # Code analysis
├── ai_fingerprint.py # AI detection
├── bus_factor.py # Ownership analysis
├── tech_debt.py # Technical debt
├── sprint_health.py # Sprint metrics
├── survey.py # Onboarding
├── interview.py # Q&A tool
├── protection.py # Module protection
├── rate_limit.py # API throttling
├── onboarding.py # Developer tracking
├── integrations/
│ ├── lemonsqueezy.py # Billing integration
│ └── github.py # GitHub API
├── dashboard/ # Next.js frontend
│ ├── app/ # 13 pages
│ ├── components/ # UI components
│ └── lib/ # Utilities
├── tests/ # Pytest suite
├── pyproject.toml # Python config
├── README.md # This file
├── CHANGELOG.md # Release notes
├── LICENSE # MIT
├── CONTRIBUTING.md # How to contribute
└── SECURITY.md # Security policy
```
## 🧪 测试
```
# 运行所有测试
pytest
# 带 Coverage
pytest --cov=codedna
# Specific test
pytest tests/test_ai_fingerprint.py
```
**测试覆盖率:** 所有模块均在 80% 以上。
## 📚 文档
- **安装指南** — [INSTALL.md](docs/INSTALL.md)
- **CLI 参考** — [docs/CLI.md](docs/CLI.md)
- **API 参考** — http://localhost:8000/docs(运行时)
- **Webhook 指南** — [docs/WEBHOOKS.md](docs/WEBHOOKS.md)
- **架构** — [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)
- **路线图** — [docs/ROADMAP.md](docs/ROADMAP.md)
## 🤝 贡献
我们欢迎你的贡献!请查看 [CONTRIBUTING.md](CONTRIBUTING.md) 了解指南。
### 开发设置
```
git clone https://github.com/natureco-official/codedna.git
cd codedna
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest
```
### 代码风格
- 使用 [Black](https://black.readthedocs.io/) 格式化 Python
- 使用 [Ruff](https://github.com/astral-sh/ruff) 进行 linting
- 对 TypeScript 使用 ESLint + Prettier
## 📜 许可证
MIT 许可证 — 详见 [LICENSE](LICENSE) 文件。
```
MIT License - Copyright (c) 2026 NatureCo
```
## 🌟 致谢
- **Tree-sitter** — 感谢其极速的解析能力
- **Typer** — 感谢其优雅的 CLI
- **FastAPI** — 感谢其现代的 API 框架
- **Lemon Squeezy** — 感谢其无忧的计费服务
- **我们所有的 Beta 测试者** — 感谢你们的反馈和 Bug 报告
## 💬 社区
- 💬 **Discord:** [https://discord.gg/4FwumbWph](https://discord.gg/4FwumbWph)
- 🐦 **Twitter:** [@naturecoofficial](https://twitter.com/naturecoofficial)
- 🐙 **GitHub:** [https://github.com/natureco-official/codedna](https://github.com/natureco-official/codedna)
- 📦 **PyPI:** [https://pypi.org/project/codedna/](https://pypi.org/project/codedna/)
- 🌐 **Website:** [https://natureco.me](https://natureco.me)
## 🗺️ 路线图
### v0.3.0 (2026 年第三季度)
- [ ] VSCode 插件(实时)
- [ ] 支持 Go/Rust/Java
- [ ] Slack bot
- [ ] Jira 集成
### v0.4.0 (2026 年第四季度)
- [ ] 团队分析仪表板
- [ ] AI 教练(推荐学习资源)
- [ ] 自定义 AI 指纹识别
- [ ] 云同步(可选)
### v1.0.0 (2027 年)
- [ ] 自托管选项
- [ ] 企业版 SSO (SAML, OIDC)
- [ ] SOC 2 合规性
- [ ] 自定义训练数据
**在土耳其倾注 🌿 制作**
[⭐ 在 GitHub 上给我们点 Star]() • [📦 从 PyPI 安装](https://pypi.org/project/codedna/) • [🐦 在 Twitter 上关注](https://twitter.com/naturecoofficial)
## 来自 NatureCo 的更多项目
- [**Cupertino Terminal**](https://github.com/natureco-official/cupertino-terminal) — 适用于 Windows、macOS 和 Linux 的 macOS 级终端 — Rust 核心,无 Electron,内置端到端加密的 P2P 远程 shell
- [**NatureCo CLI**](https://github.com/natureco-official/natureco-cli) — 原生于终端的 AI 助手:聊天、编码 agent、自动化,以及 Telegram、Discord 和 Slack 上的 bot
- [**Urðr**](https://github.com/natureco-official/urdr) — 为 AI 编码 agent 提供的树状结构记忆 — 纯 Markdown 编写,你可以直接使用 `git diff`,无需向量数据库
- [**NatureCo SDK**](https://github.com/natureco-official/natureco-sdk) — 针对 NatureCo API 的 JavaScript SDK — 构建 AI 聊天机器人并将其部署到任何地方
- [**Verðandi**](https://github.com/natureco-official/verdandi) — 针对 AI 编码 agent 的任务上下文编译器 — 使用 TypeScript AST 进行索引,让 agent 不再为了寻找正确的文件而白白消耗 token
- [**Skuld**](https://github.com/natureco-official/natureco-skuld) — 一个 Agentic 编码工作区,绝不宣称其无法证明的成功 — 每一项更改在被报告为完成之前,都必须经过验证门
**NatureCo** 生态系统的一部分 — [natureco.me](https://natureco.me) · NatureCo ekosisteminin parçası标签:AI代码检测, CLI, Git工具, Python, WiFi技术, 代码质量分析, 开发效率, 技术债务, 无后门, 网络可观测性, 逆向工具