Add DeepAudit Agent Instructions and remove outdated architecture image
Build and Push CodeReview / build (push) Has been cancelled Details

- Introduced AGENTS.md with detailed instructions for backend and frontend development, code style conventions, agent framework specifics, and repository structure.
This commit is contained in:
vinland100 2026-01-13 15:12:22 +08:00
parent 76f731cb22
commit ed1fab2c11
8 changed files with 76 additions and 1971 deletions

76
AGENTS.md Normal file
View File

@ -0,0 +1,76 @@
# DeepAudit Agent Instructions
This guide provides essential technical information for agentic coding tools operating within the DeepAudit repository.
## 🛠 Development Commands
### Backend (Python/FastAPI)
Located in `/backend`. Uses `uv` for environment management and `pytest` for testing.
- **Sync Environment:** `uv sync`
- **Start Server:** `uvicorn app.main:app --reload`
- **Run All Tests:** `pytest`
- **Run Agent Tests:** `python tests/agent/run_tests.py`
- **Run Single Test:** `pytest tests/agent/test_agents.py::test_name`
- **Linting:** `ruff check .`
- **Formatting:** `black .`
- **Type Checking:** `mypy .`
- **Database Migrations:** `alembic upgrade head`
### Frontend (React/TypeScript)
Located in `/frontend`. Uses `pnpm` and `Vite`.
- **Install Dependencies:** `pnpm install`
- **Start Dev Server:** `pnpm dev`
- **Build Project:** `pnpm build`
- **Linting:** `pnpm lint`
- **Format:** `pnpm format`
- **Type Checking:** `pnpm type-check`
---
## 🎨 Code Style & Conventions
### General
- **Language:** English for code (variables, functions, comments), though some documentation/logs may be in Chinese.
- **Architecture:** Follow the Multi-Agent architecture. Backend logic for agents is in `backend/app/agents/`.
### Backend (Python)
- **Style:** PEP 8 via `black` (100 char limit) and `ruff`.
- **Typing:** Strict type hinting is required. Use Pydantic models for data validation in `backend/app/schemas/`.
- **Imports:**
- Standard library first.
- Third-party libraries second.
- Local application imports last (using `app.xxx` absolute paths).
- **Naming:** `snake_case` for variables/functions, `PascalCase` for classes.
- **Error Handling:** Use custom exceptions where appropriate. FastAPI's `HTTPException` for API responses. Prefer `logger.error` over `print`.
- **Database:** SQLAlchemy 2.0 (async). Models in `backend/app/models/`.
### Frontend (React/TypeScript)
- **Framework:** React 18+ with Vite and TypeScript.
- **State Management:** Zustand for stores.
- **UI Components:** Shadcn/UI (Radix UI) + Tailwind CSS.
- **Structure:**
- `src/features/`: Domain-specific components and logic.
- `src/components/ui/`: Shared low-level components.
- `src/shared/`: Cross-cutting concerns (hooks, types, utils, api).
- **Types:** Define interfaces in `src/shared/types/index.ts`. Avoid `any`.
- **Imports:** Use absolute paths (e.g., `@/components/...` if configured, otherwise relative to `src`).
- **Naming:** `PascalCase` for components, `camelCase` for hooks and utilities.
- **Formatting:** Use Biome for linting and formatting.
---
## 🤖 Agent Framework specifics
- **Core Agents:** Orchestrator, Recon, Analysis, Verification.
- **Tools:** Agents use specialized tools (e.g., `sandbox_exec` for PoC verification, `semgrep_scan`, `rag_query`).
- **Sandbox:** PoC execution happens in isolated Docker containers (`docker/sandbox`).
- **RAG:** Uses ChromaDB for vector storage and Tree-sitter for intelligent code chunking.
- **Agent Logic:** Implementation resides in `backend/app/services/agent/agents/` and tools in `backend/app/services/agent/tools/`.
## 📁 Repository Structure
- `backend/app/agents/`: Agent logic.
- `backend/app/api/`: API endpoints.
- `frontend/src/features/`: Frontend modules.
- `docker/`: Deployment and sandbox configurations.
- `rules/`: Custom audit rules.

