feat(skills): add install dispatch for local skill setup
This commit is contained in:
+39
-1
@@ -2,7 +2,7 @@ import type { Command } from 'commander';
|
||||
import { resolve } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import type { Skill } from '../skills/index.js';
|
||||
import { loadAllSkills } from '../skills/index.js';
|
||||
import { loadAllSkills, SkillInstaller } from '../skills/index.js';
|
||||
import { loadConfigSafe } from './shared.js';
|
||||
|
||||
export interface SkillListRow {
|
||||
@@ -87,6 +87,19 @@ function loadSkillsFromConfig(configPath?: string): { skills?: Skill[]; error?:
|
||||
return { skills };
|
||||
}
|
||||
|
||||
export function installSkillFromDirectory(installer: SkillInstaller, sourcePath: string): { skill?: Skill; error?: string } {
|
||||
const sourceDir = resolve(sourcePath);
|
||||
try {
|
||||
const skill = installer.install(sourceDir);
|
||||
if (!skill) {
|
||||
return { error: `Failed to load skill from '${sourceDir}' after installation.` };
|
||||
}
|
||||
return { skill };
|
||||
} catch (error) {
|
||||
return { error: error instanceof Error ? error.message : String(error) };
|
||||
}
|
||||
}
|
||||
|
||||
export function registerSkillsCommand(program: Command): void {
|
||||
const skills = program
|
||||
.command('skills')
|
||||
@@ -144,4 +157,29 @@ export function registerSkillsCommand(program: Command): void {
|
||||
|
||||
console.log(renderSkillInfo(skill));
|
||||
});
|
||||
|
||||
skills
|
||||
.command('install <path>')
|
||||
.description('Install a skill from a local directory')
|
||||
.option('-c, --config <path>', 'Config file path')
|
||||
.action((pathArg: string, opts: { 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 result = installSkillFromDirectory(installer, pathArg);
|
||||
|
||||
if (result.error || !result.skill) {
|
||||
console.error(result.error ?? `Failed to install skill from '${pathArg}'.`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Installed skill '${result.skill.manifest.name}' (${result.skill.manifest.version}).`);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user