// ---------------------------------------------------------------------------
// Prompt registry + variable resolver
//
// Prompts are template strings stored in this directory, one file per agent.
// Variables are resolved at call time using {{variable_name}} syntax.
//
// Future: swap template strings for .md files with a build-time copy step.
// ---------------------------------------------------------------------------

const _prompts = new Map<string, string>();

export function registerPrompt(id: string, template: string): void {
    _prompts.set(id, template);
}

/**
 * Resolve a prompt template by ID, substituting {{variable}} placeholders.
 * Missing variables are replaced with an empty string.
 */
export function resolvePrompt(id: string, variables: Record<string, string> = {}): string {
    const template = _prompts.get(id);
    if (!template) throw new Error(`Prompt not found: "${id}"`);
    return template.replace(/\{\{(\w+)\}\}/g, (_, key) => variables[key] ?? '');
}

export function hasPrompt(id: string): boolean {
    return _prompts.has(id);
}
