@workskills/getskill 1.2.0 → 2.1.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.
- package/EXAMPLES.md +98 -72
- package/README.md +167 -200
- package/dist/lib/config.d.ts +81 -4
- package/dist/lib/config.js +473 -21
- package/dist/lib/skill-manager.d.ts +7 -4
- package/dist/lib/skill-manager.js +55 -118
- package/dist/lib/state.d.ts +11 -0
- package/dist/lib/state.js +126 -14
- package/dist/lib/system.d.ts +0 -6
- package/dist/lib/system.js +0 -159
- package/dist/lib/types.d.ts +14 -28
- package/dist/main.d.ts +9 -5
- package/dist/main.js +280 -89
- package/package.json +9 -4
- package/dist/lib/skill-validator.d.ts +0 -4
- package/dist/lib/skill-validator.js +0 -107
package/dist/lib/config.js
CHANGED
|
@@ -3,41 +3,493 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MAX_COPY_FILE_SIZE_BYTES = exports.REQUEST_TIMEOUT_MS = void 0;
|
|
7
|
-
exports.
|
|
6
|
+
exports.AGENT_PRESETS = exports.DEFAULT_AGENT_NAME = exports.CUSTOM_AGENT_NAME = exports.AUTO_AGENT_NAME = exports.MAX_COPY_FILE_SIZE_BYTES = exports.REQUEST_TIMEOUT_MS = exports.DEFAULT_BASE_URL = void 0;
|
|
7
|
+
exports.normalizePath = normalizePath;
|
|
8
|
+
exports.isSamePath = isSamePath;
|
|
9
|
+
exports.normalizeBaseUrl = normalizeBaseUrl;
|
|
10
|
+
exports.normalizeConfigKey = normalizeConfigKey;
|
|
11
|
+
exports.getHomeDirectory = getHomeDirectory;
|
|
12
|
+
exports.getGetSkillHome = getGetSkillHome;
|
|
13
|
+
exports.getConfigFilePath = getConfigFilePath;
|
|
14
|
+
exports.getStateFilePath = getStateFilePath;
|
|
15
|
+
exports.getLegacyStateFilePaths = getLegacyStateFilePaths;
|
|
16
|
+
exports.readConfigFile = readConfigFile;
|
|
17
|
+
exports.writeConfigFile = writeConfigFile;
|
|
18
|
+
exports.getAgentPreset = getAgentPreset;
|
|
19
|
+
exports.getPresetSkillsDir = getPresetSkillsDir;
|
|
20
|
+
exports.detectAgentName = detectAgentName;
|
|
21
|
+
exports.refreshConfig = refreshConfig;
|
|
22
|
+
exports.applyRuntimeOverrides = applyRuntimeOverrides;
|
|
23
|
+
exports.clearRuntimeOverrides = clearRuntimeOverrides;
|
|
24
|
+
exports.resolveConfig = resolveConfig;
|
|
25
|
+
exports.getConfigSummary = getConfigSummary;
|
|
8
26
|
exports.getBaseUrl = getBaseUrl;
|
|
9
|
-
exports.getOpenClawRootDirectory = getOpenClawRootDirectory;
|
|
10
27
|
exports.getSkillsDirectory = getSkillsDirectory;
|
|
11
28
|
exports.getSkillsCacheDirectory = getSkillsCacheDirectory;
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
29
|
+
exports.getAgentName = getAgentName;
|
|
30
|
+
exports.getAgentLabel = getAgentLabel;
|
|
31
|
+
exports.getAgentRestartCommand = getAgentRestartCommand;
|
|
32
|
+
exports.listAgents = listAgents;
|
|
33
|
+
exports.getLegacyCacheDirectories = getLegacyCacheDirectories;
|
|
34
|
+
exports.setConfigValue = setConfigValue;
|
|
35
|
+
exports.unsetConfigValue = unsetConfigValue;
|
|
36
|
+
exports.setBaseUrl = setBaseUrl;
|
|
37
|
+
exports.setAgent = setAgent;
|
|
38
|
+
exports.setSkillsDir = setSkillsDir;
|
|
39
|
+
exports.setCacheDir = setCacheDir;
|
|
40
|
+
const fs_1 = __importDefault(require("fs"));
|
|
14
41
|
const os_1 = __importDefault(require("os"));
|
|
15
42
|
const path_1 = __importDefault(require("path"));
|
|
16
|
-
|
|
43
|
+
const system_1 = require("./system");
|
|
44
|
+
exports.DEFAULT_BASE_URL = 'https://getskill.work';
|
|
17
45
|
exports.REQUEST_TIMEOUT_MS = 60000;
|
|
18
46
|
exports.MAX_COPY_FILE_SIZE_BYTES = 2 * 1024 * 1024;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
47
|
+
exports.AUTO_AGENT_NAME = 'auto';
|
|
48
|
+
exports.CUSTOM_AGENT_NAME = 'custom';
|
|
49
|
+
exports.DEFAULT_AGENT_NAME = 'claude';
|
|
50
|
+
/**
|
|
51
|
+
* 支持的 Agent 目录约定。任何 Agent 都可以通过 agent 预设、
|
|
52
|
+
* skillsDir 自定义目录或 GETSKILL_SKILLS_DIR 环境变量接入。
|
|
53
|
+
*/
|
|
54
|
+
exports.AGENT_PRESETS = [
|
|
55
|
+
{
|
|
56
|
+
name: 'claude',
|
|
57
|
+
label: 'Claude Code',
|
|
58
|
+
skillsPathSegments: ['.claude', 'skills']
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'openclaw',
|
|
62
|
+
label: 'OpenClaw',
|
|
63
|
+
skillsPathSegments: ['.openclaw', 'skills'],
|
|
64
|
+
restartCommand: 'openclaw gateway restart'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'codex',
|
|
68
|
+
label: 'OpenAI Codex CLI',
|
|
69
|
+
skillsPathSegments: ['.codex', 'skills']
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'cursor',
|
|
73
|
+
label: 'Cursor',
|
|
74
|
+
skillsPathSegments: ['.cursor', 'skills']
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'gemini',
|
|
78
|
+
label: 'Gemini CLI',
|
|
79
|
+
skillsPathSegments: ['.gemini', 'skills']
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'qwen',
|
|
83
|
+
label: 'Qwen Code',
|
|
84
|
+
skillsPathSegments: ['.qwen', 'skills']
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'copilot',
|
|
88
|
+
label: 'GitHub Copilot CLI',
|
|
89
|
+
skillsPathSegments: ['.copilot', 'skills']
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'amp',
|
|
93
|
+
label: 'Amp',
|
|
94
|
+
skillsPathSegments: ['.config', 'amp', 'skills']
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'opencode',
|
|
98
|
+
label: 'OpenCode',
|
|
99
|
+
skillsPathSegments: ['.config', 'opencode', 'skills']
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'agent',
|
|
103
|
+
label: '通用 Agent 目录',
|
|
104
|
+
skillsPathSegments: ['.agent', 'skills']
|
|
22
105
|
}
|
|
23
|
-
|
|
24
|
-
|
|
106
|
+
];
|
|
107
|
+
const CONFIG_KEY_ALIASES = {
|
|
108
|
+
'base-url': 'baseUrl',
|
|
109
|
+
baseurl: 'baseUrl',
|
|
110
|
+
base_url: 'baseUrl',
|
|
111
|
+
url: 'baseUrl',
|
|
112
|
+
index: 'baseUrl',
|
|
113
|
+
'index-url': 'baseUrl',
|
|
114
|
+
agent: 'agent',
|
|
115
|
+
target: 'agent',
|
|
116
|
+
'skills-dir': 'skillsDir',
|
|
117
|
+
skillsdir: 'skillsDir',
|
|
118
|
+
skills_dir: 'skillsDir',
|
|
119
|
+
dir: 'skillsDir',
|
|
120
|
+
'cache-dir': 'cacheDir',
|
|
121
|
+
cachedir: 'cacheDir',
|
|
122
|
+
cache_dir: 'cacheDir',
|
|
123
|
+
cache: 'cacheDir'
|
|
124
|
+
};
|
|
125
|
+
let cliOverrides = {};
|
|
126
|
+
let resolvedCache = null;
|
|
127
|
+
function isBlank(value) {
|
|
128
|
+
return typeof value !== 'string' || value.trim() === '';
|
|
25
129
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
130
|
+
function expandHome(value) {
|
|
131
|
+
const trimmed = value.trim();
|
|
132
|
+
if (trimmed === '~') {
|
|
133
|
+
return os_1.default.homedir();
|
|
134
|
+
}
|
|
135
|
+
if (trimmed.startsWith('~/') || trimmed.startsWith('~\\')) {
|
|
136
|
+
return path_1.default.join(os_1.default.homedir(), trimmed.slice(2));
|
|
137
|
+
}
|
|
138
|
+
return trimmed;
|
|
139
|
+
}
|
|
140
|
+
function normalizePath(value) {
|
|
141
|
+
return path_1.default.resolve(expandHome(value));
|
|
142
|
+
}
|
|
143
|
+
function isSamePath(left, right) {
|
|
144
|
+
const a = path_1.default.resolve(left);
|
|
145
|
+
const b = path_1.default.resolve(right);
|
|
146
|
+
return process.platform === 'win32'
|
|
147
|
+
? a.toLowerCase() === b.toLowerCase()
|
|
148
|
+
: a === b;
|
|
149
|
+
}
|
|
150
|
+
function normalizeBaseUrl(url) {
|
|
151
|
+
const trimmed = url.trim().replace(/\/+$/, '');
|
|
152
|
+
if (!/^https?:\/\/.+/i.test(trimmed)) {
|
|
153
|
+
throw new Error(`索引地址必须是 http(s) URL,例如 ${exports.DEFAULT_BASE_URL}(收到: ${url})`);
|
|
154
|
+
}
|
|
155
|
+
return trimmed;
|
|
156
|
+
}
|
|
157
|
+
function normalizeConfigKey(key) {
|
|
158
|
+
const normalized = key.trim().toLowerCase();
|
|
159
|
+
const mapped = CONFIG_KEY_ALIASES[normalized];
|
|
160
|
+
if (!mapped) {
|
|
161
|
+
throw new Error(`未知配置项: ${key}(可用: base-url, agent, skills-dir, cache-dir)`);
|
|
162
|
+
}
|
|
163
|
+
return mapped;
|
|
164
|
+
}
|
|
165
|
+
function getHomeDirectory() {
|
|
166
|
+
return os_1.default.homedir();
|
|
167
|
+
}
|
|
168
|
+
function getGetSkillHome() {
|
|
169
|
+
const fromEnv = process.env.GETSKILL_HOME;
|
|
170
|
+
if (!isBlank(fromEnv)) {
|
|
171
|
+
return normalizePath(fromEnv);
|
|
172
|
+
}
|
|
173
|
+
return path_1.default.join(os_1.default.homedir(), '.getskill');
|
|
28
174
|
}
|
|
29
|
-
function
|
|
30
|
-
return path_1.default.join(
|
|
175
|
+
function getConfigFilePath() {
|
|
176
|
+
return path_1.default.join(getGetSkillHome(), 'config.json');
|
|
177
|
+
}
|
|
178
|
+
function getStateFilePath() {
|
|
179
|
+
const fromEnv = process.env.GETSKILL_STATE_FILE;
|
|
180
|
+
if (!isBlank(fromEnv)) {
|
|
181
|
+
return normalizePath(fromEnv);
|
|
182
|
+
}
|
|
183
|
+
return path_1.default.join(getGetSkillHome(), 'state.json');
|
|
184
|
+
}
|
|
185
|
+
function getLegacyStateFilePaths() {
|
|
186
|
+
const candidates = [
|
|
187
|
+
path_1.default.join(os_1.default.homedir(), '.openclaw', 'getskill', 'state.json'),
|
|
188
|
+
path_1.default.join(path_1.default.dirname(getPresetSkillsDir(getAgentPreset('openclaw'))), 'getskill', 'state.json')
|
|
189
|
+
];
|
|
190
|
+
return [...new Set(candidates)].filter((candidate) => !isSamePath(candidate, getStateFilePath()));
|
|
191
|
+
}
|
|
192
|
+
function readConfigFile() {
|
|
193
|
+
const configFile = getConfigFilePath();
|
|
194
|
+
if (!fs_1.default.existsSync(configFile)) {
|
|
195
|
+
return {};
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const parsed = JSON.parse(fs_1.default.readFileSync(configFile, 'utf8'));
|
|
199
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
200
|
+
return {};
|
|
201
|
+
}
|
|
202
|
+
const result = {};
|
|
203
|
+
Object.keys(parsed).forEach((key) => {
|
|
204
|
+
const value = parsed[key];
|
|
205
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
206
|
+
result[key] = value.trim();
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return {};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function writeConfigFile(config) {
|
|
216
|
+
const configFile = getConfigFilePath();
|
|
217
|
+
(0, system_1.ensureDirectoryExists)(path_1.default.dirname(configFile));
|
|
218
|
+
fs_1.default.writeFileSync(configFile, `${JSON.stringify(config, null, 2)}\n`, 'utf8');
|
|
219
|
+
}
|
|
220
|
+
function getAgentPreset(name) {
|
|
221
|
+
if (isBlank(name)) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
const normalized = name.trim().toLowerCase();
|
|
225
|
+
return exports.AGENT_PRESETS.find((preset) => preset.name === normalized) || null;
|
|
226
|
+
}
|
|
227
|
+
function getPresetSkillsDir(preset) {
|
|
228
|
+
return path_1.default.join(os_1.default.homedir(), ...preset.skillsPathSegments);
|
|
229
|
+
}
|
|
230
|
+
function directoryHasEntries(dir) {
|
|
231
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
return fs_1.default.readdirSync(dir).length > 0;
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function readStateSkillsDirHint() {
|
|
242
|
+
const candidates = [
|
|
243
|
+
getStateFilePath(),
|
|
244
|
+
...getLegacyStateFilePaths().map((item) => item)
|
|
245
|
+
];
|
|
246
|
+
for (const candidate of candidates) {
|
|
247
|
+
if (!fs_1.default.existsSync(candidate)) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
const parsed = JSON.parse(fs_1.default.readFileSync(candidate, 'utf8'));
|
|
252
|
+
const records = Object.values(parsed?.skills || {});
|
|
253
|
+
for (const record of records) {
|
|
254
|
+
if (record && typeof record.installDir === 'string') {
|
|
255
|
+
return path_1.default.dirname(record.installDir);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* 自动识别当前机器上正在使用的 Agent 技能目录。
|
|
267
|
+
* 优先级:历史安装记录 > 已存在且非空的技能目录 > 已存在的 Agent 根目录 > 默认值。
|
|
268
|
+
*/
|
|
269
|
+
function detectAgentName() {
|
|
270
|
+
const hint = readStateSkillsDirHint();
|
|
271
|
+
if (hint) {
|
|
272
|
+
const fromState = exports.AGENT_PRESETS.find((preset) => isSamePath(getPresetSkillsDir(preset), hint));
|
|
273
|
+
if (fromState) {
|
|
274
|
+
return fromState.name;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const nonEmpty = exports.AGENT_PRESETS.find((preset) => directoryHasEntries(getPresetSkillsDir(preset)));
|
|
278
|
+
if (nonEmpty) {
|
|
279
|
+
return nonEmpty.name;
|
|
280
|
+
}
|
|
281
|
+
const rootExists = exports.AGENT_PRESETS.find((preset) => fs_1.default.existsSync(path_1.default.dirname(getPresetSkillsDir(preset))));
|
|
282
|
+
if (rootExists) {
|
|
283
|
+
return rootExists.name;
|
|
284
|
+
}
|
|
285
|
+
return exports.DEFAULT_AGENT_NAME;
|
|
286
|
+
}
|
|
287
|
+
function pickValue(candidates, fallback) {
|
|
288
|
+
for (const candidate of candidates) {
|
|
289
|
+
if (!isBlank(candidate.value)) {
|
|
290
|
+
return {
|
|
291
|
+
value: candidate.value.trim(),
|
|
292
|
+
source: candidate.source
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return fallback;
|
|
297
|
+
}
|
|
298
|
+
function refreshConfig() {
|
|
299
|
+
resolvedCache = null;
|
|
300
|
+
}
|
|
301
|
+
/** 仅作用于当前进程的临时覆盖(例如 CLI 的 --agent / --skills-dir 参数)。 */
|
|
302
|
+
function applyRuntimeOverrides(overrides) {
|
|
303
|
+
let changed = false;
|
|
304
|
+
Object.keys(overrides).forEach((key) => {
|
|
305
|
+
const value = overrides[key];
|
|
306
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
307
|
+
cliOverrides[key] = value.trim();
|
|
308
|
+
changed = true;
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
if (changed) {
|
|
312
|
+
refreshConfig();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function clearRuntimeOverrides() {
|
|
316
|
+
cliOverrides = {};
|
|
317
|
+
refreshConfig();
|
|
318
|
+
}
|
|
319
|
+
function resolveConfig() {
|
|
320
|
+
if (resolvedCache) {
|
|
321
|
+
return resolvedCache;
|
|
322
|
+
}
|
|
323
|
+
const file = readConfigFile();
|
|
324
|
+
const baseUrlPick = pickValue([
|
|
325
|
+
{ value: cliOverrides.baseUrl, source: 'cli' },
|
|
326
|
+
{ value: process.env.GETSKILL_BASE_URL, source: 'env' },
|
|
327
|
+
{ value: file.baseUrl, source: 'file' }
|
|
328
|
+
], { value: exports.DEFAULT_BASE_URL, source: 'default' });
|
|
329
|
+
const agentPick = pickValue([
|
|
330
|
+
{ value: cliOverrides.agent, source: 'cli' },
|
|
331
|
+
{ value: process.env.GETSKILL_AGENT, source: 'env' },
|
|
332
|
+
{ value: file.agent, source: 'file' }
|
|
333
|
+
], { value: exports.AUTO_AGENT_NAME, source: 'detect' });
|
|
334
|
+
const skillsDirPick = pickValue([
|
|
335
|
+
{ value: cliOverrides.skillsDir, source: 'cli' },
|
|
336
|
+
{ value: process.env.GETSKILL_SKILLS_DIR, source: 'env' },
|
|
337
|
+
{ value: file.skillsDir, source: 'file' }
|
|
338
|
+
], { value: '', source: 'default' });
|
|
339
|
+
const cacheDirPick = pickValue([
|
|
340
|
+
{ value: cliOverrides.cacheDir, source: 'cli' },
|
|
341
|
+
{ value: process.env.GETSKILL_CACHE_DIR, source: 'env' },
|
|
342
|
+
{ value: file.cacheDir, source: 'file' }
|
|
343
|
+
], { value: '', source: 'default' });
|
|
344
|
+
const requestedAgent = agentPick.value.toLowerCase();
|
|
345
|
+
const preset = getAgentPreset(requestedAgent);
|
|
346
|
+
const isAuto = requestedAgent === exports.AUTO_AGENT_NAME;
|
|
347
|
+
if (!preset && !isAuto && !skillsDirPick.value) {
|
|
348
|
+
throw new Error(`未知 agent: ${agentPick.value}(可用: auto, ${exports.AGENT_PRESETS.map((item) => item.name).join(', ')},或通过 skills-dir 指定任意目录)`);
|
|
349
|
+
}
|
|
350
|
+
const resolvedPreset = preset || getAgentPreset(detectAgentName());
|
|
351
|
+
const agentName = skillsDirPick.value
|
|
352
|
+
? preset
|
|
353
|
+
? preset.name
|
|
354
|
+
: exports.CUSTOM_AGENT_NAME
|
|
355
|
+
: resolvedPreset.name;
|
|
356
|
+
const agentLabel = skillsDirPick.value
|
|
357
|
+
? preset
|
|
358
|
+
? preset.label
|
|
359
|
+
: '自定义目录'
|
|
360
|
+
: resolvedPreset.label;
|
|
361
|
+
const skillsDir = skillsDirPick.value
|
|
362
|
+
? normalizePath(skillsDirPick.value)
|
|
363
|
+
: getPresetSkillsDir(resolvedPreset);
|
|
364
|
+
const skillsDirSource = skillsDirPick.value
|
|
365
|
+
? skillsDirPick.source
|
|
366
|
+
: isAuto || !preset
|
|
367
|
+
? 'detect'
|
|
368
|
+
: agentPick.source;
|
|
369
|
+
const cacheDir = cacheDirPick.value
|
|
370
|
+
? normalizePath(cacheDirPick.value)
|
|
371
|
+
: path_1.default.join(getGetSkillHome(), 'cache');
|
|
372
|
+
const envRestartCommand = process.env.GETSKILL_RESTART_CMD;
|
|
373
|
+
const restartCommand = !isBlank(envRestartCommand)
|
|
374
|
+
? envRestartCommand.trim()
|
|
375
|
+
: resolvedPreset?.restartCommand || null;
|
|
376
|
+
const resolved = {
|
|
377
|
+
baseUrl: normalizeBaseUrl(baseUrlPick.value),
|
|
378
|
+
agent: agentName,
|
|
379
|
+
agentLabel,
|
|
380
|
+
skillsDir,
|
|
381
|
+
cacheDir,
|
|
382
|
+
homeDir: getGetSkillHome(),
|
|
383
|
+
configFile: getConfigFilePath(),
|
|
384
|
+
stateFile: getStateFilePath(),
|
|
385
|
+
restartCommand,
|
|
386
|
+
sources: {
|
|
387
|
+
baseUrl: baseUrlPick.source,
|
|
388
|
+
agent: isAuto
|
|
389
|
+
? skillsDirPick.value
|
|
390
|
+
? skillsDirPick.source
|
|
391
|
+
: 'detect'
|
|
392
|
+
: agentPick.source,
|
|
393
|
+
skillsDir: skillsDirSource,
|
|
394
|
+
cacheDir: cacheDirPick.value ? cacheDirPick.source : 'default'
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
resolvedCache = resolved;
|
|
398
|
+
return resolved;
|
|
399
|
+
}
|
|
400
|
+
function getConfigSummary() {
|
|
401
|
+
return resolveConfig();
|
|
402
|
+
}
|
|
403
|
+
function getBaseUrl() {
|
|
404
|
+
return resolveConfig().baseUrl;
|
|
31
405
|
}
|
|
32
406
|
function getSkillsDirectory() {
|
|
33
|
-
return
|
|
407
|
+
return resolveConfig().skillsDir;
|
|
34
408
|
}
|
|
35
409
|
function getSkillsCacheDirectory() {
|
|
36
|
-
return
|
|
410
|
+
return resolveConfig().cacheDir;
|
|
37
411
|
}
|
|
38
|
-
function
|
|
39
|
-
return
|
|
412
|
+
function getAgentName() {
|
|
413
|
+
return resolveConfig().agent;
|
|
40
414
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
415
|
+
function getAgentLabel() {
|
|
416
|
+
return resolveConfig().agentLabel;
|
|
417
|
+
}
|
|
418
|
+
function getAgentRestartCommand() {
|
|
419
|
+
return resolveConfig().restartCommand;
|
|
420
|
+
}
|
|
421
|
+
function listAgents() {
|
|
422
|
+
const active = resolveConfig();
|
|
423
|
+
return exports.AGENT_PRESETS.map((preset) => {
|
|
424
|
+
const skillsDir = getPresetSkillsDir(preset);
|
|
425
|
+
return {
|
|
426
|
+
name: preset.name,
|
|
427
|
+
label: preset.label,
|
|
428
|
+
skillsDir,
|
|
429
|
+
exists: fs_1.default.existsSync(skillsDir),
|
|
430
|
+
active: isSamePath(skillsDir, active.skillsDir),
|
|
431
|
+
restartCommand: preset.restartCommand || null
|
|
432
|
+
};
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
/** 历史版本(2.0 及更早)遗留的缓存目录,`clean` 命令会一并清理。 */
|
|
436
|
+
function getLegacyCacheDirectories() {
|
|
437
|
+
const current = getSkillsCacheDirectory();
|
|
438
|
+
const candidates = [path_1.default.join(os_1.default.homedir(), '.openclaw', 'skills-cache')];
|
|
439
|
+
return [...new Set(candidates)].filter((candidate) => !isSamePath(candidate, current));
|
|
440
|
+
}
|
|
441
|
+
function persistConfig(patch) {
|
|
442
|
+
const next = { ...readConfigFile() };
|
|
443
|
+
Object.keys(patch).forEach((key) => {
|
|
444
|
+
const value = patch[key];
|
|
445
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
446
|
+
next[key] = value.trim();
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
delete next[key];
|
|
450
|
+
});
|
|
451
|
+
writeConfigFile(next);
|
|
452
|
+
refreshConfig();
|
|
453
|
+
return resolveConfig();
|
|
454
|
+
}
|
|
455
|
+
function normalizeConfigValue(configKey, rawValue) {
|
|
456
|
+
if (isBlank(rawValue)) {
|
|
457
|
+
throw new Error(`配置项 ${configKey} 的值不能为空`);
|
|
458
|
+
}
|
|
459
|
+
const value = rawValue.trim();
|
|
460
|
+
if (configKey === 'baseUrl') {
|
|
461
|
+
return normalizeBaseUrl(value);
|
|
462
|
+
}
|
|
463
|
+
if (configKey === 'skillsDir' || configKey === 'cacheDir') {
|
|
464
|
+
return normalizePath(value);
|
|
465
|
+
}
|
|
466
|
+
const normalized = value.toLowerCase();
|
|
467
|
+
if (normalized !== exports.AUTO_AGENT_NAME && !getAgentPreset(normalized)) {
|
|
468
|
+
throw new Error(`未知 agent: ${value}(可用: auto, ${exports.AGENT_PRESETS.map((item) => item.name).join(', ')})`);
|
|
469
|
+
}
|
|
470
|
+
return normalized;
|
|
471
|
+
}
|
|
472
|
+
/** 写入并持久化配置项,返回写入后的完整生效配置。 */
|
|
473
|
+
function setConfigValue(key, rawValue) {
|
|
474
|
+
const configKey = normalizeConfigKey(String(key));
|
|
475
|
+
return persistConfig({
|
|
476
|
+
[configKey]: normalizeConfigValue(configKey, rawValue)
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
/** 删除已持久化的配置项,恢复为环境变量 / 自动识别 / 默认值。 */
|
|
480
|
+
function unsetConfigValue(key) {
|
|
481
|
+
const configKey = normalizeConfigKey(String(key));
|
|
482
|
+
return persistConfig({ [configKey]: '' });
|
|
483
|
+
}
|
|
484
|
+
function setBaseUrl(url) {
|
|
485
|
+
return setConfigValue('baseUrl', url).baseUrl;
|
|
486
|
+
}
|
|
487
|
+
function setAgent(name) {
|
|
488
|
+
return setConfigValue('agent', name).agent;
|
|
489
|
+
}
|
|
490
|
+
function setSkillsDir(dir) {
|
|
491
|
+
return setConfigValue('skillsDir', dir).skillsDir;
|
|
492
|
+
}
|
|
493
|
+
function setCacheDir(dir) {
|
|
494
|
+
return setConfigValue('cacheDir', dir).cacheDir;
|
|
43
495
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DownloadOptions, DownloadResult,
|
|
1
|
+
import type { DownloadOptions, DownloadResult, RemoveInstalledSkillResult, SkillIndexEntry, UpdateAllOptions, UpdateAllResult } from './types';
|
|
2
2
|
export interface FetchSkillToCacheResult {
|
|
3
3
|
repoPath: string;
|
|
4
4
|
cachePath: string;
|
|
@@ -6,11 +6,14 @@ export interface FetchSkillToCacheResult {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function fetchSkillToCache(skillName: string, options?: DownloadOptions): Promise<FetchSkillToCacheResult>;
|
|
8
8
|
export declare function cloneOrUpdateRepo(skillName: string, options?: DownloadOptions): Promise<string>;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* 安装/更新后的可选 Agent 重载钩子。
|
|
11
|
+
* 仅当 Agent 预设定义了重启命令,或设置了 `GETSKILL_RESTART_CMD` 时才执行。
|
|
12
|
+
*/
|
|
13
|
+
export declare function restartAgentGateway(): Promise<void>;
|
|
10
14
|
export declare function downloadSkill(skillName: string, options?: DownloadOptions): Promise<DownloadResult>;
|
|
11
15
|
export declare function updateSkill(skillName: string, options?: DownloadOptions): Promise<DownloadResult>;
|
|
12
|
-
export declare function updateAllSkills(): Promise<UpdateAllResult[]>;
|
|
16
|
+
export declare function updateAllSkills(options?: UpdateAllOptions): Promise<UpdateAllResult[]>;
|
|
13
17
|
export declare function uninstallSkill(skillName: string, options?: {
|
|
14
18
|
removeCache?: boolean;
|
|
15
19
|
}): Promise<RemoveInstalledSkillResult>;
|
|
16
|
-
export declare function publishSkill(skillPath: string, options?: PublishOptions): Promise<PublishResult>;
|