import { z } from 'zod'; import type { Tool } from './Tool'; import type { JSRuntimeFS } from '../JSRuntime'; import { findSkill, readSkillContent } from '../plugins'; interface SkillParams { name: string; } export class SkillTool implements Tool { private fs: JSRuntimeFS; private pluginsPath: string; readonly description = 'Load and execute a skill from the configured plugins. Skills are reusable AI workflows that can be invoked by name.'; readonly inputSchema = z.object({ name: z.string().describe('The name of the skill to execute (alphanumeric lowercase only)'), }); constructor(fs: JSRuntimeFS, pluginsPath: string) { this.fs = fs; this.pluginsPath = pluginsPath; } async execute(args: SkillParams): Promise { const { name } = args; try { // Find the skill across all plugins const skill = await findSkill(this.fs, this.pluginsPath, name); if (!skill) { throw new Error(`Skill "${name}" not found. Use the skill tool to list available skills or configure plugins in Settings > AI.`); } // Read and return the skill content const content = await readSkillContent(this.fs, skill); return `# Skill: ${skill.name} **Plugin**: ${skill.plugin} **Description**: ${skill.description} **Path**: ${skill.path} --- ${content}`; } catch (error) { if (error instanceof Error) { throw error; } throw new Error(`Failed to execute skill "${name}": ${String(error)}`); } } }