insightfulpipe 0.2.0 → 0.4.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.
@@ -0,0 +1,554 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { renameSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { resolve } from 'node:path';
4
+
5
+ import { printJson, printTable, wantsJson } from '../../output.js';
6
+ import { fail } from '../errors.js';
7
+ import { confirm } from '../input.js';
8
+ import { parseIntegerOption } from '../options.js';
9
+ import { AGENT_NAMES, AGENTS, DEFAULT_AGENT, resolveSkillsDir } from '../../skills/agents.js';
10
+ import { fetchSkillZip, skillKey } from '../../skills/catalog.js';
11
+ import { installSkill, lexists, listInstalled, localChanges, removeInstalled } from '../../skills/installer.js';
12
+ import { isPrivateKey } from '../../skills/private.js';
13
+ import { forgetInstall, isRecordedInstall, realFolderPath, recordInstall } from '../../skills/records.js';
14
+ import { markerLabel, markerOrigin, openSource, sourcesForMarkers } from '../../skills/sources.js';
15
+
16
+ const MCP_TIP =
17
+ 'Skills read live data through the InsightfulPipe MCP. Connect it once: https://insightfulpipe.com/mcp-servers';
18
+ const PRIVATE_IN_PROJECT =
19
+ 'This private workspace skill is in a project folder. Keep it out of shared or public repositories (add the folder to .gitignore).';
20
+
21
+ function withTargetOptions(command) {
22
+ return command
23
+ .option('--agent <agent>', `Agent to install for: ${AGENT_NAMES.join(', ')}`, DEFAULT_AGENT)
24
+ .option('-p, --project', "Use the current folder's project skills directory instead of the global one")
25
+ .option('--dir <path>', 'Use this skills directory instead');
26
+ }
27
+
28
+ const NOT_YOURS =
29
+ 'Not installed by you here, so it is never checked or updated. To use it, install it again with --private --force.';
30
+
31
+ /** The HTTP status of a failed app request, for the JSON, when the error carries one. */
32
+ function httpStatus(error) {
33
+ return error?.httpStatus ? { http_status: error.httpStatus } : {};
34
+ }
35
+
36
+ /** The options that point a command at the same skills folder, for commands the CLI suggests. */
37
+ function folderArgs(where) {
38
+ if (where.scope === 'custom') return ` --dir ${JSON.stringify(where.dir)}`;
39
+ const agent = where.agent && where.agent !== DEFAULT_AGENT ? ` --agent ${where.agent}` : '';
40
+ return `${agent}${where.scope === 'project' ? ' --project' : ''}`;
41
+ }
42
+
43
+ /** A private marker is the user's only when the install record names its folder: any other may have come
44
+ * with a cloned repository, so nothing is fetched, written or sent for it. */
45
+ function trusted(dir, marker) {
46
+ return markerOrigin(marker) === 'public' || isRecordedInstall(dir, marker);
47
+ }
48
+
49
+ function withPrivateOptions(command) {
50
+ return command
51
+ .option('--private', "Use your workspace's private skills (app API, needs your API key) instead of the public library")
52
+ .option('-w, --workspace <id>', 'Workspace for --private (defaults to the one saved with "insightfulpipe use")');
53
+ }
54
+
55
+ function target(opts) {
56
+ try {
57
+ return resolveSkillsDir({ agent: opts.agent, project: Boolean(opts.project), dir: opts.dir });
58
+ } catch (error) {
59
+ fail(error.message);
60
+ }
61
+ }
62
+
63
+ async function loadSource(opts) {
64
+ if (opts.workspace !== undefined && !opts.private) {
65
+ fail('--workspace applies to private skills only.', 'Add --private to use your workspace\'s private skills.');
66
+ }
67
+ try {
68
+ return await openSource(opts);
69
+ } catch (error) {
70
+ fail(error.message, undefined, httpStatus(error));
71
+ }
72
+ }
73
+
74
+ /** What the JSON says about the source: public, or private with its workspace. */
75
+ function sourceFields(source) {
76
+ return source.origin === 'private' ? { source: 'private', workspace_id: source.workspaceId } : { source: 'public' };
77
+ }
78
+
79
+ function short(text, max) {
80
+ const flat = String(text ?? '').replace(/\s+/g, ' ').trim();
81
+ return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
82
+ }
83
+
84
+ function agentLabel(where) {
85
+ return where.agent ? AGENTS[where.agent].label : 'the chosen folder';
86
+ }
87
+
88
+ /** Downloads one skill and checks it; `row` describes the failure when there is no `validated`. */
89
+ async function fetchChecked(source, skill) {
90
+ let bundle;
91
+ try {
92
+ bundle = await source.files(skill);
93
+ } catch (error) {
94
+ return { row: { skill: skillKey(skill), error: error.message, ...httpStatus(error) } };
95
+ }
96
+ if (!bundle) {
97
+ return { row: { skill: skillKey(skill), error: `The ${source.origin} source has no files for this skill.` } };
98
+ }
99
+ try {
100
+ return { validated: source.validate(bundle, skill) };
101
+ } catch (error) {
102
+ return { row: { skill: skillKey(skill), error: error.message } };
103
+ }
104
+ }
105
+
106
+ /** Keeps the install record in step with the folder: a private install is recorded, anything else that
107
+ * now holds the folder is not. */
108
+ function recordOutcome(source, skill, path) {
109
+ try {
110
+ if (source.origin === 'private') recordInstall(path, { key: skill.key, workspaceId: source.workspaceId, slug: skill.slug });
111
+ else forgetInstall(realFolderPath(path));
112
+ return '';
113
+ } catch (error) {
114
+ return `The install could not be recorded (${error.message}), so list and update will not trust this private skill.`;
115
+ }
116
+ }
117
+
118
+ function installChecked(source, skill, where, validated, force) {
119
+ try {
120
+ const { path, warning } = installSkill(where.dir, skill, validated, { force, ...source.installOptions(skill) });
121
+ const notes = [
122
+ warning,
123
+ recordOutcome(source, skill, path),
124
+ source.origin === 'private' && where.scope !== 'global' ? PRIVATE_IN_PROJECT : '',
125
+ ].filter(Boolean);
126
+ return {
127
+ ok: true,
128
+ row: { skill: skillKey(skill), version: validated.version, path, ...(notes.length ? { warning: notes.join(' ') } : {}) },
129
+ };
130
+ } catch (error) {
131
+ return { ok: false, row: { skill: skillKey(skill), error: error.message } };
132
+ }
133
+ }
134
+
135
+ async function installOne(source, skill, where, force) {
136
+ const fetched = await fetchChecked(source, skill);
137
+ return fetched.validated ? installChecked(source, skill, where, fetched.validated, force) : { ok: false, row: fetched.row };
138
+ }
139
+
140
+ /** Installed skills a name points at: the folder name, `category/name`, or a private skill's key. */
141
+ function findInstalled(installed, name) {
142
+ const wanted = String(name).toLowerCase().replace(/^@insightfulpipe\//, '');
143
+ return installed.filter(
144
+ ({ marker }) =>
145
+ marker.slug === wanted ||
146
+ markerLabel(marker) === wanted ||
147
+ (markerOrigin(marker) === 'private' && isPrivateKey(wanted) && marker.key === wanted),
148
+ );
149
+ }
150
+
151
+ export function registerSkillsCommand(program) {
152
+ const skills = program
153
+ .command('skills')
154
+ .description('Find and install InsightfulPipe skills for Claude Code, OpenClaw, Codex, Cursor and Gemini CLI');
155
+
156
+ withPrivateOptions(
157
+ skills
158
+ .command('search')
159
+ .argument('[query...]', 'Words to look for in the skill name, category or description')
160
+ .option('-c, --category <category>', 'Only skills in this category (e.g., google-ads, seo)')
161
+ .option('--limit <n>', 'Show at most this many skills')
162
+ .description('Browse or search the public library, or your private skills with --private'),
163
+ ).action(async (words, opts, command) => {
164
+ if (opts.private && opts.category) fail('--category applies to the public library, not to private skills.');
165
+ const source = await loadSource(opts);
166
+ const terms = (words || []).join(' ').toLowerCase().split(/\s+/).filter(Boolean);
167
+ let found = source.skills.filter((skill) => {
168
+ if (opts.category && skill.category !== opts.category) return false;
169
+ const haystack = [skill.slug, skill.key, skill.displayName, skill.name, skill.description, skill.category, skill.data_source]
170
+ .filter(Boolean)
171
+ .join(' ')
172
+ .toLowerCase();
173
+ return terms.every((term) => haystack.includes(term));
174
+ });
175
+ if (opts.limit) found = found.slice(0, parseIntegerOption('limit', opts.limit));
176
+
177
+ if (wantsJson(command)) {
178
+ printJson({ status: 'success', ...sourceFields(source), count: found.length, skills: found.map(source.summarize) });
179
+ return;
180
+ }
181
+ printTable(
182
+ found.map((skill) => ({ skill: skill.slug, category: skill.category, description: short(skill.description, 70) })),
183
+ [
184
+ { key: 'skill', label: 'Skill' },
185
+ { key: 'category', label: 'Category' },
186
+ { key: 'description', label: 'Description' },
187
+ ],
188
+ );
189
+ });
190
+
191
+ withPrivateOptions(
192
+ skills
193
+ .command('info')
194
+ .argument('<skill>', 'Skill name, category/name, or @insightfulpipe/name (with --private: name or key)')
195
+ .description('Show what a skill does, its files and how to install it'),
196
+ ).action(async (name, opts, command) => {
197
+ const source = await loadSource(opts);
198
+ const found = source.resolve(name);
199
+ if (found.error) fail(found.error);
200
+ const skill = found.skill;
201
+ const info = {
202
+ ...source.summarize(skill),
203
+ files: (skill.files || []).map((file) => ({ path: file.path, size: file.size })),
204
+ };
205
+
206
+ if (wantsJson(command)) {
207
+ printJson({ status: 'success', ...sourceFields(source), skill: info });
208
+ return;
209
+ }
210
+ console.log(`${info.name} (${skillKey(skill)}${info.key ? `, ${info.key}, workspace ${source.workspaceId}` : ''})`);
211
+ console.log(`Version: ${info.version ?? 'unknown'}`);
212
+ if (info.page) console.log(`Page: ${info.page}`);
213
+ console.log(`Install: ${info.install}`);
214
+ console.log(`Files: ${info.files.map((file) => file.path).join(', ') || 'unknown'}`);
215
+ console.log('');
216
+ console.log(info.description);
217
+ });
218
+
219
+ withPrivateOptions(
220
+ withTargetOptions(
221
+ skills
222
+ .command('install')
223
+ .argument('[skills...]', 'One or more skills: name, category/name, or @insightfulpipe/name (with --private: name or key)')
224
+ .option('-c, --category <category>', 'Install every skill in this category')
225
+ .option('-f, --force', 'Replace a skill folder that already exists')
226
+ .description('Download skills into your agent\'s skills folder (Claude Code by default)'),
227
+ ),
228
+ ).action(async (names, opts, command) => {
229
+ if (opts.private && opts.category) fail('--category applies to the public library, not to private skills.');
230
+ if (!names?.length && !opts.category) {
231
+ fail('Name at least one skill, or use --category.', 'Run: insightfulpipe skills search');
232
+ }
233
+ const where = target(opts);
234
+ const source = await loadSource(opts);
235
+
236
+ const chosen = [];
237
+ for (const name of names || []) {
238
+ const found = source.resolve(name);
239
+ if (found.error) fail(found.error);
240
+ chosen.push(found.skill);
241
+ }
242
+ if (opts.category) {
243
+ const inCategory = source.skills.filter((skill) => skill.category === opts.category);
244
+ if (!inCategory.length) fail(`No skills in category "${opts.category}".`, 'Run: insightfulpipe skills search');
245
+ chosen.push(...inCategory);
246
+ }
247
+ const unique = [...new Map(chosen.map((skill) => [skill.key ?? skillKey(skill), skill])).values()];
248
+
249
+ const installed = [];
250
+ const failed = [];
251
+ const folders = new Map();
252
+ for (const skill of unique) {
253
+ const label = skill.key ? `${skillKey(skill)} (${skill.key})` : skillKey(skill);
254
+ if (folders.has(skill.slug)) {
255
+ failed.push({
256
+ skill: skillKey(skill),
257
+ error: `${folders.get(skill.slug)} goes into the same folder, ${skill.slug}. Install one of them, or the other into another folder with --dir.`,
258
+ });
259
+ continue;
260
+ }
261
+ folders.set(skill.slug, label);
262
+ const result = await installOne(source, skill, where, Boolean(opts.force));
263
+ (result.ok ? installed : failed).push(result.row);
264
+ }
265
+
266
+ if (wantsJson(command)) {
267
+ const report = { ...sourceFields(source), agent: where.agent, scope: where.scope, skills_dir: where.dir, installed, failed };
268
+ if (!installed.length) fail('No skill was installed.', undefined, report);
269
+ printJson({
270
+ status: failed.length ? 'partial' : 'success',
271
+ ...report,
272
+ next_step: `Start a new ${agentLabel(where)} session to load the skill. ${MCP_TIP}`,
273
+ });
274
+ } else {
275
+ for (const row of installed) console.log(`Installed ${row.skill} (${row.version}) -> ${row.path}`);
276
+ for (const row of installed) if (row.warning) console.error(`Warning: ${row.warning}`);
277
+ for (const row of failed) console.error(`Failed ${row.skill}: ${row.error}`);
278
+ if (installed.length) console.log(`\nStart a new ${agentLabel(where)} session to load it. ${MCP_TIP}`);
279
+ }
280
+ if (failed.length) process.exitCode = 1;
281
+ });
282
+
283
+ withTargetOptions(
284
+ skills.command('list').description('List the InsightfulPipe skills installed in a skills folder'),
285
+ ).action(async (opts, command) => {
286
+ const where = target(opts);
287
+ const installed = listInstalled(where.dir);
288
+ const sourceFor = sourcesForMarkers();
289
+ let publicReached = null;
290
+
291
+ const rows = [];
292
+ for (const { dir, marker } of installed) {
293
+ const origin = markerOrigin(marker);
294
+ const ours = trusted(dir, marker);
295
+ let latest = null;
296
+ let checked = false;
297
+ let status = {};
298
+ const problems = [];
299
+ if (ours) {
300
+ try {
301
+ latest = (await sourceFor(marker)).find(marker)?.version ?? null;
302
+ checked = true;
303
+ if (origin === 'public') publicReached = true;
304
+ } catch (error) {
305
+ // Offline, the public library still lists what is installed; a private source that refuses is an error.
306
+ if (origin === 'public') publicReached = false;
307
+ else {
308
+ problems.push(`Could not check for updates: ${error.message}`);
309
+ status = httpStatus(error);
310
+ }
311
+ }
312
+ }
313
+ let edited = null;
314
+ try {
315
+ edited = localChanges(dir, marker).edited;
316
+ } catch (error) {
317
+ problems.push(`Could not check for local edits: ${error.message}`);
318
+ }
319
+ rows.push({
320
+ skill: markerLabel(marker),
321
+ origin,
322
+ ...(origin === 'private' ? { trusted: ours } : {}),
323
+ ...(origin === 'private' && ours ? { key: marker.key, workspace_id: marker.workspace_id } : {}),
324
+ version: marker.version,
325
+ latest,
326
+ latest_checked: checked,
327
+ ...(ours ? {} : { note: NOT_YOURS }),
328
+ update_available: Boolean(latest && latest !== marker.version),
329
+ locally_edited: edited,
330
+ path: dir,
331
+ ...(problems.length ? { error: problems.join(' '), ...status } : {}),
332
+ });
333
+ }
334
+
335
+ const unchecked = rows.some((row) => row.error);
336
+ if (wantsJson(command)) {
337
+ printJson({
338
+ status: unchecked ? 'partial' : 'success',
339
+ agent: where.agent,
340
+ scope: where.scope,
341
+ skills_dir: where.dir,
342
+ catalog: publicReached === null ? 'not needed' : publicReached ? 'checked' : 'unreachable',
343
+ skills: rows,
344
+ });
345
+ if (unchecked) process.exitCode = 1;
346
+ return;
347
+ }
348
+ printTable(
349
+ rows.map((row) => ({
350
+ skill: row.skill,
351
+ version: row.version,
352
+ status: row.update_available ? `update: ${row.latest}` : row.latest ? 'up to date' : 'unknown',
353
+ edited: row.locally_edited === null ? 'unknown' : row.locally_edited ? 'yes' : '',
354
+ })),
355
+ [
356
+ { key: 'skill', label: 'Skill' },
357
+ { key: 'version', label: 'Version' },
358
+ { key: 'status', label: 'Status' },
359
+ { key: 'edited', label: 'Edited' },
360
+ ],
361
+ );
362
+ for (const row of rows) {
363
+ if (row.note) console.error(`${row.skill}: ${row.note}`);
364
+ if (row.error) {
365
+ console.error(`${row.skill}: ${row.error}`);
366
+ process.exitCode = 1;
367
+ }
368
+ }
369
+ });
370
+
371
+ withTargetOptions(
372
+ skills
373
+ .command('update')
374
+ .argument('[skills...]', 'Installed skills to update')
375
+ .option('--all', 'Update every InsightfulPipe skill in the folder')
376
+ .option('-f, --force', 'Update even if you edited the installed files (your edits are replaced)')
377
+ .description('Update installed skills to the latest version, keeping your local edits unless --force'),
378
+ ).action(async (names, opts, command) => {
379
+ if (!names?.length && !opts.all) {
380
+ fail('Name the skills to update, or use --all.');
381
+ }
382
+ const where = target(opts);
383
+ const installed = listInstalled(where.dir);
384
+
385
+ const targets = [];
386
+ if (opts.all) {
387
+ targets.push(...installed);
388
+ } else {
389
+ for (const name of names) {
390
+ const matches = findInstalled(installed, name);
391
+ if (matches.length !== 1) {
392
+ fail(matches.length ? `"${name}" matches more than one installed skill.` : `"${name}" is not installed in ${where.dir}.`);
393
+ }
394
+ targets.push(matches[0]);
395
+ }
396
+ }
397
+
398
+ const sourceFor = sourcesForMarkers();
399
+ const result = { updated: [], up_to_date: [], skipped: [], failed: [] };
400
+ for (const { dir, marker } of targets) {
401
+ const key = markerLabel(marker);
402
+ if (!trusted(dir, marker)) {
403
+ result.skipped.push({ skill: key, reason: NOT_YOURS });
404
+ continue;
405
+ }
406
+ let source;
407
+ try {
408
+ source = await sourceFor(marker);
409
+ } catch (error) {
410
+ result.failed.push({ skill: key, error: `Could not check for updates: ${error.message}`, ...httpStatus(error) });
411
+ continue;
412
+ }
413
+ const latest = source.find(marker);
414
+ if (!latest) {
415
+ result.skipped.push({ skill: key, reason: `It is no longer in the ${source.origin === 'private' ? "workspace's private skills" : 'catalogue'}; left as it is.` });
416
+ continue;
417
+ }
418
+ if (source.origin === 'private' && latest.slug !== marker.slug) {
419
+ result.skipped.push({
420
+ skill: key,
421
+ reason: `It was renamed to ${latest.slug}. Install it again with "insightfulpipe skills install ${latest.key} --private --workspace ${marker.workspace_id}${folderArgs(where)}", then remove ${marker.slug}${folderArgs(where)}.`,
422
+ });
423
+ continue;
424
+ }
425
+ if (latest.version && latest.version === marker.version) {
426
+ result.up_to_date.push({ skill: key, version: marker.version });
427
+ continue;
428
+ }
429
+ const fetched = await fetchChecked(source, latest);
430
+ if (!fetched.validated) {
431
+ result.failed.push(fetched.row);
432
+ continue;
433
+ }
434
+ let changes;
435
+ try {
436
+ changes = localChanges(dir, marker);
437
+ } catch (error) {
438
+ result.failed.push({ skill: key, error: `Could not check for local edits: ${error.message}` });
439
+ continue;
440
+ }
441
+ if (changes.edited && !opts.force) {
442
+ result.skipped.push({
443
+ skill: key,
444
+ reason: 'You edited the installed files. Re-run with --force to replace them.',
445
+ changed: changes.changed,
446
+ missing: changes.missing,
447
+ added: changes.added,
448
+ });
449
+ continue;
450
+ }
451
+ const outcome = installChecked(source, latest, where, fetched.validated, true);
452
+ if (outcome.ok) result.updated.push({ ...outcome.row, from: marker.version });
453
+ else result.failed.push(outcome.row);
454
+ }
455
+
456
+ if (wantsJson(command)) {
457
+ if (result.failed.length && !result.updated.length) fail('No skill was updated.', undefined, { skills_dir: where.dir, ...result });
458
+ printJson({ status: result.failed.length ? 'partial' : 'success', skills_dir: where.dir, ...result });
459
+ } else {
460
+ for (const row of result.updated) console.log(`Updated ${row.skill} ${row.from} -> ${row.version}`);
461
+ for (const row of result.updated) if (row.warning) console.error(`Warning: ${row.warning}`);
462
+ for (const row of result.up_to_date) console.log(`Up to date ${row.skill} (${row.version})`);
463
+ for (const row of result.skipped) console.log(`Skipped ${row.skill}: ${row.reason}`);
464
+ for (const row of result.failed) console.error(`Failed ${row.skill}: ${row.error}`);
465
+ if (!targets.length) console.log('No InsightfulPipe skills installed here.');
466
+ }
467
+ if (result.failed.length) process.exitCode = 1;
468
+ });
469
+
470
+ withTargetOptions(
471
+ skills
472
+ .command('remove')
473
+ .argument('<skills...>', 'Installed skills to remove')
474
+ .option('-y, --yes', 'Skip the confirmation prompt')
475
+ .description('Remove installed InsightfulPipe skills (only folders this CLI installed)'),
476
+ ).action(async (names, opts, command) => {
477
+ const where = target(opts);
478
+ const installed = listInstalled(where.dir);
479
+ const targets = names.map((name) => {
480
+ const matches = findInstalled(installed, name);
481
+ if (matches.length !== 1) {
482
+ fail(matches.length ? `"${name}" matches more than one installed skill.` : `"${name}" is not an InsightfulPipe skill installed in ${where.dir}.`);
483
+ }
484
+ return matches[0];
485
+ });
486
+
487
+ if (!opts.yes) {
488
+ if (!process.stdin.isTTY) fail('Removing skills needs confirmation in non-interactive mode. Re-run with --yes.');
489
+ const ok = await confirm(`Remove ${targets.map((t) => t.slug).join(', ')} from ${where.dir}? [y/N] `);
490
+ if (!ok) fail('Nothing removed.');
491
+ }
492
+
493
+ const removed = [];
494
+ for (const { dir, marker } of targets) {
495
+ const realPath = realFolderPath(dir);
496
+ try {
497
+ removeInstalled(dir);
498
+ } catch (error) {
499
+ fail(error.message);
500
+ }
501
+ let warning;
502
+ try {
503
+ forgetInstall(realPath);
504
+ } catch (error) {
505
+ warning = `The install record could not be updated (${error.message}).`;
506
+ }
507
+ removed.push({ skill: markerLabel(marker), path: dir, ...(warning ? { warning } : {}) });
508
+ }
509
+ if (wantsJson(command)) printJson({ status: 'success', removed });
510
+ else for (const row of removed) console.log(`Removed ${row.skill} (${row.path})`);
511
+ });
512
+
513
+ skills
514
+ .command('download')
515
+ .argument('<skill>', 'Skill name, category/name, or @insightfulpipe/name')
516
+ .option('-o, --output <file>', 'Where to save the ZIP (default: <skill>.zip in this folder)')
517
+ .option('-f, --force', 'Overwrite the file if it exists')
518
+ .option('--private', 'Not available yet for private skills')
519
+ .description('Save a public skill as a ZIP, for uploading in Claude.ai or Claude Desktop')
520
+ .action(async (name, opts, command) => {
521
+ if (opts.private) {
522
+ fail(
523
+ 'Private skills cannot be downloaded as a ZIP from the CLI yet.',
524
+ "Use Download on the skill in the app's Skills Library, or install it with: insightfulpipe skills install <skill> --private",
525
+ );
526
+ }
527
+ const source = await loadSource({});
528
+ const found = source.resolve(name);
529
+ if (found.error) fail(found.error);
530
+ const skill = found.skill;
531
+ const output = resolve(opts.output || `${skill.slug}.zip`);
532
+ if (lexists(output) && !opts.force) fail(`${output} already exists. Add --force to overwrite it.`);
533
+
534
+ let zip;
535
+ try {
536
+ zip = await fetchSkillZip(skill.category, skill.slug);
537
+ } catch (error) {
538
+ fail(error.message);
539
+ }
540
+ if (!zip) fail('The catalogue has no ZIP for this skill.');
541
+ const partial = `${output}.${randomBytes(4).toString('hex')}.part`;
542
+ try {
543
+ writeFileSync(partial, zip, { flag: 'wx' });
544
+ renameSync(partial, output);
545
+ } catch (error) {
546
+ rmSync(partial, { force: true });
547
+ fail(`Could not save ${output}: ${error.message}`);
548
+ }
549
+
550
+ const next = 'Upload this ZIP as a custom skill in Claude.ai or Claude Desktop.';
551
+ if (wantsJson(command)) printJson({ status: 'success', skill: skillKey(skill), path: output, bytes: zip.length, next_step: next });
552
+ else console.log(`Saved ${skillKey(skill)} to ${output}\n${next}`);
553
+ });
554
+ }