insightfulpipe 0.3.0 → 0.4.1

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