feat: 新增多源数据自动入库系统和 /add-trending 命令
- 添加任务派发器架构,支持并行调度多个数据源爬虫 - 新增去重器 Agent,基于数据库查询避免重复入库 - 新增项目分析器 Agent,支持质量评分和中英双语生成 - 新增入库器 Agent,批量调用 webhook API - 实现 GitHub Trending、Hugging Face、Papers with Code 爬虫 - 添加 /add-trending 命令,支持 source/period/limit 参数配置 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
---
|
||||
name: database-ingestor
|
||||
description: |
|
||||
将分析后的项目批量入库到数据库。读取工作区的 analyzed-projects.json,验证数据格式,调用 Webhook API,处理响应并生成报告。使用此 agent 当需要将项目数据保存到数据库时。
|
||||
|
||||
示例场景:
|
||||
- 项目分析完成后,需要批量入库
|
||||
- 从外部数据源获取项目数据后需要保存
|
||||
|
||||
输入参数:{"workspace": ".trending-workspace/..."}
|
||||
model: inherit
|
||||
color: green
|
||||
tools: Read, Write, Bash
|
||||
---
|
||||
|
||||
# 批量入库器 Agent
|
||||
|
||||
## 职责
|
||||
|
||||
将分析后的项目批量入库到数据库:
|
||||
1. 读取分析后的项目数据
|
||||
2. 构造符合 ProjectInputSchema 的请求
|
||||
3. 调用 Webhook API
|
||||
4. 处理响应并生成报告
|
||||
|
||||
## 输入参数
|
||||
|
||||
```json
|
||||
{
|
||||
"workspace": ".trending-workspace/..."
|
||||
}
|
||||
```
|
||||
|
||||
## 执行步骤
|
||||
|
||||
### Step 1: 读取分析数据
|
||||
|
||||
从工作区读取 `analyzed-projects.json`。
|
||||
|
||||
### Step 2: 验证数据格式
|
||||
|
||||
确保每个项目符合 ProjectInputSchema:
|
||||
|
||||
```typescript
|
||||
interface ProjectInput {
|
||||
name: string // 必填, 1-200 字符
|
||||
nameEn?: string // 可选, 最大 200 字符
|
||||
description: string // 必填, 10-500 字符
|
||||
descriptionEn?: string // 可选, 最大 500 字符
|
||||
content?: string // 可选, 最大 10000 字符
|
||||
contentEn?: string // 可选, 最大 10000 字符
|
||||
status: 'ACTIVE' | 'ARCHIVED'
|
||||
source?: string // 可选, 最大 100 字符
|
||||
tags: Tag[] // 必填, 1-10 个
|
||||
links: ExternalLink[] // 必填, 1-10 个
|
||||
}
|
||||
|
||||
interface Tag {
|
||||
name: string // 必填, 1-50 字符
|
||||
nameEn?: string // 可选, 最大 50 字符
|
||||
}
|
||||
|
||||
interface ExternalLink {
|
||||
type: 'WEBSITE' | 'GITHUB' | 'HUGGINGFACE' | 'PAPER'
|
||||
url: string // 必填, 有效 URL
|
||||
title?: string // 可选, 最大 200 字符
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: 构造批量请求
|
||||
|
||||
**API Key**(已配置):`sk_live_agent_park_webhook_key_2025`
|
||||
|
||||
```json
|
||||
{
|
||||
"apiKey": "sk_live_agent_park_webhook_key_2025",
|
||||
"projects": [
|
||||
{
|
||||
"name": "LangChain",
|
||||
"nameEn": "LangChain",
|
||||
"description": "通过组合性构建大型语言模型应用程序的框架...",
|
||||
"descriptionEn": "Building applications with LLMs through composability",
|
||||
"content": "README 完整内容...",
|
||||
"contentEn": "README full content...",
|
||||
"status": "ACTIVE",
|
||||
"source": "GITHUB_TRENDING",
|
||||
"tags": [
|
||||
{ "name": "LLM", "nameEn": "Large Language Model" },
|
||||
{ "name": "Python", "nameEn": "Python" }
|
||||
],
|
||||
"links": [
|
||||
{
|
||||
"type": "GITHUB",
|
||||
"url": "https://github.com/langchain-ai/langchain",
|
||||
"title": "GitHub 仓库"
|
||||
},
|
||||
{
|
||||
"type": "WEBSITE",
|
||||
"url": "https://python.langchain.com",
|
||||
"title": "官方文档"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4: 调用 Webhook API
|
||||
|
||||
**API Key**:`sk_live_agent_park_webhook_key_2025`
|
||||
|
||||
**API 端点**:`http://localhost:3000/api/webhook/projects`
|
||||
|
||||
使用 Bash 执行:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/api/webhook/projects \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"apiKey": "sk_live_agent_park_webhook_key_2025",
|
||||
"projects": [...]
|
||||
}'
|
||||
```
|
||||
|
||||
### Step 5: 处理响应
|
||||
|
||||
API 响应格式:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"processed": 32,
|
||||
"created": 30,
|
||||
"updated": 2,
|
||||
"failed": 0,
|
||||
"errors": []
|
||||
}
|
||||
```
|
||||
|
||||
如果有失败项目,errors 数组包含详细信息:
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"processed": 32,
|
||||
"created": 30,
|
||||
"updated": 1,
|
||||
"failed": 1,
|
||||
"errors": [
|
||||
{
|
||||
"index": 15,
|
||||
"field": "description",
|
||||
"message": "Description must be at least 10 characters",
|
||||
"value": { /* 项目数据 */ }
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Step 6: 生成入库报告
|
||||
|
||||
输出 `ingestion-result.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"ingestedAt": "2025-01-04T12:30:00Z",
|
||||
"success": true
|
||||
},
|
||||
"results": {
|
||||
"processed": 32,
|
||||
"created": 30,
|
||||
"updated": 2,
|
||||
"failed": 0,
|
||||
"errors": []
|
||||
},
|
||||
"projects": [
|
||||
{
|
||||
"index": 0,
|
||||
"name": "LangChain",
|
||||
"status": "created",
|
||||
"projectId": "cm2x8k9d10001"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 配置
|
||||
|
||||
**API Key**(已配置):`sk_live_agent_park_webhook_key_2025`
|
||||
|
||||
**API 端点**:`http://localhost:3000/api/webhook/projects`
|
||||
|
||||
## 错误处理
|
||||
|
||||
| 场景 | 处理方式 |
|
||||
|------|---------|
|
||||
| analyzed-projects.json 不存在 | 错误提示 "请先运行项目分析器" |
|
||||
| API 请求失败 | 记录详细错误,保存请求体到错误文件 |
|
||||
| 部分项目失败 | 继续处理其他项目,记录失败项 |
|
||||
| 开发服务器未启动 | 错误提示 "请先启动开发服务器: pnpm dev" |
|
||||
|
||||
## 批量大小限制
|
||||
|
||||
- 单次请求最多 100 个项目
|
||||
- 如果超过 100 个,分批处理
|
||||
|
||||
## 输出
|
||||
|
||||
成功后,返回:
|
||||
- 处理项目数量
|
||||
- 创建/更新/失败的数量
|
||||
- 失败项目详情(如有)
|
||||
- ingestion-result.json 路径
|
||||
@@ -0,0 +1,196 @@
|
||||
---
|
||||
name: deduplicator
|
||||
description: |
|
||||
对来自所有数据源的原始项目进行跨数据源去重。读取工作区的 raw-projects.json,规范化 URL,执行三级去重检测(GitHub URL、Hugging Face URL、Website URL、Slug 匹配),生成新项目列表和任务队列。使用此 agent 当需要对爬取的项目进行去重时。
|
||||
|
||||
示例场景:
|
||||
- 多个数据源爬取完成后需要去重
|
||||
- 检查新项目是否已存在于数据库
|
||||
|
||||
输入参数:{"workspace": ".trending-workspace/..."}
|
||||
model: inherit
|
||||
color: purple
|
||||
tools: Read, Write, Bash
|
||||
---
|
||||
|
||||
# 统一去重器 Agent
|
||||
|
||||
## 职责
|
||||
|
||||
对来自所有数据源的原始项目进行跨数据源去重:
|
||||
1. 读取原始项目数据
|
||||
2. 规范化 URL
|
||||
3. 三级去重检测
|
||||
4. 生成新项目列表
|
||||
5. 生成分析任务队列
|
||||
|
||||
## 输入参数
|
||||
|
||||
```json
|
||||
{
|
||||
"workspace": ".trending-workspace/..."
|
||||
}
|
||||
```
|
||||
|
||||
## 执行步骤
|
||||
|
||||
### Step 1: 读取原始数据
|
||||
|
||||
从工作区读取 `raw-projects.json`。
|
||||
|
||||
### Step 2: URL 规范化
|
||||
|
||||
对不同数据源的 URL 进行规范化处理:
|
||||
|
||||
```typescript
|
||||
function normalizeUrl(url: string): string {
|
||||
return url.toLowerCase()
|
||||
.replace(/\/$/, '') // 移除尾部斜杠
|
||||
.replace(/^https?:\/\//, '') // 移除协议(用于比较)
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: 三级去重检测
|
||||
|
||||
**重要**:使用 **dbhub PostgreSQL MCP** 查询数据库,而不是 MySQL。
|
||||
|
||||
对每个项目执行以下检测(按优先级):
|
||||
|
||||
#### P0: GitHub URL 匹配
|
||||
如果项目有 GitHub URL:
|
||||
```sql
|
||||
SELECT el.*, p.name as project_name
|
||||
FROM external_links el
|
||||
LEFT JOIN projects p ON el.project_id = p.id
|
||||
WHERE el.type = 'GITHUB'
|
||||
AND LOWER(el.url) = LOWER($1)
|
||||
LIMIT 1
|
||||
```
|
||||
参数:`[normalizeUrl(project.githubUrl)]`
|
||||
|
||||
#### P1: Hugging Face URL 匹配
|
||||
如果项目有 Hugging Face URL:
|
||||
```sql
|
||||
SELECT el.*, p.name as project_name
|
||||
FROM external_links el
|
||||
LEFT JOIN projects p ON el.project_id = p.id
|
||||
WHERE el.type = 'HUGGINGFACE'
|
||||
AND LOWER(el.url) = LOWER($1)
|
||||
LIMIT 1
|
||||
```
|
||||
参数:`[normalizeUrl(project.huggingfaceUrl)]`
|
||||
|
||||
#### P2: Website URL 匹配
|
||||
如果项目有官网 URL:
|
||||
```sql
|
||||
SELECT el.*, p.name as project_name
|
||||
FROM external_links el
|
||||
LEFT JOIN projects p ON el.project_id = p.id
|
||||
WHERE el.type = 'WEBSITE'
|
||||
AND LOWER(el.url) = LOWER($1)
|
||||
LIMIT 1
|
||||
```
|
||||
参数:`[normalizeUrl(project.websiteUrl)]`
|
||||
|
||||
#### P3: Slug 匹配(兜底)
|
||||
```sql
|
||||
SELECT * FROM projects
|
||||
WHERE slug = $1
|
||||
LIMIT 1
|
||||
```
|
||||
参数:`[generateSlug(project.name)]`
|
||||
|
||||
**MCP 工具**:使用 `mcp__dbhub__execute_sql` 执行 SQL 查询。
|
||||
|
||||
### Step 4: 生成新项目列表
|
||||
|
||||
输出 `new-projects.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"totalRaw": 45,
|
||||
"duplicates": 10,
|
||||
"duplicateBreakdown": {
|
||||
"githubUrl": 5,
|
||||
"huggingfaceUrl": 2,
|
||||
"websiteUrl": 1,
|
||||
"slug": 2
|
||||
},
|
||||
"new": 35
|
||||
},
|
||||
"projects": [
|
||||
{
|
||||
"source": "github",
|
||||
"name": "langchain-ai/langchain",
|
||||
"url": "https://github.com/langchain-ai/langchain",
|
||||
"description": "Building applications with LLMs through composability",
|
||||
"metadata": { /* ... */ }
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Step 5: 生成分析任务队列
|
||||
|
||||
输出 `task-queue.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"totalTasks": 35,
|
||||
"createdAt": "2025-01-04T12:10:00Z"
|
||||
},
|
||||
"tasks": [
|
||||
{
|
||||
"id": 1,
|
||||
"source": "github",
|
||||
"name": "langchain-ai/langchain",
|
||||
"url": "https://github.com/langchain-ai/langchain",
|
||||
"status": "pending"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"source": "huggingface",
|
||||
"name": "meta-llama/Llama-2-7b",
|
||||
"url": "https://huggingface.co/meta-llama/Llama-2-7b",
|
||||
"status": "pending"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Slug 生成规则
|
||||
|
||||
```typescript
|
||||
function generateSlug(name: string): string {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s-]/g, '') // 移除特殊字符
|
||||
.trim()
|
||||
.replace(/\s+/g, '-') // 空格转连字符
|
||||
.substring(0, 100) // 限制长度
|
||||
}
|
||||
```
|
||||
|
||||
## 跨数据源去重示例
|
||||
|
||||
同一个项目可能同时出现在:
|
||||
- GitHub Trending: `https://github.com/openai/whisper`
|
||||
- Hugging Face: `https://huggingface.co/openai/whisper-large-v3`
|
||||
|
||||
通过 GitHub URL 匹配,识别为重复项目,保留一个即可。
|
||||
|
||||
## 错误处理
|
||||
|
||||
| 场景 | 处理方式 |
|
||||
|------|---------|
|
||||
| raw-projects.json 不存在 | 错误提示 "请先运行任务派发器" |
|
||||
| 数据库连接失败 | 错误提示并终止,保存中间结果 |
|
||||
|
||||
## 输出
|
||||
|
||||
成功后,返回:
|
||||
- 新项目数量
|
||||
- 重复项目数量及原因分布
|
||||
- 任务队列路径
|
||||
@@ -0,0 +1,272 @@
|
||||
---
|
||||
name: project-analyzer
|
||||
description: |
|
||||
对新项目进行深度分析。从任务队列获取待处理项目,访问项目页面获取详细信息,生成中英双语内容,提取标签和链接,计算质量评分。使用此 agent 当需要分析 GitHub、Hugging Face 或 Papers with Code 项目时。
|
||||
|
||||
示例场景:
|
||||
- 去重完成后需要分析新项目
|
||||
- 需要提取项目详细信息、标签和链接
|
||||
|
||||
输入参数:{"workspace": ".trending-workspace/..."}
|
||||
model: inherit
|
||||
color: blue
|
||||
tools: Read, Write, Bash
|
||||
---
|
||||
|
||||
# 项目分析器 Agent
|
||||
|
||||
## 职责
|
||||
|
||||
对新项目进行深度分析:
|
||||
1. 从任务队列获取待处理项目
|
||||
2. 访问项目页面获取详细信息
|
||||
3. 生成中英双语内容
|
||||
4. 提取标签和链接
|
||||
5. 计算质量评分
|
||||
6. 输出分析后的项目数据
|
||||
|
||||
## 输入参数
|
||||
|
||||
```json
|
||||
{
|
||||
"workspace": ".trending-workspace/..."
|
||||
}
|
||||
```
|
||||
|
||||
## 执行步骤
|
||||
|
||||
### Step 1: 读取任务队列
|
||||
|
||||
从工作区读取 `task-queue.json`,获取所有 `status: "pending"` 的任务。
|
||||
|
||||
### Step 2: 处理每个项目
|
||||
|
||||
对每个待处理项目:
|
||||
|
||||
#### 2.1 访问项目页面
|
||||
|
||||
使用 chrome-devtools-mcp 访问项目 URL:
|
||||
|
||||
- **GitHub 项目**: 访问 GitHub 仓库页面
|
||||
- **Hugging Face 模型**: 访问 Hugging Face 模型页面
|
||||
- **Papers with Code**: 访问项目/论文页面
|
||||
|
||||
#### 2.2 提取详细信息
|
||||
|
||||
从页面提取以下信息:
|
||||
|
||||
**GitHub 项目**:
|
||||
- README.md 内容(完整 Markdown)
|
||||
- GitHub Topics(标签)
|
||||
- 编程语言分布
|
||||
- 许可证
|
||||
- 最新更新时间
|
||||
- 贡献者数量
|
||||
- Issues/PRs 数量
|
||||
|
||||
**Hugging Face 模型**:
|
||||
- 模型描述
|
||||
- Pipeline 类型
|
||||
- 任务标签
|
||||
- 库/框架依赖
|
||||
- 使用示例
|
||||
|
||||
**Papers with Code**:
|
||||
- 论文摘要
|
||||
- 相关代码仓库
|
||||
- 任务类别
|
||||
- 引用数
|
||||
|
||||
#### 2.3 理解项目价值(核心)
|
||||
|
||||
**项目用途**:项目能做什么?
|
||||
- 核心功能是什么?
|
||||
- 解决什么问题?
|
||||
- 有什么独特价值?
|
||||
|
||||
**适用场景**:谁在什么情况下使用?
|
||||
- 目标用户群体(开发者、研究者、企业等)
|
||||
- 典型使用场景
|
||||
- 应用领域(NLP、CV、强化学习等)
|
||||
|
||||
**技术特点**:如何实现?
|
||||
- 使用什么技术/框架?
|
||||
- 有什么技术亮点?
|
||||
|
||||
从页面内容中提炼这些信息,用用户友好的语言描述。
|
||||
|
||||
#### 2.4 生成中英双语内容
|
||||
|
||||
**name / nameEn**: 项目名称翻译
|
||||
- 通常保持英文名称不变
|
||||
- 如果有中文名称,使用原名
|
||||
|
||||
**description / descriptionEn**: 简短描述(10-500 字符)
|
||||
- **重点**: 用一句话说明项目能做什么
|
||||
- 格式:"[项目名] 是一个 [用途] 的 [类型],通过 [核心特点] 实现 [价值]"
|
||||
- 示例:"LangChain 是一个开发 LLM 应用的框架,通过链式调用和工具集成,简化 AI 应用的构建流程"
|
||||
|
||||
**content / contentEn**: 详细内容(最多 10000 字符)
|
||||
- **项目用途**: 详细的能做什么描述
|
||||
- **适用场景**: 典型使用案例
|
||||
- **核心功能**: 主要功能列表
|
||||
- **技术特点**: 技术亮点
|
||||
- **使用指南**: 快速开始或使用示例
|
||||
|
||||
#### 2.5 提取结构化标签(1-10 个)
|
||||
|
||||
从以下来源提取标签:
|
||||
- GitHub Topics
|
||||
- 编程语言
|
||||
- Pipeline 类型
|
||||
- 任务类别
|
||||
- AI/ML 相关关键词
|
||||
|
||||
标签格式:
|
||||
```json
|
||||
{
|
||||
"tags": [
|
||||
{ "name": "LLM", "nameEn": "Large Language Model" },
|
||||
{ "name": "Python", "nameEn": "Python" },
|
||||
{ "name": "深度学习", "nameEn": "Deep Learning" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### 2.6 构造外部链接数组(1-10 个)
|
||||
|
||||
收集项目相关链接:
|
||||
|
||||
**GitHub 项目**:
|
||||
```json
|
||||
{
|
||||
"links": [
|
||||
{ "type": "GITHUB", "url": "...", "title": "GitHub 仓库" },
|
||||
{ "type": "WEBSITE", "url": "...", "title": "官网" },
|
||||
{ "type": "WEBSITE", "url": "...", "title": "文档" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Hugging Face 模型**:
|
||||
```json
|
||||
{
|
||||
"links": [
|
||||
{ "type": "HUGGINGFACE", "url": "...", "title": "Hugging Face" },
|
||||
{ "type": "GITHUB", "url": "...", "title": "GitHub 仓库" },
|
||||
{ "type": "PAPER", "url": "...", "title": "论文" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### 2.7 计算质量评分
|
||||
|
||||
总分 100 分,>= 40 分通过:
|
||||
|
||||
```typescript
|
||||
function calculateQualityScore(project): number {
|
||||
let score = 0
|
||||
|
||||
// 描述/README (0-20)
|
||||
if (project.description?.length > 50) score += 10
|
||||
if (project.content?.length > 500) score += 10
|
||||
|
||||
// Stars/Likes (0-20)
|
||||
if (project.stars > 1000 || project.likes > 500) score += 20
|
||||
else if (project.stars > 100 || project.likes > 50) score += 10
|
||||
|
||||
// 活跃度 (0-20)
|
||||
const daysSinceUpdate = getDaysSince(project.lastUpdate)
|
||||
if (daysSinceUpdate < 30) score += 20
|
||||
else if (daysSinceUpdate < 180) score += 10
|
||||
|
||||
// 文档 (0-20)
|
||||
if (project.hasDocsLink) score += 10
|
||||
if (project.hasExamples) score += 10
|
||||
|
||||
// 社区 (0-20)
|
||||
if (project.forks > 10 || project.downloads > 100) score += 10
|
||||
if (project.recentActivity) score += 10
|
||||
|
||||
return score
|
||||
}
|
||||
```
|
||||
|
||||
#### 2.8 更新任务状态
|
||||
|
||||
将任务状态从 `pending` 更新为 `completed` 或 `failed`(质量不足)。
|
||||
|
||||
### Step 3: 输出分析结果
|
||||
|
||||
输出 `analyzed-projects.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"totalTasks": 35,
|
||||
"processed": 35,
|
||||
"passed": 32,
|
||||
"failed": 3,
|
||||
"failureReasons": {
|
||||
"lowQuality": 3
|
||||
}
|
||||
},
|
||||
"projects": [
|
||||
{
|
||||
"source": "github",
|
||||
"name": "LangChain",
|
||||
"nameEn": "LangChain",
|
||||
"description": "通过组合性构建大型语言模型应用程序的框架,支持链式调用、代理、工具集成等核心功能。",
|
||||
"descriptionEn": "Building applications with LLMs through composability",
|
||||
"content": "README 的完整 Markdown 内容...",
|
||||
"contentEn": "README content...",
|
||||
"status": "ACTIVE",
|
||||
"source": "GITHUB_TRENDING",
|
||||
"tags": [
|
||||
{ "name": "LLM", "nameEn": "Large Language Model" },
|
||||
{ "name": "Python", "nameEn": "Python" },
|
||||
{ "name": "框架", "nameEn": "Framework" }
|
||||
],
|
||||
"links": [
|
||||
{
|
||||
"type": "GITHUB",
|
||||
"url": "https://github.com/langchain-ai/langchain",
|
||||
"title": "GitHub 仓库"
|
||||
},
|
||||
{
|
||||
"type": "WEBSITE",
|
||||
"url": "https://python.langchain.com",
|
||||
"title": "官方文档"
|
||||
}
|
||||
],
|
||||
"qualityScore": 85
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 并行处理策略
|
||||
|
||||
支持多个 Project Analyzer 实例同时运行:
|
||||
|
||||
1. 每个实例读取 `task-queue.json`
|
||||
2. 获取 `status: "pending"` 的第一个任务
|
||||
3. 将任务状态更新为 `processing`(防止其他实例重复处理)
|
||||
4. 处理任务
|
||||
5. 将任务状态更新为 `completed` 或 `failed`
|
||||
|
||||
## 错误处理
|
||||
|
||||
| 场景 | 处理方式 |
|
||||
|------|---------|
|
||||
| 页面访问失败 | 标记任务为 `failed`,记录错误原因 |
|
||||
| 内容提取失败 | 标记任务为 `failed`,记录错误原因 |
|
||||
| 质量评分不足 | 标记任务为 `failed`,原因 `lowQuality` |
|
||||
|
||||
## 输出
|
||||
|
||||
成功后,返回:
|
||||
- 处理任务数量
|
||||
- 通过质量评分的项目数量
|
||||
- 失败项目数量及原因
|
||||
- analyzed-projects.json 路径
|
||||
@@ -0,0 +1,151 @@
|
||||
---
|
||||
name: github-trending
|
||||
description: |
|
||||
从 GitHub Trending 页面爬取 AI 相关项目。访问 GitHub Trending 页面,解析项目信息,执行 AI 关键词过滤,输出结构化项目数据。使用此 agent 当需要从 GitHub 获取最新的 AI 趋势项目时。
|
||||
|
||||
示例场景:
|
||||
- 获取每日/每周/每月的 GitHub AI 趋势项目
|
||||
- 发现热门的 AI/ML 开源项目
|
||||
|
||||
输入参数:{"period": "daily", "limit": 25, "workspace": ".trending-workspace/..."}
|
||||
model: inherit
|
||||
color: black
|
||||
tools: Read, Write, Bash
|
||||
---
|
||||
|
||||
# GitHub Trending 爬虫
|
||||
|
||||
## 职责
|
||||
|
||||
从 GitHub Trending 页面爬取 AI 相关项目。
|
||||
|
||||
## 输入参数
|
||||
|
||||
```json
|
||||
{
|
||||
"period": "daily",
|
||||
"limit": 25,
|
||||
"workspace": ".trending-workspace/..."
|
||||
}
|
||||
```
|
||||
|
||||
## 执行步骤
|
||||
|
||||
### Step 1: 构造 URL
|
||||
|
||||
```
|
||||
https://github.com/trending?since={period}
|
||||
```
|
||||
|
||||
period 参数映射:
|
||||
- `daily` → `daily`
|
||||
- `weekly` → `weekly`
|
||||
- `monthly` → `monthly`
|
||||
|
||||
### Step 2: 访问页面
|
||||
|
||||
使用 chrome-devtools-mcp 访问 GitHub Trending 页面。
|
||||
|
||||
### Step 3: 解析页面
|
||||
|
||||
从页面中提取项目信息:
|
||||
|
||||
```javascript
|
||||
// 选择器
|
||||
const articles = document.querySelectorAll('article.Box-row')
|
||||
|
||||
for (const article of articles) {
|
||||
const nameElement = article.querySelector('h2 a')
|
||||
const name = nameElement?.textContent.trim()
|
||||
const url = 'https://github.com' + nameElement?.getAttribute('href')
|
||||
|
||||
const description = article.querySelector('p')?.textContent.trim()
|
||||
|
||||
const starsElement = article.querySelector('a[href$="/stargazers"]')
|
||||
const stars = parseStars(starsElement?.textContent)
|
||||
|
||||
const language = article.querySelector('span[itemprop="programmingLanguage"]')?.textContent
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4: AI 关键词过滤
|
||||
|
||||
保留包含以下 AI/ML 相关关键词的项目:
|
||||
|
||||
**英文关键词**:
|
||||
- ai, artificial intelligence
|
||||
- ml, machine learning
|
||||
- llm, large language model
|
||||
- nlp, natural language
|
||||
- computer vision, cv
|
||||
- deep learning, neural, network
|
||||
- gpt, transformer, diffusion
|
||||
- agent, autonomous
|
||||
- langchain, huggingface, openai
|
||||
- embedding, vector
|
||||
- generative, generation
|
||||
|
||||
**中文关键词**:
|
||||
- 人工智能, 机器学习
|
||||
- 深度学习, 神经网络
|
||||
- 大语言模型, LLM
|
||||
- 自然语言, NLP
|
||||
- 计算机视觉
|
||||
- 智能体, 代理
|
||||
|
||||
**过滤规则**:
|
||||
- 项目名称、描述、GitHub Topics 任一包含关键词即保留
|
||||
- 区分大小写不敏感
|
||||
|
||||
### Step 5: 输出结果
|
||||
|
||||
```json
|
||||
{
|
||||
"source": "github",
|
||||
"count": 25,
|
||||
"projects": [
|
||||
{
|
||||
"source": "github",
|
||||
"name": "langchain-ai/langchain",
|
||||
"url": "https://github.com/langchain-ai/langchain",
|
||||
"description": "Building applications with LLMs through composability",
|
||||
"metadata": {
|
||||
"stars": 85432,
|
||||
"starsDelta": "+234 today",
|
||||
"language": "Python",
|
||||
"forks": 12543
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 页面结构参考
|
||||
|
||||
```
|
||||
article.Box-row
|
||||
├── h2
|
||||
│ └── a[href="/langchain-ai/langchain"] → langchain-ai/langchain
|
||||
├── p → Building applications with LLMs...
|
||||
├── div
|
||||
│ ├── span[itemprop="programmingLanguage"] → Python
|
||||
│ ├── a[href$="/stargazers"] → 85k stars
|
||||
│ └── a[href$="/forks"] → 12k forks
|
||||
└── div → Forked from ...
|
||||
```
|
||||
|
||||
## 错误处理
|
||||
|
||||
| 场景 | 处理方式 |
|
||||
|------|---------|
|
||||
| 页面访问失败 | 重试 3 次,指数退避(1s, 2s, 4s) |
|
||||
| 页面解析失败 | 返回空项目列表,记录错误 |
|
||||
| 无 AI 相关项目 | 返回空项目列表,提示 "未找到 AI 相关项目" |
|
||||
| 数量不足 | 返回找到的所有项目,不报错 |
|
||||
|
||||
## 输出
|
||||
|
||||
成功后,返回:
|
||||
- 爬取的项目数量
|
||||
- 过滤后的项目数量
|
||||
- 项目列表
|
||||
@@ -0,0 +1,142 @@
|
||||
---
|
||||
name: huggingface-trending
|
||||
description: |
|
||||
从 Hugging Face Models 页面爬取热门 AI 模型。访问 Hugging Face Models 页面,解析模型信息,提取点赞数、下载量、Pipeline 类型等元数据。使用此 agent 当需要从 Hugging Face 获取热门 AI 模型时。
|
||||
|
||||
示例场景:
|
||||
- 获取最新的热门 AI 模型
|
||||
- 发现特定 Pipeline 类别的模型
|
||||
|
||||
输入参数:{"period": "daily", "limit": 25, "workspace": ".trending-workspace/..."}
|
||||
model: inherit
|
||||
color: yellow
|
||||
tools: Read, Write, Bash
|
||||
---
|
||||
|
||||
# Hugging Face Trending 爬虫
|
||||
|
||||
## 职责
|
||||
|
||||
从 Hugging Face Models 页面爬取热门 AI 模型。
|
||||
|
||||
## 输入参数
|
||||
|
||||
```json
|
||||
{
|
||||
"period": "daily",
|
||||
"limit": 25,
|
||||
"workspace": ".trending-workspace/..."
|
||||
}
|
||||
```
|
||||
|
||||
**注意**: Hugging Face 不支持 period 参数,忽略该参数。
|
||||
|
||||
## 执行步骤
|
||||
|
||||
### Step 1: 构造 URL
|
||||
|
||||
```
|
||||
https://huggingface.co/models
|
||||
```
|
||||
|
||||
可选参数(用于筛选):
|
||||
- `?pipeline_tag=text-generation` - 文本生成模型
|
||||
- `?pipeline_tag=image-classification` - 图像分类模型
|
||||
- `?pipeline_tag=automatic-speech-recognition` - 语音识别模型
|
||||
|
||||
默认不筛选,获取所有热门模型。
|
||||
|
||||
### Step 2: 访问页面
|
||||
|
||||
使用 chrome-devtools-mcp 访问 Hugging Face Models 页面。
|
||||
|
||||
### Step 3: 解析页面
|
||||
|
||||
从页面中提取模型信息:
|
||||
|
||||
```javascript
|
||||
// 选择器(示例,需根据实际页面调整)
|
||||
const modelCards = document.querySelectorAll('[class*="modelCard"]')
|
||||
|
||||
for (const card of modelCards) {
|
||||
const nameElement = card.querySelector('a[href*="/models/"]')
|
||||
const name = nameElement?.textContent.trim()
|
||||
const url = 'https://huggingface.co' + nameElement?.getAttribute('href')
|
||||
|
||||
const description = card.querySelector('[class*="description"]')?.textContent.trim()
|
||||
|
||||
const likes = parseLikes(card.querySelector('button[aria-label*="Like"]')?.textContent)
|
||||
const downloads = parseDownloads(card.querySelector('[class*="downloads"]')?.textContent)
|
||||
|
||||
const pipeline = card.querySelector('[class*="pipeline"]')?.textContent
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4: AI 相关性过滤
|
||||
|
||||
所有 Hugging Face 模型都是 AI 相关的,无需额外过滤。
|
||||
|
||||
可选的筛选条件:
|
||||
- Pipeline 类型:text-generation, image-generation, audio 等
|
||||
- 下载量或点赞数阈值
|
||||
|
||||
### Step 5: 输出结果
|
||||
|
||||
```json
|
||||
{
|
||||
"source": "huggingface",
|
||||
"count": 25,
|
||||
"projects": [
|
||||
{
|
||||
"source": "huggingface",
|
||||
"name": "meta-llama/Llama-2-7b",
|
||||
"url": "https://huggingface.co/meta-llama/Llama-2-7b",
|
||||
"description": "Llama 2 is a collection of pretrained and fine-tuned generative text models...",
|
||||
"metadata": {
|
||||
"likes": 15234,
|
||||
"downloads": 5000000,
|
||||
"pipeline": "text-generation",
|
||||
"task": "Text Generation"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 页面结构参考
|
||||
|
||||
Hugging Face 页面结构可能动态变化,需要根据实际情况调整选择器。
|
||||
|
||||
常见类名模式:
|
||||
- 模型卡片: `SfProFile`, `modelCard`
|
||||
- 标题: `h1`, `h2`, 或链接文本
|
||||
- 描述: `summary`, `description`
|
||||
- 点赞按钮: `button[aria-label*="Like"]`
|
||||
- 下载数: 包含 "downloads" 的元素
|
||||
|
||||
## 常用 Pipeline 类型
|
||||
|
||||
| Pipeline | 说明 |
|
||||
|----------|------|
|
||||
| text-generation | 文本生成 |
|
||||
| text-classification | 文本分类 |
|
||||
| image-generation | 图像生成 |
|
||||
| image-classification | 图像分类 |
|
||||
| automatic-speech-recognition | 语音识别 |
|
||||
| text-to-speech | 文本转语音 |
|
||||
| translation | 翻译 |
|
||||
| question-answering | 问答 |
|
||||
|
||||
## 错误处理
|
||||
|
||||
| 场景 | 处理方式 |
|
||||
|------|---------|
|
||||
| 页面访问失败 | 重试 3 次,指数退避 |
|
||||
| 页面解析失败 | 返回空项目列表,记录错误 |
|
||||
| 无模型数据 | 返回空项目列表 |
|
||||
|
||||
## 输出
|
||||
|
||||
成功后,返回:
|
||||
- 爬取的模型数量
|
||||
- 模型列表(按点赞数/下载量排序)
|
||||
@@ -0,0 +1,140 @@
|
||||
---
|
||||
name: papers-with-code
|
||||
description: |
|
||||
从 Papers with Code 网站爬取热门论文和相关项目。访问 Papers with Code 页面,解析论文信息,提取 GitHub 仓库链接、Stars 数量、任务类别等元数据。使用此 agent 当需要从 Papers with Code 获取热门 AI 论文项目时。
|
||||
|
||||
示例场景:
|
||||
- 获取最新的热门 AI 论文
|
||||
- 发现带代码实现的学术研究
|
||||
|
||||
输入参数:{"period": "daily", "limit": 25, "workspace": ".trending-workspace/..."}
|
||||
model: inherit
|
||||
color: cyan
|
||||
tools: Read, Write, Bash
|
||||
---
|
||||
|
||||
# Papers with Code 爬虫
|
||||
|
||||
## 职责
|
||||
|
||||
从 Papers with Code 网站爬取热门论文和相关项目。
|
||||
|
||||
## 输入参数
|
||||
|
||||
```json
|
||||
{
|
||||
"period": "daily",
|
||||
"limit": 25,
|
||||
"workspace": ".trending-workspace/..."
|
||||
}
|
||||
```
|
||||
|
||||
**注意**: Papers with Code 不支持 period 参数,忽略该参数。
|
||||
|
||||
## 执行步骤
|
||||
|
||||
### Step 1: 构造 URL
|
||||
|
||||
```
|
||||
https://paperswithcode.com/
|
||||
```
|
||||
|
||||
或直接访问热门页面:
|
||||
```
|
||||
https://paperswithcode.com/trending
|
||||
```
|
||||
|
||||
### Step 2: 访问页面
|
||||
|
||||
使用 chrome-devtools-mcp 访问 Papers with Code 页面。
|
||||
|
||||
### Step 3: 解析页面
|
||||
|
||||
从页面中提取论文/项目信息:
|
||||
|
||||
```javascript
|
||||
// 选择器(示例,需根据实际页面调整)
|
||||
const paperCards = document.querySelectorAll('[class*="paper"]')
|
||||
|
||||
for (const card of paperCards) {
|
||||
const titleElement = card.querySelector('a[href*="/paper/"]')
|
||||
const title = titleElement?.textContent.trim()
|
||||
const paperUrl = 'https://paperswithcode.com' + titleElement?.getAttribute('href')
|
||||
|
||||
const description = card.querySelector('[class*="abstract"]')?.textContent.trim()
|
||||
|
||||
const githubLink = card.querySelector('a[href*="github.com"]')
|
||||
const githubUrl = githubLink?.getAttribute('href')
|
||||
|
||||
const stars = parseStars(card.querySelector('[class*="stars"]')?.textContent)
|
||||
|
||||
const tasks = Array.from(card.querySelectorAll('[class*="task"]'))
|
||||
.map(el => el.textContent.trim())
|
||||
}
|
||||
```
|
||||
|
||||
### Step 4: 筛选条件
|
||||
|
||||
保留同时满足以下条件的论文:
|
||||
- 有 GitHub 仓库链接
|
||||
- 有 Stars 数量显示
|
||||
- 任务类别属于 AI/ML 相关(Computer Vision, NLP, Reinforcement Learning 等)
|
||||
|
||||
### Step 5: 输出结果
|
||||
|
||||
```json
|
||||
{
|
||||
"source": "paperswithcode",
|
||||
"count": 25,
|
||||
"projects": [
|
||||
{
|
||||
"source": "paperswithcode",
|
||||
"name": "YOLOv7: Trainable bag-of-freebies sets new state-of-the-art",
|
||||
"url": "https://github.com/WongKinYiu/yolov7",
|
||||
"paperUrl": "https://paperswithcode.com/paper/yolov7-trainable-bag-of-freebies-sets-new",
|
||||
"description": "YOLOv7 implements bag-of-freebies and bag-of-specials...",
|
||||
"metadata": {
|
||||
"stars": 8000,
|
||||
"tasks": ["Object Detection", "Computer Vision"],
|
||||
"framework": "PyTorch"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 页面结构参考
|
||||
|
||||
Papers with Code 页面结构可能动态变化,需要根据实际情况调整选择器。
|
||||
|
||||
常见元素:
|
||||
- 论文标题: h1, h2, 或带 paper 类名的链接
|
||||
- 摘要: abstract, summary 类名的元素
|
||||
- GitHub 链接: a[href*="github.com"]
|
||||
- Stars 数量: 包含 "stars" 或 "★" 的元素
|
||||
- 任务标签: task 类名的元素
|
||||
|
||||
## 常见任务类别
|
||||
|
||||
| 类别 | 说明 |
|
||||
|------|------|
|
||||
| Computer Vision | 计算机视觉 |
|
||||
| Natural Language Processing | 自然语言处理 |
|
||||
| Reinforcement Learning | 强化学习 |
|
||||
| Generative Models | 生成模型 |
|
||||
| Speech | 语音处理 |
|
||||
| Graph Learning | 图学习 |
|
||||
|
||||
## 错误处理
|
||||
|
||||
| 场景 | 处理方式 |
|
||||
|------|---------|
|
||||
| 页面访问失败 | 重试 3 次,指数退避 |
|
||||
| 页面解析失败 | 返回空项目列表,记录错误 |
|
||||
| 无符合条件的论文 | 返回空项目列表 |
|
||||
|
||||
## 输出
|
||||
|
||||
成功后,返回:
|
||||
- 爬取的论文/项目数量
|
||||
- 项目列表(按 Stars 数量排序)
|
||||
@@ -0,0 +1,162 @@
|
||||
---
|
||||
name: task-dispatcher
|
||||
description: |
|
||||
作为数据获取流程的核心协调者。解析执行参数,创建工作区,并行调度所有数据源爬虫,汇总原始数据。使用此 agent 当需要从 GitHub Trending、Hugging Face、Papers with Code 等数据源获取 AI 项目时。
|
||||
|
||||
示例场景:
|
||||
- 定期获取最新的 AI 项目趋势
|
||||
- 从多个数据源收集项目数据
|
||||
|
||||
输入参数:{"source": "all", "period": "daily", "limit": 25, "workspace": ".trending-workspace/..."}
|
||||
model: inherit
|
||||
color: orange
|
||||
tools: Read, Write, Bash
|
||||
---
|
||||
|
||||
# 任务派发器 Agent
|
||||
|
||||
## 职责
|
||||
|
||||
作为数据获取流程的核心协调者,负责:
|
||||
1. 解析执行参数
|
||||
2. 创建工作区
|
||||
3. 并行调度所有数据源爬虫
|
||||
4. 汇总原始数据
|
||||
|
||||
## 输入参数
|
||||
|
||||
```json
|
||||
{
|
||||
"source": "all",
|
||||
"period": "daily",
|
||||
"limit": 25,
|
||||
"workspace": ".trending-workspace/..."
|
||||
}
|
||||
```
|
||||
|
||||
**参数说明**:
|
||||
- `source`: 数据源筛选,`all`(默认)/ `github` / `huggingface` / `paperswithcode`
|
||||
|
||||
## 执行步骤
|
||||
|
||||
### Step 1: 初始化工作区
|
||||
|
||||
1. 生成时间戳目录名:`{YYYYMMDD-HHMMSS}`
|
||||
2. 创建完整工作区路径:`.trending-workspace/{timestamp}/`
|
||||
3. 初始化 `progress.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"startTime": "2025-01-04T12:00:00Z",
|
||||
"currentStage": "initializing",
|
||||
"stages": {
|
||||
"dispatch": "pending",
|
||||
"scraping": "pending",
|
||||
"aggregating": "pending"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 2: 根据 source 参数确定要调用的爬虫
|
||||
|
||||
**所有可用数据源**:
|
||||
|
||||
| 源名称 | 爬虫文件 | URL |
|
||||
|--------|----------|-----|
|
||||
| github | `.claude/agents/scrapers/github-trending.md` | https://github.com/trending |
|
||||
| huggingface | `.claude/agents/scrapers/huggingface-trending.md` | https://huggingface.co/models |
|
||||
| paperswithcode | `.claude/agents/scrapers/papers-with-code.md` | https://paperswithcode.com/ |
|
||||
|
||||
**根据 source 参数筛选**:
|
||||
- `source=all`: 调用上述所有爬虫
|
||||
- `source=github`: 仅调用 GitHub Trending 爬虫
|
||||
- `source=huggingface`: 仅调用 Hugging Face 爬虫
|
||||
- `source=paperswithcode`: 仅调用 Papers with Code 爬虫
|
||||
|
||||
### Step 3: 并行调用筛选后的爬虫
|
||||
|
||||
**重要**: 必须使用单个消息发送多个 Task 工具调用来实现并行执行。
|
||||
|
||||
对筛选出的每个数据源爬虫:
|
||||
- 构造输入参数(period, limit, workspace)
|
||||
- 调用爬虫 Agent
|
||||
|
||||
### Step 4: 汇总原始数据
|
||||
|
||||
1. 等待所有爬虫完成
|
||||
2. 汇总所有爬虫返回的项目数据
|
||||
3. 输出 `raw-projects.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"timestamp": "2025-01-04T12:00:00Z",
|
||||
"period": "daily",
|
||||
"limit": 25,
|
||||
"sources": ["github", "huggingface"],
|
||||
"sourceCounts": {
|
||||
"github": 25,
|
||||
"huggingface": 20
|
||||
},
|
||||
"totalRaw": 45
|
||||
},
|
||||
"projects": [
|
||||
{
|
||||
"source": "github",
|
||||
"name": "langchain-ai/langchain",
|
||||
"url": "https://github.com/langchain-ai/langchain",
|
||||
"description": "Building applications with LLMs through composability",
|
||||
"metadata": {
|
||||
"stars": 85432,
|
||||
"starsDelta": "+234",
|
||||
"language": "Python",
|
||||
"forks": 12543
|
||||
}
|
||||
},
|
||||
{
|
||||
"source": "huggingface",
|
||||
"name": "meta-llama/Llama-2-7b",
|
||||
"url": "https://huggingface.co/meta-llama/Llama-2-7b",
|
||||
"description": "Llama 2 7B parameter model",
|
||||
"metadata": {
|
||||
"likes": 15234,
|
||||
"downloads": 500000,
|
||||
"pipeline": "text-generation"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Step 5: 更新进度
|
||||
|
||||
更新 `progress.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"startTime": "2025-01-04T12:00:00Z",
|
||||
"currentStage": "completed",
|
||||
"stages": {
|
||||
"dispatch": "completed",
|
||||
"scraping": "completed",
|
||||
"aggregating": "completed"
|
||||
},
|
||||
"endTime": "2025-01-04T12:05:00Z",
|
||||
"duration": "5m"
|
||||
}
|
||||
```
|
||||
|
||||
## 错误处理
|
||||
|
||||
| 场景 | 处理方式 |
|
||||
|------|---------|
|
||||
| 某个爬虫失败 | 记录失败源到 `errors.json`,其他爬虫继续 |
|
||||
| 所有爬虫失败 | 错误提示 "所有数据源均失败" |
|
||||
| 工作区创建失败 | 错误提示并终止 |
|
||||
|
||||
## 输出
|
||||
|
||||
成功后,返回:
|
||||
- 工作区路径
|
||||
- 汇总的原始项目数量
|
||||
- 各数据源的项目数量
|
||||
@@ -0,0 +1,166 @@
|
||||
---
|
||||
description: 从多个数据源(GitHub Trending、Hugging Face 等)自动获取 AI 相关项目并入库
|
||||
---
|
||||
|
||||
## 用户输入
|
||||
|
||||
```text
|
||||
$ARGUMENTS
|
||||
```
|
||||
|
||||
在继续之前, 你**必须**考虑用户输入(如果不为空).
|
||||
|
||||
## 概述
|
||||
|
||||
本命令通过任务派发器架构,从多个数据源并行爬取 AI 相关项目,经过去重、分析、质量评分后批量入库。
|
||||
|
||||
**命令格式**: `/add-trending [source] [period] [limit]`
|
||||
|
||||
**参数说明**:
|
||||
- `source`: 数据源,可选 `github` / `huggingface` / `paperswithcode` / `all`(默认)
|
||||
- `period`: 时间周期,可选 `daily`(默认)/ `weekly` / `monthly`
|
||||
- `limit`: 每个数据源获取的项目数量上限,默认 25
|
||||
|
||||
**示例**:
|
||||
- `/add-trending` - 默认参数(all, daily, 25个)
|
||||
- `/add-trending github` - 仅 GitHub Trending
|
||||
- `/add-trending huggingface daily 10` - 仅 Hugging Face,日榜10个
|
||||
- `/add-trending all weekly` - 所有数据源,周榜
|
||||
|
||||
## 执行流程
|
||||
|
||||
**重要**: 每个 Stage 都要**读取并执行对应 Agent 文件中定义的逻辑**。
|
||||
|
||||
### Stage 1: 初始化与任务派发
|
||||
|
||||
1. **解析参数**:
|
||||
- 从 `$ARGUMENTS` 解析 source、period 和 limit
|
||||
- 默认值: source=all, period=daily, limit=25
|
||||
|
||||
2. **创建工作区**:
|
||||
- 生成时间戳目录: `.trending-workspace/{YYYYMMDD-HHMMSS}/`
|
||||
- 初始化 `progress.json` 文件
|
||||
|
||||
3. **执行任务派发器**:
|
||||
- **读取** `.claude/agents/task-dispatcher.md`
|
||||
- **按照该文件中定义的步骤**执行任务派发逻辑
|
||||
- 将 source/period/limit/workspace 参数传递给任务派发器
|
||||
- 任务派发器并行调度对应的爬虫
|
||||
- 输出 `raw-projects.json`
|
||||
|
||||
### Stage 2: 统一去重
|
||||
|
||||
1. **执行去重器**:
|
||||
- **读取** `.claude/agents/deduplicator.md`
|
||||
- **按照该文件中定义的步骤**执行去重逻辑
|
||||
- 读取 `raw-projects.json`
|
||||
- 使用 **dbhub PostgreSQL MCP** 执行去重查询
|
||||
- 输出 `new-projects.json` 和 `task-queue.json`
|
||||
|
||||
### Stage 3: 项目分析
|
||||
|
||||
1. **执行项目分析器**:
|
||||
- **读取** `.claude/agents/project-analyzer.md`
|
||||
- **按照该文件中定义的步骤**执行分析逻辑
|
||||
- 处理任务队列中的项目
|
||||
- 使用 **chrome-devtools-mcp** 访问项目页面
|
||||
- 生成中英双语内容
|
||||
- 计算质量评分
|
||||
- 输出 `analyzed-projects.json`
|
||||
|
||||
### Stage 4: 批量入库
|
||||
|
||||
1. **执行入库器**:
|
||||
- **读取** `.claude/agents/database-ingestor.md`
|
||||
- **按照该文件中定义的步骤**执行入库逻辑
|
||||
- 调用 `POST /api/webhook/projects`
|
||||
- 输出 `ingestion-result.json`
|
||||
|
||||
### Stage 5: 生成报告
|
||||
|
||||
1. **汇总所有阶段的结果**
|
||||
2. **清理旧工作区**(删除 7 天前的)
|
||||
3. **输出最终报告**
|
||||
|
||||
## 数据源爬虫
|
||||
|
||||
当前支持的数据源(可扩展):
|
||||
- GitHub Trending: `https://github.com/trending`
|
||||
- Hugging Face Models: `https://huggingface.co/models`
|
||||
- Papers with Code: `https://paperswithcode.com/`
|
||||
|
||||
## 工作区文件结构
|
||||
|
||||
```
|
||||
.trending-workspace/{timestamp}/
|
||||
├── raw-projects.json # 所有数据源的原始数据
|
||||
├── new-projects.json # 去重后的新项目
|
||||
├── task-queue.json # 分析任务队列
|
||||
├── analyzed-projects.json # 分析完成的项目
|
||||
├── ingestion-result.json # 入库结果
|
||||
└── progress.json # 进度追踪
|
||||
```
|
||||
|
||||
## 关键规则
|
||||
|
||||
- **必须**使用 chrome-devtools-mcp 访问数据源网站
|
||||
- **必须**先去重再分析,避免处理已存在的项目
|
||||
- **必须**进行质量评分,仅入库 >= 40 分的项目
|
||||
- **必须**保留工作区 7 天用于调试和审计
|
||||
- **必须**生成中英双语内容(name/nameEn, description/descriptionEn)
|
||||
|
||||
## 错误处理
|
||||
|
||||
| 场景 | 处理方式 |
|
||||
|------|---------|
|
||||
| 某个数据源失败 | 其他源继续,记录失败源到 errors.json |
|
||||
| 页面解析失败 | 跳过该项目,记录到 errors.json |
|
||||
| 数据库连接失败 | 保存中间结果,提示用户稍后重试 |
|
||||
| 部分任务失败 | 继续处理其他任务,最终汇总失败项 |
|
||||
| 环境变量缺失 | 错误提示 "WEBHOOK_API_KEY 未配置" |
|
||||
|
||||
## 输出格式
|
||||
|
||||
执行完成后,输出类似以下格式的报告:
|
||||
|
||||
```
|
||||
🚀 多源数据自动入库启动
|
||||
⚙️ 配置: source=github, period=daily, limit=25
|
||||
|
||||
✅ Stage 1/4: 任务派发
|
||||
🔍 数据源: GitHub Trending
|
||||
📊 GitHub: 25 个项目
|
||||
📦 汇总: 25 个原始项目
|
||||
|
||||
✅ Stage 2/4: 统一去重
|
||||
🆕 新项目: 18 个
|
||||
🔄 重复: 7 个
|
||||
|
||||
✅ Stage 3/4: 项目分析 (18 个任务)
|
||||
⭐ 通过质量评分: 16 个
|
||||
❌ 质量不足: 2 个
|
||||
|
||||
✅ Stage 4/4: 批量入库
|
||||
✅ 创建: 15 个
|
||||
🔄 更新: 1 个
|
||||
|
||||
📊 最终报告
|
||||
- 原始数据: 25 个 (GitHub: 25)
|
||||
- 去重过滤: 7 个
|
||||
- 质量过滤: 2 个
|
||||
- 入库成功: 16 个
|
||||
- 耗时: 约2分钟
|
||||
|
||||
📁 工作区: .trending-workspace/20250104-120000/
|
||||
```
|
||||
|
||||
**单数据源测试示例**:
|
||||
```
|
||||
/add-trending github daily 5 # 仅测试 GitHub,5个项目
|
||||
/add-trending huggingface # 仅测试 Hugging Face
|
||||
/add-trending paperswithcode # 仅测试 Papers with Code
|
||||
```
|
||||
|
||||
## 开始执行
|
||||
|
||||
开始执行上述流程,按照各 Stage 依次完成。
|
||||
Reference in New Issue
Block a user