diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index b56d2b6e..01e3e3b0 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -59,6 +59,7 @@ import { buildMessageContent } from '@/lib/buildMessageContent'; import { DotAI } from '@/lib/DotAI'; import { parseProviderModel } from '@/lib/parseProviderModel'; import { AIMessage } from '@/lib/SessionManager'; +import { getAllSkills } from '@/lib/skills'; // Clean interfaces now handled by proper hooks @@ -106,6 +107,7 @@ export const ChatPane = forwardRef(({ const [templateInfo, setTemplateInfo] = useState<{ name: string; description: string; url: string } | null>(null); const [showTemplateInfo, setShowTemplateInfo] = useState(false); const [showToolsDialog, setShowToolsDialog] = useState(false); + const [availableSkills, setAvailableSkills] = useState>([]); // Determine which error to show - AI errors take priority over console errors // since they are more immediately relevant to the user's current action @@ -176,6 +178,19 @@ export const ChatPane = forwardRef(({ queryClient.invalidateQueries({ queryKey: ['git-sync', cwd] }); }, [queryClient, cwd]); + // Load available skills + useEffect(() => { + const loadSkills = async () => { + const skills = await getAllSkills(fs, pluginsPath, cwd); + setAvailableSkills(skills); + }; + + loadSkills().catch(err => { + console.error('Failed to load skills:', err); + setAvailableSkills([]); + }); + }, [fs, pluginsPath, cwd]); + // Fetch MCP tools const { tools: mcpOpenAITools, clients: mcpClients } = useMCPTools(); @@ -204,7 +219,7 @@ export const ChatPane = forwardRef(({ nostr_publish_events: new NostrPublishEventsTool(), shell: new ShellTool(fs, cwd, git, config.corsProxy, user?.signer), read_console_messages: new ReadConsoleMessagesTool(), - skill: new SkillTool(fs, pluginsPath, cwd), + skill: new SkillTool(fs, availableSkills), webfetch: new WebFetchTool({ corsProxy: config.corsProxy }), websearch: new WebSearchTool(), todowrite: new TodoWriteTool(fs, projectId, { projectsPath }), @@ -260,7 +275,7 @@ export const ChatPane = forwardRef(({ } return tools; - }, [fs, git, cwd, user, projectsPath, tmpPath, pluginsPath, config.corsProxy, settings, aiSettings, models, handleFileChanged, handleCommit, projectId]); + }, [fs, git, cwd, user, projectsPath, tmpPath, config.corsProxy, settings, aiSettings, models, handleFileChanged, handleCommit, projectId, availableSkills]); // MCP tools wrapped for execution const mcpToolWrappers = useMemo(() => createMCPTools(mcpClients), [mcpClients]); diff --git a/src/lib/tools/SkillTool.ts b/src/lib/tools/SkillTool.ts index c7476231..58a1efca 100644 --- a/src/lib/tools/SkillTool.ts +++ b/src/lib/tools/SkillTool.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; import type { Tool, ToolResult } from './Tool'; import type { JSRuntimeFS } from '../JSRuntime'; -import { findSkill, readSkillContent } from '../skills'; +import { readSkillContent, type Skill } from '../skills'; interface SkillParams { name: string; @@ -9,45 +9,65 @@ interface SkillParams { export class SkillTool implements Tool { private fs: JSRuntimeFS; - private pluginsPath: string; - private projectPath: string; - - readonly description = 'Load and execute a skill from the configured plugins or project. Skills are reusable AI workflows that can be invoked by name.'; + private availableSkills: Skill[]; + readonly description: string; readonly inputSchema = z.object({ - name: z.string().describe('The name of the skill to execute (lowercase alphanumeric with hyphens)'), + name: z.string().describe('The skill identifier from available_skills'), }); - constructor(fs: JSRuntimeFS, pluginsPath: string, projectPath: string) { + /** + * Create a SkillTool instance. + * @param fs - Filesystem instance + * @param availableSkills - List of available skills (should be pre-loaded) + */ + constructor(fs: JSRuntimeFS, availableSkills: Skill[]) { this.fs = fs; - this.pluginsPath = pluginsPath; - this.projectPath = projectPath; + this.availableSkills = availableSkills; + this.description = this.generateDescription(availableSkills); + } + + /** + * Generate description text for SkillTool based on available skills. + */ + private generateDescription(skills: Skill[]): string { + if (skills.length === 0) { + return 'Load a skill to get detailed instructions for a specific task. No skills are currently available.'; + } + + return [ + 'Load a skill to get detailed instructions for a specific task.', + 'Skills provide specialized knowledge and step-by-step guidance.', + 'Use this when a task matches an available skill\'s description.', + '', + ...skills.map(skill => + ` \n ${skill.name}\n ${skill.description}\n ` + ), + '', + ].join('\n'); } async execute(args: SkillParams): Promise { const { name } = args; try { - // Find the skill across all plugins and project - const skill = await findSkill(this.fs, this.pluginsPath, this.projectPath, name); + // Find the skill in the pre-loaded list + const skill = this.availableSkills.find(s => s.name === name); if (!skill) { - throw new Error(`Skill "${name}" not found. Use the skill tool to list available skills or configure plugins in Settings > AI.`); + const available = this.availableSkills.map(s => s.name).join(', '); + throw new Error(`Skill "${name}" not found. Available skills: ${available || 'none'}`); } // Read and return the skill content const content = await readSkillContent(this.fs, skill); return { - content: `# Skill: ${skill.name} + content: `## Skill: ${skill.name} -**Source**: ${skill.plugin === 'project' ? 'Project' : `Plugin: ${skill.plugin}`} -**Description**: ${skill.description} -**Path**: ${skill.path} +**Base directory**: ${skill.path} ---- - -${content}` +${content.trim()}` }; } catch (error) { if (error instanceof Error) {