{
  "name": "GitHub 开源项目质量评估 Agent",
  "platform": "Coze (扣子)",
  "version": "1.0.0",
  "description": "基于 Coze 打造的开源项目审查智能体，输入 GitHub 仓库链接即可自动评估 Star 趋势、代码质量与社区活跃度",
  "bot": {
    "model": "Claude 3.5 Sonnet",
    "systemPrompt": "你是一个专业的开源项目评估专家。你的职责是对 GitHub 仓库进行全面的质量评估，包括代码规范、社区活跃度、安全性和可维护性。\n\n## 评估维度\n1. **社区活跃度** (25%): Star 趋势、PR/Issue 响应速度、贡献者数量\n2. **代码质量** (25%): 目录结构、代码规范、测试覆盖率\n3. **安全性** (20%): 依赖漏洞、敏感信息泄露、权限控制\n4. **可维护性** (20%): 文档质量、架构设计、技术债务\n5. **合规性** (10%): License 合规、贡献指南、行为准则\n\n## 输出格式\n生成包含以下内容的 Markdown 报告：\n- 总体评分 (A+/A/B/C/D 等级)\n- 各维度分项得分\n- 核心发现与风险提示\n- 替代方案推荐\n\n## 约束\n- 评分必须基于数据，不要主观臆断\n- 如果 API 数据获取失败，明确标注\n- 对安全风险给予更高权重",
    "openingMessage": "你好！我是一个开源项目质量评估助手。只需输入 GitHub 仓库链接（如 https://github.com/facebook/react），我会自动分析代码质量、社区活跃度、安全性等维度，并给出综合评分。",
    "suggestedQuestions": [
      "分析 https://github.com/langchain-ai/langchain",
      "评估最新 Trending 的 Python 项目",
      "对比 React 和 Vue 的质量分"
    ]
  },
  "plugins": [
    {
      "name": "GitHub 仓库信息",
      "type": "api_request",
      "description": "通过 GitHub API 获取仓库基本信息",
      "config": {
        "method": "GET",
        "url": "https://api.github.com/repos/{{owner}}/{{repo}}",
        "headers": {
          "Authorization": "Bearer {{GITHUB_TOKEN}}",
          "Accept": "application/vnd.github.v3+json"
        }
      }
    },
    {
      "name": "GitHub Star 历史",
      "type": "api_request",
      "description": "获取仓库 Star 增长趋势",
      "config": {
        "method": "GET",
        "url": "https://api.github.com/repos/{{owner}}/{{repo}}/stargazers",
        "headers": {
          "Authorization": "Bearer {{GITHUB_TOKEN}}",
          "Accept": "application/vnd.github.v3.star+json"
        },
        "queryParams": {
          "per_page": 100,
          "page": 1
        }
      }
    },
    {
      "name": "GitHub Commit 活跃度",
      "type": "api_request",
      "description": "获取仓库 Commit 活跃度统计",
      "config": {
        "method": "GET",
        "url": "https://api.github.com/repos/{{owner}}/{{repo}}/stats/commit_activity",
        "headers": {
          "Authorization": "Bearer {{GITHUB_TOKEN}}",
          "Accept": "application/vnd.github.v3+json"
        }
      }
    },
    {
      "name": "GitHub Issues 统计",
      "type": "api_request",
      "description": "获取仓库 Issue 和 PR 响应数据",
      "config": {
        "method": "GET",
        "url": "https://api.github.com/repos/{{owner}}/{{repo}}/issues",
        "headers": {
          "Authorization": "Bearer {{GITHUB_TOKEN}}",
          "Accept": "application/vnd.github.v3+json"
        },
        "queryParams": {
          "state": "all",
          "per_page": 100,
          "sort": "updated",
          "direction": "desc"
        }
      }
    },
    {
      "name": "GitHub 贡献者统计",
      "type": "api_request",
      "description": "获取仓库贡献者列表",
      "config": {
        "method": "GET",
        "url": "https://api.github.com/repos/{{owner}}/{{repo}}/contributors",
        "headers": {
          "Authorization": "Bearer {{GITHUB_TOKEN}}",
          "Accept": "application/vnd.github.v3+json"
        },
        "queryParams": {
          "per_page": 30
        }
      }
    },
    {
      "name": "GitHub 仓库内容",
      "type": "api_request",
      "description": "获取仓库根目录文件结构",
      "config": {
        "method": "GET",
        "url": "https://api.github.com/repos/{{owner}}/{{repo}}/contents/",
        "headers": {
          "Authorization": "Bearer {{GITHUB_TOKEN}}",
          "Accept": "application/vnd.github.v3+json"
        }
      }
    },
    {
      "name": "依赖安全扫描",
      "type": "api_request",
      "description": "通过 GitHub Advisory API 检查依赖漏洞",
      "config": {
        "method": "GET",
        "url": "https://api.github.com/repos/{{owner}}/{{repo}}/dependabot/alerts",
        "headers": {
          "Authorization": "Bearer {{GITHUB_TOKEN}}",
          "Accept": "application/vnd.github.v3+json"
        },
        "queryParams": {
          "state": "open",
          "severity": "critical,high"
        }
      }
    }
  ],
  "workflows": [
    {
      "name": "仓库评估流程",
      "description": "输入 GitHub URL → 解析 owner/repo → 多维度数据拉取 → AI 分析打分 → 输出报告",
      "steps": [
        {
          "order": 1,
          "node": "url_parser",
          "description": "从用户输入的 GitHub URL 中提取 owner 和 repo",
          "type": "code",
          "code": "function parseGitHubUrl(url) {\n  const match = url.match(/github\\.com\\/([^\\/]+)\\/([^\\/\\s]+)/);\n  if (!match) throw new Error('请输入有效的 GitHub 仓库链接');\n  return {\n    owner: match[1],\n    repo: match[2].replace('.git', '')\n  };\n}\n\nconst result = parseGitHubUrl('{{userInput}}');\nreturn result;"
        },
        {
          "order": 2,
          "node": "data_collection",
          "description": "并行调用多个 GitHub API 获取仓库数据",
          "parallel": true,
          "calls": [
            "GitHub 仓库信息",
            "GitHub Star 历史",
            "GitHub Commit 活跃度",
            "GitHub Issues 统计",
            "GitHub 贡献者统计",
            "GitHub 仓库内容",
            "依赖安全扫描"
          ]
        },
        {
          "order": 3,
          "node": "data_aggregation",
          "description": "聚合所有 API 返回数据，提取关键指标",
          "type": "code",
          "code": "const repoInfo = $('GitHub 仓库信息').output;\nconst stars = $('GitHub Star 历史').output;\nconst commits = $('GitHub Commit 活跃度').output;\nconst issues = $('GitHub Issues 统计').output;\nconst contributors = $('GitHub 贡献者统计').output;\nconst contents = $('GitHub 仓库内容').output;\nconst alerts = $('依赖安全扫描').output;\n\n// 计算关键指标\nconst metrics = {\n  repoName: repoInfo.full_name,\n  description: repoInfo.description,\n  stars: repoInfo.stargazers_count,\n  forks: repoInfo.forks_count,\n  openIssues: repoInfo.open_issues_count,\n  watchers: repoInfo.watchers_count,\n  language: repoInfo.language,\n  license: repoInfo.license ? repoInfo.license.spdx_id : 'No License',\n  createdAt: repoInfo.created_at,\n  updatedAt: repoInfo.updated_at,\n  pushedAt: repoInfo.pushed_at,\n  \n  // 社区活跃度\n  contributorCount: Array.isArray(contributors) ? contributors.length : 0,\n  recentCommits: Array.isArray(commits) ? commits.slice(-4).reduce((sum, w) => sum + (w.total || 0), 0) : 0,\n  \n  // Issue 响应\n  issueResponseTime: calculateAvgResponseTime(issues),\n  openIssuesRatio: repoInfo.open_issues_count > 0 && repoInfo.stargazers_count > 0 \n    ? (repoInfo.open_issues_count / repoInfo.stargazers_count * 100).toFixed(1) \n    : 0,\n  \n  // 安全性\n  criticalAlerts: Array.isArray(alerts) ? alerts.filter(a => a.severity === 'critical').length : 0,\n  highAlerts: Array.isArray(alerts) ? alerts.filter(a => a.severity === 'high').length : 0,\n  \n  // 项目结构\n  hasReadme: contents.some(f => f.name.toLowerCase() === 'readme.md'),\n  hasContributing: contents.some(f => f.name.toLowerCase() === 'contributing.md'),\n  hasCodeOfConduct: contents.some(f => f.name.toLowerCase().includes('code_of_conduct')),\n  hasTests: contents.some(f => f.name.toLowerCase().includes('test') || f.name.toLowerCase().includes('spec')),\n  hasCI: contents.some(f => f.name.toLowerCase().includes('.github/workflows')),\n  \n  // 维护状态\n  daysSinceLastPush: Math.floor((Date.now() - new Date(repoInfo.pushed_at).getTime()) / (1000 * 60 * 60 * 24)),\n  repoAge: Math.floor((Date.now() - new Date(repoInfo.created_at).getTime()) / (1000 * 60 * 60 * 24))\n};\n\nreturn metrics;\n\nfunction calculateAvgResponseTime(issues) {\n  if (!Array.isArray(issues) || issues.length === 0) return null;\n  const responseTimes = [];\n  for (const issue of issues.slice(0, 50)) {\n    if (issue.comments > 0 && issue.created_at) {\n      const firstComment = issue.created_at; // 简化：用创建时间作为参考\n      responseTimes.push(issue.comments);\n    }\n  }\n  return responseTimes.length > 0 \n    ? (responseTimes.reduce((a, b) => a + b, 0) / responseTimes.length).toFixed(1) \n    : null;\n}"
        },
        {
          "order": 4,
          "node": "ai_scoring",
          "description": "AI 综合评分与报告生成",
          "type": "llm",
          "model": "Claude 3.5 Sonnet",
          "prompt": "你是一个专业的开源项目评估专家。请根据以下数据，对 GitHub 仓库进行综合评分并生成报告。\n\n## 评分标准\n\n### 社区活跃度 (25分)\n- Star 数量: <100=1分, 100-1k=3分, 1k-10k=5分, 10k+=8分\n- 贡献者数量: <5=1分, 5-20=3分, 20-50=5分, 50+=6分\n- 近期提交频率: 月均<5=1分, 5-20=3分, 20-50=5分, 50+=6分\n- Issue 活跃度: 根据 openIssuesRatio 判断\n\n### 代码质量 (25分)\n- 项目结构规范性\n- 是否有测试目录\n- 是否有 CI/CD 配置\n- 文档完整度\n\n### 安全性 (20分)\n- 依赖漏洞数量\n- License 合规性\n\n### 可维护性 (20分)\n- 最近更新状态\n- 项目年龄与成熟度\n\n### 合规性 (10分)\n- License 声明\n- 贡献指南\n- 行为准则\n\n## 数据\n{{metrics}}\n\n## 输出格式\n生成 Markdown 格式报告，包含：\n1. 总评等级 (A+到D)\n2. 各维度分项得分\n3. 核心发现 (3-5条)\n4. 风险提示\n5. 推荐替代方案 (如有)\n6. 改进建议"
        }
      ]
    }
  ],
  "variables": [
    {
      "name": "GITHUB_TOKEN",
      "type": "secret",
      "required": true,
      "description": "GitHub Personal Access Token (需要 repo 和 read:org 权限)"
    }
  ],
  "tags": ["GitHub", "Code Review", "Open Source", "Security Audit", "Coze", "Developer Tools"],
  "versionId": "1",
  "id": "github-repo-reviewer-agent",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "coze-instance-placeholder"
  }
}