insightfulpipe 0.4.1 → 0.5.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/CHANGELOG.md +149 -1
- package/README.md +35 -22
- package/package.json +2 -2
- package/src/cli/commands/skills.js +371 -140
- package/src/cli/errors.js +2 -2
- package/src/cli/program.js +2 -0
- package/src/output.js +66 -20
- package/src/skills/agents.js +5 -3
- package/src/skills/folders.js +129 -0
- package/src/skills/installer.js +41 -32
- package/src/skills/keys.js +21 -0
- package/src/skills/moves.js +87 -0
- package/src/skills/names.js +40 -0
- package/src/skills/paths.js +12 -0
- package/src/skills/private.js +33 -46
- package/src/skills/records.js +16 -5
- package/src/skills/sources.js +62 -34
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import { resolve } from 'node:path';
|
|
2
|
+
import { statSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, join, resolve } from 'node:path';
|
|
4
4
|
|
|
5
|
-
import { printJson, printTable, say, wantsJson, warn } from '../../output.js';
|
|
5
|
+
import { clause, printJson, printTable, say, UNPRINTABLE, wantsJson, warn } from '../../output.js';
|
|
6
6
|
import { fail } from '../errors.js';
|
|
7
7
|
import { confirm } from '../input.js';
|
|
8
8
|
import { parseIntegerOption } from '../options.js';
|
|
9
9
|
import { AGENT_NAMES, AGENTS, DEFAULT_AGENT, resolveSkillsDir } from '../../skills/agents.js';
|
|
10
10
|
import { fetchSkillZip, skillKey } from '../../skills/catalog.js';
|
|
11
|
-
import { installSkill,
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
import { installSkill, listInstalled, localChanges, removeInstalled } from '../../skills/installer.js';
|
|
12
|
+
import {
|
|
13
|
+
installedLabel,
|
|
14
|
+
installedMatches,
|
|
15
|
+
keyPair,
|
|
16
|
+
nameForInstalled,
|
|
17
|
+
printsBare,
|
|
18
|
+
quotedCommand,
|
|
19
|
+
refuseInstalled,
|
|
20
|
+
resolveInstalled,
|
|
21
|
+
UNPRINTED,
|
|
22
|
+
} from '../../skills/folders.js';
|
|
23
|
+
import { TYPE_LABEL } from '../../skills/keys.js';
|
|
24
|
+
import { lexists, moveFile, withLeftover } from '../../skills/moves.js';
|
|
25
|
+
import { parseWorkspaceId } from '../../skills/private.js';
|
|
26
|
+
import { forgetInstall, isRecordedInstall, realFolderPath, recordExists, recordInstall } from '../../skills/records.js';
|
|
27
|
+
import { listedOrigin, markerLabel, markerOrigin, markerType, openSource, sourcesForMarkers } from '../../skills/sources.js';
|
|
15
28
|
|
|
16
29
|
const MCP_TIP =
|
|
17
30
|
'Skills read live data through the InsightfulPipe MCP. Connect it once: https://insightfulpipe.com/mcp-servers';
|
|
18
|
-
const
|
|
19
|
-
|
|
31
|
+
const INSTALLED_WORDS = 'a name as list shows it, or the folder path the CLI prints';
|
|
32
|
+
const WORKSPACE_IN_PROJECT =
|
|
33
|
+
'This workspace skill is in a project folder. Keep it out of shared or public repositories (add the folder to .gitignore).';
|
|
20
34
|
|
|
21
35
|
function withTargetOptions(command) {
|
|
22
36
|
return command
|
|
@@ -25,27 +39,91 @@ function withTargetOptions(command) {
|
|
|
25
39
|
.option('--dir <path>', 'Use this skills directory instead');
|
|
26
40
|
}
|
|
27
41
|
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
|
|
42
|
+
/** A folder or a link to one. A path stat cannot follow (a link loop, a folder you may not read) is not, so the
|
|
43
|
+
* save treats it as a file and reports it the way it reports any other. */
|
|
44
|
+
function isFolder(path) {
|
|
45
|
+
try {
|
|
46
|
+
return Boolean(statSync(path, { throwIfNoEntry: false })?.isDirectory());
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Where download saves: `--output` names the file, or a folder that exists (or a link to one) to save
|
|
53
|
+
* `<skill>.zip` in, as `cp` does. */
|
|
54
|
+
function zipPath(output, slug) {
|
|
55
|
+
const path = resolve(output || `${slug}.zip`);
|
|
56
|
+
return output && isFolder(path) ? join(path, `${slug}.zip`) : path;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Whether a command was pointed at a workspace, with `--workspace` or 0.4's `--private`. */
|
|
60
|
+
function wantsWorkspace(opts) {
|
|
61
|
+
return Boolean(opts.private) || opts.workspace !== undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** `--workspace` and `--private` on list, update and remove keep only workspace skills, so the flag that
|
|
65
|
+
* installed a skill also works on everything done to it afterwards. */
|
|
66
|
+
function withWorkspaceFilter(command) {
|
|
67
|
+
return command
|
|
68
|
+
.option('-w, --workspace <id>', 'Only skills installed from this workspace')
|
|
69
|
+
.option('--private', 'Only skills installed from a workspace (Public and Custom)');
|
|
70
|
+
}
|
|
31
71
|
|
|
72
|
+
/** The `--workspace` filter as a number, or undefined without one. */
|
|
73
|
+
function workspaceFilter(opts) {
|
|
74
|
+
if (opts.workspace === undefined) return undefined;
|
|
75
|
+
try {
|
|
76
|
+
return parseWorkspaceId(opts.workspace, '--workspace');
|
|
77
|
+
} catch (error) {
|
|
78
|
+
fail(error.message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A planted marker may claim any workspace: the filter only selects rows, and nothing it claims is trusted. */
|
|
32
83
|
function inScope(installed, opts) {
|
|
33
|
-
|
|
84
|
+
const id = workspaceFilter(opts);
|
|
85
|
+
if (!opts.private && id === undefined) return installed;
|
|
86
|
+
return installed.filter(({ marker }) => markerOrigin(marker) === 'private' && (id === undefined || marker.workspace_id === id));
|
|
34
87
|
}
|
|
35
88
|
|
|
36
|
-
|
|
89
|
+
function notInScope(name, where, opts) {
|
|
90
|
+
const id = workspaceFilter(opts);
|
|
91
|
+
return id === undefined
|
|
92
|
+
? `"${name}" is not a workspace skill installed in ${where.dir}.`
|
|
93
|
+
: `"${name}" is not a skill from workspace ${id} installed in ${where.dir}.`;
|
|
94
|
+
}
|
|
37
95
|
|
|
38
96
|
const NOT_YOURS =
|
|
39
|
-
'Not installed by you here, so it is never checked or updated. To use it, install it again with --
|
|
97
|
+
'Not installed by you here, so it is never checked or updated. To use it, install it again with --workspace <id> --force.';
|
|
40
98
|
|
|
41
99
|
/** The HTTP status of a failed app request, for the JSON, when the error carries one. */
|
|
42
100
|
function httpStatus(error) {
|
|
43
101
|
return error?.httpStatus ? { http_status: error.httpStatus } : {};
|
|
44
102
|
}
|
|
45
103
|
|
|
46
|
-
/**
|
|
104
|
+
/** What no quoting keeps as typed in every Windows shell: `%` expands inside cmd.exe's double quotes, `& | < > ^`
|
|
105
|
+
* reach cmd.exe bare when PowerShell runs npm's .cmd shim, and Git Bash reads `\\` inside double quotes as `\`. */
|
|
106
|
+
const WINDOWS_NEVER = /["%&|<>^]|\\\\/;
|
|
107
|
+
/** What Windows double quotes do not keep: PowerShell's `$`, backtick and curly double quotes, and Git Bash's `!`. */
|
|
108
|
+
const WINDOWS_NOT_DOUBLE = /[$`!\u201c-\u201e]/;
|
|
109
|
+
/** What Windows single quotes do not keep: PowerShell's quote characters, and spaces, which split words in cmd.exe. */
|
|
110
|
+
const WINDOWS_NOT_SINGLE = /['\u2018-\u201b\s]/;
|
|
111
|
+
|
|
112
|
+
/** A path as one shell word that pastes back exactly, or null when the output shows a character in it as an escape,
|
|
113
|
+
* or on Windows when no quoting keeps it in cmd.exe, PowerShell and Git Bash (cmd.exe keeps single quotes). */
|
|
114
|
+
export function shellWord(text, platform = process.platform) {
|
|
115
|
+
if (text.search(UNPRINTABLE) !== -1) return null;
|
|
116
|
+
if (platform !== 'win32') return /^[\w./:-]+$/.test(text) ? text : `'${text.replaceAll("'", "'\\''")}'`;
|
|
117
|
+
if (/^[\w./:-]+$/.test(text)) return text;
|
|
118
|
+
if (WINDOWS_NEVER.test(text)) return null;
|
|
119
|
+
if (!WINDOWS_NOT_DOUBLE.test(text) && !text.endsWith('\\')) return `"${text}"`;
|
|
120
|
+
return /^[A-Za-z]:/.test(text) && !WINDOWS_NOT_SINGLE.test(text) ? `'${text}'` : null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The options that point a command at the same skills folder, for commands the CLI suggests; null when the
|
|
124
|
+
* folder's path cannot be printed as one word. */
|
|
47
125
|
function folderArgs(where) {
|
|
48
|
-
if (where.scope === 'custom') return ` --dir ${
|
|
126
|
+
if (where.scope === 'custom') return shellWord(where.dir) === null ? null : ` --dir ${shellWord(where.dir)}`;
|
|
49
127
|
const agent = where.agent && where.agent !== DEFAULT_AGENT ? ` --agent ${where.agent}` : '';
|
|
50
128
|
return `${agent}${where.scope === 'project' ? ' --project' : ''}`;
|
|
51
129
|
}
|
|
@@ -56,10 +134,24 @@ function trusted(dir, marker) {
|
|
|
56
134
|
return markerOrigin(marker) === 'public' || isRecordedInstall(dir, marker);
|
|
57
135
|
}
|
|
58
136
|
|
|
59
|
-
|
|
137
|
+
/** The skills installed in a folder, each marked with whether the install record names it, read once before
|
|
138
|
+
* anything changes. */
|
|
139
|
+
function installedHere(dir) {
|
|
140
|
+
return listInstalled(dir).map((entry) => ({ ...entry, ours: trusted(entry.dir, entry.marker) }));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The fields `list` gives an installed folder in JSON: label and type, and the key only when the record names it. */
|
|
144
|
+
function folderRow({ marker, ours }) {
|
|
145
|
+
const type = markerType(marker);
|
|
146
|
+
const fields = { skill: markerLabel(marker), ...(type ? { type } : {}) };
|
|
147
|
+
if (markerOrigin(marker) === 'public') return fields;
|
|
148
|
+
return ours ? { ...fields, trusted: true, key: marker.key } : { ...fields, trusted: false };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function withWorkspaceOptions(command) {
|
|
60
152
|
return command
|
|
61
|
-
.option('--
|
|
62
|
-
.option('
|
|
153
|
+
.option('-w, --workspace <id>', 'Use this workspace\'s skills, Public and Custom (needs "insightfulpipe auth")')
|
|
154
|
+
.option('--private', 'Same as --workspace; without it, uses the workspace saved with "insightfulpipe use"');
|
|
63
155
|
}
|
|
64
156
|
|
|
65
157
|
function target(opts) {
|
|
@@ -71,9 +163,6 @@ function target(opts) {
|
|
|
71
163
|
}
|
|
72
164
|
|
|
73
165
|
async function loadSource(opts) {
|
|
74
|
-
if (opts.workspace !== undefined && !opts.private) {
|
|
75
|
-
fail('--workspace applies to private skills only.', 'Add --private to use your workspace\'s private skills.');
|
|
76
|
-
}
|
|
77
166
|
try {
|
|
78
167
|
return await openSource(opts);
|
|
79
168
|
} catch (error) {
|
|
@@ -81,9 +170,19 @@ async function loadSource(opts) {
|
|
|
81
170
|
}
|
|
82
171
|
}
|
|
83
172
|
|
|
84
|
-
/** What the JSON says about the source: public, or private with its
|
|
173
|
+
/** What the JSON says about the source: public, or a workspace (`private` under 0.4's flag) with its id. */
|
|
85
174
|
function sourceFields(source) {
|
|
86
|
-
return source.origin === 'private' ? { source:
|
|
175
|
+
return source.origin === 'private' ? { source: source.sourceName, workspace_id: source.workspaceId } : { source: 'public' };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** A per-skill row; workspace skills also carry their key and type. */
|
|
179
|
+
function skillRow(skill) {
|
|
180
|
+
return { skill: skillKey(skill), ...(skill.key ? { key: skill.key, type: skill.type } : {}) };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** A row's name with its key beside it: in install and info, `private/<x>` reads as the key x. */
|
|
184
|
+
function withKey(row) {
|
|
185
|
+
return row.key ? `${row.skill} (${row.key})` : row.skill;
|
|
87
186
|
}
|
|
88
187
|
|
|
89
188
|
function short(text, max) {
|
|
@@ -101,19 +200,34 @@ async function fetchChecked(source, skill) {
|
|
|
101
200
|
try {
|
|
102
201
|
bundle = await source.files(skill);
|
|
103
202
|
} catch (error) {
|
|
104
|
-
return { row: {
|
|
203
|
+
return { row: { ...skillRow(skill), error: error.message, ...httpStatus(error) } };
|
|
105
204
|
}
|
|
106
205
|
if (!bundle) {
|
|
107
|
-
return { row: {
|
|
206
|
+
return { row: { ...skillRow(skill), error: source.noFiles } };
|
|
108
207
|
}
|
|
109
208
|
try {
|
|
110
209
|
return { validated: source.validate(bundle, skill) };
|
|
111
210
|
} catch (error) {
|
|
112
|
-
return { row: {
|
|
211
|
+
return { row: { ...skillRow(skill), error: error.message } };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** What a record left unwritten or unremoved means: list and update always trust an insightfulpipe.com skill, and a
|
|
216
|
+
* workspace skill only while a record names it, as the earlier one still may. */
|
|
217
|
+
function recordFailure(source, skill, path, reason) {
|
|
218
|
+
if (source.origin !== 'private' && recordExists(realFolderPath(path))) {
|
|
219
|
+
return `The earlier workspace record for this folder could not be removed (${reason}); list and update do not need it for this insightfulpipe.com skill.`;
|
|
220
|
+
}
|
|
221
|
+
if (source.origin !== 'private') {
|
|
222
|
+
return `An earlier workspace record for this folder, if there is one, could not be removed (${reason}); list and update do not need one for this insightfulpipe.com skill.`;
|
|
223
|
+
}
|
|
224
|
+
if (isRecordedInstall(path, { key: skill.key, workspace_id: source.workspaceId, slug: skill.slug })) {
|
|
225
|
+
return `The install could not be recorded again (${reason}); the earlier record of this skill is kept, so list and update still trust it.`;
|
|
113
226
|
}
|
|
227
|
+
return `The install could not be recorded (${reason}), so list and update will not trust this workspace skill.`;
|
|
114
228
|
}
|
|
115
229
|
|
|
116
|
-
/** Keeps the install record in step with the folder: a
|
|
230
|
+
/** Keeps the install record in step with the folder: a workspace install is recorded, anything else that
|
|
117
231
|
* now holds the folder is not. */
|
|
118
232
|
function recordOutcome(source, skill, path) {
|
|
119
233
|
try {
|
|
@@ -121,24 +235,25 @@ function recordOutcome(source, skill, path) {
|
|
|
121
235
|
else forgetInstall(realFolderPath(path));
|
|
122
236
|
return '';
|
|
123
237
|
} catch (error) {
|
|
124
|
-
return
|
|
238
|
+
return recordFailure(source, skill, path, clause(error.message));
|
|
125
239
|
}
|
|
126
240
|
}
|
|
127
241
|
|
|
128
242
|
function installChecked(source, skill, where, validated, force) {
|
|
129
243
|
try {
|
|
130
|
-
const
|
|
244
|
+
const updateHint = force ? null : updateHintFor(where, skill.slug);
|
|
245
|
+
const { path, warning } = installSkill(where.dir, skill, validated, { force, ...source.installOptions(skill), updateHint });
|
|
131
246
|
const notes = [
|
|
132
247
|
warning,
|
|
133
248
|
recordOutcome(source, skill, path),
|
|
134
|
-
source.origin === 'private' && where.scope !== 'global' ?
|
|
249
|
+
source.origin === 'private' && where.scope !== 'global' ? WORKSPACE_IN_PROJECT : '',
|
|
135
250
|
].filter(Boolean);
|
|
136
251
|
return {
|
|
137
252
|
ok: true,
|
|
138
|
-
row: {
|
|
253
|
+
row: { ...skillRow(skill), version: validated.version, path, ...(notes.length ? { warning: notes.join(' ') } : {}) },
|
|
139
254
|
};
|
|
140
255
|
} catch (error) {
|
|
141
|
-
return { ok: false, row: {
|
|
256
|
+
return { ok: false, row: { ...skillRow(skill), error: error.message } };
|
|
142
257
|
}
|
|
143
258
|
}
|
|
144
259
|
|
|
@@ -147,15 +262,110 @@ async function installOne(source, skill, where, force) {
|
|
|
147
262
|
return fetched.validated ? installChecked(source, skill, where, fetched.validated, force) : { ok: false, row: fetched.row };
|
|
148
263
|
}
|
|
149
264
|
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
);
|
|
265
|
+
/** How `update` or `remove` reads its words and prints a command for one folder (null, said in words instead, when
|
|
266
|
+
* a shell could misread its path). `update` never reaches an untrusted folder by path; a `--force` is kept. */
|
|
267
|
+
function folderCommand(verb, where, opts = {}) {
|
|
268
|
+
const force = verb === 'update' && opts.force ? ' --force' : '';
|
|
269
|
+
const words = (word) => {
|
|
270
|
+
const [quoted, folder] = [shellWord(word), folderArgs(where)];
|
|
271
|
+
return quoted === null || folder === null ? null : `${verb} ${quoted}${folder}${force}`;
|
|
272
|
+
};
|
|
273
|
+
const run = (word) => (words(word) === null ? null : `insightfulpipe skills ${words(word)}`);
|
|
274
|
+
const same = force ? ' and the same options' : folderArgs(where) === '' ? '' : ' and the same folder options';
|
|
275
|
+
const unprinted = (word, entry) => `${verb} with ${word === entry.dir ? 'that path' : word}${same}`;
|
|
276
|
+
return { forUpdate: verb === 'update', words, run, unprinted };
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** A removal the rename message names in words when its command cannot be printed; null when it can. */
|
|
280
|
+
function unprintedRemoval(where, remove, word, old) {
|
|
281
|
+
if (remove.words(word) !== null) return null;
|
|
282
|
+
return `remove ${word === old.dir ? `the folder ${old.dir}` : word}${folderArgs(where) === '' ? '' : ' with the same folder options'}`;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** The update to run instead of reinstalling the folder `slug`, by a name that reaches it alone (at worst its path),
|
|
286
|
+
* or --force; null when `update` cannot see that folder. */
|
|
287
|
+
function updateHintFor(where, slug) {
|
|
288
|
+
const installed = installedHere(where.dir);
|
|
289
|
+
const entry = installed.find((one) => one.slug === slug);
|
|
290
|
+
const how = folderCommand('update', where);
|
|
291
|
+
const name = entry && nameForInstalled(entry, installed, how);
|
|
292
|
+
if (!name) return null;
|
|
293
|
+
const command = how.run(name);
|
|
294
|
+
if (command === null) return `Run ${how.unprinted(name, entry)} (${UNPRINTED}), or add --force to reinstall.`;
|
|
295
|
+
return printsBare(command) ? `Add --force to reinstall, or run: ${command}` : `Run ${quotedCommand(command)}, or add --force to reinstall.`;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** What a rename message says about the old folder's local edits, which a reinstall does not carry over. */
|
|
299
|
+
function editsNote(entry) {
|
|
300
|
+
try {
|
|
301
|
+
return localChanges(entry.dir, entry.marker).edited ? 'The old folder has local edits.' : '';
|
|
302
|
+
} catch (error) {
|
|
303
|
+
return `The old folder could not be checked for local edits (${error.message}).`;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Gives the reinstall only: the next update prints the removal once it finds the new copy installed by you
|
|
308
|
+
* (renamedOntoTaken), so no line can remove the old copy while the reinstall fails. */
|
|
309
|
+
function renameReason(where, entry, slug, installBase) {
|
|
310
|
+
const now = installedHere(where.dir);
|
|
311
|
+
const old = now.find((one) => one.dir === entry.dir) ?? entry;
|
|
312
|
+
if (lexists(resolve(where.dir, slug))) return renamedOntoTaken(where, old, slug, installBase, now);
|
|
313
|
+
const folder = folderArgs(where);
|
|
314
|
+
const edits = editsNote(old);
|
|
315
|
+
const intro = `It was renamed to ${slug}.${edits ? ` ${edits}` : ''}`;
|
|
316
|
+
const again = 'run this update again to remove the old folder';
|
|
317
|
+
if (folder === null) return `${intro} Install it again with ${quotedCommand(installBase)} and the same folder options (${UNPRINTED}), then ${again}.`;
|
|
318
|
+
const install = `${installBase}${folder}`;
|
|
319
|
+
if (printsBare(install)) return `${intro} Install it again: ${install}\nThen ${again}.`;
|
|
320
|
+
return `${intro} Install it again with ${quotedCommand(install)}, then ${again}.`;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** The rename message when a folder already has the new name: either the user reinstalled it there, so only the
|
|
324
|
+
* old folder goes, or the name is taken and the old copy must stay, since a reinstall here would be refused. */
|
|
325
|
+
function renamedOntoTaken(where, old, slug, installBase, now) {
|
|
326
|
+
const holder = now.find((one) => one.slug === slug);
|
|
327
|
+
const same = holder?.ours && holder.marker.key === old.marker.key && holder.marker.workspace_id === old.marker.workspace_id;
|
|
328
|
+
if (same) {
|
|
329
|
+
const remove = folderCommand('remove', where);
|
|
330
|
+
const word = nameForInstalled(old, now, remove) ?? old.dir;
|
|
331
|
+
const unprinted = unprintedRemoval(where, remove, word, old);
|
|
332
|
+
const edits = editsNote(old);
|
|
333
|
+
const removal = unprinted === null ? remove.words(word) : `${unprinted} (${UNPRINTED})`;
|
|
334
|
+
const command = `insightfulpipe skills ${removal}`;
|
|
335
|
+
if (unprinted === null && printsBare(command)) return `It was renamed to ${slug}, which is already installed here.${edits ? ` ${edits}` : ''} Remove the old folder: ${command}`;
|
|
336
|
+
return `It was renamed to ${slug}, which is already installed here${edits ? `. ${edits} Then` : ';'} ${removal}.`;
|
|
337
|
+
}
|
|
338
|
+
const what = holder ? installedLabel(holder, { workspace: old.marker.workspace_id }) : 'files this CLI did not install';
|
|
339
|
+
return `It was renamed to ${slug}, but the folder ${slug} here holds ${what}, so it is left as it is. To install it in another folder: ${quotedCommand(`${installBase} --dir <folder>`)}.`;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** The one installed skill a name reaches, as `how` (from folderCommand) reads it, or a refusal that names every
|
|
343
|
+
* folder it points at. */
|
|
344
|
+
function oneInstalled(installed, name, notFound, how) {
|
|
345
|
+
const entry = resolveInstalled(installed, name, how);
|
|
346
|
+
if (entry) return entry;
|
|
347
|
+
const matches = installedMatches(installed, name);
|
|
348
|
+
fail(matches.length ? refuseInstalled(installed, name, matches, how) : notFound);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** The folder `update` takes for each word. A key held only by a renamed old copy and the new copy reinstalled at the
|
|
352
|
+
* renamed slug reaches the old copy, whose update prints the removal; any other match refuses as oneInstalled does. */
|
|
353
|
+
async function updateTargets(installed, names, notFound, how, sourceFor) {
|
|
354
|
+
const targets = [];
|
|
355
|
+
for (const name of names) {
|
|
356
|
+
const pair = resolveInstalled(installed, name, how) ? null : keyPair(installed, name);
|
|
357
|
+
targets.push((pair && (await renamedOldCopy(pair, sourceFor))) ?? oneInstalled(installed, name, notFound(name), how));
|
|
358
|
+
}
|
|
359
|
+
return [...new Set(targets)];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** The old copy of a key pair when its source names the other folder's slug as the skill's new name; null otherwise,
|
|
363
|
+
* and when the source cannot be read, so the word is refused as before. */
|
|
364
|
+
async function renamedOldCopy(pair, sourceFor) {
|
|
365
|
+
const latest = await sourceFor(pair[0].marker).then((source) => source.find(pair[0].marker), () => null);
|
|
366
|
+
const fresh = pair.find((one) => one.slug === latest?.slug);
|
|
367
|
+
const old = pair.find((one) => one !== fresh);
|
|
368
|
+
return fresh && old.marker.slug !== latest.slug ? old : null;
|
|
159
369
|
}
|
|
160
370
|
|
|
161
371
|
export function registerSkillsCommand(program) {
|
|
@@ -163,20 +373,20 @@ export function registerSkillsCommand(program) {
|
|
|
163
373
|
.command('skills')
|
|
164
374
|
.description('Find and install InsightfulPipe skills for Claude Code, OpenClaw, Codex, Cursor and Gemini CLI');
|
|
165
375
|
|
|
166
|
-
|
|
376
|
+
withWorkspaceOptions(
|
|
167
377
|
skills
|
|
168
378
|
.command('search')
|
|
169
379
|
.argument('[query...]', 'Words to look for in the skill name, category or description')
|
|
170
380
|
.option('-c, --category <category>', 'Only skills in this category (e.g., google-ads, seo)')
|
|
171
381
|
.option('--limit <n>', 'Show at most this many skills')
|
|
172
|
-
.description(
|
|
382
|
+
.description("Browse or search insightfulpipe.com skills, or your workspace's skills with --workspace <id>"),
|
|
173
383
|
).action(async (words, opts, command) => {
|
|
174
|
-
if (opts
|
|
384
|
+
if (wantsWorkspace(opts) && opts.category) fail('--category applies to insightfulpipe.com skills, not to workspace skills.');
|
|
175
385
|
const source = await loadSource(opts);
|
|
176
386
|
const terms = (words || []).join(' ').toLowerCase().split(/\s+/).filter(Boolean);
|
|
177
387
|
let found = source.skills.filter((skill) => {
|
|
178
388
|
if (opts.category && skill.category !== opts.category) return false;
|
|
179
|
-
const haystack = [skill.slug, skill.key, skill.displayName, skill.name, skill.description, skill.category, skill.data_source]
|
|
389
|
+
const haystack = [skill.slug, skill.key, skill.type, skill.displayName, skill.name, skill.description, skill.category, skill.data_source]
|
|
180
390
|
.filter(Boolean)
|
|
181
391
|
.join(' ')
|
|
182
392
|
.toLowerCase();
|
|
@@ -188,6 +398,18 @@ export function registerSkillsCommand(program) {
|
|
|
188
398
|
printJson({ status: 'success', ...sourceFields(source), count: found.length, skills: found.map(source.summarize) });
|
|
189
399
|
return;
|
|
190
400
|
}
|
|
401
|
+
if (source.origin === 'private') {
|
|
402
|
+
printTable(
|
|
403
|
+
found.map((skill) => ({ skill: skill.slug, type: TYPE_LABEL[skill.type], key: skill.key, description: short(skill.description, 70) })),
|
|
404
|
+
[
|
|
405
|
+
{ key: 'skill', label: 'Skill' },
|
|
406
|
+
{ key: 'type', label: 'Type' },
|
|
407
|
+
{ key: 'key', label: 'Key' },
|
|
408
|
+
{ key: 'description', label: 'Description' },
|
|
409
|
+
],
|
|
410
|
+
);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
191
413
|
printTable(
|
|
192
414
|
found.map((skill) => ({ skill: skill.slug, category: skill.category, description: short(skill.description, 70) })),
|
|
193
415
|
[
|
|
@@ -198,10 +420,10 @@ export function registerSkillsCommand(program) {
|
|
|
198
420
|
);
|
|
199
421
|
});
|
|
200
422
|
|
|
201
|
-
|
|
423
|
+
withWorkspaceOptions(
|
|
202
424
|
skills
|
|
203
425
|
.command('info')
|
|
204
|
-
.argument('<skill>', 'Skill name, category/name, or @insightfulpipe/name (with --
|
|
426
|
+
.argument('<skill>', 'Skill name, category/name, or @insightfulpipe/name (with --workspace: name or key, such as public-12)')
|
|
205
427
|
.description('Show what a skill does, its files and how to install it'),
|
|
206
428
|
).action(async (name, opts, command) => {
|
|
207
429
|
const source = await loadSource(opts);
|
|
@@ -217,7 +439,8 @@ export function registerSkillsCommand(program) {
|
|
|
217
439
|
printJson({ status: 'success', ...sourceFields(source), skill: info });
|
|
218
440
|
return;
|
|
219
441
|
}
|
|
220
|
-
say(`${info.name}
|
|
442
|
+
say(info.key ? `${info.name}: ${withKey(skillRow(skill))}, workspace ${source.workspaceId}` : `${info.name} (${skillKey(skill)})`);
|
|
443
|
+
if (info.type) say(`Type: ${TYPE_LABEL[info.type]}`);
|
|
221
444
|
say(`Version: ${info.version ?? 'unknown'}`);
|
|
222
445
|
if (info.page) say(`Page: ${info.page}`);
|
|
223
446
|
say(`Install: ${info.install}`);
|
|
@@ -226,17 +449,17 @@ export function registerSkillsCommand(program) {
|
|
|
226
449
|
say(info.description);
|
|
227
450
|
});
|
|
228
451
|
|
|
229
|
-
|
|
452
|
+
withWorkspaceOptions(
|
|
230
453
|
withTargetOptions(
|
|
231
454
|
skills
|
|
232
455
|
.command('install')
|
|
233
|
-
.argument('[skills...]', 'One or more skills: name, category/name, or @insightfulpipe/name (with --
|
|
456
|
+
.argument('[skills...]', 'One or more skills: name, category/name, or @insightfulpipe/name (with --workspace: name or key, such as public-12)')
|
|
234
457
|
.option('-c, --category <category>', 'Install every skill in this category')
|
|
235
458
|
.option('-f, --force', 'Replace a skill folder that already exists')
|
|
236
459
|
.description('Download skills into your agent\'s skills folder (Claude Code by default)'),
|
|
237
460
|
),
|
|
238
461
|
).action(async (names, opts, command) => {
|
|
239
|
-
if (opts
|
|
462
|
+
if (wantsWorkspace(opts) && opts.category) fail('--category applies to insightfulpipe.com skills, not to workspace skills.');
|
|
240
463
|
if (!names?.length && !opts.category) {
|
|
241
464
|
fail('Name at least one skill, or use --category.', 'Run: insightfulpipe skills search');
|
|
242
465
|
}
|
|
@@ -263,7 +486,7 @@ export function registerSkillsCommand(program) {
|
|
|
263
486
|
const label = skill.key ? `${skillKey(skill)} (${skill.key})` : skillKey(skill);
|
|
264
487
|
if (folders.has(skill.slug)) {
|
|
265
488
|
failed.push({
|
|
266
|
-
|
|
489
|
+
...skillRow(skill),
|
|
267
490
|
error: `${folders.get(skill.slug)} goes into the same folder, ${skill.slug}. Install one of them, or the other into another folder with --dir.`,
|
|
268
491
|
});
|
|
269
492
|
continue;
|
|
@@ -282,16 +505,16 @@ export function registerSkillsCommand(program) {
|
|
|
282
505
|
next_step: `Start a new ${agentLabel(where)} session to load the skill. ${MCP_TIP}`,
|
|
283
506
|
});
|
|
284
507
|
} else {
|
|
285
|
-
for (const row of installed) say(`Installed ${row
|
|
508
|
+
for (const row of installed) say(`Installed ${withKey(row)} (${row.version}) -> ${row.path}`);
|
|
286
509
|
for (const row of installed) if (row.warning) warn(`Warning: ${row.warning}`);
|
|
287
|
-
for (const row of failed) warn(`Failed ${row
|
|
510
|
+
for (const row of failed) warn(`Failed ${withKey(row)}: ${row.error}`);
|
|
288
511
|
if (installed.length) say(`\nStart a new ${agentLabel(where)} session to load it. ${MCP_TIP}`);
|
|
289
512
|
}
|
|
290
513
|
if (failed.length) process.exitCode = 1;
|
|
291
514
|
});
|
|
292
515
|
|
|
293
516
|
withTargetOptions(
|
|
294
|
-
skills.command('list')
|
|
517
|
+
withWorkspaceFilter(skills.command('list')).description('List the InsightfulPipe skills installed in a skills folder'),
|
|
295
518
|
).action(async (opts, command) => {
|
|
296
519
|
const where = target(opts);
|
|
297
520
|
const installed = inScope(listInstalled(where.dir), opts);
|
|
@@ -303,12 +526,15 @@ export function registerSkillsCommand(program) {
|
|
|
303
526
|
const origin = markerOrigin(marker);
|
|
304
527
|
const ours = trusted(dir, marker);
|
|
305
528
|
let latest = null;
|
|
529
|
+
let renamed = null;
|
|
306
530
|
let checked = false;
|
|
307
531
|
let status = {};
|
|
308
532
|
const problems = [];
|
|
309
533
|
if (ours) {
|
|
310
534
|
try {
|
|
311
|
-
|
|
535
|
+
const found = (await sourceFor(marker)).find(marker);
|
|
536
|
+
latest = found?.version ?? null;
|
|
537
|
+
if (origin === 'private' && found && found.slug !== marker.slug) renamed = found.slug;
|
|
312
538
|
checked = true;
|
|
313
539
|
if (origin === 'public') publicReached = true;
|
|
314
540
|
} catch (error) {
|
|
@@ -326,13 +552,16 @@ export function registerSkillsCommand(program) {
|
|
|
326
552
|
} catch (error) {
|
|
327
553
|
problems.push(`Could not check for local edits: ${error.message}`);
|
|
328
554
|
}
|
|
555
|
+
const type = markerType(marker);
|
|
329
556
|
rows.push({
|
|
330
557
|
skill: markerLabel(marker),
|
|
331
|
-
origin,
|
|
558
|
+
origin: listedOrigin(marker),
|
|
559
|
+
...(type ? { type } : {}),
|
|
332
560
|
...(origin === 'private' ? { trusted: ours } : {}),
|
|
333
561
|
...(origin === 'private' && ours ? { key: marker.key, workspace_id: marker.workspace_id } : {}),
|
|
334
562
|
version: marker.version,
|
|
335
563
|
latest,
|
|
564
|
+
...(renamed ? { renamed_to: renamed } : {}),
|
|
336
565
|
latest_checked: checked,
|
|
337
566
|
...(ours ? {} : { note: NOT_YOURS }),
|
|
338
567
|
update_available: Boolean(latest && latest !== marker.version),
|
|
@@ -357,13 +586,17 @@ export function registerSkillsCommand(program) {
|
|
|
357
586
|
}
|
|
358
587
|
printTable(
|
|
359
588
|
rows.map((row) => ({
|
|
360
|
-
skill: row
|
|
589
|
+
skill: withKey(row),
|
|
590
|
+
type: row.origin === 'public' ? 'insightfulpipe.com' : (TYPE_LABEL[row.type] ?? ''),
|
|
361
591
|
version: row.version,
|
|
362
|
-
status: row.
|
|
592
|
+
status: row.renamed_to
|
|
593
|
+
? `renamed to ${row.renamed_to}`
|
|
594
|
+
: row.update_available ? `update: ${row.latest}` : row.latest ? 'up to date' : 'unknown',
|
|
363
595
|
edited: row.locally_edited === null ? 'unknown' : row.locally_edited ? 'yes' : '',
|
|
364
596
|
})),
|
|
365
597
|
[
|
|
366
598
|
{ key: 'skill', label: 'Skill' },
|
|
599
|
+
{ key: 'type', label: 'Type' },
|
|
367
600
|
{ key: 'version', label: 'Version' },
|
|
368
601
|
{ key: 'status', label: 'Status' },
|
|
369
602
|
{ key: 'edited', label: 'Edited' },
|
|
@@ -379,80 +612,69 @@ export function registerSkillsCommand(program) {
|
|
|
379
612
|
});
|
|
380
613
|
|
|
381
614
|
withTargetOptions(
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
615
|
+
withWorkspaceFilter(
|
|
616
|
+
skills
|
|
617
|
+
.command('update')
|
|
618
|
+
.argument('[skills...]', `Installed skills to update: ${INSTALLED_WORDS}`)
|
|
619
|
+
.option('--all', 'Update every InsightfulPipe skill in the folder')
|
|
620
|
+
.option('-f, --force', 'Update even if you edited the installed files (your edits are replaced)'),
|
|
621
|
+
).description('Update installed skills to the latest version, keeping your local edits unless --force'),
|
|
389
622
|
).action(async (names, opts, command) => {
|
|
390
623
|
if (!names?.length && !opts.all) {
|
|
391
624
|
fail('Name the skills to update, or use --all.');
|
|
392
625
|
}
|
|
393
626
|
const where = target(opts);
|
|
394
|
-
const installed = inScope(
|
|
395
|
-
|
|
396
|
-
const
|
|
397
|
-
if (opts.all) {
|
|
398
|
-
targets.push(...installed);
|
|
399
|
-
} else {
|
|
400
|
-
for (const name of names) {
|
|
401
|
-
const matches = findInstalled(installed, name);
|
|
402
|
-
if (matches.length !== 1) {
|
|
403
|
-
if (matches.length) fail(`"${name}" matches more than one installed skill.`);
|
|
404
|
-
fail(opts.private ? notPrivate(name, where) : `"${name}" is not installed in ${where.dir}.`);
|
|
405
|
-
}
|
|
406
|
-
targets.push(matches[0]);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
627
|
+
const installed = inScope(installedHere(where.dir), opts);
|
|
628
|
+
const notFound = (name) => (wantsWorkspace(opts) ? notInScope(name, where, opts) : `"${name}" is not installed in ${where.dir}.`);
|
|
629
|
+
const how = folderCommand('update', where, opts);
|
|
410
630
|
const sourceFor = sourcesForMarkers();
|
|
631
|
+
const targets = opts.all ? installed : await updateTargets(installed, names, notFound, how, sourceFor);
|
|
632
|
+
const labels = new Map(targets.map((entry) => [markerLabel(entry.marker), installedLabel(entry)]));
|
|
633
|
+
|
|
411
634
|
const result = { updated: [], up_to_date: [], skipped: [], failed: [] };
|
|
412
|
-
for (const
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
635
|
+
for (const entry of targets) {
|
|
636
|
+
const { dir, marker } = entry;
|
|
637
|
+
const base = folderRow(entry);
|
|
638
|
+
if (!entry.ours) {
|
|
639
|
+
result.skipped.push({ ...base, reason: NOT_YOURS });
|
|
416
640
|
continue;
|
|
417
641
|
}
|
|
418
642
|
let source;
|
|
419
643
|
try {
|
|
420
644
|
source = await sourceFor(marker);
|
|
421
645
|
} catch (error) {
|
|
422
|
-
result.failed.push({
|
|
646
|
+
result.failed.push({ ...base, error: `Could not check for updates: ${error.message}`, ...httpStatus(error) });
|
|
423
647
|
continue;
|
|
424
648
|
}
|
|
425
649
|
const latest = source.find(marker);
|
|
426
650
|
if (!latest) {
|
|
427
|
-
result.skipped.push({
|
|
651
|
+
result.skipped.push({ ...base, reason: `It is no longer in ${source.origin === 'private' ? `workspace ${source.workspaceId}` : 'the catalogue'}; left as it is.` });
|
|
428
652
|
continue;
|
|
429
653
|
}
|
|
430
654
|
if (source.origin === 'private' && latest.slug !== marker.slug) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
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)}.`,
|
|
434
|
-
});
|
|
655
|
+
const install = `insightfulpipe skills install ${source.installName(latest)} --workspace ${marker.workspace_id}`;
|
|
656
|
+
result.skipped.push({ ...base, reason: renameReason(where, entry, latest.slug, install) });
|
|
435
657
|
continue;
|
|
436
658
|
}
|
|
437
659
|
if (latest.version && latest.version === marker.version) {
|
|
438
|
-
result.up_to_date.push({
|
|
660
|
+
result.up_to_date.push({ ...base, version: marker.version });
|
|
439
661
|
continue;
|
|
440
662
|
}
|
|
441
663
|
const fetched = await fetchChecked(source, latest);
|
|
442
664
|
if (!fetched.validated) {
|
|
443
|
-
result.failed.push(fetched.row);
|
|
665
|
+
result.failed.push({ ...base, ...fetched.row });
|
|
444
666
|
continue;
|
|
445
667
|
}
|
|
446
668
|
let changes;
|
|
447
669
|
try {
|
|
448
670
|
changes = localChanges(dir, marker);
|
|
449
671
|
} catch (error) {
|
|
450
|
-
result.failed.push({
|
|
672
|
+
result.failed.push({ ...base, error: `Could not check for local edits: ${error.message}` });
|
|
451
673
|
continue;
|
|
452
674
|
}
|
|
453
675
|
if (changes.edited && !opts.force) {
|
|
454
676
|
result.skipped.push({
|
|
455
|
-
|
|
677
|
+
...base,
|
|
456
678
|
reason: 'You edited the installed files. Re-run with --force to replace them.',
|
|
457
679
|
changed: changes.changed,
|
|
458
680
|
missing: changes.missing,
|
|
@@ -461,88 +683,98 @@ export function registerSkillsCommand(program) {
|
|
|
461
683
|
continue;
|
|
462
684
|
}
|
|
463
685
|
const outcome = installChecked(source, latest, where, fetched.validated, true);
|
|
464
|
-
if (outcome.ok) result.updated.push({ ...outcome.row, from: marker.version });
|
|
465
|
-
else result.failed.push(outcome.row);
|
|
686
|
+
if (outcome.ok) result.updated.push({ ...base, ...outcome.row, from: marker.version });
|
|
687
|
+
else result.failed.push({ ...base, ...outcome.row });
|
|
466
688
|
}
|
|
467
689
|
|
|
468
690
|
if (wantsJson(command)) {
|
|
469
691
|
if (result.failed.length && !result.updated.length) fail('No skill was updated.', undefined, { skills_dir: where.dir, ...result });
|
|
470
692
|
printJson({ status: result.failed.length ? 'partial' : 'success', skills_dir: where.dir, ...result });
|
|
471
693
|
} else {
|
|
472
|
-
|
|
694
|
+
const label = (row) => labels.get(row.skill) ?? row.skill;
|
|
695
|
+
for (const row of result.updated) say(`Updated ${label(row)} ${row.from} -> ${row.version}`);
|
|
473
696
|
for (const row of result.updated) if (row.warning) warn(`Warning: ${row.warning}`);
|
|
474
|
-
for (const row of result.up_to_date) say(`Up to date ${row
|
|
475
|
-
for (const row of result.skipped) say(`Skipped ${row
|
|
476
|
-
for (const row of result.failed) warn(`Failed ${row
|
|
477
|
-
if (!targets.length) say(`No ${opts
|
|
697
|
+
for (const row of result.up_to_date) say(`Up to date ${label(row)} (${row.version})`);
|
|
698
|
+
for (const row of result.skipped) say(`Skipped ${label(row)}: ${row.reason}`);
|
|
699
|
+
for (const row of result.failed) warn(`Failed ${label(row)}: ${row.error}`);
|
|
700
|
+
if (!targets.length) say(`No ${wantsWorkspace(opts) ? 'workspace' : 'InsightfulPipe'} skills installed here.`);
|
|
478
701
|
}
|
|
479
702
|
if (result.failed.length) process.exitCode = 1;
|
|
480
703
|
});
|
|
481
704
|
|
|
482
705
|
withTargetOptions(
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
706
|
+
withWorkspaceFilter(
|
|
707
|
+
skills
|
|
708
|
+
.command('remove')
|
|
709
|
+
.argument('<skills...>', `Installed skills to remove: ${INSTALLED_WORDS}`)
|
|
710
|
+
.option('-y, --yes', 'Skip the confirmation prompt'),
|
|
711
|
+
).description('Remove installed InsightfulPipe skills (only folders this CLI installed)'),
|
|
489
712
|
).action(async (names, opts, command) => {
|
|
490
713
|
const where = target(opts);
|
|
491
|
-
const installed = inScope(
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
return matches[0];
|
|
499
|
-
});
|
|
714
|
+
const installed = inScope(installedHere(where.dir), opts);
|
|
715
|
+
const notFound = (name) =>
|
|
716
|
+
wantsWorkspace(opts) ? notInScope(name, where, opts) : `"${name}" is not an InsightfulPipe skill installed in ${where.dir}.`;
|
|
717
|
+
const how = folderCommand('remove', where, opts);
|
|
718
|
+
const targets = [...new Set(names.map((name) => oneInstalled(installed, name, notFound(name), how)))];
|
|
719
|
+
const labels = new Map(targets.map((entry) => [entry.dir, installedLabel(entry)]));
|
|
500
720
|
|
|
501
721
|
if (!opts.yes) {
|
|
502
722
|
if (!process.stdin.isTTY) fail('Removing skills needs confirmation in non-interactive mode. Re-run with --yes.');
|
|
503
|
-
const ok = await confirm(`Remove ${
|
|
723
|
+
const ok = await confirm(`Remove ${[...labels.values()].join(', ')} from ${where.dir}? [y/N] `);
|
|
504
724
|
if (!ok) fail('Nothing removed.');
|
|
505
725
|
}
|
|
506
726
|
|
|
507
727
|
const removed = [];
|
|
508
|
-
|
|
509
|
-
|
|
728
|
+
const failed = [];
|
|
729
|
+
for (const entry of targets) {
|
|
730
|
+
const realPath = realFolderPath(entry.dir);
|
|
731
|
+
const row = { ...folderRow(entry), path: entry.dir };
|
|
732
|
+
let leftover;
|
|
510
733
|
try {
|
|
511
|
-
removeInstalled(dir);
|
|
734
|
+
leftover = removeInstalled(entry.dir);
|
|
512
735
|
} catch (error) {
|
|
513
|
-
|
|
736
|
+
failed.push({ ...row, error: error.message });
|
|
737
|
+
continue;
|
|
514
738
|
}
|
|
515
|
-
|
|
739
|
+
const warnings = leftover ? [leftover] : [];
|
|
516
740
|
try {
|
|
517
741
|
forgetInstall(realPath);
|
|
518
742
|
} catch (error) {
|
|
519
|
-
|
|
743
|
+
warnings.push(`The install record could not be updated (${error.message}).`);
|
|
520
744
|
}
|
|
521
|
-
removed.push({
|
|
745
|
+
removed.push(warnings.length ? { ...row, warning: warnings.join(' ') } : row);
|
|
746
|
+
}
|
|
747
|
+
if (failed.length) process.exitCode = 1;
|
|
748
|
+
if (wantsJson(command)) {
|
|
749
|
+
if (!removed.length && failed.length) fail('Nothing was removed.', undefined, { skills_dir: where.dir, removed, failed });
|
|
750
|
+
printJson({ status: failed.length ? 'partial' : 'success', removed, ...(failed.length ? { failed } : {}) });
|
|
751
|
+
} else {
|
|
752
|
+
for (const row of removed) say(`Removed ${labels.get(row.path)} from ${row.path}`);
|
|
753
|
+
for (const row of removed) if (row.warning) warn(`Warning: ${row.warning}`);
|
|
754
|
+
for (const row of failed) warn(`Failed ${labels.get(row.path)}: ${row.error}`);
|
|
522
755
|
}
|
|
523
|
-
if (wantsJson(command)) printJson({ status: 'success', removed });
|
|
524
|
-
else for (const row of removed) say(`Removed ${row.skill} (${row.path})`);
|
|
525
756
|
});
|
|
526
757
|
|
|
527
758
|
skills
|
|
528
759
|
.command('download')
|
|
529
760
|
.argument('<skill>', 'Skill name, category/name, or @insightfulpipe/name')
|
|
530
|
-
.option('-o, --output <
|
|
761
|
+
.option('-o, --output <path>', 'Where to save the ZIP: a file, or a folder to save <skill>.zip in (default: this folder)')
|
|
531
762
|
.option('-f, --force', 'Overwrite the file if it exists')
|
|
532
|
-
.option('--
|
|
533
|
-
.
|
|
763
|
+
.option('-w, --workspace <id>', 'Not available yet for workspace skills')
|
|
764
|
+
.option('--private', 'Not available yet for workspace skills')
|
|
765
|
+
.description('Save an insightfulpipe.com skill as a ZIP, for uploading in Claude.ai or Claude Desktop')
|
|
534
766
|
.action(async (name, opts, command) => {
|
|
535
|
-
if (opts
|
|
767
|
+
if (wantsWorkspace(opts)) {
|
|
536
768
|
fail(
|
|
537
|
-
'
|
|
538
|
-
"Use Download on the skill in the app's Skills Library, or install it with: insightfulpipe skills install <skill> --
|
|
769
|
+
'Workspace skills cannot be downloaded as a ZIP from the CLI yet.',
|
|
770
|
+
"Use Download on the skill in the app's Skills Library, or install it with: insightfulpipe skills install <skill> --workspace <id>",
|
|
539
771
|
);
|
|
540
772
|
}
|
|
541
773
|
const source = await loadSource({});
|
|
542
774
|
const found = source.resolve(name);
|
|
543
775
|
if (found.error) fail(found.error);
|
|
544
776
|
const skill = found.skill;
|
|
545
|
-
const output =
|
|
777
|
+
const output = zipPath(opts.output, skill.slug);
|
|
546
778
|
if (lexists(output) && !opts.force) fail(`${output} already exists. Add --force to overwrite it.`);
|
|
547
779
|
|
|
548
780
|
let zip;
|
|
@@ -555,10 +787,9 @@ export function registerSkillsCommand(program) {
|
|
|
555
787
|
const partial = `${output}.${randomBytes(4).toString('hex')}.part`;
|
|
556
788
|
try {
|
|
557
789
|
writeFileSync(partial, zip, { flag: 'wx' });
|
|
558
|
-
|
|
790
|
+
moveFile(partial, output, basename(output));
|
|
559
791
|
} catch (error) {
|
|
560
|
-
|
|
561
|
-
fail(`Could not save ${output}: ${error.message}`);
|
|
792
|
+
fail(`Could not save ${output}: ${withLeftover(error, partial).message}`);
|
|
562
793
|
}
|
|
563
794
|
|
|
564
795
|
const next = 'Upload this ZIP as a custom skill in Claude.ai or Claude Desktop.';
|