docs: 更新 AGENTS.md 知识库,新增模块/管道/设计系统文档
This commit is contained in:
83
src/design-system/AGENTS.md
Normal file
83
src/design-system/AGENTS.md
Normal file
@@ -0,0 +1,83 @@
|
||||
# 设计系统指南
|
||||
|
||||
**生成时间:** 2026-03-08
|
||||
|
||||
## 概述
|
||||
|
||||
基于 CVA 的可复用 UI 组件库,与业务组件分离。
|
||||
|
||||
## 组件分类
|
||||
|
||||
| 类别 | 路径 | 组件 |
|
||||
|------|------|------|
|
||||
| 基础 | `base/` | button, input, card, checkbox, radio, switch, select, textarea, range |
|
||||
| 反馈 | `feedback/` | alert, progress, skeleton, toast |
|
||||
| 布局 | `layout/` | container, grid, stack (VStack, HStack) |
|
||||
| 覆盖层 | `overlay/` | modal |
|
||||
| 导航 | `navigation/` | tabs |
|
||||
|
||||
## CVA 模式
|
||||
|
||||
```tsx
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
const buttonVariants = cva("base-styles", {
|
||||
variants: {
|
||||
variant: { primary: "...", secondary: "...", ghost: "..." },
|
||||
size: { sm: "...", md: "...", lg: "..." },
|
||||
},
|
||||
defaultVariants: { variant: "secondary", size: "md" },
|
||||
});
|
||||
|
||||
export type ButtonVariant = VariantProps<typeof buttonVariants>["variant"];
|
||||
```
|
||||
|
||||
## 组件模板
|
||||
|
||||
```tsx
|
||||
"use client";
|
||||
import { forwardRef } from "react";
|
||||
import { cn } from "@/design-system/lib/utils";
|
||||
|
||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, leftIcon, rightIcon, children, ...props }, ref) => (
|
||||
<button ref={ref} className={cn(buttonVariants({ variant, size }), className)} {...props}>
|
||||
{leftIcon && <span className="mr-2">{leftIcon}</span>}
|
||||
{children}
|
||||
{rightIcon && <span className="ml-2">{rightIcon}</span>}
|
||||
</button>
|
||||
)
|
||||
);
|
||||
Button.displayName = "Button";
|
||||
export const PrimaryButton = (props: Omit<ButtonProps, "variant">) => <Button variant="primary" {...props} />;
|
||||
```
|
||||
|
||||
## 复合组件
|
||||
|
||||
```tsx
|
||||
<Card variant="bordered"><CardHeader><CardTitle>标题</CardTitle></CardHeader><CardBody>内容</CardBody></Card>
|
||||
<Modal open={isOpen}><Modal.Header><Modal.Title>标题</Modal.Title></Modal.Header><Modal.Body>内容</Modal.Body></Modal>
|
||||
```
|
||||
|
||||
## 导入方式
|
||||
|
||||
```tsx
|
||||
// ✅ 显式导入
|
||||
import { Button } from "@/design-system/base/button";
|
||||
import { Card, CardHeader, CardTitle, CardBody } from "@/design-system/base/card";
|
||||
// ❌ 不要创建 barrel export
|
||||
```
|
||||
|
||||
## 工具函数
|
||||
|
||||
```tsx
|
||||
import { cn } from "@/design-system/lib/utils";
|
||||
<div className={cn("base", condition && "conditional", className)} />
|
||||
```
|
||||
|
||||
## 添加新组件
|
||||
|
||||
1. 确定类别目录
|
||||
2. 创建 `{name}.tsx`,使用 CVA 定义变体
|
||||
3. 添加 `"use client"` + `forwardRef` + `displayName`
|
||||
4. 导出组件、变体类型、快捷组件
|
||||
90
src/lib/bigmodel/AGENTS.md
Normal file
90
src/lib/bigmodel/AGENTS.md
Normal file
@@ -0,0 +1,90 @@
|
||||
# AI 管道架构指南
|
||||
|
||||
**生成时间:** 2026-03-08
|
||||
|
||||
## 概述
|
||||
|
||||
AI 处理采用多阶段管道路径,由 orchestrator 协调各 stage 执行。
|
||||
|
||||
## 结构
|
||||
|
||||
```
|
||||
{name}/
|
||||
├── orchestrator.ts # 协调器:编排所有阶段
|
||||
├── types.ts # 共享接口定义
|
||||
├── stage1-{name}.ts # 阶段 1
|
||||
├── stage2-{name}.ts # 阶段 2
|
||||
└── ...
|
||||
```
|
||||
|
||||
## 现有管道
|
||||
|
||||
| 管道 | 阶段数 | 用途 |
|
||||
|------|--------|------|
|
||||
| dictionary | 4 | 词典查询(输入分析→语义映射→标准形式→词条生成)|
|
||||
| translator | 1 | 翻译处理 |
|
||||
|
||||
## 阶段命名约定
|
||||
|
||||
```typescript
|
||||
// 函数命名:动词+名词
|
||||
async function analyzeInput(text: string): Promise<InputAnalysisResult>
|
||||
async function determineSemanticMapping(...): Promise<SemanticMappingResult>
|
||||
async function generateStandardForm(...): Promise<StandardFormResult>
|
||||
async function generateEntries(...): Promise<EntriesResult>
|
||||
|
||||
// 结果接口命名:动词+名词+Result
|
||||
interface InputAnalysisResult {
|
||||
language: string;
|
||||
normalizedText: string;
|
||||
}
|
||||
```
|
||||
|
||||
## Orchestrator 模板
|
||||
|
||||
```typescript
|
||||
// orchestrator.ts
|
||||
import { analyzeInput } from "./stage1-inputAnalysis";
|
||||
import { determineSemanticMapping } from "./stage2-semanticMapping";
|
||||
import { generateStandardForm } from "./stage3-standardForm";
|
||||
import { generateEntries } from "./stage4-entriesGeneration";
|
||||
|
||||
export async function orchestrateDictionaryLookup(text: string, queryLang: string, defLang: string) {
|
||||
// 阶段 1:输入分析
|
||||
const analysis = await analyzeInput(text, queryLang);
|
||||
|
||||
// 阶段 2:语义映射
|
||||
const mapping = await determineSemanticMapping(analysis);
|
||||
|
||||
// 阶段 3:标准形式
|
||||
const standard = await generateStandardForm(mapping, defLang);
|
||||
|
||||
// 阶段 4:词条生成
|
||||
const entries = await generateEntries(standard);
|
||||
|
||||
return entries;
|
||||
}
|
||||
```
|
||||
|
||||
## AI 响应解析
|
||||
|
||||
```typescript
|
||||
import { parseAIGeneratedJSON } from "@/utils/json";
|
||||
|
||||
// AI 返回的 JSON 可能包含 markdown 代码块,用此函数解析
|
||||
const result = parseAIGeneratedJSON<ExpectedType>(aiResponseString);
|
||||
```
|
||||
|
||||
## 添加新管道
|
||||
|
||||
1. 创建目录 `src/lib/bigmodel/{name}/`
|
||||
2. 创建 `types.ts` 定义阶段间传递的接口
|
||||
3. 创建 `stage{n}-{name}.ts` 实现各阶段
|
||||
4. 创建 `orchestrator.ts` 编排调用顺序
|
||||
5. 在 Service 层调用 orchestrator
|
||||
|
||||
## 依赖
|
||||
|
||||
- `@/lib/bigmodel/zhipu.ts` — 智谱 AI 客户端
|
||||
- `@/lib/bigmodel/tts.ts` — 阿里云千问 TTS
|
||||
- `@/utils/json` — AI JSON 响应解析
|
||||
88
src/modules/AGENTS.md
Normal file
88
src/modules/AGENTS.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# 模块层架构指南
|
||||
|
||||
**生成时间:** 2026-03-08
|
||||
|
||||
## 概述
|
||||
|
||||
业务模块采用 Action-Service-Repository 三层架构,每模块 6 个文件。
|
||||
|
||||
## 结构
|
||||
|
||||
```
|
||||
{name}/
|
||||
├── {name}-action.ts # Server Actions
|
||||
├── {name}-action-dto.ts # Zod 验证 + 类型
|
||||
├── {name}-service.ts # 业务逻辑
|
||||
├── {name}-service-dto.ts # Service 类型
|
||||
├── {name}-repository.ts # 数据库操作
|
||||
└── {name}-repository-dto.ts # Repository 类型
|
||||
```
|
||||
|
||||
## 文件职责
|
||||
|
||||
| 层级 | 文件 | 职责 |
|
||||
|------|------|------|
|
||||
| Action | `*-action.ts` | 表单处理、Zod 验证、重定向、返回 ActionOutput |
|
||||
| Service | `*-service.ts` | 业务逻辑、跨模块调用、调用 Repository |
|
||||
| Repository | `*-repository.ts` | Prisma 查询、纯数据访问 |
|
||||
|
||||
## 命名约定
|
||||
|
||||
```typescript
|
||||
// 类型命名
|
||||
type ActionInputSignUp = { ... };
|
||||
type ActionOutputSignUp = { ... };
|
||||
type ServiceInputSignUp = { ... };
|
||||
type RepoOutputUser = { ... };
|
||||
|
||||
// 函数命名
|
||||
async function actionSignUp(input: ActionInputSignUp): Promise<ActionOutputSignUp>
|
||||
async function serviceSignUp(input: ServiceInputSignUp): Promise<ServiceOutputSignUp>
|
||||
async function repoFindUserByUsername(username: string): Promise<RepoOutputUser | null>
|
||||
|
||||
// 验证函数
|
||||
function validateActionInputSignUp(input: unknown): ActionInputSignUp
|
||||
```
|
||||
|
||||
## Action 模板
|
||||
|
||||
```typescript
|
||||
"use server";
|
||||
|
||||
import { validate } from "@/utils/validate";
|
||||
import { ActionInputSignUp, ActionOutputSignUp, schemaActionInputSignUp } from "./auth-action-dto";
|
||||
import { serviceSignUp } from "./auth-service";
|
||||
|
||||
export async function actionSignUp(input: unknown): Promise<ActionOutputSignUp> {
|
||||
const validated = validate(schemaActionInputSignUp, input);
|
||||
if (!validated.success) return { success: false, message: validated.message };
|
||||
|
||||
return serviceSignUp(validated.data);
|
||||
}
|
||||
```
|
||||
|
||||
## 受保护操作
|
||||
|
||||
```typescript
|
||||
// 在 Action 中检查会话
|
||||
import { auth } from "@/auth";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, message: "未授权" };
|
||||
}
|
||||
|
||||
// 变更前检查所有权
|
||||
const isOwner = await checkOwnership(resourceId, session.user.id);
|
||||
if (!isOwner) {
|
||||
return { success: false, message: "无权限" };
|
||||
}
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 所有 action 文件必须有 `"use server"` 指令
|
||||
- DTO 文件只放 Zod schema 和类型定义
|
||||
- Repository 层不处理业务逻辑,只做数据访问
|
||||
- 跨模块调用通过 Service 层
|
||||
Reference in New Issue
Block a user