From 642d2ff64eb2534b446440c15d6d5cedc3bdc23f Mon Sep 17 00:00:00 2001 From: lroyia Date: Tue, 31 Mar 2026 16:34:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=93=E5=BA=93=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude-plugin/plugin.json | 23 +++++ .gitignore | 1 + CLAUDE.md | 58 +++++++++++++ README.md | 64 +++++++++++++- skills/chinaweal-pms/SKILL.md | 135 ++++++++++++++++++++++++++++++ skills/gitea-api/SKILL.md | 99 ++++++++++++++++++++++ skills/gitea-api/scripts/gitea.js | 93 ++++++++++++++++++++ skills/pms-development/SKILL.md | 88 +++++++++++++++++++ 8 files changed, 560 insertions(+), 1 deletion(-) create mode 100644 .claude-plugin/plugin.json create mode 100644 .gitignore create mode 100644 CLAUDE.md create mode 100644 skills/chinaweal-pms/SKILL.md create mode 100644 skills/gitea-api/SKILL.md create mode 100644 skills/gitea-api/scripts/gitea.js create mode 100644 skills/pms-development/SKILL.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..8327938 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,23 @@ +{ + "name": "chinaweal-skills", + "version": "1.0.0", + "description": "众望通企业内部 Claude Code Skills 集合,包含 PMS 开发、Gitea API 等企业业务集成技能", + "author": { + "name": "lirh", + "email": "lirh@chinaweal.com" + }, + "homepage": "https://github.com/lirh chinaweal-skills", + "repository": "https://github.com/lirh/chinaweal-skills", + "license": "Apache-2.0", + "keywords": [ + "pms", + "gitea", + "enterprise", + "chinaweal", + "development" + ], + "categories": [ + "development", + "enterprise" + ] +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..edb1527 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +settings.local.json \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..7b43349 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,58 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Overview + +This is a Claude Code Skills plugin for 众望通 (ChinaWeal) enterprise, providing PMS (Project Management System) integration and Gitea code hosting platform integration. + +## Repository Structure + +``` +. +├── .claude-plugin/plugin.json # Plugin marketplace manifest +└── skills/ + ├── chinaweal-pms/ # PMS todo query skill + ├── gitea-api/ # Gitea API integration + │ └── scripts/gitea.js # Node.js helper for Gitea API calls + └── pms-development/ # PMS todo development workflow (depends on above two) +``` + +## Available Skills + +| Skill | Purpose | Trigger Keywords | +|-------|---------|------------------| +| chinaweal-pms | Query PMS todos | PMS, 待办, todo | +| gitea-api | Gitea repository management | Gitea, 仓库管理 | +| pms-development | Full PMS todo development workflow | 开发PMS待办 | + +## Required Environment Variables + +```bash +CHINAWEAL_PMS_TOKEN # PMS system authentication token +GITEA_TOKEN47 # Gitea API token (server: 47.107.61.133:3000) +``` + +## Key APIs + +**PMS API** (chinaweal.com.cn): +- `GET /pms-api/api/todo/unfinished/list/all` - List unfinished todos +- `GET /pms-api/api/todo/detail/{todoNo}` - Get todo details + +**Gitea API** (47.107.61.133:3000/api/v1): +- User: `GET /user`, `GET /users/{username}/repos` +- Repos: `POST /user/repos`, `GET /repos/{owner}/{repo}/branches` +- Issues: `GET /repos/{owner}/{repo}/issues`, `POST /repos/{owner}/{repo}/issues` + +## Development Workflow (pms-development) + +1. **Get requirements** - Use chinaweal-pms to fetch todo details if only todoNo provided +2. **Prepare repo** - Use gitea-api to find and clone the correct repository +3. **Create branch** - Branch name = todoNo (e.g., `TODO2024030001`) +4. **Develop** - Create `devdoc/{branch}/` documentation, implement backend by default +5. **Push** - Force push to remote after checking branch doesn't exist remotely + +**Constraints**: +- Default is backend-only development unless frontend is explicitly specified +- Compile failures > 3 attempts → terminate and report +- Development docs saved to `devdoc/` directory diff --git a/README.md b/README.md index bac9f9a..9df7b4c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,65 @@ # chinaweal-skills -公司适用的skills \ No newline at end of file +众望通企业 Claude Code Skills 插件集合,用于企业业务系统集成开发。 + +## 插件列表 + +### pms-development + +PMS 待办开发工具。用于开发 PMS 系统中的待办任务,包括仓库克隆、分支创建、需求开发、代码检查和分支推送。 + +**触发场景**: 开发 PMS 待办、开发待办 + +**依赖**: chinaweal-pms, gitea-api + +--- + +### chinaweal-pms + +众望通 PMS 系统数据查询工具。用于查询 PMS 系统中的待办任务数据。 + +**触发场景**: 查询待办、待办详情、"PMS"、"待办"、"todo" + +**前置要求**: 需要配置环境变量 `CHINAWEAL_PMS_TOKEN` + +--- + +### gitea-api + +Gitea API 调用工具。用于与 Gitea 代码托管平台进行交互。 + +**触发场景**: 调用 Gitea API、仓库管理、用户管理、Issue/PR 管理 + +**前置要求**: 需要配置环境变量 `GITEA_TOKEN47` + +**API 基础地址**: `http://47.107.61.133:3000/api/v1` + +--- + +## 安装 + +将插件克隆到本地: + +```bash +git clone https://github.com/lirh/chinaweal-skills.git ~/.claude/skills/chinaweal-skills +``` + +## 配置 + +### 环境变量 + +使用 `chinaweal-pms` 需要配置: + +```bash +export CHINAWEAL_PMS_TOKEN="your-pms-token" +``` + +使用 `gitea-api` 需要配置: + +```bash +export GITEA_TOKEN47="your-gitea-token" +``` + +## License + +Apache-2.0 diff --git a/skills/chinaweal-pms/SKILL.md b/skills/chinaweal-pms/SKILL.md new file mode 100644 index 0000000..6b63bb9 --- /dev/null +++ b/skills/chinaweal-pms/SKILL.md @@ -0,0 +1,135 @@ +--- +name: chinaweal-pms +description: | + 众望通 PMS 系统数据查询工具。用于查询 PMS 系统中的待办任务数据。 + + 当用户提到以下场景时使用此 Skill: + (1) 查询待办、待办详情、待办任务 + (2) 需要从 PMS 系统获取任务信息 + (3) 用户提到 "PMS"、"待办"、"todo"、"所有待办"、"未完成待办" +version: 1.0.0 +license: Apache-2.0 +metadata: + author: lirh + category: development + tags: + - pms + - chinaweal + - enterprise + - todo +--- + +# Chinaweal PMS 系统查询 + +## 概述 + +此 Skill 用于查询众望通 PMS 系统(Project Management System)的数据。 + +## 认证配置 + +使用此 Skill 前,需要配置环境变量 `CHINAWEAL_PMS_TOKEN`: + +- **环境变量名称**: `CHINAWEAL_PMS_TOKEN` +- **用途**: PMS 系统的用户授权 Token + +### 请求鉴权方式 + +所有 API 请求需要在请求头中携带 Authorization 信息: + +``` +Authorization: Bearer {CHINAWEAL_PMS_TOKEN} +``` + +其中 `{CHINAWEAL_PMS_TOKEN}` 需要替换为环境变量 `CHINAWEAL_PMS_TOKEN` 的值。 + +## 功能清单 + +### 功能1: 查询所有未完成待办 + +查询当前用户的所有未完成待办任务列表。 + +**接口地址**: `https://www.chinaweal.com.cn/pms-api/api/todo/unfinished/list/all` + +**请求方法**: GET + +**请求头**: +``` +Authorization: Bearer {CHINAWEAL_PMS_TOKEN} +Content-Type: application/json +``` + +**查询参数**: +- `status` - 任务状态,0 表示未完成 + +**响应关键字段**: +- `todoNo` - 待办编号 +- `todoTitle` - 待办标题 +- `todoDescription` - 待办描述 +- `createTime` - 创建时间 + +**使用示例** + +``` +帮我查询所有待办 +查询所有未完成的待办 +看看我有哪些待办任务 +我的待办有哪些 +``` + +### 功能2: 查询待办详情 + +查询指定待办编号的详细信息。 + +**接口地址**: `https://www.chinaweal.com.cn/pms-api/api/todo/detail/{todoNo}` + +**请求方法**: GET + +**请求头**: +``` +Authorization: Bearer {CHINAWEAL_PMS_TOKEN} +Content-Type: application/json +``` + +**路径参数**: +- `todoNo` - 待办编号 + +**响应关键字段**: +- `todoTitle` - 待办标题 +- `todoDescription` - 待办任务的详情描述 +- `todoAtt` - 待办附件下载地址清单(下载地址中包含 `filename` 参数,表示附件原名) + +### 使用示例 + +``` +帮我查询待办号 TODO2024030001 的详情 +查询一下 todoNo 为 12345 的待办信息 +``` + +### 调用方式 + +使用 exec 工具执行 curl 命令进行 API 调用。 + +**查询所有未完成待办**: +```bash +CHINAWEAL_PMS_TOKEN="your-token-here" + +curl -X GET "https://www.chinaweal.com.cn/pms-api/api/todo/unfinished/list/all" \ + -H "Authorization: Bearer ${CHINAWEAL_PMS_TOKEN}" \ + -H "Content-Type: application/json" +``` + +**查询单个待办详情**: +```bash +CHINAWEAL_PMS_TOKEN="your-token-here" +TODO_NO="TODO2024030001" + +curl -X GET "https://www.chinaweal.com.cn/pms-api/api/todo/detail/${TODO_NO}" \ + -H "Authorization: Bearer ${CHINAWEAL_PMS_TOKEN}" \ + -H "Content-Type: application/json" +``` + +## 注意事项 + +1. 确保环境变量 `CHINAWEAL_PMS_TOKEN` 已正确配置 +2. 待办编号 `todoNo` 需要从 PMS 系统获取 +3. 附件下载地址中包含 `filename` 参数,即为附件原文件名 diff --git a/skills/gitea-api/SKILL.md b/skills/gitea-api/SKILL.md new file mode 100644 index 0000000..aff8949 --- /dev/null +++ b/skills/gitea-api/SKILL.md @@ -0,0 +1,99 @@ +--- +name: gitea-api +description: | + Gitea API 调用工具。用于与 Gitea 代码托管平台进行交互,包括仓库管理、用户管理、组织操作、Issue/PR 管理等。 + + 当用户提到以下场景时使用此 Skill: + (1) 需要调用 Gitea API (如 /api/v1/ 开头的接口) + (2) 需要在 Gitea 上创建/查询/管理仓库 + (3) 需要管理用户、组织、团队 + (4) 需要操作 Issue、Pull Request + (5) 需要查看/管理 Git 提交、分支 + (6) 用户提到 "Gitea"、"代码托管"、"仓库管理" +version: 1.0.0 +license: Apache-2.0 +metadata: + author: lirh + category: development + tags: + - gitea + - api + - git + - repository +--- + +# Gitea API Skill + +## 快速开始 + +此 Skill 提供调用 Gitea API 的能力。API 基础 URL: `http://47.107.61.133:3000/api/v1` + +认证方式:使用环境变量 `GITEA_TOKEN47` 作为 Bearer Token。 + +## 使用方法 + +### 方式一:使用封装好的工具函数 + +直接调用以下工具函数(见 scripts/gitea.js): + +- `gitea_get(endpoint, params)` - GET 请求 +- `gitea_post(endpoint, data)` - POST 请求 +- `gitea_patch(endpoint, data)` - PATCH 请求 +- `gitea_delete(endpoint)` - DELETE 请求 + +示例: +``` +调用 gitea_get 获取当前用户信息 +调用 gitea_get 获取仓库列表 +调用 gitea_post 创建新仓库 +``` + +### 方式二:直接使用 curl + +```bash +TOKEN=$GITEA_TOKEN47 +curl -H "Authorization: token $TOKEN" http://47.107.61.133:3000/api/v1/user +``` + +## 常用 API 示例 + +### 用户相关 +- `GET /user` - 获取当前用户信息 +- `GET /users/{username}` - 获取指定用户信息 +- `GET /users/{username}/repos` - 获取用户仓库列表 + +### 仓库相关 +- `GET /repos/{owner}/{repo}` - 获取仓库信息 +- `POST /user/repos` - 创建仓库(当前用户) +- `POST /orgs/{org}/repos` - 在组织中创建仓库 +- `GET /repos/{owner}/{repo}/branches` - 获取分支列表 +- `GET /repos/{owner}/{repo}/commits` - 获取提交历史 + +### Issue 相关 +- `GET /repos/{owner}/{repo}/issues` - 获取 Issue 列表 +- `POST /repos/{owner}/{repo}/issues` - 创建 Issue +- `GET /repos/{owner}/{repo}/issues/{index}` - 获取 Issue 详情 +- `PATCH /repos/{owner}/{repo}/issues/{index}` - 更新 Issue + +### 组织相关 +- `GET /orgs` - 获取组织列表 +- `GET /orgs/{org}` - 获取组织详情 +- `POST /orgs` - 创建组织 +- `GET /orgs/{org}/members` - 获取组织成员 + +### 管理相关 (需要管理员权限) +- `GET /admin/users` - 列出所有用户 +- `POST /admin/users` - 创建用户 +- `DELETE /admin/users/{username}` - 删除用户 + +## 错误处理 + +API 返回状态码说明: +- 200/201: 成功 +- 204: 成功(无返回内容) +- 400: 请求参数错误 +- 401: 未认证 +- 403: 权限不足 +- 404: 资源不存在 +- 422: 验证错误 +- 500: 服务器错误 diff --git a/skills/gitea-api/scripts/gitea.js b/skills/gitea-api/scripts/gitea.js new file mode 100644 index 0000000..7a8dcde --- /dev/null +++ b/skills/gitea-api/scripts/gitea.js @@ -0,0 +1,93 @@ +#!/usr/bin/env node + +/** + * Gitea API Client + * 提供调用 Gitea API 的工具函数 + */ + +const BASE_URL = 'http://47.107.61.133:3000/api/v1'; + +function getToken() { + // 优先从环境变量读取,其次从命令行参数读取 + const token = process.env['GITEA_TOKEN47']; + if (!token) { + // 检查是否有命令行传入的 token + const tokenArg = process.argv.find(arg => arg.startsWith('--token=')); + if (tokenArg) { + return tokenArg.replace('--token=', ''); + } + throw new Error('环境变量 GITEA_TOKEN47 未设置,请设置环境变量或使用 --token= 参数'); + } + return token; +} + +async function giteaRequest(method, endpoint, data = null, params = {}) { + const token = getToken(); + let url = `${BASE_URL}${endpoint}`; + + // 添加查询参数 + if (Object.keys(params).length > 0) { + const queryString = new URLSearchParams(params).toString(); + url += `?${queryString}`; + } + + const options = { + method, + headers: { + 'Authorization': `token ${token}`, + 'Content-Type': 'application/json', + 'Accept': 'application/json' + } + }; + + if (data && (method === 'POST' || method === 'PATCH' || method === 'PUT')) { + options.body = JSON.stringify(data); + } + + const response = await fetch(url, options); + + // 处理响应 + const contentType = response.headers.get('content-type'); + if (contentType && contentType.includes('application/json')) { + const result = await response.json(); + if (!response.ok) { + throw new Error(`API Error: ${response.status} - ${JSON.stringify(result)}`); + } + return result; + } else { + if (!response.ok) { + throw new Error(`API Error: ${response.status} - ${response.statusText}`); + } + return response.status === 204 ? null : await response.text(); + } +} + +// 导出工具函数 +const gitea = { + get: (endpoint, params = {}) => giteaRequest('GET', endpoint, null, params), + post: (endpoint, data = {}) => giteaRequest('POST', endpoint, data), + patch: (endpoint, data = {}) => giteaRequest('PATCH', endpoint, data), + put: (endpoint, data = {}) => giteaRequest('PUT', endpoint, data), + delete: (endpoint) => giteaRequest('DELETE', endpoint) +}; + +// CLI 模式 +if (require.main === module) { + const args = process.argv.slice(2); + const command = args[0]; + + if (command === 'get') { + const endpoint = args[1]; + gitea.get(endpoint).then(result => console.log(JSON.stringify(result, null, 2))); + } else if (command === 'post') { + const endpoint = args[1]; + const data = JSON.parse(args[2] || '{}'); + gitea.post(endpoint, data).then(result => console.log(JSON.stringify(result, null, 2))); + } else { + console.log('Usage:'); + console.log(' node gitea.js get '); + console.log(' node gitea.js post '); + } +} + +module.exports = gitea; diff --git a/skills/pms-development/SKILL.md b/skills/pms-development/SKILL.md new file mode 100644 index 0000000..364e845 --- /dev/null +++ b/skills/pms-development/SKILL.md @@ -0,0 +1,88 @@ +--- +name: pms-development +description: PMS待办开发工具。用于开发PMS系统中的待办任务。当用户提到开发PMS待办、开发待办时使用此技能。需要根据待办详情进行代码开发,包括仓库克隆、分支创建、需求开发、代码检查和分支推送。 +version: 1.0.0 +license: Apache-2.0 +metadata: + author: lirh + category: development + tags: + - pms + - development + - enterprise +--- + +# PMS待办开发 + +## 触发条件 + +用户要求开发PMS待办时使用此技能。 + +## 步骤一:获取需求 + +### 情况A:用户已提供详细需求 +直接进入步骤二。 + +### 情况B:用户只提供PMS待办编号 +1. 调用 chinaweal-pms skill 查询待办详情 +2. 从待办详情中提取需求描述、技术要求等信息 + +## 步骤二:仓库准备 + +### 2.1 确定仓库 +1. 分析需求/待办详情,判断属于哪个仓库 +2. 如无法判断,使用 gitea-api skill 查询仓库清单 +3. 从仓库清单中找到匹配的仓库 + +### 2.2 克隆仓库 +1. 选择合适的本地路径存放仓库 +2. 如果父目录不存在,创建父目录 +3. 克隆命令:`git clone <仓库地址> <本地路径>` + +### 2.3 检查仓库状态 +- 如果仓库为空,删除目录后重新克隆 + +## 步骤三:分支创建 + +1. 切换到仓库目录 +2. 拉取远端主分支最新代码 +3. 创建新分支: + - 如果是开发PMS待办,分支名 = 待办编号 + - 否则分支名 = 当前日期时间(格式:yyyyMMddHHmm) +4. 切换到新分支 + +## 步骤四:需求开发 + +### 4.1 创建开发文档 + +在项目根目录创建 `devdoc/` 目录,然后创建(文件名前缀为当前分支名称): + +**{分支名}_需求清单.md** - 列出需要开发的功能点 + +**{分支名}_开发思路与改动.md** - 记录每个需求的开发思路和具体代码改动 + +**{分支名}_失败报告.md** - 记录开发失败的原因和尝试次数 + +### 4.2 进行开发 +在新建分支中进行代码开发。 + +### 4.3 代码检查 +开发完成后: +1. 检查语法错误 +2. 尝试编译项目 +3. 如有错误,尝试修复 +4. 同一问题修复3次仍失败,记录到 `devdoc/{分支名}_失败报告.md`,终止开发 + +## 步骤五:推送分支 + +1. 检查远端仓库是否存在当前分支 +2. 如果远端分支已存在,报告用户无法推送 +3. 如果远端分支不存在,强制推送分支到远端 + +## 关键约束 + +- **默认只开发后端接口**:如果没有明确指定仓库,或者没有明确指定需要开发前端,则默认只开发后端接口 +- 所有操作在workspace中进行 +- 开发文档必须保存到 `devdoc/` 目录,文件名以分支名为前缀 +- 编译失败超过3次必须终止并报告 +- 推送前必须检查远端分支是否存在