View File

@ -1,18 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
## [3.0.1] - 2025-12-16
### Fixed
- **Agent Task Cancellation**: Fixed an issue where Agent tasks would continue running in the background after cancellation.
- **Event Streaming**: Resolved `UnboundLocalError` in `event_manager.py` and removed artificial delays to prevent event queue buildup.
- **Agent Timeout**: Increased Verification Agent timeout to 10 minutes to support complex PoC generation.
- **LLM Streaming**: Improved robustness of `stream_llm_call` with explicit string timeouts to prevent hanging.
## [3.0.0] - 2025-12-15
### Added
- **Multi-Agent System**: Introduced Orchestrator, Recon, Analysis, and Verification agents for autonomous security auditing.
- **RAG Integration**: Added Retrieval-Augmented Generation for better code understanding.
- **Docker Sandbox**: Implemented secure environment for tool execution.

View File

@ -1,325 +0,0 @@
# 贡献指南
感谢你对 DeepAudit 的关注!我们热烈欢迎所有形式的贡献,无论是提交 Issue、创建 PR还是改进文档。
## 目录
- [行为准则](#行为准则)
- [如何贡献](#如何贡献)
- [开发环境搭建](#开发环境搭建)
- [代码规范](#代码规范)
- [提交规范](#提交规范)
- [Pull Request 流程](#pull-request-流程)
---
## 行为准则
请在参与项目时保持友善和尊重。我们致力于为每个人提供一个开放、包容的环境。
---
## 如何贡献
### 报告 Bug
1. 先搜索 [Issues](https://github.com/lintsinghua/DeepAudit/issues) 确认问题未被报告
2. 创建新 Issue使用 Bug 报告模板
3. 提供详细信息:
- 操作系统和版本
- 部署方式Docker/本地)
- 复现步骤
- 错误日志或截图
- 期望行为 vs 实际行为
### 提出新功能
1. 先搜索 Issues 确认功能未被提出
2. 创建新 Issue描述
- 功能需求背景
- 期望的实现方式
- 可能的替代方案
### 改进文档
文档改进同样重要!你可以:
- 修复文档中的错误
- 补充缺失的说明
- 改进文档结构
- 添加使用示例
### 贡献代码
1. Fork 本项目
2. 创建功能分支
3. 编写代码和测试
4. 提交 Pull Request
---
## 开发环境搭建
### 环境要求
| 依赖 | 版本要求 | 说明 |
|------|---------|------|
| Node.js | 18+ | 前端运行环境 |
| Python | 3.13+ | 后端运行环境 |
| PostgreSQL | 15+ | 数据库 |
| pnpm | 8+ | 推荐的前端包管理器 |
| uv | 最新版 | 推荐的 Python 包管理器 |
### 数据库准备
```bash
# 使用 Docker 启动 PostgreSQL推荐
docker run -d \
--name deepaudit-db \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=deepaudit \
-p 5432:5432 \
postgres:15-alpine
```
### 后端启动
```bash
# 1. 进入后端目录
cd backend
# 2. 创建虚拟环境
uv venv
source .venv/bin/activate # Linux/macOS
# 或 .venv\Scripts\activate # Windows
# 3. 安装依赖
uv pip install -e .
# 4. 配置环境变量
cp env.example .env
# 编辑 .env 文件,配置数据库和 LLM 参数
# 5. 初始化数据库
alembic upgrade head
# 6. 启动后端服务
uvicorn app.main:app --reload --port 8000
```
### 前端启动
```bash
# 1. 进入前端目录
cd frontend
# 2. 安装依赖
pnpm install
# 3. 配置环境变量(可选)
cp .env.example .env
# 4. 启动开发服务器
pnpm dev
```
---
## 代码规范
### 后端 (Python)
- 使用 Python 3.11+ 类型注解
- 遵循 PEP 8 代码风格
- 使用 Ruff 进行代码格式化和检查
- 使用 mypy 进行类型检查
```bash
# 代码格式化
ruff format app
# 代码检查
ruff check app
# 类型检查
mypy app
```
### 前端 (TypeScript/React)
- 使用 TypeScript 严格模式
- 遵循 React 最佳实践
- 使用 Biome 进行代码格式化和检查
```bash
# 代码检查
pnpm lint
# 类型检查
pnpm type-check
# 代码格式化
pnpm format
```
### 通用规范
- 变量和函数使用有意义的命名
- 添加必要的注释,特别是复杂逻辑
- 保持函数简短,单一职责
- 避免硬编码,使用配置或常量
---
## 提交规范
我们使用 [Conventional Commits](https://www.conventionalcommits.org/) 规范。
### 提交格式
```
<type>(<scope>): <subject>
<body>
<footer>
```
### Type 类型
| Type | 说明 |
|------|------|
| `feat` | 新功能 |
| `fix` | Bug 修复 |
| `docs` | 文档更新 |
| `style` | 代码格式(不影响功能) |
| `refactor` | 代码重构 |
| `perf` | 性能优化 |
| `test` | 测试相关 |
| `chore` | 构建/工具相关 |
| `ci` | CI/CD 相关 |
### 示例
```bash
# 新功能
git commit -m "feat(llm): add support for DeepSeek API"
# Bug 修复
git commit -m "fix(scan): handle empty file content"
# 文档更新
git commit -m "docs: update deployment guide"
# 代码重构
git commit -m "refactor(api): simplify error handling"
```
---
## Pull Request 流程
### 1. Fork 和克隆
```bash
# Fork 项目到你的 GitHub 账号
# 然后克隆到本地
git clone https://github.com/YOUR_USERNAME/DeepAudit.git
cd DeepAudit
# 添加上游仓库
git remote add upstream https://github.com/lintsinghua/DeepAudit.git
```
### 2. 创建分支
```bash
# 同步上游代码
git fetch upstream
git checkout main
git merge upstream/main
# 创建功能分支
git checkout -b feature/your-feature-name
```
### 3. 开发和测试
```bash
# 编写代码...
# 确保代码通过检查
cd frontend && pnpm lint && pnpm type-check
cd backend && ruff check app && mypy app
# 提交代码
git add .
git commit -m "feat: your feature description"
```
### 4. 推送和创建 PR
```bash
# 推送到你的 Fork
git push origin feature/your-feature-name
```
然后在 GitHub 上创建 Pull Request
1. 填写 PR 标题(遵循提交规范)
2. 描述改动内容和原因
3. 关联相关 Issue如有
4. 等待 Review
### 5. 代码审查
- 回应 Review 意见
- 根据反馈修改代码
- 保持 PR 更新rebase 上游代码)
---
## 项目结构
```
DeepAudit/
├── backend/ # 后端 (FastAPI)
│ ├── app/
│ │ ├── api/ # API 路由
│ │ ├── core/ # 核心配置
│ │ ├── db/ # 数据库
│ │ ├── models/ # 数据模型
│ │ ├── schemas/ # Pydantic 模式
│ │ └── services/ # 业务逻辑
│ │ └── llm/ # LLM 适配器
│ ├── alembic/ # 数据库迁移
│ └── pyproject.toml
├── frontend/ # 前端 (React + TypeScript)
│ ├── src/
│ │ ├── app/ # 应用配置
│ │ ├── components/ # UI 组件
│ │ ├── features/ # 功能模块
│ │ ├── pages/ # 页面组件
│ │ └── shared/ # 共享工具
│ └── package.json
├── docs/ # 文档
├── docker-compose.yml # Docker 编排
└── README.md
```
---
## 贡献者
感谢所有贡献者的付出!
[![Contributors](https://contrib.rocks/image?repo=lintsinghua/DeepAudit)](https://github.com/lintsinghua/DeepAudit/graphs/contributors)
---
## 问题反馈
如有问题,请通过以下方式联系:
- [GitHub Issues](https://github.com/lintsinghua/DeepAudit/issues)
- 邮箱: lintsinghua@qq.com

View File

@ -1,220 +0,0 @@
# 免责声明 (Disclaimer)
本免责声明旨在明确用户使用本开源项目的相关责任和风险,保护项目作者、贡献者和维护者的合法权益。
**本开源项目提供的代码、工具及相关内容仅供参考和学习使用。**
---
## 1. 代码隐私与安全警告
### ⚠️ 重要提示
本工具通过调用第三方 LLM 服务商 API 进行代码分析,**您的代码将被发送到所选择的 LLM 服务商服务器**。
### 严禁上传以下类型的代码
| 类型 | 说明 |
|------|------|
| 🔒 商业机密 | 包含商业机密、专有算法或核心业务逻辑的代码 |
| 🛡️ 保密信息 | 涉及国家秘密、国防安全或其他保密信息的代码 |
| 🔑 敏感数据 | 包含用户数据、密钥、密码、token 等敏感信息的代码 |
| ⚖️ 受限代码 | 受法律法规限制不得外传的代码 |
| 📋 第三方代码 | 客户或第三方的专有代码(未经授权) |
### 用户责任
- 用户**必须自行评估代码的敏感性**
- 对上传代码及其可能导致的信息泄露承担**全部责任**
- 对于敏感代码,请使用 **Ollama 本地模型部署功能**,或使用私有部署的 LLM 服务
### 免责声明
项目作者、贡献者和维护者**对因用户上传敏感代码导致的任何信息泄露、知识产权侵权、法律纠纷或其他损失不承担任何责任**。
---
## 2. 非专业建议
### 分析结果仅供参考
- 本工具提供的代码分析结果和建议**仅供参考**
- **不构成**专业的安全审计、代码审查或法律意见
- **不能替代**人类专家的专业判断
### 建议做法
- 结合人工审查验证分析结果
- 使用专业安全工具进行补充检测
- 对关键代码(尤其是涉及安全、金融、医疗等高风险领域)进行全面验证
- 在生产环境部署前进行充分测试
---
## 3. 无担保与免责
### 无担保声明
本项目以 **"原样"AS IS** 形式提供,**不附带任何明示或默示担保**,包括但不限于:
- 适销性担保
- 特定用途适用性担保
- 非侵权性担保
- 准确性或完整性担保
### 责任限制
作者、贡献者和维护者**不对任何直接、间接、附带、特殊、惩戒性或后果性损害承担责任**,包括但不限于:
| 损害类型 | 说明 |
|---------|------|
| 数据丢失 | 因使用本工具导致的数据丢失或损坏 |
| 系统中断 | 服务中断或系统故障 |
| 安全漏洞 | 因依赖分析结果导致的安全问题 |
| 商业损失 | 利润损失、业务中断或其他商业损失 |
| 法律纠纷 | 因使用本工具引发的法律诉讼或纠纷 |
即使已知此类风险存在,上述免责条款仍然适用。
---
## 4. AI 分析局限性
### 技术局限
- 本工具依赖多种 AI 模型进行代码分析
- 分析结果可能包含**错误、遗漏或不准确信息**
- **无法保证** 100% 的准确性和可靠性
### AI 输出特性
| 特性 | 说明 |
|------|------|
| 概率性 | AI 输出基于概率模型,可能产生不同结果 |
| 上下文依赖 | 分析质量受代码上下文完整性影响 |
| 模型差异 | 不同 LLM 模型可能给出不同的分析结果 |
| 知识截止 | AI 模型的知识有截止日期,可能不了解最新漏洞 |
### 用户责任
- AI 输出**不能替代人类专家判断**
- 用户应对最终代码质量及应用后果**全权负责**
- 建议将 AI 分析作为辅助工具,而非唯一依据
---
## 5. 第三方服务与数据隐私
### 集成的第三方服务
本项目集成以下第三方服务:
| 服务类型 | 服务商 | 用途 |
|---------|--------|------|
| LLM API | OpenAI, Google Gemini, Anthropic Claude | 代码分析 |
| LLM API | 通义千问, DeepSeek, 智谱AI, Kimi | 代码分析 |
| LLM API | 百度文心, MiniMax, 字节豆包 | 代码分析 |
| 数据库 | Supabase | 数据存储(可选) |
| 代码托管 | GitHub, GitLab | 仓库集成 |
### 数据传输说明
- 用户提交的代码将通过 API 发送到所选 LLM 服务商进行分析
- 传输过程和数据处理遵循各服务商的隐私政策
- 用户需自行了解并接受各服务商的数据处理方式
### API 密钥管理
- 用户需自行获取、管理 API 密钥
- 本项目**不存储、传输或处理用户的 API 密钥**(除本地配置文件外)
- 运行时配置的密钥仅存储在用户浏览器本地
### 第三方服务风险
第三方服务的以下风险由服务提供商负责,本项目作者不承担任何连带责任:
- 服务可用性
- 数据准确性
- 隐私保护
- 数据留存政策
- 服务中断
---
## 6. 用户责任
### 使用前确认
用户在使用本工具前须确保:
- ✅ 代码不侵犯第三方知识产权
- ✅ 代码不包含保密信息
- ✅ 严格遵守开源许可证及相关法规
- ✅ 拥有代码的使用和分析权限
### 用户承诺
用户**对上传代码的内容、性质和合规性承担全部责任**,包括但不限于:
| 责任 | 说明 |
|------|------|
| 内容审查 | 确保代码不包含敏感信息或商业机密 |
| 权限确认 | 确保拥有代码的使用和分析权限 |
| 法规遵守 | 遵守所在国家/地区关于数据保护和隐私的法律法规 |
| 政策遵守 | 遵守公司或组织的保密协议和安全政策 |
### 禁止行为
**严禁将本工具用于以下活动**
- ❌ 非法活动
- ❌ 恶意代码分析或开发
- ❌ 损害他人权益的行为
- ❌ 违反服务条款的行为
用户对所有使用后果承担**全部法律与经济责任**。
---
## 7. 开源贡献
### 贡献者声明
- 贡献者的代码、内容或建议**不代表项目官方观点**
- 其准确性、安全性及合规性由贡献者自行负责
### 维护者权利
项目维护者保留以下权利:
- 审查任何贡献
- 修改贡献内容
- 拒绝不符合要求的贡献
- 移除已合并的贡献
---
## 8. 许可证
本项目采用 [MIT 许可证](LICENSE) 开源。
MIT 许可证明确声明软件按"原样"提供,不提供任何形式的担保。
---
## 9. 管辖法律
本免责声明受项目所在地法律管辖。
---
## 联系方式
如有疑问,请通过以下方式联系维护者:
- **GitHub Issues**: [https://github.com/lintsinghua/DeepAudit/issues](https://github.com/lintsinghua/DeepAudit/issues)
- **邮箱**: lintsinghua@qq.com
---
**使用本工具即表示您已阅读、理解并同意本免责声明的所有条款。**

View File

@ -1,152 +0,0 @@
# 安全政策
## 代码隐私与安全警告
⚠️ **重要提示**:本工具通过调用第三方 LLM 服务商 API 进行代码分析,**您的代码将被发送到所选择的 LLM 服务商服务器**。
### 严禁上传以下类型的代码
- 🔒 包含商业机密、专有算法或核心业务逻辑的代码
- 🛡️ 涉及国家秘密、国防安全或其他保密信息的代码
- 🔑 包含敏感数据如用户数据、密钥、密码、token 等)的代码
- ⚖️ 受法律法规限制不得外传的代码
- 📋 客户或第三方的专有代码(未经授权)
### 安全建议
1. **评估代码敏感性**
- 用户必须自行评估代码的敏感性
- 对上传代码及其可能导致的信息泄露承担全部责任
2. **使用本地模型处理敏感代码**
- 对于敏感代码,请使用 **Ollama 本地模型部署功能**
- 或使用私有部署的 LLM 服务
- 本地模型不会将代码发送到任何外部服务器
3. **代码脱敏**
- 上传前移除敏感信息API Key、密码、Token 等)
- 使用占位符替换真实数据
- 移除包含个人身份信息PII的代码
4. **遵守合规要求**
- 遵守所在国家/地区关于数据保护和隐私的法律法规
- 遵守公司或组织的保密协议和安全政策
- 确保拥有代码的使用和分析权限
---
## 支持的安全版本
| 版本 | 支持状态 |
|------|---------|
| 2.x.x | ✅ 支持 |
| 1.x.x | ❌ 不再支持 |
---
## 报告安全漏洞
如果您发现安全漏洞,请通过以下方式负责任地披露:
### 报告方式
1. **邮箱报告(推荐)**
- 发送邮件至: lintsinghua@qq.com
- 邮件标题请注明: `[Security] DeepAudit 安全漏洞报告`
2. **GitHub Issues**
- 地址: [GitHub Issues](https://github.com/lintsinghua/DeepAudit/issues)
- ⚠️ **请勿公开披露敏感漏洞详情**
- 仅描述漏洞类型,详细信息请通过邮件发送
### 报告内容
请在报告中包含以下信息:
- 漏洞类型和严重程度评估
- 受影响的版本和组件
- 复现步骤
- 潜在影响
- 建议的修复方案(如有)
### 响应时间
- 我们会在 **48 小时内** 确认收到报告
- 在 **7 天内** 提供初步评估
- 根据漏洞严重程度,在 **30-90 天内** 发布修复
### 致谢
我们感谢所有负责任地报告安全问题的研究人员。在漏洞修复后,我们会在发布说明中致谢(除非您希望保持匿名)。
---
## 安全最佳实践
### 部署安全
1. **修改默认密钥**
```env
# 生产环境必须修改!
SECRET_KEY=your-random-secret-key-at-least-32-characters
```
2. **配置 HTTPS**
- 生产环境务必启用 HTTPS
- 使用 Let's Encrypt 或其他 SSL 证书
3. **限制 CORS**
- 生产环境配置具体的前端域名
- 不要使用 `allow_origins=["*"]`
4. **数据库安全**
- 修改默认数据库密码
- 限制数据库访问 IP
- 定期备份数据
5. **API 限流**
- 配置 Nginx 或应用层限流
- 防止 API 滥用
### 运行时安全
1. **定期更新依赖**
```bash
# 后端
cd backend && pip install --upgrade -r requirements.txt
# 前端
cd frontend && pnpm update
```
2. **监控日志**
- 配置日志收集
- 设置异常告警
3. **最小权限原则**
- 使用最小必要的权限运行服务
- 不要以 root 用户运行容器
---
## 第三方服务安全
本项目集成以下第三方服务,使用时请遵守其各自的服务条款和隐私政策:
| 服务 | 用途 | 隐私政策 |
|------|------|---------|
| OpenAI | LLM API | [Privacy Policy](https://openai.com/privacy/) |
| Google Gemini | LLM API | [Privacy Policy](https://policies.google.com/privacy) |
| Anthropic Claude | LLM API | [Privacy Policy](https://www.anthropic.com/privacy) |
| 阿里云通义千问 | LLM API | [隐私政策](https://terms.alicdn.com/legal-agreement/terms/suit_bu1_ali_cloud/suit_bu1_ali_cloud202112071754_83380.html) |
| DeepSeek | LLM API | [Privacy Policy](https://www.deepseek.com/privacy) |
| Supabase | 数据库 | [Privacy Policy](https://supabase.com/privacy) |
| GitHub | 仓库集成 | [Privacy Policy](https://docs.github.com/en/site-policy/privacy-policies) |
---
## 免责声明
项目作者、贡献者和维护者对因用户上传敏感代码导致的任何信息泄露、知识产权侵权、法律纠纷或其他损失不承担任何责任。
详细免责声明请参阅 [DISCLAIMER.md](DISCLAIMER.md)。

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 569 KiB