feat(skills): guard uninstall with explicit confirmation
This commit is contained in:
@@ -100,6 +100,28 @@ export function installSkillFromDirectory(installer: SkillInstaller, sourcePath:
|
||||
}
|
||||
}
|
||||
|
||||
export function uninstallSkillByName(
|
||||
installer: SkillInstaller,
|
||||
name: string,
|
||||
opts: { confirm: boolean; discoveredSkill?: Skill },
|
||||
): { removed?: true; error?: string } {
|
||||
if (!opts.confirm) {
|
||||
return { error: 'Refusing to uninstall without --yes. Re-run with --yes to confirm.' };
|
||||
}
|
||||
|
||||
if (opts.discoveredSkill && opts.discoveredSkill.manifest.tier !== 'managed' && !installer.isInstalled(name)) {
|
||||
return {
|
||||
error: `Skill '${name}' is '${opts.discoveredSkill.manifest.tier}' and cannot be uninstalled from managed skills.`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!installer.uninstall(name)) {
|
||||
return { error: `Managed skill '${name}' is not installed.` };
|
||||
}
|
||||
|
||||
return { removed: true };
|
||||
}
|
||||
|
||||
export function registerSkillsCommand(program: Command): void {
|
||||
const skills = program
|
||||
.command('skills')
|
||||
@@ -182,4 +204,42 @@ export function registerSkillsCommand(program: Command): void {
|
||||
|
||||
console.log(`Installed skill '${result.skill.manifest.name}' (${result.skill.manifest.version}).`);
|
||||
});
|
||||
|
||||
skills
|
||||
.command('uninstall <name>')
|
||||
.description('Uninstall a managed skill by name')
|
||||
.option('--yes', 'Confirm uninstall without prompt')
|
||||
.option('-c, --config <path>', 'Config file path')
|
||||
.action((name: string, opts: { yes?: boolean; config?: string }) => {
|
||||
const loaded = loadConfigSafe(opts.config);
|
||||
if (loaded.error || !loaded.config) {
|
||||
console.error(loaded.error ?? 'Failed to load config');
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultManagedDir = resolve(homedir(), '.flynn/workspace/skills');
|
||||
const installer = new SkillInstaller(loaded.config.skills.managed_dir ?? defaultManagedDir);
|
||||
const discoveredSkills = loadAllSkills({
|
||||
bundledDir: loaded.config.skills.bundled_dir,
|
||||
managedDir: loaded.config.skills.managed_dir ?? defaultManagedDir,
|
||||
workspaceDir: loaded.config.skills.workspace_dir,
|
||||
});
|
||||
const discovered = discoveredSkills.find(
|
||||
(skill) => skill.manifest.name === name && skill.manifest.tier === 'managed',
|
||||
) ?? discoveredSkills.find((skill) => skill.manifest.name === name);
|
||||
|
||||
const result = uninstallSkillByName(installer, name, {
|
||||
confirm: opts.yes ?? false,
|
||||
discoveredSkill: discovered,
|
||||
});
|
||||
|
||||
if (result.error || !result.removed) {
|
||||
console.error(result.error ?? `Failed to uninstall skill '${name}'.`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Uninstalled skill '${name}'.`);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user