@sokeai/cli 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,9 +42,52 @@ cd soke-cli
42
42
  make install
43
43
  ```
44
44
 
45
+ ## AI Agent Skills
46
+
47
+ `soke-cli` 提供了 AI Agent 技能(Skills),使 AI 助手能够自动发现和调用 CLI 功能,无需记忆复杂的命令参数。
48
+
49
+ ### 安装 Skills
50
+
51
+ ```bash
52
+ # 安装 CLI 后,安装 AI Agent Skills
53
+ npx skills add liuchenlong1111/soke-cli -y -g
54
+ ```
55
+
56
+ ### 使用方式
57
+
58
+ 安装 Skills 后,在支持 Skills 的 AI Agent(如 Claude Code)中,可以直接用自然语言描述需求:
59
+
60
+ - **"查询考试成绩"** - AI 会自动调用 `soke-cli exam +get-exam-user`
61
+ - **"列出最近的考试"** - AI 会自动调用 `soke-cli exam +list-exams`
62
+ - **"查看考试分类"** - AI 会自动调用 `soke-cli exam +list-categories`
63
+
64
+ AI Agent 会自动:
65
+ 1. 识别你的意图
66
+ 2. 选择合适的命令
67
+ 3. 提示你提供必要的参数
68
+ 4. 执行命令并展示结果
69
+
70
+ ### 可用的 Skills
71
+
72
+ - **soke-shared**: 配置初始化、用户认证、权限处理等基础功能
73
+ - **soke-exam**: 考试管理(查询考试、考试成绩、考试分类)
74
+ - 更多业务模块的 Skills 正在开发中...
75
+
76
+ 详细文档:[skills/README.md](skills/README.md)
77
+
45
78
  ## 快速开始
46
79
 
47
- ### 1. 初始化配置
80
+ ### 1. 安装 CLI 和 Skills
81
+
82
+ ```bash
83
+ # 安装 CLI
84
+ npm install -g @sokeai/cli
85
+
86
+ # 安装 AI Agent Skills(可选,推荐)
87
+ npx skills add liuchenlong1111/soke-cli -y -g
88
+ ```
89
+
90
+ ### 2. 初始化配置
48
91
  首次使用前,需要配置你的开放平台凭证:
49
92
  ```bash
50
93
  soke-cli config init
@@ -53,7 +96,7 @@ soke-cli config init
53
96
 
54
97
  可以使用 `soke-cli config show` 来查看当前配置。
55
98
 
56
- ### 2. 用户登录授权
99
+ ### 3. 用户登录授权
57
100
  配置完成后,进行设备授权登录:
