import { readPaseoConfigJson } from "./paseo-config-file.js";
import { PaseoConfigSchema } from "@kong-link/protocol/paseo-config-schema";
import { wrapWithUserInstructions } from "./wrap-user-instructions.js";
export async function buildMetadataPrompt(options) {
    const instructions = await readProjectMetadataInstructions(options);
    const head = isNonEmptyString(instructions)
        ? wrapWithUserInstructions(options.before, instructions, options.after)
        : `${options.before}\n${options.after}`;
    return options.trailing ? `${head}\n\n${options.trailing}` : head;
}
async function readProjectMetadataInstructions(options) {
    if (!options.workspaceGitService) {
        return undefined;
    }
    try {
        const repoRoot = await options.workspaceGitService.resolveRepoRoot(options.cwd);
        const json = readPaseoConfigJson(repoRoot);
        const config = PaseoConfigSchema.parse(json);
        return config.metadataGeneration?.[options.configKey]?.instructions;
    }
    catch {
        return undefined;
    }
}
function isNonEmptyString(value) {
    return typeof value === "string" && value.trim() !== "";
}
//# sourceMappingURL=build-metadata-prompt.js.map