@workskills/getskill 1.1.9 → 1.2.0

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.
@@ -22,6 +22,22 @@ export interface SearchOptions {
22
22
  page?: number;
23
23
  limit?: number;
24
24
  }
25
+ export interface SkillIndexEntry {
26
+ id: string;
27
+ name: string;
28
+ description: string;
29
+ category?: string;
30
+ tags?: string[];
31
+ version: string;
32
+ author?: string;
33
+ updated?: string;
34
+ file: string;
35
+ size?: number;
36
+ source?: string;
37
+ }
38
+ export interface SkillsIndexPayload {
39
+ skills?: SkillIndexEntry[];
40
+ }
25
41
  export interface SearchSkill {
26
42
  name: string;
27
43
  full_name: string;
@@ -29,27 +45,11 @@ export interface SearchSkill {
29
45
  html_url: string;
30
46
  git_url: string;
31
47
  clone_url: string;
32
- }
33
- export interface RepositoryCandidate {
34
- name?: string;
35
- full_name?: string;
36
- description?: string;
37
- html_url?: string;
38
- clone_url?: string;
39
- private?: boolean;
40
- empty?: boolean;
41
- archived?: boolean;
42
- template?: boolean;
43
- fork?: boolean;
44
- }
45
- export interface SearchApiItem {
46
- repository?: RepositoryCandidate;
47
- [key: string]: unknown;
48
- }
49
- export interface SearchApiPayload {
50
- ok?: boolean;
51
- message?: string;
52
- data?: Array<RepositoryCandidate | SearchApiItem>;
48
+ download_url: string;
49
+ version: string;
50
+ category: string;
51
+ author: string;
52
+ size: number;
53
53
  }
54
54
  export interface SkillStateRecord {
55
55
  inputSkillName: string;
@@ -62,6 +62,7 @@ export interface SkillStateRecord {
62
62
  updatedAt: string;
63
63
  gitCommitHash: string | null;
64
64
  requestedVersion?: string | null;
65
+ version?: string | null;
65
66
  }
66
67
  export interface InstallState {
67
68
  skills: Record<string, SkillStateRecord>;
@@ -71,6 +72,8 @@ export interface DownloadResult {
71
72
  repoPath: string;
72
73
  files: string[];
73
74
  requestedVersion?: string | null;
75
+ version?: string | null;
76
+ upToDate?: boolean;
74
77
  }
75
78
  export interface DownloadOptions {
76
79
  version?: string;
@@ -105,26 +108,6 @@ export interface PublishOptions {
105
108
  message?: string;
106
109
  username?: string;
107
110
  email?: string;
108
- password?: string;
109
- visibility?: 'public' | 'private';
110
- }
111
- export interface AuthSession {
112
- username: string;
113
- email?: string | null;
114
- token: string;
115
- }
116
- export interface EnsureAuthResult extends AuthSession {
117
- mode: 'stored-token' | 'login' | 'register';
118
- }
119
- export interface RegistryUser {
120
- username: string;
121
- email?: string | null;
122
- }
123
- export interface RepoCreationResult {
124
- name: string;
125
- cloneUrl: string;
126
- htmlUrl?: string;
127
- existed: boolean;
128
111
  }
129
112
  export interface SkillValidationResult {
130
113
  valid: boolean;
@@ -145,6 +128,4 @@ export interface PublishResult {
145
128
  branch: string;
146
129
  committed: boolean;
147
130
  repositoryName?: string;
148
- createdRemoteRepo?: boolean;
149
- authMode?: 'stored-token' | 'login' | 'register' | 'not-required';
150
131
  }
@@ -0,0 +1,3 @@
1
+ export declare function sanitizeZipEntryName(entryName: string): string;
2
+ export declare function extractZip(zipPath: string, destDir: string): string[];
3
+ export declare function resolveSkillRoot(dir: string, maxDepth?: number): string;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sanitizeZipEntryName = sanitizeZipEntryName;
7
+ exports.extractZip = extractZip;
8
+ exports.resolveSkillRoot = resolveSkillRoot;
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const zlib_1 = __importDefault(require("zlib"));
12
+ const EOCD_SIGNATURE = 0x06054b50;
13
+ const CENTRAL_DIRECTORY_SIGNATURE = 0x02014b50;
14
+ const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
15
+ const EOCD_MIN_SIZE = 22;
16
+ const EOCD_MAX_COMMENT_SIZE = 0xffff;
17
+ function sanitizeZipEntryName(entryName) {
18
+ const normalized = entryName.replace(/\\/g, '/');
19
+ if (path_1.default.isAbsolute(normalized) || /^[a-zA-Z]:/.test(normalized)) {
20
+ throw new Error(`zip 条目包含非法绝对路径: ${entryName}`);
21
+ }
22
+ const segments = normalized
23
+ .split('/')
24
+ .filter((segment) => segment && segment !== '.')
25
+ .filter((segment) => segment !== '');
26
+ for (const segment of segments) {
27
+ if (segment === '..') {
28
+ throw new Error(`zip 条目包含非法上级路径: ${entryName}`);
29
+ }
30
+ }
31
+ return segments.join(path_1.default.sep);
32
+ }
33
+ function findEndOfCentralDirectory(buffer) {
34
+ const searchStart = Math.max(0, buffer.length - EOCD_MIN_SIZE - EOCD_MAX_COMMENT_SIZE);
35
+ for (let offset = buffer.length - EOCD_MIN_SIZE; offset >= searchStart; offset -= 1) {
36
+ if (buffer.readUInt32LE(offset) === EOCD_SIGNATURE) {
37
+ return offset;
38
+ }
39
+ }
40
+ return -1;
41
+ }
42
+ function extractZip(zipPath, destDir) {
43
+ if (!fs_1.default.existsSync(zipPath)) {
44
+ throw new Error(`zip 文件不存在: ${zipPath}`);
45
+ }
46
+ const buffer = fs_1.default.readFileSync(zipPath);
47
+ const eocdOffset = findEndOfCentralDirectory(buffer);
48
+ if (eocdOffset < 0) {
49
+ throw new Error('解压失败: 无效的 zip 文件(未找到中央目录记录)');
50
+ }
51
+ const entryCount = buffer.readUInt16LE(eocdOffset + 10);
52
+ let cursor = buffer.readUInt32LE(eocdOffset + 16);
53
+ const extractedFiles = [];
54
+ for (let index = 0; index < entryCount; index += 1) {
55
+ if (cursor + 46 > buffer.length ||
56
+ buffer.readUInt32LE(cursor) !== CENTRAL_DIRECTORY_SIGNATURE) {
57
+ throw new Error('解压失败: 中央目录记录损坏');
58
+ }
59
+ const method = buffer.readUInt16LE(cursor + 10);
60
+ const compressedSize = buffer.readUInt32LE(cursor + 20);
61
+ const fileNameLength = buffer.readUInt16LE(cursor + 28);
62
+ const extraFieldLength = buffer.readUInt16LE(cursor + 30);
63
+ const commentLength = buffer.readUInt16LE(cursor + 32);
64
+ const localHeaderOffset = buffer.readUInt32LE(cursor + 42);
65
+ const rawName = buffer.subarray(cursor + 46, cursor + 46 + fileNameLength);
66
+ const entryName = rawName.toString('utf8');
67
+ cursor += 46 + fileNameLength + extraFieldLength + commentLength;
68
+ const isDirectory = entryName.endsWith('/');
69
+ const safeName = sanitizeZipEntryName(entryName);
70
+ if (!safeName) {
71
+ continue;
72
+ }
73
+ const targetPath = path_1.default.join(destDir, safeName);
74
+ if (isDirectory) {
75
+ fs_1.default.mkdirSync(targetPath, { recursive: true });
76
+ continue;
77
+ }
78
+ if (localHeaderOffset + 30 > buffer.length ||
79
+ buffer.readUInt32LE(localHeaderOffset) !==
80
+ LOCAL_FILE_HEADER_SIGNATURE) {
81
+ throw new Error(`解压失败: 本地文件头损坏 (${entryName})`);
82
+ }
83
+ const localNameLength = buffer.readUInt16LE(localHeaderOffset + 26);
84
+ const localExtraLength = buffer.readUInt16LE(localHeaderOffset + 28);
85
+ const dataStart = localHeaderOffset + 30 + localNameLength + localExtraLength;
86
+ const dataEnd = dataStart + compressedSize;
87
+ if (dataEnd > buffer.length) {
88
+ throw new Error(`解压失败: 文件数据不完整 (${entryName})`);
89
+ }
90
+ const compressedData = buffer.subarray(dataStart, dataEnd);
91
+ let fileData;
92
+ if (method === 0) {
93
+ fileData = Buffer.from(compressedData);
94
+ }
95
+ else if (method === 8) {
96
+ fileData = zlib_1.default.inflateRawSync(compressedData);
97
+ }
98
+ else {
99
+ throw new Error(`解压失败: 不支持的压缩算法 ${method} (${entryName})`);
100
+ }
101
+ fs_1.default.mkdirSync(path_1.default.dirname(targetPath), { recursive: true });
102
+ fs_1.default.writeFileSync(targetPath, fileData);
103
+ extractedFiles.push(safeName);
104
+ }
105
+ return extractedFiles;
106
+ }
107
+ function resolveSkillRoot(dir, maxDepth = 5) {
108
+ let current = dir;
109
+ for (let depth = 0; depth < maxDepth; depth += 1) {
110
+ if (!fs_1.default.existsSync(current)) {
111
+ break;
112
+ }
113
+ const entries = fs_1.default.readdirSync(current, { withFileTypes: true });
114
+ const directories = entries.filter((entry) => entry.isDirectory());
115
+ const files = entries.filter((entry) => entry.isFile());
116
+ if (directories.length !== 1 || files.length !== 0) {
117
+ break;
118
+ }
119
+ current = path_1.default.join(current, directories[0].name);
120
+ }
121
+ return current;
122
+ }
package/dist/main.js CHANGED
@@ -75,40 +75,39 @@ function parseCommandOptions(rawArgs) {
75
75
  return { positionals, options };
76
76
  }
77
77
  function printHelp() {
78
- console.log('GetSkill - OpenClaw 技能管理工具');
78
+ console.log('GetSkill - OpenClaw 技能管理工具 (getskill.work · Cloudflare 静态托管)');
79
79
  console.log('');
80
80
  console.log('用法:');
81
81
  console.log(' getskill --help - 显示帮助信息');
82
82
  console.log(' getskill --version - 显示版本号');
83
- console.log(' getskill search <关键词> - 从 API 搜索技能');
83
+ console.log(' getskill search <关键词> - 从技能索引搜索技能');
84
84
  console.log(' getskill search <关键词> --json - JSON 格式输出搜索结果');
85
- console.log(' getskill install <技能名称> - 通过 git clone 安装技能');
86
- console.log(' getskill install <技能名称> --version <tag> - 安装指定版本');
87
- console.log(' getskill update <技能名称> - 通过 git pull 更新技能');
88
- console.log(' getskill update <技能名称> --version <tag> - 切换到指定版本');
85
+ console.log(' getskill install <技能名称> - 通过 HTTPS 下载 zip 包安装技能');
86
+ console.log(' getskill install <技能名称> --version <tag> - 安装指定版本(需与站点当前版本一致)');
87
+ console.log(' getskill update <技能名称> - 检查在线版本并更新技能');
88
+ console.log(' getskill update <技能名称> --version <tag> - 更新到指定版本');
89
89
  console.log(' getskill update --all - 批量更新所有已安装技能');
90
- console.log(' getskill publish <目录> [--repo <git-url>] - 自动注册/登录并发布技能');
91
- console.log(' getskill publish <目录> --name <repo-name> - 自动创建远程仓库并提交');
90
+ console.log(' getskill publish <目录> [--repo <git-url>] - 发布技能到你自己的 Git 仓库');
91
+ console.log(' getskill publish <目录> --name <repo-name> - 指定仓库名(需配合 --repo)');
92
92
  console.log(' getskill uninstall <技能名称> - 卸载本地技能');
93
93
  console.log(' getskill inspect <技能名称> - 查看本地安装与缓存状态');
94
94
  console.log(' getskill list - 列出本地技能');
95
95
  console.log(' getskill path - 显示目录路径');
96
- console.log(' getskill config set <URL> - 设置自定义 API 地址');
97
- console.log(' getskill config get - 查看当前 API 地址');
98
- console.log(' getskill clean - 清理 git 缓存');
96
+ console.log(' getskill config set <URL> - 设置自定义站点地址');
97
+ console.log(' getskill config get - 查看当前站点地址');
98
+ console.log(' getskill clean - 清理下载缓存');
99
99
  console.log('');
100
100
  console.log('示例:');
101
- console.log(' getskill install pdf-extract');
102
- console.log(' getskill install skills/xejrax_pdf-extract');
103
- console.log(' getskill install pdf-extract --version v1.0.0');
101
+ console.log(' getskill install ab-testing');
102
+ console.log(' getskill install ab-testing --version 2.0.7');
104
103
  console.log(' getskill search pdf --json');
105
- console.log(' getskill update pdf-extract');
104
+ console.log(' getskill update ab-testing');
106
105
  console.log(' getskill update --all');
107
- console.log(' getskill publish ./my-skill --name my-skill');
108
- console.log(' getskill publish ./my-skill --repo https://getskill.work/user/my-skill.git');
109
- console.log(' getskill inspect pdf-extract');
106
+ console.log(' getskill publish ./my-skill --repo https://github.com/yourname/my-skill.git');
107
+ console.log(' getskill inspect ab-testing');
110
108
  console.log('');
111
- console.log(`当前 API: ${(0, config_1.getBaseUrl)()}`);
109
+ console.log(`当前站点: ${(0, config_1.getBaseUrl)()}`);
110
+ console.log(`技能索引: ${(0, config_1.getBaseUrl)()}/data/skills.json`);
112
111
  console.log(`技能目录: ${(0, config_1.getSkillsDirectory)()}`);
113
112
  console.log(`缓存目录: ${(0, config_1.getSkillsCacheDirectory)()}`);
114
113
  }
@@ -170,12 +169,15 @@ async function cli() {
170
169
  }
171
170
  console.log(`找到 ${results.length} 个技能:\n`);
172
171
  results.forEach((skill, index) => {
173
- console.log(`${index + 1}. ${skill.full_name}`);
172
+ console.log(`${index + 1}. ${skill.full_name} (v${skill.version})`);
174
173
  if (skill.description) {
175
174
  console.log(` 描述: ${skill.description}`);
176
175
  }
177
- if (skill.git_url) {
178
- console.log(` Git: ${skill.git_url}`);
176
+ if (skill.category) {
177
+ console.log(` 分类: ${skill.category}`);
178
+ }
179
+ if (skill.download_url) {
180
+ console.log(` 下载: ${skill.download_url}`);
179
181
  }
180
182
  console.log('');
181
183
  });
@@ -200,9 +202,9 @@ async function cli() {
200
202
  });
201
203
  console.log('\n技能已安装到 skills 目录:');
202
204
  result.files.forEach((file) => console.log(` - ${file}`));
203
- console.log(`\nGit 仓库缓存: ${result.repoPath}`);
204
- if (result.requestedVersion) {
205
- console.log(`已安装版本: ${result.requestedVersion}`);
205
+ console.log(`\n本地缓存: ${result.repoPath}`);
206
+ if (result.version) {
207
+ console.log(`已安装版本: ${result.version}`);
206
208
  }
207
209
  break;
208
210
  }
@@ -238,10 +240,14 @@ async function cli() {
238
240
  const result = await (0, skill_manager_1.updateSkill)(skillName, {
239
241
  version: requestedVersion
240
242
  });
243
+ if (result.upToDate) {
244
+ console.log(`\n技能已是最新版本 (v${result.version || 'unknown'}),无需更新。`);
245
+ break;
246
+ }
241
247
  console.log('\n技能已更新到 skills 目录:');
242
248
  result.files.forEach((file) => console.log(` - ${file}`));
243
- if (result.requestedVersion) {
244
- console.log(`已切换到版本: ${result.requestedVersion}`);
249
+ if (result.version) {
250
+ console.log(`当前版本: ${result.version}`);
245
251
  }
246
252
  break;
247
253
  }
@@ -262,10 +268,6 @@ async function cli() {
262
268
  const email = typeof options.email === 'string'
263
269
  ? options.email
264
270
  : undefined;
265
- const password = typeof options.password === 'string'
266
- ? options.password
267
- : undefined;
268
- const visibility = options.private ? 'private' : 'public';
269
271
  if (!skillPath) {
270
272
  console.error('请提供技能目录路径');
271
273
  console.log('用法: getskill publish <目录> [--repo <git-url>] [--name repo-name] [--branch main] [--message "..."]');
@@ -277,17 +279,13 @@ async function cli() {
277
279
  branch,
278
280
  message,
279
281
  username,
280
- email,
281
- password,
282
- visibility
282
+ email
283
283
  });
284
284
  console.log('\n发布完成:');
285
285
  console.log(` 目录: ${result.skillPath}`);
286
286
  console.log(` 仓库: ${result.repositoryName || 'unknown'}`);
287
287
  console.log(` 远程: ${result.remoteUrl}`);
288
288
  console.log(` 分支: ${result.branch}`);
289
- console.log(` 登录方式: ${result.authMode || 'unknown'}`);
290
- console.log(` 本次是否自动创建远程仓库: ${result.createdRemoteRepo ? '是' : '否'}`);
291
289
  console.log(` 本次是否提交新变更: ${result.committed ? '是' : '否'}`);
292
290
  break;
293
291
  }
@@ -322,7 +320,7 @@ async function cli() {
322
320
  console.log(`最后动作: ${info.state.lastAction || 'unknown'}`);
323
321
  console.log(`安装时间: ${info.state.installedAt || 'unknown'}`);
324
322
  console.log(`更新时间: ${info.state.updatedAt || 'unknown'}`);
325
- console.log(`Commit: ${info.state.gitCommitHash || 'unknown'}`);
323
+ console.log(`版本: ${info.state.version || info.state.gitCommitHash || 'unknown'}`);
326
324
  }
327
325
  else {
328
326
  console.log('状态文件中暂无该技能记录。');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workskills/getskill",
3
- "version": "1.1.9",
3
+ "version": "1.2.0",
4
4
  "description": "A skill management tool for OpenClaw that enables searching, downloading, and updating skill files from the getskill.work repository",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -59,7 +59,9 @@
59
59
  "win32"
60
60
  ],
61
61
  "files": [
62
- "dist/",
62
+ "dist/main.js",
63
+ "dist/main.d.ts",
64
+ "dist/lib/",
63
65
  "README.md",
64
66
  "EXAMPLES.md",
65
67
  "LICENSE"
@@ -1,15 +0,0 @@
1
- import type { AuthSession, EnsureAuthResult, PublishOptions, RegistryUser, RepoCreationResult } from './types';
2
- export declare function loadAuthSession(): AuthSession | null;
3
- export declare function saveAuthSession(session: AuthSession): void;
4
- export declare function clearAuthSession(): void;
5
- export declare function isRegistryRepoUrl(repoUrl: string): boolean;
6
- export declare function buildAuthenticatedGitUrl(cloneUrl: string, session: AuthSession): string;
7
- export declare function buildGitHttpExtraHeader(session: AuthSession): string;
8
- export declare function fetchCurrentUser(token: string): Promise<RegistryUser | null>;
9
- export declare function createAccessToken(username: string, password: string): Promise<AuthSession>;
10
- export declare function registerUser(username: string, email: string, password: string): Promise<void>;
11
- export declare function ensureRegistryAuth(options?: PublishOptions): Promise<EnsureAuthResult>;
12
- export declare function ensureRemoteRepository(session: AuthSession, repoName: string, options?: {
13
- description?: string;
14
- visibility?: 'public' | 'private';
15
- }): Promise<RepoCreationResult>;