持续 AI (Continuous AI)
MyDeskBot 的 Continuous AI 功能让您在整个开发过程中享受 AI 的持续辅助,从需求分析到代码实现再到测试部署。
目录
什么是持续 AI
Continuous AI 是一种开发理念,将 AI 智能无缝集成到软件开发生命周期的每个环节:
- 📋 需求阶段 - 帮助理解和澄清需求
- 🎨 设计阶段 - 提供架构和设计建议
- 💻 开发阶段 - 辅助编码和重构
- 🧪 测试阶段 - 生成测试用例和测试代码
- 🚀 部署阶段 - 生成部署脚本和配置
- 🔧 维护阶段 - 辅助调试和文档更新
工作流程
开发生命周期集成
mermaid
graph TD
A[需求分析] --> B[系统设计]
B --> C[代码实现]
C --> D[代码审查]
D --> E[测试]
E --> F[部署]
F --> G[监控与维护]
G --> A
style A fill:#e1f5fe
style B fill:#fff3e0
style C fill:#f3e5f5
style D fill:#ffebee
style E fill:#e8f5e9
style F fill:#fff8e1
style G fill:#fce4ec核心功能
1. 需求分析辅助
自然语言到技术规格
输入:
用户需要一个博客系统,支持文章的增删改查,支持评论功能,
需要用户登录和权限管理,文章可以分类和标签管理。AI 输出 - 技术规格文档:
markdown
# 博客系统技术规格
## 功能需求
### 1. 文章管理
- 创建文章
- 标题(必填,1-200字符)
- 内容(必填,支持 Markdown)
- 摘要(可选,最多500字符)
- 封面图(可选)
- 状态:草稿/已发布
- 发布时间
- 查询文章
- 列表查询(分页、排序)
- 详情查询
- 按分类查询
- 按标签查询
- 全文搜索
- 更新文章
- 支持草稿和已发布状态
- 版本历史
- 删除文章
- 软删除
- 管理员可硬删除
### 2. 评论系统
- 评论文章
- 内容(必填,1-1000字符)
- 用户信息
- 时间戳
- 评论回复(支持多级)
- 评论管理(删除、审核)
### 3. 用户系统
- 用户注册/登录
- 邮箱验证
- 密码加密存储
- JWT 认证
- 角色管理
- 管理员
- 普通用户
- 权限管理
- 文章 CRUD 权限
- 评论管理权限
### 4. 分类和标签
- 分类管理
- 名称(必填)
- 描述(可选)
- 层级结构(可选)
- 标签管理
- 名称(必填)
- 文章数量统计
## 技术栈建议
### 后端
- 框架:NestJS / Spring Boot / Express
- 数据库:PostgreSQL
- ORM:TypeORM / Hibernate / Prisma
- 认证:JWT + Passport
- 缓存:Redis
### 前端
- 框架:React / Vue / Next.js
- UI 库:Ant Design / Element Plus / shadcn/ui
- 状态管理:Redux / Zustand / Pinia
- 富文本编辑器:Quill / Tiptap
### 部署
- 容器化:Docker
- CI/CD:GitHub Actions / GitLab CI
- 容器编排:Kubernetes(可选)
- 云服务:AWS / GCP / Azure
## 数据模型
```sql
-- 用户表
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
username VARCHAR(100) UNIQUE NOT NULL,
role VARCHAR(50) DEFAULT 'user',
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
-- 文章表
CREATE TABLE articles (
id SERIAL PRIMARY KEY,
title VARCHAR(200) NOT NULL,
content TEXT NOT NULL,
summary VARCHAR(500),
cover_image VARCHAR(500),
status VARCHAR(20) DEFAULT 'draft',
author_id INTEGER REFERENCES users(id),
category_id INTEGER REFERENCES categories(id),
published_at TIMESTAMP,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW(),
deleted_at TIMESTAMP
);
-- 评论表
CREATE TABLE comments (
id SERIAL PRIMARY KEY,
content TEXT NOT NULL,
article_id INTEGER REFERENCES articles(id) ON DELETE CASCADE,
user_id INTEGER REFERENCES users(id),
parent_id INTEGER REFERENCES comments(id) ON DELETE CASCADE,
created_at TIMESTAMP DEFAULT NOW()
);
-- 分类表
CREATE TABLE categories (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
description TEXT,
parent_id INTEGER REFERENCES categories(id),
created_at TIMESTAMP DEFAULT NOW()
);
-- 标签表
CREATE TABLE tags (
id SERIAL PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
-- 文章-标签关联表
CREATE TABLE article_tags (
article_id INTEGER REFERENCES articles(id) ON DELETE CASCADE,
tag_id INTEGER REFERENCES tags(id) ON DELETE CASCADE,
PRIMARY KEY (article_id, tag_id)
);
```API 端点设计
文章 API
- GET /api/articles - 获取文章列表
- GET /api/articles/:id - 获取文章详情
- POST /api/articles - 创建文章
- PUT /api/articles/:id - 更新文章
- DELETE /api/articles/:id - 删除文章
- GET /api/articles/search?q=keyword - 搜索文章
评论 API
- GET /api/articles/:id/comments - 获取文章评论
- POST /api/articles/:id/comments - 发表评论
- DELETE /api/comments/:id - 删除评论
用户 API
- POST /api/auth/register - 用户注册
- POST /api/auth/login - 用户登录
- GET /api/users/me - 获取当前用户信息
- PUT /api/users/me - 更新用户信息
### 2. 设计阶段辅助
#### 架构设计
**输入**: 请求生成微服务架构设计
**AI 输出**:
```yaml
# 微服务架构设计
services:
- name: api-gateway
description: API 网关,处理路由、认证、限流
port: 8080
dependencies:
- auth-service
- user-service
- article-service
- comment-service
- name: auth-service
description: 认证服务,处理用户认证和授权
port: 8081
database: users_db
cache: redis
- name: user-service
description: 用户服务,管理用户信息
port: 8082
database: users_db
- name: article-service
description: 文章服务,管理文章内容
port: 8083
database: articles_db
cache: redis
storage: s3
- name: comment-service
description: 评论服务,管理评论
port: 8084
database: comments_db
- name: search-service
description: 搜索服务,提供全文搜索
port: 8085
database: elasticsearch
databases:
- name: users_db
type: PostgreSQL
version: 14
- name: articles_db
type: PostgreSQL
version: 14
- name: comments_db
type: PostgreSQL
version: 14
- name: elasticsearch
type: Elasticsearch
version: 8.0
infrastructure:
message_queue: RabbitMQ
cache: Redis
storage: S3 compatible
monitoring: Prometheus + Grafana
logging: ELK Stack3. 开发阶段辅助
智能代码生成
typescript
// AI 根据需求自动生成完整的服务类
@Injectable()
export class ArticleService {
constructor(
@InjectRepository(Article)
private articleRepo: Repository<Article>,
private categoryService: CategoryService,
private tagService: TagService,
private cacheService: CacheService,
) {}
async findAll(dto: FindArticlesDto): Promise<PaginatedResult<Article>> {
const { page, limit, category, tags, status } = dto;
const skip = (page - 1) * limit;
const query = this.articleRepo
.createQueryBuilder("article")
.leftJoinAndSelect("article.author", "author")
.leftJoinAndSelect("article.category", "category")
.leftJoinAndSelect("article.tags", "tags");
if (category) {
query.andWhere("article.categoryId = :categoryId", {
categoryId: category,
});
}
if (tags && tags.length > 0) {
query.andWhere("tags.id IN (:...tagIds)", { tagIds: tags });
}
if (status) {
query.andWhere("article.status = :status", { status });
}
const [items, total] = await query
.skip(skip)
.take(limit)
.orderBy("article.createdAt", "DESC")
.getManyAndCount();
return {
items,
total,
page,
limit,
totalPages: Math.ceil(total / limit),
};
}
// ... 其他方法也会自动生成
}4. 测试阶段辅助
自动生成测试用例
typescript
// AI 自动生成完整的测试套件
describe("ArticleService", () => {
let service: ArticleService;
let repo: Repository<Article>;
beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [
ArticleService,
{
provide: getRepositoryToken(Article),
useValue: mockRepository(),
},
],
}).compile();
service = module.get<ArticleService>(ArticleService);
repo = module.get<Repository<Article>>(getRepositoryToken(Article));
});
describe("findAll", () => {
it("should return paginated articles", async () => {
const mockArticles = createMockArticles(5);
jest.spyOn(repo, "createQueryBuilder").mockReturnValue({
// Mock query builder methods
} as any);
const result = await service.findAll({ page: 1, limit: 10 });
expect(result.items).toHaveLength(5);
expect(result.total).toBe(5);
expect(result.page).toBe(1);
});
it("should filter by category", async () => {
// 测试分类过滤
});
it("should filter by status", async () => {
// 测试状态过滤
});
});
describe("create", () => {
it("should create an article", async () => {
const dto = createCreateArticleDto();
const expectedArticle = createMockArticle(dto);
jest.spyOn(repo, "create").mockReturnValue(expectedArticle);
jest.spyOn(repo, "save").mockResolvedValue(expectedArticle);
const result = await service.create(dto);
expect(result).toEqual(expectedArticle);
expect(repo.create).toHaveBeenCalledWith(dto);
expect(repo.save).toHaveBeenCalledWith(expectedArticle);
});
it("should throw error if title is empty", async () => {
const dto = { ...createCreateArticleDto(), title: "" };
await expect(service.create(dto)).rejects.toThrow(BadRequestException);
});
});
});5. 部署阶段辅助
生成部署配置
yaml
# docker-compose.yml (AI 自动生成)
version: "3.8"
services:
api-gateway:
build: ./services/api-gateway
ports:
- "8080:8080"
environment:
- AUTH_SERVICE_URL=http://auth-service:8081
- ARTICLE_SERVICE_URL=http://article-service:8083
depends_on:
- auth-service
- article-service
auth-service:
build: ./services/auth-service
ports:
- "8081:8081"
environment:
- DATABASE_URL=postgresql://postgres:password@users_db:5432/users
- REDIS_URL=redis://redis:6379
- JWT_SECRET=${JWT_SECRET}
depends_on:
- users_db
- redis
article-service:
build: ./services/article-service
ports:
- "8083:8083"
environment:
- DATABASE_URL=postgresql://postgres:password@articles_db:5432/articles
- REDIS_URL=redis://redis:6379
- S3_BUCKET=${S3_BUCKET}
- S3_REGION=${S3_REGION}
- S3_ACCESS_KEY=${S3_ACCESS_KEY}
- S3_SECRET_KEY=${S3_SECRET_KEY}
depends_on:
- articles_db
- redis
users_db:
image: postgres:14
environment:
- POSTGRES_DB=users
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
volumes:
- users_data:/var/lib/postgresql/data
articles_db:
image: postgres:14
environment:
- POSTGRES_DB=articles
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
volumes:
- articles_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
users_data:
articles_data:生成 CI/CD 配置
yaml
# .github/workflows/deploy.yml (AI 自动生成)
name: Deploy
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
env:
POSTGRES_PASSWORD: password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18"
cache: "yarn"
- run: yarn install
- run: yarn test
env:
DATABASE_URL: postgresql://postgres:password@localhost:5432/test
build:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Docker images
run: |
docker build -t myapp/api-gateway:${{ github.sha }} ./services/api-gateway
docker build -t myapp/auth-service:${{ github.sha }} ./services/auth-service
- name: Push to registry
run: |
docker push myapp/api-gateway:${{ github.sha }}
docker push myapp/auth-service:${{ github.sha }}
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to production
run: |
kubectl set image deployment/api-gateway api-gateway=myapp/api-gateway:${{ github.sha }}
kubectl set image deployment/auth-service auth-service=myapp/auth-service:${{ github.sha }}集成场景
场景 1: 功能开发流程
1. 需求输入
↓
2. AI 生成技术规格
↓
3. AI 设计数据模型和 API
↓
4. AI 生成项目骨架
↓
5. AI 辅助编码
↓
6. AI 生成测试用例
↓
7. AI 审查代码
↓
8. AI 生成部署配置
↓
9. 自动部署场景 2: Bug 修复流程
1. 报告 Bug
↓
2. AI 分析错误日志
↓
3. AI 定位可能原因
↓
4. AI 建议修复方案
↓
5. AI 生成修复代码
↓
6. AI 生成回归测试
↓
7. AI 审查修复
↓
8. 自动验证场景 3: 重构流程
1. AI 分析代码质量
↓
2. AI 识别重构机会
↓
3. AI 建议重构方案
↓
4. AI 生成重构计划
↓
5. AI 辅助逐步重构
↓
6. AI 验证重构
↓
7. AI 更新文档配置持续 AI
启用各阶段辅助
json
{
"mydeskbot": {
"continuous_ai": {
"enabled": true,
"stages": {
"requirements": {
"enabled": true,
"auto_generate": true,
"template": "tech-spec"
},
"design": {
"enabled": true,
"diagrams": true,
"architecture_patterns": ["microservices", "monolith", "serverless"]
},
"development": {
"enabled": true,
"code_generation": true,
"auto_complete": true,
"inline_suggestions": true
},
"testing": {
"enabled": true,
"auto_generate_tests": true,
"coverage_target": 80
},
"deployment": {
"enabled": true,
"generate_docker": true,
"generate_ci_cd": true
}
}
}
}
}最佳实践
1. 循序渐进
不要一次性启用所有功能,按阶段逐步引入:
- 第一阶段: 仅启用代码补全和审查
- 第二阶段: 添加测试生成
- 第三阶段: 启用设计和部署辅助
- 第四阶段: 全流程持续 AI
2. 人工审核
AI 的所有建议都需要人工审核和确认:
typescript
// AI 生成后,需要您:
// 1. 理解生成的代码
// 2. 验证是否符合需求
// 3. 检查安全性
// 4. 测试功能
// 5. 必要时修改3. 持续反馈
提供反馈帮助 AI 改进:
bash
# 记录 AI 建议
mydeskbot feedback --suggestion-id 12345 --type accept
# 修正 AI 建议
mydeskbot feedback --suggestion-id 12345 --type modify --correction "..."