/** * Skill Service * * Manages AI agent skills including loading from directories, * CRUD operations, and skill matching for prompts. * * Skills are the evolution of the SOP (Standard Operating Procedures) system, * combining prompts, scripts, environment variables, and browser automation. * * @module services/skill/skill.service */ import { Skill, SkillWithPrompt, SkillSummary, CreateSkillInput, UpdateSkillInput, SkillFilter } from '../../types/skill.types.js'; /** * Options for initializing the SkillService */ export interface SkillServiceOptions { /** Directory containing built-in skills */ builtinSkillsDir?: string; /** Directory for user-created skills */ userSkillsDir?: string; /** Directory for marketplace-installed skills */ marketplaceSkillsDir?: string; } /** * Service for managing AI agent skills * * Handles: * - Loading built-in skills from config/skills/ * - Managing user-created skills in ~/.crewly/skills/ * - CRUD operations for skills * - Skill matching for prompts * - Integration with role service for skill assignment */ export declare class SkillService { private readonly builtinSkillsDir; private readonly userSkillsDir; private readonly marketplaceSkillsDir; private skillsCache; private initialized; private readonly logger; /** * Create a new SkillService instance * * @param options - Configuration options */ constructor(options?: SkillServiceOptions); /** * Initialize the service by loading all skills * * Creates user skills directory if it doesn't exist and loads * both built-in and user-defined skills into memory. */ initialize(): Promise; /** * Get all skills, optionally filtered * * @param filter - Optional filter criteria * @returns Array of skill summaries */ listSkills(filter?: SkillFilter): Promise; /** * Get a skill by ID with full prompt content * * @param id - Skill identifier * @returns Skill with prompt content or null if not found */ getSkill(id: string): Promise; /** * Get skills matching a prompt/input * * Used by agents to find relevant skills for a task. Scores skills * based on trigger matches, tag matches, name matches, and description * keyword matches. * * @param input - User input or prompt to match against * @param roleId - Optional role ID to filter by * @param maxResults - Maximum number of results to return (default: 5) * @returns Array of matching skills with prompt content, sorted by relevance */ matchSkills(input: string, roleId?: string, maxResults?: number): Promise; /** * Create a new user-defined skill * * @param input - Skill creation input * @returns The created skill * @throws SkillValidationError if input is invalid */ createSkill(input: CreateSkillInput): Promise; /** * Update an existing skill * * @param id - Skill identifier * @param input - Update input with partial skill data * @returns The updated skill * @throws SkillNotFoundError if skill doesn't exist * @throws BuiltinSkillModificationError if trying to modify a built-in skill */ updateSkill(id: string, input: UpdateSkillInput): Promise; /** * Delete a user-created skill * * @param id - Skill identifier * @throws SkillNotFoundError if skill doesn't exist * @throws BuiltinSkillModificationError if trying to delete a built-in skill */ deleteSkill(id: string): Promise; /** * Enable or disable a skill * * @param id - Skill identifier * @param enabled - Whether to enable or disable * @returns The updated skill */ setSkillEnabled(id: string, enabled: boolean): Promise; /** * Get skills assigned to a specific role * * @param roleId - Role identifier * @returns Array of skill summaries for the role */ getSkillsForRole(roleId: string): Promise; /** * Refresh skills from disk (reload) * * Clears the cache and reloads all skills from both * built-in and user directories. */ refresh(): Promise; /** * Get the count of all skills * * @returns Total number of skills in cache */ getSkillCount(): Promise; /** * Check if a skill exists * * @param id - Skill identifier * @returns True if skill exists */ skillExists(id: string): Promise; /** * Ensure the service is initialized before operations */ private ensureInitialized; /** * Ensure the user skills directory exists */ private ensureUserSkillsDir; /** * Load all skills from both builtin and user directories */ private loadAllSkills; /** * Check if a directory is a skill directory (has SKILL.md or legacy skill.json). * * @param dir - Directory path to check * @returns True if the directory contains a skill definition */ private isSkillDirectory; /** * Load skills from a directory * * Handles both flat structure (SKILL.md in immediate subdirs) * and nested category structure (category/skill/SKILL.md). * * @param dir - Directory path * @param isBuiltin - Whether these are built-in skills * @returns Array of loaded skills */ private loadSkillsFromDir; /** * Load skills from nested directories (category/skill structure) * * @param categoryDir - Category directory path * @param isBuiltin - Whether these are built-in skills * @returns Array of loaded skills from the category */ private loadNestedSkills; /** * Load a single skill from a directory. Tries SKILL.md first, * then falls back to legacy skill.json format. * * @param skillDir - Directory containing the skill * @param isBuiltin - Whether this is a built-in skill * @returns Loaded skill or null if loading fails */ private loadSkillFromDir; /** * Load a skill from SKILL.md format (YAML frontmatter + markdown body). * * @param skillDir - Directory containing the skill * @param skillMdPath - Path to SKILL.md file * @param isBuiltin - Whether this is a built-in skill * @returns Loaded skill or null if loading fails */ private loadSkillFromSkillMd; /** * Load a single skill from a legacy skill.json file. * * @param skillDir - Directory containing the skill * @param skillJsonPath - Path to skill.json file * @param isBuiltin - Whether this is a built-in skill * @returns Loaded skill or null if loading fails */ private loadSkillFromLegacyJson; /** * Load prompt content for a skill. * * For SKILL.md format, extracts the markdown body (after frontmatter). * For legacy format, reads the separate instructions.md file. * * @param skill - Skill to load prompt for * @returns Prompt content string */ private loadPromptContent; /** * Save a skill to disk in SKILL.md format (YAML frontmatter + markdown body). * * @param skill - Skill to save * @param promptContent - Optional prompt content (markdown body) */ private saveSkill; } /** * Error thrown when a skill is not found */ export declare class SkillNotFoundError extends Error { readonly skillId: string; /** * Create a SkillNotFoundError * * @param id - ID of the skill that was not found */ constructor(skillId: string); } /** * Error thrown when skill validation fails */ export declare class SkillValidationError extends Error { readonly errors: string[]; /** * Create a SkillValidationError * * @param errors - Array of validation error messages */ constructor(errors: string[]); } /** * Error thrown when attempting to modify a built-in skill */ export declare class BuiltinSkillModificationError extends Error { readonly action: string; /** * Create a BuiltinSkillModificationError * * @param action - The action that was attempted (e.g., 'update', 'delete') */ constructor(action: string); } /** * Get the singleton SkillService instance * * @returns The shared SkillService instance */ export declare function getSkillService(): SkillService; /** * Reset the singleton SkillService instance * * Used primarily for testing to ensure a clean state. */ export declare function resetSkillService(): void; //# sourceMappingURL=skill.service.d.ts.map