58
101
  ```bash
59
102
  soke-cli auth login
@@ -61,6 +104,26 @@ soke-cli auth login
61
104
  命令会返回一个设备码和链接,请在浏览器中打开链接并输入设备码完成授权。成功后即可调用需要用户授权的接口。
62
105
  如果需要退出登录,可以执行 `soke-cli auth logout`。
63
106
 
107
+ ### 4. 开始使用
108
+
109
+ **方式一:通过 AI Agent(推荐)**
110
+
111
+ 如果已安装 Skills,在 AI Agent 中直接用自然语言:
112
+ ```
113
+ "查询考试成绩"
114
+ "列出最近的考试"
115
+ ```
116
+
117
+ **方式二:直接使用命令行**
118
+
119
+ ```bash
120
+ # 查看课程列表
121
+ soke-cli course +list-courses --start-time 1672502400000 --end-time 1704038400000
122
+
123
+ # 查询考试成绩
124
+ soke-cli exam +get-exam-user --exam-id exam123 --dept-user-id user456
125
+ ```
126
+
64
127
  ## 使用示例
65
128
 
66
129
  ### 调用快捷业务命令
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sokeai/cli",
3
- "version": "1.0.0",
4
- "description": "授客AI官方CLI工具",
3
+ "version": "1.0.2",
4
+ "description": "授客AI官方CLI工具 - 支持AI Agent Skills",
5
5
  "bin": {
6
6
  "soke-cli": "scripts/run.js"
7
7
  },
@@ -15,14 +15,17 @@
15
15
  ],
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://codeup.aliyun.com/5edbc121d1d1abe63b55f1c7/soke/soke-cli.git"
18
+ "url": "https://github.com/liuchenlong1111/soke-cli.git"
19
19
  },
20
20
  "keywords": [
21
21
  "soke",
22
22
  "cli",
23
23
  "授客AI",
24
24
  "shouke",
25
- "command-line"
25
+ "command-line",
26
+ "ai-agent",
27
+ "skills",
28
+ "claude-code"
26
29
  ],
27
30
  "author": "授客AI",
28
31
  "license": "MIT",
@@ -0,0 +1,207 @@
1
+ #!/bin/bash
2
+
3
+ # soke-cli 端到端测试脚本
4
+ # 测试所有命令是否能正常执行
5
+ # 支持按模块测试: ./e2e-test.sh [module_name]
6
+
7
+ # 注意:不使用 set -e,让所有测试都能运行完
8
+
9
+ # 颜色输出
10
+ RED='\033[0;31m'
11
+ GREEN='\033[0;32m'
12
+ YELLOW='\033[1;33m'
13
+ BLUE='\033[0;34m'
14
+ NC='\033[0m'
15
+
16
+ # 测试结果统计
17
+ TOTAL_TESTS=0
18
+ PASSED_TESTS=0
19
+ FAILED_TESTS=0
20
+ FAILED_COMMANDS=()
21
+
22
+ # 获取版本号
23
+ VERSION=$(node -p "require('./package.json').version")
24
+
25
+ # 获取要测试的模块(如果指定)
26
+ TEST_MODULE=$1
27
+
28
+ echo -e "${BLUE}========================================${NC}"
29
+ if [ -z "$TEST_MODULE" ]; then
30
+ echo -e "${BLUE} soke-cli E2E 测试 v${VERSION}${NC}"
31
+ else
32
+ echo -e "${BLUE} soke-cli E2E 测试 - ${TEST_MODULE} 模块${NC}"
33
+ fi
34
+ echo -e "${BLUE}========================================${NC}"
35
+ echo ""
36
+
37
+ # 检查是否已编译
38
+ if [ ! -f "./soke-cli" ]; then
39
+ echo -e "${YELLOW}未找到编译文件,开始编译...${NC}"
40
+ go build -o soke-cli main.go
41
+ echo -e "${GREEN}✓ 编译完成${NC}"
42
+ echo ""
43
+ fi
44
+
45
+ # 检查是否已登录
46
+ echo -e "${YELLOW}检查登录状态...${NC}"
47
+ if ! ./soke-cli config show &>/dev/null; then
48
+ echo -e "${RED}错误: 未配置或未登录${NC}"
49
+ echo "请先运行: ./soke-cli config init && ./soke-cli auth login"
50
+ exit 1
51
+ fi
52
+ echo -e "${GREEN}✓ 已登录${NC}"
53
+ echo ""
54
+
55
+ # 测试函数
56
+ test_command() {
57
+ local module=$1
58
+ local command=$2
59
+ local args=$3
60
+ local description=$4
61
+
62
+ TOTAL_TESTS=$((TOTAL_TESTS + 1))
63
+
64
+ echo -n "测试 [$module $command]: $description ... "
65
+
66
+ if ./soke-cli $module $command $args &>/dev/null; then
67
+ echo -e "${GREEN}✓ 通过${NC}"
68
+ PASSED_TESTS=$((PASSED_TESTS + 1))
69
+ return 0
70
+ else
71
+ echo -e "${RED}✗ 失败${NC}"
72
+ FAILED_TESTS=$((FAILED_TESTS + 1))
73
+ FAILED_COMMANDS+=("$module $command $args")
74
+ return 1
75
+ fi
76
+ }
77
+
78
+ # 判断是否应该运行某个模块的测试
79
+ should_test_module() {
80
+ local module=$1
81
+ if [ -z "$TEST_MODULE" ]; then
82
+ return 0 # 没有指定模块,测试所有
83
+ elif [ "$TEST_MODULE" = "$module" ]; then
84
+ return 0 # 指定的模块匹配
85
+ else
86
+ return 1 # 不匹配,跳过
87
+ fi
88
+ }
89
+
90
+ echo -e "${BLUE}开始测试...${NC}"
91
+ echo ""
92
+
93
+ # ==================== Contact 模块 ====================
94
+ if should_test_module "contact"; then
95
+ echo -e "${YELLOW}[Contact 模块]${NC}"
96
+ test_command "contact" "+list-departments" "" "获取部门列表"
97
+ test_command "contact" "+get-department" "--dept-id 1" "获取部门详情"
98
+ test_command "contact" "+list-department-users" "--dept-id 1" "获取部门用户列表"
99
+ test_command "contact" "+list-lectors" "" "获取讲师列表"
100
+ test_command "contact" "+list-groups" "--start-time 1672502400000 --end-time 1704038400000" "获取用户组列表"
101
+ test_command "contact" "+search-user" "--dept-user-name 测试" "搜索用户"
102
+ echo ""
103
+ fi
104
+
105
+ # ==================== Course 模块 ====================
106
+ if should_test_module "course"; then
107
+ echo -e "${YELLOW}[Course 模块]${NC}"
108
+ test_command "course" "+list-courses" "--start-time 1672502400000 --end-time 1704038400000" "获取课程列表"
109
+ test_command "course" "+list-categories" "" "获取课程分类"
110
+ test_command "course" "+list-lessons" "--course-id F4025496-6566-4ACD-8CD4-06E3D55BBA79" "获取课程章节"
111
+ echo ""
112
+ fi
113
+
114
+ # ==================== Exam 模块 ====================
115
+ if should_test_module "exam"; then
116
+ echo -e "${YELLOW}[Exam 模块]${NC}"
117
+ test_command "exam" "+list-exams" "--start-time 1672502400000 --end-time 1704038400000" "获取考试列表"
118
+ test_command "exam" "+list-categories" "" "获取考试分类"
119
+ echo ""
120
+ fi
121
+
122
+ # ==================== Certificate 模块 ====================
123
+ if should_test_module "certificate"; then
124
+ echo -e "${YELLOW}[Certificate 模块]${NC}"
125
+ test_command "certificate" "+list-certificates" "--start-time 1672502400000 --end-time 1704038400000" "获取证书列表"
126
+ test_command "certificate" "+list-categories" "" "获取证书分类"
127
+ echo ""
128
+ fi
129
+
130
+ # ==================== Credit 模块 ====================
131
+ if should_test_module "credit"; then
132
+ echo -e "${YELLOW}[Credit 模块]${NC}"
133
+ test_command "credit" "+list-logs" "--start-time 1672502400000 --end-time 1704038400000" "获取学分日志"
134
+ echo ""
135
+ fi
136
+
137
+ # ==================== Point 模块 ====================
138
+ if should_test_module "point"; then
139
+ echo -e "${YELLOW}[Point 模块]${NC}"
140
+ test_command "point" "+list-logs" "--start-time 1672502400000 --end-time 1704038400000" "获取积分日志"
141
+ echo ""
142
+ fi
143
+
144
+ # ==================== Training 模块 ====================
145
+ if should_test_module "training"; then
146
+ echo -e "${YELLOW}[Training 模块]${NC}"
147
+ test_command "training" "+list-trainings" "--start-time 1672502400000 --end-time 1704038400000" "获取培训列表"
148
+ test_command "training" "+list-categories" "" "获取培训分类"
149
+ echo ""
150
+ fi
151
+
152
+ # ==================== Learning Map 模块 ====================
153
+ if should_test_module "learning-map"; then
154
+ echo -e "${YELLOW}[Learning Map 模块]${NC}"
155
+ test_command "learning-map" "+list-maps" "--start-time 1672502400000 --end-time 1704038400000" "获取学习地图列表"
156
+ test_command "learning-map" "+list-categories" "" "获取学习地图分类"
157
+ echo ""
158
+ fi
159
+
160
+ # ==================== News 模块 ====================
161
+ if should_test_module "news"; then
162
+ echo -e "${YELLOW}[News 模块]${NC}"
163
+ test_command "news" "+list-news" "" "获取新闻列表"
164
+ test_command "news" "+list-categories" "" "获取新闻分类"
165
+ echo ""
166
+ fi
167
+
168
+ # ==================== Clock 模块 ====================
169
+ if should_test_module "clock"; then
170
+ echo -e "${YELLOW}[Clock 模块]${NC}"
171
+ test_command "clock" "list-learnings" "--page 1 --page-size 10" "获取作业列表"
172
+ echo ""
173
+ fi
174
+
175
+ # ==================== File 模块 ====================
176
+ if should_test_module "file"; then
177
+ echo -e "${YELLOW}[File 模块]${NC}"
178
+ test_command "file" "list-files" "" "获取素材库列表"
179
+ test_command "file" "list-categories" "" "获取素材库分类"
180
+ echo ""
181
+ fi
182
+
183
+ # ==================== 测试结果汇总 ====================
184
+ echo ""
185
+ echo -e "${BLUE}========================================${NC}"
186
+ echo -e "${BLUE} 测试结果汇总${NC}"
187
+ echo -e "${BLUE}========================================${NC}"
188
+ echo ""
189
+ echo -e "总测试数: ${BLUE}${TOTAL_TESTS}${NC}"
190
+ echo -e "通过: ${GREEN}${PASSED_TESTS}${NC}"
191
+ echo -e "失败: ${RED}${FAILED_TESTS}${NC}"
192
+ echo ""
193
+
194
+ if [ ${FAILED_TESTS} -gt 0 ]; then
195
+ echo -e "${RED}失败的命令:${NC}"
196
+ for cmd in "${FAILED_COMMANDS[@]}"; do
197
+ echo -e " ${RED}✗${NC} ./soke-cli $cmd"
198
+ done
199
+ echo ""
200
+ echo -e "${RED}测试失败! 请修复以上问题后再发布。${NC}"
201
+ exit 1
202
+ else
203
+ echo -e "${GREEN}========================================${NC}"
204
+ echo -e "${GREEN} 所有测试通过! ✓${NC}"
205
+ echo -e "${GREEN}========================================${NC}"
206
+ exit 0
207
+ fi
@@ -75,14 +75,24 @@ check_tag() {
75
75
 
76
76
  # 运行测试
77
77
  run_tests() {
78
- echo -e "${YELLOW}运行测试...${NC}"
78
+ echo -e "${YELLOW}运行单元测试...${NC}"
79
79
 
80
80
  if ! go test ./...; then
81
- echo -e "${RED}错误: 测试失败${NC}"
81
+ echo -e "${RED}错误: 单元测试失败${NC}"
82
82
  exit 1
83
83
  fi
84
84
 
85
- echo -e "${GREEN}✓ 测试通过${NC}"
85
+ echo -e "${GREEN}✓ 单元测试通过${NC}"
86
+ echo ""
87
+
88
+ echo -e "${YELLOW}运行端到端测试...${NC}"
89
+
90
+ if ! ./scripts/e2e-test.sh; then
91
+ echo -e "${RED}错误: 端到端测试失败${NC}"
92
+ exit 1
93
+ fi
94
+
95
+ echo -e "${GREEN}✓ 端到端测试通过${NC}"
86
96
  echo ""
87
97
  }
88
98