Files
syops/.cursor/rules/code-comments.mdc
T

71 lines
2.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: 文件层与函数层注释强制规范(撰写与调整代码时均适用)
alwaysApply: true
---
# 代码注释(强制)
撰写或**修改**代码时,必须补齐或更新两层注释。完整说明见 `AGENTS.md` §5。
## 文件层(文件顶部)
块注释须包含:**用途**、**主要 import/依赖**、**与上下游文件的逻辑关系**。
```typescript
/**
* features/kb/composables/useKbWorkspace.ts
* 用途:知识库作业面编排入口,组合 state / computed / data 等子模块。
* 依赖:kb-workspace/* composables、kb.api、kb-display.utils。
* 逻辑:KbWorkspaceView 调用本 composable;本文件再分发至 useKbWorkspaceData 等子模块。
*/
```
```python
"""
services/kb_sync.py
用途:知识库文档与 Dify 之间的同步编排。
依赖:dify_service、models.KbDocument、minio_service。
逻辑:由 api/knowledge_base 路由调用;内部委托 chunking 与 job 状态机。
"""
```
## 函数层(每个函数定义上方)
须说明:**用途**、**核心逻辑与实现方式**、**参数**与**返回值**(及异常)。
```typescript
/**
* 加载当前分组下的文档列表,并在静默刷新时合并 stable 项避免闪烁。
* 核心逻辑:调用 getKbGroupFilesSafe,按 mergeStableItems 策略合并新旧列表。
* @param options.silent - 为 true 时不切换 loading,用于轮询刷新
* @returns 是否成功拉取到数据
*/
async function loadDocuments(options?: LoadListOptions): Promise<boolean> { ... }
```
```python
def sync_document_to_dify(document_id: int, *, force: bool = False) -> SyncResult:
"""
将指定文档切片同步至 Dify 知识库。
核心逻辑:读 MinIO 原文 → 切块 → 调 Dify API upsert;失败写入 KbJob 供重试。
Args:
document_id: 本地 KbDocument 主键。
force: 为 True 时忽略已完成状态强制重同步。
Returns:
SyncResult: 含 dify_document_id 与分段数。
Raises:
KbNotFoundError: 文档不存在或无权限。
"""
```
## 修改既有文件时
- 改函数逻辑/签名 → 同步改该函数注释。
- 改 import 或模块协作关系 → 同步改文件头注释。
- Vue SFC:`<script setup>` 内每个函数同样要求函数层注释。