/** * Skill Invoker — Central orchestrator for skill invocation flow. * * This module consolidates the skill invocation logic that was previously * scattered across the CLI (src/index.ts) and agent (src/agent.ts). * * Invocation flow: * 1. Parse input → extract skill name and arguments * 2. Registry lookup → resolve skill metadata * 3. @path resolution → inline file references * 4. Prompt construction → build the final prompt * 5. Return result with provider switching metadata * * The invoker does NOT handle provider switching itself — it returns * metadata so the adapter can decide whether to switch. */ import { type SkillRegistry } from '../skills/types.js'; import { type SkillMetadata } from './types.js'; import type { LLMProvider } from '../providers/types.js'; /** * Result of a skill invocation. * * Contains the constructed prompt along with metadata about * whether the skill has a preferred provider/model configuration. */ export interface SkillInvocationResult { /** The constructed prompt to send to the agent */ prompt: string; /** Resolved skill metadata */ skill: SkillMetadata; /** Whether the skill has a preferredProvider that needs switching */ providerSwitchNeeded: boolean; /** The preferred provider type (if any) */ preferredProvider?: string; /** The preferred model (if any) */ preferredModel?: string; } /** * Invoke a skill by name with the provided arguments. * * This function orchestrates the complete skill invocation flow: * 1. Parses the input to extract skill name and arguments * 2. Looks up the skill in the registry * 3. Substitutes arguments into the skill body * 4. Resolves @path references * 5. Constructs the final prompt * 6. Returns metadata about provider switching if needed * * @param options - Invocation options * @param options.input - Raw "/skillname args" input from user * @param options.registry - The skill registry to look up skills from * @param options.skillsPath - Optional path for @path resolution (defaults to cwd) * @returns SkillInvocationResult or null if no skill matches * * @example * ```ts * const result = await invokeSkill({ * input: '/code-review src/app.ts', * registry: skillRegistry, * }); * * if (result) { * if (result.providerSwitchNeeded) { * await switchProvider(result.preferredProvider!, result.preferredModel!); * } * await agent.chat(result.prompt); * } * ``` */ export declare function invokeSkill(options: { input: string; registry: SkillRegistry; skillsPath?: string; }): Promise; /** * Configuration for creating a skill provider switcher. */ export interface ProviderSwitcherConfig { /** The current active provider */ provider: LLMProvider; /** The current active model name */ model: string; /** Available model configurations keyed by provider type */ models: Record; } /** * A switcher that temporarily changes the active provider/model based on * skill preferences and can restore the original when done. */ export interface SkillProviderSwitcher { /** Switch provider if the skill requires it. Returns true if switched. */ switchIfNeeded(skillResult: SkillInvocationResult): Promise; /** Restore the original provider/model. */ restore(): void; /** The current active provider. */ readonly activeProvider: LLMProvider; /** The current active model name. */ readonly activeModel: string; } /** * Create a skill provider switcher that captures the original provider/model * state and can temporarily switch based on skill preferences. * * The switcher gracefully handles errors — if provider creation fails, * `switchIfNeeded` returns `false` instead of throwing. * * @example * ```ts * const switcher = createSkillProviderSwitcher({ * provider: currentProvider, * model: 'gpt-4', * models: config.models, * }); * * const switched = await switcher.switchIfNeeded(skillResult); * try { * await agent.chat(skillResult.prompt); * } finally { * if (switched) switcher.restore(); * } * ``` */ export declare function createSkillProviderSwitcher(config: ProviderSwitcherConfig): SkillProviderSwitcher;