insightfulpipe 0.4.2 → 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 +128 -0
- package/README.md +35 -22
- package/package.json +1 -1
- package/src/cli/commands/skills.js +367 -144
- package/src/cli/program.js +2 -0
- package/src/output.js +6 -1
- package/src/skills/folders.js +129 -0
- package/src/skills/installer.js +33 -31
- package/src/skills/keys.js +21 -0
- package/src/skills/moves.js +87 -0
- package/src/skills/names.js +40 -0
- package/src/skills/private.js +33 -46
- package/src/skills/records.js +14 -4
- 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,35 +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
|
-
/**
|
|
47
|
-
*
|
|
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). */
|
|
48
114
|
export function shellWord(text, platform = process.platform) {
|
|
115
|
+
if (text.search(UNPRINTABLE) !== -1) return null;
|
|
49
116
|
if (platform !== 'win32') return /^[\w./:-]+$/.test(text) ? text : `'${text.replaceAll("'", "'\\''")}'`;
|
|
50
|
-
if (/^[\w
|
|
51
|
-
|
|
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;
|
|
52
121
|
}
|
|
53
122
|
|
|
54
|
-
/** The options that point a command at the same skills folder, for commands the CLI suggests
|
|
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. */
|
|
55
125
|
function folderArgs(where) {
|
|
56
|
-
if (where.scope === 'custom') return ` --dir ${shellWord(where.dir)}`;
|
|
126
|
+
if (where.scope === 'custom') return shellWord(where.dir) === null ? null : ` --dir ${shellWord(where.dir)}`;
|
|
57
127
|
const agent = where.agent && where.agent !== DEFAULT_AGENT ? ` --agent ${where.agent}` : '';
|
|
58
128
|
return `${agent}${where.scope === 'project' ? ' --project' : ''}`;
|
|
59
129
|
}
|
|
@@ -64,10 +134,24 @@ function trusted(dir, marker) {
|
|
|
64
134
|
return markerOrigin(marker) === 'public' || isRecordedInstall(dir, marker);
|
|
65
135
|
}
|
|
66
136
|
|
|
67
|
-
|
|
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) {
|
|
68
152
|
return command
|
|
69
|
-
.option('--
|
|
70
|
-
.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"');
|
|
71
155
|
}
|
|
72
156
|
|
|
73
157
|
function target(opts) {
|
|
@@ -79,9 +163,6 @@ function target(opts) {
|
|
|
79
163
|
}
|
|
80
164
|
|
|
81
165
|
async function loadSource(opts) {
|
|
82
|
-
if (opts.workspace !== undefined && !opts.private) {
|
|
83
|
-
fail('--workspace applies to private skills only.', 'Add --private to use your workspace\'s private skills.');
|
|
84
|
-
}
|
|
85
166
|
try {
|
|
86
167
|
return await openSource(opts);
|
|
87
168
|
} catch (error) {
|
|
@@ -89,9 +170,19 @@ async function loadSource(opts) {
|
|
|
89
170
|
}
|
|
90
171
|
}
|
|
91
172
|
|
|
92
|
-
/** 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. */
|
|
93
174
|
function sourceFields(source) {
|
|
94
|
-
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;
|
|
95
186
|
}
|
|
96
187
|
|
|
97
188
|
function short(text, max) {
|
|
@@ -109,19 +200,34 @@ async function fetchChecked(source, skill) {
|
|
|
109
200
|
try {
|
|
110
201
|
bundle = await source.files(skill);
|
|
111
202
|
} catch (error) {
|
|
112
|
-
return { row: {
|
|
203
|
+
return { row: { ...skillRow(skill), error: error.message, ...httpStatus(error) } };
|
|
113
204
|
}
|
|
114
205
|
if (!bundle) {
|
|
115
|
-
return { row: {
|
|
206
|
+
return { row: { ...skillRow(skill), error: source.noFiles } };
|
|
116
207
|
}
|
|
117
208
|
try {
|
|
118
209
|
return { validated: source.validate(bundle, skill) };
|
|
119
210
|
} catch (error) {
|
|
120
|
-
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.`;
|
|
121
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.`;
|
|
226
|
+
}
|
|
227
|
+
return `The install could not be recorded (${reason}), so list and update will not trust this workspace skill.`;
|
|
122
228
|
}
|
|
123
229
|
|
|
124
|
-
/** 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
|
|
125
231
|
* now holds the folder is not. */
|
|
126
232
|
function recordOutcome(source, skill, path) {
|
|
127
233
|
try {
|
|
@@ -129,24 +235,25 @@ function recordOutcome(source, skill, path) {
|
|
|
129
235
|
else forgetInstall(realFolderPath(path));
|
|
130
236
|
return '';
|
|
131
237
|
} catch (error) {
|
|
132
|
-
return
|
|
238
|
+
return recordFailure(source, skill, path, clause(error.message));
|
|
133
239
|
}
|
|
134
240
|
}
|
|
135
241
|
|
|
136
242
|
function installChecked(source, skill, where, validated, force) {
|
|
137
243
|
try {
|
|
138
|
-
const
|
|
244
|
+
const updateHint = force ? null : updateHintFor(where, skill.slug);
|
|
245
|
+
const { path, warning } = installSkill(where.dir, skill, validated, { force, ...source.installOptions(skill), updateHint });
|
|
139
246
|
const notes = [
|
|
140
247
|
warning,
|
|
141
248
|
recordOutcome(source, skill, path),
|
|
142
|
-
source.origin === 'private' && where.scope !== 'global' ?
|
|
249
|
+
source.origin === 'private' && where.scope !== 'global' ? WORKSPACE_IN_PROJECT : '',
|
|
143
250
|
].filter(Boolean);
|
|
144
251
|
return {
|
|
145
252
|
ok: true,
|
|
146
|
-
row: {
|
|
253
|
+
row: { ...skillRow(skill), version: validated.version, path, ...(notes.length ? { warning: notes.join(' ') } : {}) },
|
|
147
254
|
};
|
|
148
255
|
} catch (error) {
|
|
149
|
-
return { ok: false, row: {
|
|
256
|
+
return { ok: false, row: { ...skillRow(skill), error: error.message } };
|
|
150
257
|
}
|
|
151
258
|
}
|
|
152
259
|
|
|
@@ -155,15 +262,110 @@ async function installOne(source, skill, where, force) {
|
|
|
155
262
|
return fetched.validated ? installChecked(source, skill, where, fetched.validated, force) : { ok: false, row: fetched.row };
|
|
156
263
|
}
|
|
157
264
|
|
|
158
|
-
/**
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
);
|
|
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;
|
|
167
369
|
}
|
|
168
370
|
|
|
169
371
|
export function registerSkillsCommand(program) {
|
|
@@ -171,20 +373,20 @@ export function registerSkillsCommand(program) {
|
|
|
171
373
|
.command('skills')
|
|
172
374
|
.description('Find and install InsightfulPipe skills for Claude Code, OpenClaw, Codex, Cursor and Gemini CLI');
|
|
173
375
|
|
|
174
|
-
|
|
376
|
+
withWorkspaceOptions(
|
|
175
377
|
skills
|
|
176
378
|
.command('search')
|
|
177
379
|
.argument('[query...]', 'Words to look for in the skill name, category or description')
|
|
178
380
|
.option('-c, --category <category>', 'Only skills in this category (e.g., google-ads, seo)')
|
|
179
381
|
.option('--limit <n>', 'Show at most this many skills')
|
|
180
|
-
.description(
|
|
382
|
+
.description("Browse or search insightfulpipe.com skills, or your workspace's skills with --workspace <id>"),
|
|
181
383
|
).action(async (words, opts, command) => {
|
|
182
|
-
if (opts
|
|
384
|
+
if (wantsWorkspace(opts) && opts.category) fail('--category applies to insightfulpipe.com skills, not to workspace skills.');
|
|
183
385
|
const source = await loadSource(opts);
|
|
184
386
|
const terms = (words || []).join(' ').toLowerCase().split(/\s+/).filter(Boolean);
|
|
185
387
|
let found = source.skills.filter((skill) => {
|
|
186
388
|
if (opts.category && skill.category !== opts.category) return false;
|
|
187
|
-
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]
|
|
188
390
|
.filter(Boolean)
|
|
189
391
|
.join(' ')
|
|
190
392
|
.toLowerCase();
|
|
@@ -196,6 +398,18 @@ export function registerSkillsCommand(program) {
|
|
|
196
398
|
printJson({ status: 'success', ...sourceFields(source), count: found.length, skills: found.map(source.summarize) });
|
|
197
399
|
return;
|
|
198
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
|
+
}
|
|
199
413
|
printTable(
|
|
200
414
|
found.map((skill) => ({ skill: skill.slug, category: skill.category, description: short(skill.description, 70) })),
|
|
201
415
|
[
|
|
@@ -206,10 +420,10 @@ export function registerSkillsCommand(program) {
|
|
|
206
420
|
);
|
|
207
421
|
});
|
|
208
422
|
|
|
209
|
-
|
|
423
|
+
withWorkspaceOptions(
|
|
210
424
|
skills
|
|
211
425
|
.command('info')
|
|
212
|
-
.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)')
|
|
213
427
|
.description('Show what a skill does, its files and how to install it'),
|
|
214
428
|
).action(async (name, opts, command) => {
|
|
215
429
|
const source = await loadSource(opts);
|
|
@@ -225,7 +439,8 @@ export function registerSkillsCommand(program) {
|
|
|
225
439
|
printJson({ status: 'success', ...sourceFields(source), skill: info });
|
|
226
440
|
return;
|
|
227
441
|
}
|
|
228
|
-
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]}`);
|
|
229
444
|
say(`Version: ${info.version ?? 'unknown'}`);
|
|
230
445
|
if (info.page) say(`Page: ${info.page}`);
|
|
231
446
|
say(`Install: ${info.install}`);
|
|
@@ -234,17 +449,17 @@ export function registerSkillsCommand(program) {
|
|
|
234
449
|
say(info.description);
|
|
235
450
|
});
|
|
236
451
|
|
|
237
|
-
|
|
452
|
+
withWorkspaceOptions(
|
|
238
453
|
withTargetOptions(
|
|
239
454
|
skills
|
|
240
455
|
.command('install')
|
|
241
|
-
.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)')
|
|
242
457
|
.option('-c, --category <category>', 'Install every skill in this category')
|
|
243
458
|
.option('-f, --force', 'Replace a skill folder that already exists')
|
|
244
459
|
.description('Download skills into your agent\'s skills folder (Claude Code by default)'),
|
|
245
460
|
),
|
|
246
461
|
).action(async (names, opts, command) => {
|
|
247
|
-
if (opts
|
|
462
|
+
if (wantsWorkspace(opts) && opts.category) fail('--category applies to insightfulpipe.com skills, not to workspace skills.');
|
|
248
463
|
if (!names?.length && !opts.category) {
|
|
249
464
|
fail('Name at least one skill, or use --category.', 'Run: insightfulpipe skills search');
|
|
250
465
|
}
|
|
@@ -271,7 +486,7 @@ export function registerSkillsCommand(program) {
|
|
|
271
486
|
const label = skill.key ? `${skillKey(skill)} (${skill.key})` : skillKey(skill);
|
|
272
487
|
if (folders.has(skill.slug)) {
|
|
273
488
|
failed.push({
|
|
274
|
-
|
|
489
|
+
...skillRow(skill),
|
|
275
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.`,
|
|
276
491
|
});
|
|
277
492
|
continue;
|
|
@@ -290,16 +505,16 @@ export function registerSkillsCommand(program) {
|
|
|
290
505
|
next_step: `Start a new ${agentLabel(where)} session to load the skill. ${MCP_TIP}`,
|
|
291
506
|
});
|
|
292
507
|
} else {
|
|
293
|
-
for (const row of installed) say(`Installed ${row
|
|
508
|
+
for (const row of installed) say(`Installed ${withKey(row)} (${row.version}) -> ${row.path}`);
|
|
294
509
|
for (const row of installed) if (row.warning) warn(`Warning: ${row.warning}`);
|
|
295
|
-
for (const row of failed) warn(`Failed ${row
|
|
510
|
+
for (const row of failed) warn(`Failed ${withKey(row)}: ${row.error}`);
|
|
296
511
|
if (installed.length) say(`\nStart a new ${agentLabel(where)} session to load it. ${MCP_TIP}`);
|
|
297
512
|
}
|
|
298
513
|
if (failed.length) process.exitCode = 1;
|
|
299
514
|
});
|
|
300
515
|
|
|
301
516
|
withTargetOptions(
|
|
302
|
-
skills.command('list')
|
|
517
|
+
withWorkspaceFilter(skills.command('list')).description('List the InsightfulPipe skills installed in a skills folder'),
|
|
303
518
|
).action(async (opts, command) => {
|
|
304
519
|
const where = target(opts);
|
|
305
520
|
const installed = inScope(listInstalled(where.dir), opts);
|
|
@@ -311,12 +526,15 @@ export function registerSkillsCommand(program) {
|
|
|
311
526
|
const origin = markerOrigin(marker);
|
|
312
527
|
const ours = trusted(dir, marker);
|
|
313
528
|
let latest = null;
|
|
529
|
+
let renamed = null;
|
|
314
530
|
let checked = false;
|
|
315
531
|
let status = {};
|
|
316
532
|
const problems = [];
|
|
317
533
|
if (ours) {
|
|
318
534
|
try {
|
|
319
|
-
|
|
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;
|
|
320
538
|
checked = true;
|
|
321
539
|
if (origin === 'public') publicReached = true;
|
|
322
540
|
} catch (error) {
|
|
@@ -334,13 +552,16 @@ export function registerSkillsCommand(program) {
|
|
|
334
552
|
} catch (error) {
|
|
335
553
|
problems.push(`Could not check for local edits: ${error.message}`);
|
|
336
554
|
}
|
|
555
|
+
const type = markerType(marker);
|
|
337
556
|
rows.push({
|
|
338
557
|
skill: markerLabel(marker),
|
|
339
|
-
origin,
|
|
558
|
+
origin: listedOrigin(marker),
|
|
559
|
+
...(type ? { type } : {}),
|
|
340
560
|
...(origin === 'private' ? { trusted: ours } : {}),
|
|
341
561
|
...(origin === 'private' && ours ? { key: marker.key, workspace_id: marker.workspace_id } : {}),
|
|
342
562
|
version: marker.version,
|
|
343
563
|
latest,
|
|
564
|
+
...(renamed ? { renamed_to: renamed } : {}),
|
|
344
565
|
latest_checked: checked,
|
|
345
566
|
...(ours ? {} : { note: NOT_YOURS }),
|
|
346
567
|
update_available: Boolean(latest && latest !== marker.version),
|
|
@@ -365,13 +586,17 @@ export function registerSkillsCommand(program) {
|
|
|
365
586
|
}
|
|
366
587
|
printTable(
|
|
367
588
|
rows.map((row) => ({
|
|
368
|
-
skill: row
|
|
589
|
+
skill: withKey(row),
|
|
590
|
+
type: row.origin === 'public' ? 'insightfulpipe.com' : (TYPE_LABEL[row.type] ?? ''),
|
|
369
591
|
version: row.version,
|
|
370
|
-
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',
|
|
371
595
|
edited: row.locally_edited === null ? 'unknown' : row.locally_edited ? 'yes' : '',
|
|
372
596
|
})),
|
|
373
597
|
[
|
|
374
598
|
{ key: 'skill', label: 'Skill' },
|
|
599
|
+
{ key: 'type', label: 'Type' },
|
|
375
600
|
{ key: 'version', label: 'Version' },
|
|
376
601
|
{ key: 'status', label: 'Status' },
|
|
377
602
|
{ key: 'edited', label: 'Edited' },
|
|
@@ -387,80 +612,69 @@ export function registerSkillsCommand(program) {
|
|
|
387
612
|
});
|
|
388
613
|
|
|
389
614
|
withTargetOptions(
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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'),
|
|
397
622
|
).action(async (names, opts, command) => {
|
|
398
623
|
if (!names?.length && !opts.all) {
|
|
399
624
|
fail('Name the skills to update, or use --all.');
|
|
400
625
|
}
|
|
401
626
|
const where = target(opts);
|
|
402
|
-
const installed = inScope(
|
|
403
|
-
|
|
404
|
-
const
|
|
405
|
-
if (opts.all) {
|
|
406
|
-
targets.push(...installed);
|
|
407
|
-
} else {
|
|
408
|
-
for (const name of names) {
|
|
409
|
-
const matches = findInstalled(installed, name);
|
|
410
|
-
if (matches.length !== 1) {
|
|
411
|
-
if (matches.length) fail(`"${name}" matches more than one installed skill.`);
|
|
412
|
-
fail(opts.private ? notPrivate(name, where) : `"${name}" is not installed in ${where.dir}.`);
|
|
413
|
-
}
|
|
414
|
-
targets.push(matches[0]);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
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);
|
|
418
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
|
+
|
|
419
634
|
const result = { updated: [], up_to_date: [], skipped: [], failed: [] };
|
|
420
|
-
for (const
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
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 });
|
|
424
640
|
continue;
|
|
425
641
|
}
|
|
426
642
|
let source;
|
|
427
643
|
try {
|
|
428
644
|
source = await sourceFor(marker);
|
|
429
645
|
} catch (error) {
|
|
430
|
-
result.failed.push({
|
|
646
|
+
result.failed.push({ ...base, error: `Could not check for updates: ${error.message}`, ...httpStatus(error) });
|
|
431
647
|
continue;
|
|
432
648
|
}
|
|
433
649
|
const latest = source.find(marker);
|
|
434
650
|
if (!latest) {
|
|
435
|
-
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.` });
|
|
436
652
|
continue;
|
|
437
653
|
}
|
|
438
654
|
if (source.origin === 'private' && latest.slug !== marker.slug) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
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)}.`,
|
|
442
|
-
});
|
|
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) });
|
|
443
657
|
continue;
|
|
444
658
|
}
|
|
445
659
|
if (latest.version && latest.version === marker.version) {
|
|
446
|
-
result.up_to_date.push({
|
|
660
|
+
result.up_to_date.push({ ...base, version: marker.version });
|
|
447
661
|
continue;
|
|
448
662
|
}
|
|
449
663
|
const fetched = await fetchChecked(source, latest);
|
|
450
664
|
if (!fetched.validated) {
|
|
451
|
-
result.failed.push(fetched.row);
|
|
665
|
+
result.failed.push({ ...base, ...fetched.row });
|
|
452
666
|
continue;
|
|
453
667
|
}
|
|
454
668
|
let changes;
|
|
455
669
|
try {
|
|
456
670
|
changes = localChanges(dir, marker);
|
|
457
671
|
} catch (error) {
|
|
458
|
-
result.failed.push({
|
|
672
|
+
result.failed.push({ ...base, error: `Could not check for local edits: ${error.message}` });
|
|
459
673
|
continue;
|
|
460
674
|
}
|
|
461
675
|
if (changes.edited && !opts.force) {
|
|
462
676
|
result.skipped.push({
|
|
463
|
-
|
|
677
|
+
...base,
|
|
464
678
|
reason: 'You edited the installed files. Re-run with --force to replace them.',
|
|
465
679
|
changed: changes.changed,
|
|
466
680
|
missing: changes.missing,
|
|
@@ -469,88 +683,98 @@ export function registerSkillsCommand(program) {
|
|
|
469
683
|
continue;
|
|
470
684
|
}
|
|
471
685
|
const outcome = installChecked(source, latest, where, fetched.validated, true);
|
|
472
|
-
if (outcome.ok) result.updated.push({ ...outcome.row, from: marker.version });
|
|
473
|
-
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 });
|
|
474
688
|
}
|
|
475
689
|
|
|
476
690
|
if (wantsJson(command)) {
|
|
477
691
|
if (result.failed.length && !result.updated.length) fail('No skill was updated.', undefined, { skills_dir: where.dir, ...result });
|
|
478
692
|
printJson({ status: result.failed.length ? 'partial' : 'success', skills_dir: where.dir, ...result });
|
|
479
693
|
} else {
|
|
480
|
-
|
|
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}`);
|
|
481
696
|
for (const row of result.updated) if (row.warning) warn(`Warning: ${row.warning}`);
|
|
482
|
-
for (const row of result.up_to_date) say(`Up to date ${row
|
|
483
|
-
for (const row of result.skipped) say(`Skipped ${row
|
|
484
|
-
for (const row of result.failed) warn(`Failed ${row
|
|
485
|
-
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.`);
|
|
486
701
|
}
|
|
487
702
|
if (result.failed.length) process.exitCode = 1;
|
|
488
703
|
});
|
|
489
704
|
|
|
490
705
|
withTargetOptions(
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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)'),
|
|
497
712
|
).action(async (names, opts, command) => {
|
|
498
713
|
const where = target(opts);
|
|
499
|
-
const installed = inScope(
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
return matches[0];
|
|
507
|
-
});
|
|
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)]));
|
|
508
720
|
|
|
509
721
|
if (!opts.yes) {
|
|
510
722
|
if (!process.stdin.isTTY) fail('Removing skills needs confirmation in non-interactive mode. Re-run with --yes.');
|
|
511
|
-
const ok = await confirm(`Remove ${
|
|
723
|
+
const ok = await confirm(`Remove ${[...labels.values()].join(', ')} from ${where.dir}? [y/N] `);
|
|
512
724
|
if (!ok) fail('Nothing removed.');
|
|
513
725
|
}
|
|
514
726
|
|
|
515
727
|
const removed = [];
|
|
516
|
-
|
|
517
|
-
|
|
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;
|
|
518
733
|
try {
|
|
519
|
-
removeInstalled(dir);
|
|
734
|
+
leftover = removeInstalled(entry.dir);
|
|
520
735
|
} catch (error) {
|
|
521
|
-
|
|
736
|
+
failed.push({ ...row, error: error.message });
|
|
737
|
+
continue;
|
|
522
738
|
}
|
|
523
|
-
|
|
739
|
+
const warnings = leftover ? [leftover] : [];
|
|
524
740
|
try {
|
|
525
741
|
forgetInstall(realPath);
|
|
526
742
|
} catch (error) {
|
|
527
|
-
|
|
743
|
+
warnings.push(`The install record could not be updated (${error.message}).`);
|
|
528
744
|
}
|
|
529
|
-
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}`);
|
|
530
755
|
}
|
|
531
|
-
if (wantsJson(command)) printJson({ status: 'success', removed });
|
|
532
|
-
else for (const row of removed) say(`Removed ${row.skill} (${row.path})`);
|
|
533
756
|
});
|
|
534
757
|
|
|
535
758
|
skills
|
|
536
759
|
.command('download')
|
|
537
760
|
.argument('<skill>', 'Skill name, category/name, or @insightfulpipe/name')
|
|
538
|
-
.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)')
|
|
539
762
|
.option('-f, --force', 'Overwrite the file if it exists')
|
|
540
|
-
.option('--
|
|
541
|
-
.
|
|
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')
|
|
542
766
|
.action(async (name, opts, command) => {
|
|
543
|
-
if (opts
|
|
767
|
+
if (wantsWorkspace(opts)) {
|
|
544
768
|
fail(
|
|
545
|
-
'
|
|
546
|
-
"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>",
|
|
547
771
|
);
|
|
548
772
|
}
|
|
549
773
|
const source = await loadSource({});
|
|
550
774
|
const found = source.resolve(name);
|
|
551
775
|
if (found.error) fail(found.error);
|
|
552
776
|
const skill = found.skill;
|
|
553
|
-
const output =
|
|
777
|
+
const output = zipPath(opts.output, skill.slug);
|
|
554
778
|
if (lexists(output) && !opts.force) fail(`${output} already exists. Add --force to overwrite it.`);
|
|
555
779
|
|
|
556
780
|
let zip;
|
|
@@ -563,10 +787,9 @@ export function registerSkillsCommand(program) {
|
|
|
563
787
|
const partial = `${output}.${randomBytes(4).toString('hex')}.part`;
|
|
564
788
|
try {
|
|
565
789
|
writeFileSync(partial, zip, { flag: 'wx' });
|
|
566
|
-
|
|
790
|
+
moveFile(partial, output, basename(output));
|
|
567
791
|
} catch (error) {
|
|
568
|
-
|
|
569
|
-
fail(`Could not save ${output}: ${error.message}`);
|
|
792
|
+
fail(`Could not save ${output}: ${withLeftover(error, partial).message}`);
|
|
570
793
|
}
|
|
571
794
|
|
|
572
795
|
const next = 'Upload this ZIP as a custom skill in Claude.ai or Claude Desktop.';
|