import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
const TEMPLATE_PLACEHOLDER_PATTERN = /\{\{([a-zA-Z0-9_]+)\}\}/g;
const STATIC_PROMPT_PATHS = {
    "default-subagent-wrapper": "./prompts/default-subagent-wrapper.md",
    "diff-review-wrapper": "./prompts/diff-review-wrapper.md",
};
export function getStaticPromptPath(promptId) {
    return fileURLToPath(new URL(STATIC_PROMPT_PATHS[promptId], import.meta.url));
}
export function loadStaticPrompt(promptId) {
    return readFileSync(getStaticPromptPath(promptId), "utf8");
}
function interpolateTemplate(template, values) {
    const templatePlaceholders = Array.from(template.matchAll(TEMPLATE_PLACEHOLDER_PATTERN))
        .map((match) => match[1])
        .filter((key) => typeof key === "string");
    const uniqueTemplatePlaceholders = new Set(templatePlaceholders);
    const missingPlaceholders = Object.keys(values)
        .filter((key) => !uniqueTemplatePlaceholders.has(key))
        .map((key) => `{{${key}}}`);
    if (missingPlaceholders.length > 0) {
        throw new Error(`template is missing placeholders: ${missingPlaceholders.join(", ")}`);
    }
    const unresolvedPlaceholders = Array.from(uniqueTemplatePlaceholders)
        .filter((key) => !Object.hasOwn(values, key))
        .map((key) => `{{${key}}}`);
    if (unresolvedPlaceholders.length > 0) {
        throw new Error(`template has unresolved placeholders: ${unresolvedPlaceholders.join(", ")}`);
    }
    return template.replace(TEMPLATE_PLACEHOLDER_PATTERN, (_match, key) => values[key] ?? "");
}
const DEFAULT_SUBAGENT_WRAPPER_PROMPT = loadStaticPrompt("default-subagent-wrapper").trim();
const DIFF_REVIEW_WRAPPER_PROMPT = loadStaticPrompt("diff-review-wrapper").trim();
export function loadDefaultSubagentWrapperPrompt() {
    return DEFAULT_SUBAGENT_WRAPPER_PROMPT;
}
export function loadDiffReviewWrapperPrompt() {
    return DIFF_REVIEW_WRAPPER_PROMPT;
}
export function renderDefaultSubagentWrapperPrompt(args) {
    return interpolateTemplate(DEFAULT_SUBAGENT_WRAPPER_PROMPT, {
        inherited_instructions: args.inheritedInstructions.trim(),
    });
}
export function renderDiffReviewWrapperPrompt(args) {
    return interpolateTemplate(DIFF_REVIEW_WRAPPER_PROMPT, {
        inherited_instructions: args.inheritedInstructions.trim(),
        review_context: args.reviewContext.trim(),
    });
}
//# sourceMappingURL=index.js.map