@quadient/skillshare 1.16.0 → 1.17.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/README.md CHANGED
@@ -278,6 +278,17 @@ npx @quadient/skillshare update "Prompt Lint" --dry-run
278
278
  npx @quadient/skillshare update 12 --target ./installed
279
279
  ```
280
280
 
281
+ When an installed skill has been removed from the registry, the interactive CLI and
282
+ `skillshare update` show each local copy with a preview of the files to remove and
283
+ the local edits or extra paths to keep. Choose **Remove installed files** to select
284
+ copies in one batch, **Keep local copies and stop checking them** to keep all files
285
+ and stop future reminders, or **Decide later** to review them on the next run.
286
+ Only unchanged files recorded at installation are removed; an edited `SKILL.md`
287
+ stays available to your agents. Older installations that cannot be verified can
288
+ also be kept without reminders. Records for directories already removed manually
289
+ are cleared without prompting. `--dry-run` previews all changes without writing;
290
+ non-interactive runs leave files untouched. Each copy is offered only once per run.
291
+
281
292
  Publish an authenticated static page. The upload replaces the page's complete
282
293
  content, and the directory must contain `index.html` at its root. By default the
283
294
  directory name is used as the page slug; build output folders such as `dist` need `--slug`:
package/dist/help.js CHANGED
@@ -56,7 +56,7 @@ export const COMMANDS = [
56
56
  name: 'update',
57
57
  summary: 'Update installed skills to their latest versions',
58
58
  usage: ['update [skillId|skillName] [--target <directory>] [--dry-run] [--force]'],
59
- description: 'Removes files that the new version no longer contains. Installs with local changes are skipped unless you pass --force.',
59
+ description: 'Removes files that the new version no longer contains. Installs with local changes are skipped unless you pass --force. For skills removed from SkillShare, preview the files, select copies to remove in one batch, keep copies without future reminders, or decide later. Local edits and extra files are kept. Missing installation records are cleared automatically; --dry-run changes nothing.',
60
60
  options: [
61
61
  ['--target <directory>', 'Only update the install in this directory'],
62
62
  ['--dry-run', 'Print planned changes without writing files'],
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import { SERVICE_ENV } from './agents-update.js';
7
7
  import { formatUnknownCommand, parseCliArgs } from './cli-args.js';
8
8
  import { findCommand, readCliVersion, renderCommandHelp, renderUsage } from './help.js';
9
9
  import { inspectInstallTarget, installFilesAtomically } from './install-files.js';
10
+ import { formatRemovedSkillCleanup, offerRemovedSkillUninstalls } from './removed-skills.js';
10
11
  import { preparePageFiles, resolvePageSlug } from './pages.js';
11
12
  import { formatByteSize, formatDateTime, pageUrl, plural, renderPageDetail, renderPageList, renderPageRuntime, renderSkillDetail, renderSkillList, renderSkillVersion, renderUser, } from './output.js';
12
13
  import { runPageDev } from './pages-dev.js';
@@ -82,6 +83,7 @@ const AGENTS = [
82
83
  const LOGIN_TIMEOUT_MS = 5 * 60_000;
83
84
  // Progress goes to stderr with --json so stdout stays machine-readable.
84
85
  let statusOutput = process.stdout;
86
+ const reviewedRemovedSkills = new Set();
85
87
  async function main() {
86
88
  const args = process.argv.slice(2);
87
89
  const command = args[0];
@@ -415,7 +417,8 @@ async function runInteractive() {
415
417
  const user = await ensureInteractiveLogin(baseUrl);
416
418
  const client = await createClient(baseUrl);
417
419
  log.info(`Signed in as ${user.displayName}${user.email ? ` <${user.email}>` : ''} · ${new URL(client.baseUrl).host}`);
418
- const pendingInstalledUpdates = await checkInstalledSkillsForUpdates(client);
420
+ const { candidates: pendingInstalledUpdates, removedRecords } = await checkInstalledSkillsForUpdates(client);
421
+ await uninstallRemovedSkills(removedRecords);
419
422
  if (pendingInstalledUpdates.length > 0) {
420
423
  const shouldUpdateInstalled = await promptConfirm(pendingInstalledUpdates.length === 1
421
424
  ? `There is 1 installed skill with a newer version available. Update it now?`
@@ -439,7 +442,7 @@ async function runInteractive() {
439
442
  message: 'What do you want to do?',
440
443
  options: [
441
444
  { value: 'install', label: 'Install a skill', hint: 'Browse registry and install to agents' },
442
- { value: 'update', label: 'Update installed skills', hint: 'Refresh recorded installs to the latest registry versions' },
445
+ { value: 'update', label: 'Update installed skills', hint: 'Get new versions and review skills removed from SkillShare' },
443
446
  { value: 'upload', label: 'Upload a skill', hint: 'Create a new skill or publish a version' },
444
447
  { value: 'exit', label: 'Exit' },
445
448
  ],
@@ -466,33 +469,38 @@ async function runInteractive() {
466
469
  async function checkInstalledSkillsForUpdates(client) {
467
470
  const records = (await readInstalledSkillRecords()).filter((record) => record.baseUrl === client.baseUrl);
468
471
  if (records.length === 0) {
469
- return [];
472
+ return { candidates: [], removedRecords: [] };
470
473
  }
471
474
  const status = spinner({ output: statusOutput });
472
475
  status.start(`Checking ${records.length} installed skill${records.length === 1 ? '' : 's'} for updates`);
473
476
  const problems = [];
477
+ const removedRecords = [];
474
478
  try {
475
479
  const candidates = await collectInstalledSkillUpdateCandidates(client, {
476
480
  records,
477
481
  onSkipped(skip) {
478
- if (skip.reason === 'removed' || skip.reason === 'error') {
482
+ if (skip.reason === 'removed')
483
+ removedRecords.push(skip.record);
484
+ if (skip.reason === 'error') {
479
485
  problems.push(skip.message);
480
486
  }
481
487
  },
482
488
  });
483
- status.stop(candidates.length > 0
484
- ? `${candidates.length} installed skill${candidates.length === 1 ? ' has' : 's have'} a newer version`
485
- : 'Installed skills are up to date');
489
+ status.stop(problems.length > 0
490
+ ? `Check finished with ${problems.length} ${problems.length === 1 ? 'error' : 'errors'}`
491
+ : candidates.length > 0
492
+ ? `${candidates.length} installed skill${candidates.length === 1 ? ' has' : 's have'} a newer version`
493
+ : removedRecords.length > 0 ? 'Some installed skills were removed from SkillShare' : 'Installed skills are up to date');
486
494
  if (problems.length > 0) {
487
495
  log.warn(problems.join('\n'));
488
496
  }
489
- return candidates;
497
+ return { candidates, removedRecords };
490
498
  }
491
499
  catch (error) {
492
500
  // The update check is optional; never let it block the main menu.
493
501
  status.stop('Could not check installed skills for updates');
494
502
  log.warn(error instanceof Error ? error.message : String(error));
495
- return [];
503
+ return { candidates: [], removedRecords: [] };
496
504
  }
497
505
  }
498
506
  async function ensureInteractiveLogin(baseUrl) {
@@ -643,20 +651,25 @@ async function updateInstalledSkills(client, options) {
643
651
  console.log(`No installed skills recorded for ${client.baseUrl}${selectionDescription}.`);
644
652
  return;
645
653
  }
654
+ const removedRecords = [];
646
655
  const candidates = options?.candidates
647
656
  ?? await collectInstalledSkillUpdateCandidates(client, {
648
657
  records: installedRecords,
649
658
  onSkipped(skip) {
650
- console.log(skip.message);
659
+ if (skip.reason === 'removed')
660
+ removedRecords.push(skip.record);
661
+ if (skip.reason !== 'removed')
662
+ console.log(skip.message);
651
663
  },
652
664
  });
653
- let skippedCount = installedRecords.length - candidates.length;
665
+ const cleanup = await uninstallRemovedSkills(removedRecords, dryRun);
666
+ let skippedCount = installedRecords.length - candidates.length - cleanup.uninstalled - cleanup.kept - cleanup.cleared;
654
667
  if (candidates.length === 0) {
655
668
  if (dryRun) {
656
669
  console.log(`Dry run finished. Would update 0, skipped ${skippedCount}.`);
657
670
  }
658
671
  else {
659
- console.log(`Update finished. Updated 0, skipped ${skippedCount}.`);
672
+ console.log(`Update finished. Updated 0${formatRemovedSkillCleanup(cleanup)}, skipped ${skippedCount}.`);
660
673
  }
661
674
  return;
662
675
  }
@@ -706,7 +719,20 @@ async function updateInstalledSkills(client, options) {
706
719
  console.log(`Dry run finished. Would update ${plannedCount}, skipped ${skippedCount}.`);
707
720
  return;
708
721
  }
709
- console.log(`Update finished. Updated ${updatedCount}, skipped ${skippedCount}.`);
722
+ console.log(`Update finished. Updated ${updatedCount}${formatRemovedSkillCleanup(cleanup)}, skipped ${skippedCount}.`);
723
+ }
724
+ async function uninstallRemovedSkills(records, dryRun = false) {
725
+ return offerRemovedSkillUninstalls(records, {
726
+ dryRun,
727
+ interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
728
+ reviewed: reviewedRemovedSkills,
729
+ formatTarget: formatInstallTargetRoot,
730
+ log: (message) => console.log(message),
731
+ async forget(record) {
732
+ const current = await readInstalledSkillRecords();
733
+ await writeStateFile(INSTALLED_STATE_PATH, current.filter((item) => !(item.baseUrl === record.baseUrl && item.targetRoot === record.targetRoot && item.skillId === record.skillId)));
734
+ },
735
+ });
710
736
  }
711
737
  async function collectInstalledSkillUpdateCandidates(client, options) {
712
738
  const records = options?.records
@@ -1,6 +1,6 @@
1
1
  import { createHash, randomBytes } from 'node:crypto';
2
2
  import { createReadStream } from 'node:fs';
3
- import { mkdir, readdir, rename, rm, rmdir, stat } from 'node:fs/promises';
3
+ import { lstat, mkdir, readdir, rename, rm, rmdir, stat } from 'node:fs/promises';
4
4
  import { basename, dirname, join, relative, resolve, sep } from 'node:path';
5
5
  export function resolveInsideRoot(root, relativePath) {
6
6
  const resolvedRoot = resolve(root);
@@ -46,6 +46,97 @@ export async function inspectInstallTarget(targetRoot, record) {
46
46
  }
47
47
  return modified.length > 0 ? { state: 'modified', paths: modified } : { state: 'clean' };
48
48
  }
49
+ /** Preview both installed and extra files without following symbolic links. */
50
+ export async function inspectSkillUninstall(targetRoot, files) {
51
+ const root = resolve(targetRoot);
52
+ const trackedDirectories = new Set();
53
+ for (const path of Object.keys(files ?? {})) {
54
+ const normalized = relative(root, resolveInsideRoot(root, path)).replaceAll('\\', '/');
55
+ const parts = normalized.split('/');
56
+ for (let length = 1; length < parts.length; length++)
57
+ trackedDirectories.add(parts.slice(0, length).join('/'));
58
+ }
59
+ const preview = { missing: false, legacy: !files, removable: [], preserved: [] };
60
+ let info;
61
+ try {
62
+ info = await lstat(root);
63
+ }
64
+ catch (error) {
65
+ if (error?.code !== 'ENOENT')
66
+ throw error;
67
+ return { ...preview, missing: true };
68
+ }
69
+ if (!info.isDirectory() || info.isSymbolicLink()) {
70
+ preview.preserved.push('.');
71
+ return preview;
72
+ }
73
+ async function visit(directory, prefix) {
74
+ const entries = await readdir(directory, { withFileTypes: true });
75
+ if (entries.length === 0 && prefix)
76
+ preview.preserved.push(`${prefix}/`);
77
+ for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
78
+ const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
79
+ const path = resolveInsideRoot(root, relativePath);
80
+ if (entry.isDirectory() && !entry.isSymbolicLink()) {
81
+ if (trackedDirectories.has(relativePath))
82
+ await visit(path, relativePath);
83
+ else
84
+ preview.preserved.push(`${relativePath}/`);
85
+ }
86
+ else if (files && await isUnchangedInstalledFile(root, relativePath, files[relativePath])) {
87
+ preview.removable.push(relativePath);
88
+ }
89
+ else {
90
+ preview.preserved.push(relativePath);
91
+ }
92
+ }
93
+ }
94
+ await visit(root, '');
95
+ return preview;
96
+ }
97
+ /** Uninstall only unchanged, tracked regular files. Recheck after the user's decision. */
98
+ export async function uninstallSkillFiles(targetRoot, files) {
99
+ const root = resolve(targetRoot);
100
+ const preview = await inspectSkillUninstall(root, files);
101
+ const removed = [];
102
+ for (const relativePath of preview.removable) {
103
+ if (!await isUnchangedInstalledFile(root, relativePath, files[relativePath]))
104
+ continue;
105
+ await rm(resolveInsideRoot(root, relativePath), { force: true });
106
+ removed.push(relativePath);
107
+ await removeEmptyParents(dirname(resolveInsideRoot(root, relativePath)), root);
108
+ }
109
+ try {
110
+ await rmdir(root);
111
+ }
112
+ catch (error) {
113
+ if (!['ENOENT', 'ENOTEMPTY', 'EEXIST', 'ENOTDIR'].includes(error?.code ?? ''))
114
+ throw error;
115
+ }
116
+ return { removed, preserved: (await inspectSkillUninstall(root, files)).preserved };
117
+ }
118
+ async function isUnchangedInstalledFile(root, relativePath, expectedHash) {
119
+ if (!expectedHash)
120
+ return false;
121
+ const path = resolveInsideRoot(root, relativePath);
122
+ try {
123
+ let parent = dirname(path);
124
+ while (true) {
125
+ const info = await lstat(parent);
126
+ if (!info.isDirectory() || info.isSymbolicLink())
127
+ return false;
128
+ if (parent === root)
129
+ break;
130
+ parent = dirname(parent);
131
+ }
132
+ return (await lstat(path)).isFile() && await hashFile(path) === expectedHash;
133
+ }
134
+ catch (error) {
135
+ if (error?.code !== 'ENOENT')
136
+ throw error;
137
+ return false;
138
+ }
139
+ }
49
140
  /**
50
141
  * Downloads every file into a sibling staging directory first, so a failed transfer
51
142
  * leaves the existing install untouched. Files from the previous manifest that the
@@ -0,0 +1,138 @@
1
+ import { inspectSkillUninstall, uninstallSkillFiles } from './install-files.js';
2
+ import { cancel, isCancel, multiselect, select } from '@clack/prompts';
3
+ import { plural } from './output.js';
4
+ export function formatRemovedSkillCleanup(result) {
5
+ return [
6
+ result.uninstalled ? `uninstalled ${result.uninstalled}` : '',
7
+ result.kept ? `kept locally ${result.kept}` : '',
8
+ result.cleared ? `cleared ${result.cleared} missing install record${result.cleared === 1 ? '' : 's'}` : '',
9
+ ].filter(Boolean).map(part => `, ${part}`).join('');
10
+ }
11
+ export async function offerRemovedSkillUninstalls(records, options) {
12
+ const result = { uninstalled: 0, kept: 0, cleared: 0 };
13
+ const key = (record) => JSON.stringify([record.baseUrl, record.skillId, record.targetRoot]);
14
+ if (!options.dryRun)
15
+ records = records.filter(record => !options.reviewed?.has(key(record)));
16
+ if (records.length === 0)
17
+ return result;
18
+ const reviews = [];
19
+ for (const record of records) {
20
+ if (!options.dryRun)
21
+ options.reviewed?.add(key(record));
22
+ const label = `${record.skillName || `Skill ${record.skillId}`} · ${options.formatTarget?.(record.targetRoot) ?? record.targetRoot}`;
23
+ try {
24
+ const preview = await inspectSkillUninstall(record.targetRoot, record.files);
25
+ if (preview.missing) {
26
+ if (options.dryRun) {
27
+ options.log(`Would clear missing installation: ${label}. No files remain.`);
28
+ }
29
+ else {
30
+ await options.forget(record);
31
+ result.cleared++;
32
+ options.log(`Cleared missing installation: ${label}. No files were deleted.`);
33
+ }
34
+ continue;
35
+ }
36
+ reviews.push({ record, label, preview });
37
+ }
38
+ catch (error) {
39
+ options.log(`Could not inspect ${label}: ${error instanceof Error ? error.message : String(error)}`);
40
+ }
41
+ }
42
+ if (reviews.length === 0)
43
+ return result;
44
+ options.log(`${reviews.length} local ${reviews.length === 1 ? 'copy belongs' : 'copies belong'} to skills removed from SkillShare:`);
45
+ for (const { label, preview } of reviews) {
46
+ options.log(` ${label}\n ${preview.legacy ? 'Older installation: files cannot be verified for removal.'
47
+ : `${plural(preview.removable.length, 'unchanged file')} to remove; ${plural(preview.preserved.length, 'path')} to keep (local edits or extra files).`}`);
48
+ if (preview.preserved.length > 0 && !preview.legacy) {
49
+ const shown = preview.preserved.slice(0, 4).join(', ');
50
+ options.log(` Keep: ${shown}${preview.preserved.length > 4 ? ` and ${preview.preserved.length - 4} more` : ''}`);
51
+ if (preview.preserved.includes('SKILL.md'))
52
+ options.log(' Your local SKILL.md will remain available to your agents.');
53
+ }
54
+ }
55
+ if (options.dryRun) {
56
+ options.log('Dry run: no files or installation records were changed.');
57
+ return result;
58
+ }
59
+ if (!options.interactive) {
60
+ options.log('Run "skillshare update" in an interactive terminal to remove selected copies or keep them locally and stop checking them.');
61
+ return result;
62
+ }
63
+ const uninstallable = reviews.filter(({ preview, record }) => Boolean(record.files) && preview.removable.length > 0);
64
+ const action = await (options.chooseAction ?? promptRemovedSkillAction)(uninstallable.length > 0);
65
+ if (action === 'later') {
66
+ options.log('Local copies kept. You can review them again with "skillshare update".');
67
+ return result;
68
+ }
69
+ const eligible = action === 'uninstall' ? uninstallable : reviews;
70
+ if (eligible.length === 0)
71
+ return result;
72
+ const selected = eligible.length === 1 ? eligible : await (options.chooseCopies ?? promptRemovedSkillCopies)(eligible, action);
73
+ const allowed = new Set(eligible);
74
+ for (const review of new Set(selected)) {
75
+ if (!allowed.has(review))
76
+ continue;
77
+ const { record, label } = review;
78
+ try {
79
+ if (action === 'keep') {
80
+ await options.forget(record);
81
+ result.kept++;
82
+ options.log(`Kept locally: ${label}. Files unchanged; SkillShare will no longer check this copy.`);
83
+ }
84
+ else {
85
+ const removed = await uninstallSkillFiles(record.targetRoot, record.files);
86
+ await options.forget(record);
87
+ result.uninstalled++;
88
+ options.log(`Removed ${plural(removed.removed.length, 'installed file')}: ${label}.`);
89
+ if (removed.preserved.length > 0) {
90
+ options.log(`Kept ${plural(removed.preserved.length, 'local or extra path')} in ${options.formatTarget?.(record.targetRoot) ?? record.targetRoot}. This copy will no longer be checked.`);
91
+ if (removed.preserved.includes('SKILL.md'))
92
+ options.log('Your local SKILL.md is still available to your agents.');
93
+ }
94
+ }
95
+ }
96
+ catch (error) {
97
+ options.log(`Could not ${action === 'keep' ? 'stop checking' : 'uninstall'} ${label}: ${error instanceof Error ? error.message : String(error)}`);
98
+ }
99
+ }
100
+ if (selected.length === 0)
101
+ options.log('No copies selected. Local copies and installation records kept.');
102
+ else if (reviews.length > selected.length) {
103
+ const remaining = reviews.length - selected.length;
104
+ options.log(`${remaining} other ${remaining === 1 ? 'copy' : 'copies'} left unchanged. Review again with "skillshare update".`);
105
+ }
106
+ return result;
107
+ }
108
+ async function promptRemovedSkillAction(canUninstall) {
109
+ const action = await select({
110
+ message: 'What should happen to these local copies?',
111
+ initialValue: 'later',
112
+ options: [
113
+ ...(canUninstall ? [{ value: 'uninstall', label: 'Remove installed files', hint: 'Keep local edits and extra files; choose copies next if there are several' }] : []),
114
+ { value: 'keep', label: 'Keep local copies and stop checking them', hint: 'All files stay; choose copies next if there are several' },
115
+ { value: 'later', label: 'Decide later', hint: 'Keep files and review again the next time you run SkillShare' },
116
+ ],
117
+ });
118
+ if (isCancel(action)) {
119
+ cancel('Cancelled. Local copies kept.');
120
+ process.exit(0);
121
+ }
122
+ return action;
123
+ }
124
+ async function promptRemovedSkillCopies(copies, action) {
125
+ const selected = await multiselect({
126
+ message: action === 'uninstall' ? 'Select copies to remove (local edits and extra files stay)' : 'Select local copies to stop checking (all files stay)',
127
+ options: copies.map((copy, index) => ({ value: index, label: copy.label,
128
+ hint: action === 'uninstall' ? `${plural(copy.preview.removable.length, 'file')} removed · ${plural(copy.preview.preserved.length, 'path')} kept` : 'Files unchanged',
129
+ })),
130
+ initialValues: [],
131
+ required: false,
132
+ });
133
+ if (isCancel(selected)) {
134
+ cancel('Cancelled. Local copies kept.');
135
+ process.exit(0);
136
+ }
137
+ return selected.map(index => copies[index]);
138
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quadient/skillshare",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "description": "Skillshare CLI for installing and publishing Quadient skills",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,7 @@
16
16
  "build": "rm -rf dist && tsc -p tsconfig.build.json && node -e \"require('node:fs').copyFileSync('page-browser-client.js', 'dist/page-browser-client.js')\"",
17
17
  "start": "node ./dist/index.js",
18
18
  "prepublishOnly": "npm run build",
19
- "test": "tsx --test session-auth.test.ts cli-args.test.ts install-files.test.ts output.test.ts pages.test.ts page-links.test.ts pages-secrets.test.ts pages-comments.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-browser.test.ts salesforce.test.ts agents.test.ts agents-update.test.ts login-callback.test.ts"
19
+ "test": "tsx --test session-auth.test.ts cli-args.test.ts install-files.test.ts removed-skills.test.ts output.test.ts pages.test.ts page-links.test.ts pages-secrets.test.ts pages-comments.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-browser.test.ts salesforce.test.ts agents.test.ts agents-update.test.ts login-callback.test.ts"
20
20
  },
21
21
  "publishConfig": {
22
22
  "access": "public"