"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MCP_RESOLUTION_ISSUE_MARKER = exports.MCP_RESOLUTION_SYSTEM_WORKFLOW_TEMPLATE = void 0;
exports.buildMcpResolutionIssueBody = buildMcpResolutionIssueBody;
exports.isMcpResolutionIssueBody = isMcpResolutionIssueBody;
exports.isMcpResolutionIssueDraft = isMcpResolutionIssueDraft;
exports.buildMcpResolutionProcessLines = buildMcpResolutionProcessLines;
exports.buildMcpResolutionDoneWhenLines = buildMcpResolutionDoneWhenLines;
const markdown_1 = require("../core/markdown");
const catalog_1 = require("../i18n/catalog");
exports.MCP_RESOLUTION_SYSTEM_WORKFLOW_TEMPLATE = "__system/mcp-resolution.md";
exports.MCP_RESOLUTION_ISSUE_MARKER = "<!-- alpaca-mcp-resolution-issue -->";
function buildMcpResolutionIssueBody(input) {
    return [
        exports.MCP_RESOLUTION_ISSUE_MARKER,
        "",
        `## ${(0, catalog_1.translate)(input.locale, "mcp.resolution.heading.capability")}`,
        ...(0, markdown_1.renderMarkdownCodeBlock)(input.capability, "text"),
        ...(input.originalRequest === undefined
            ? []
            : [
                "",
                `## ${(0, catalog_1.translate)(input.locale, "mcp.resolution.heading.originalRequest")}`,
                ...(0, markdown_1.renderMarkdownCodeBlock)(input.originalRequest, "text"),
            ]),
        "",
        `## ${(0, catalog_1.translate)(input.locale, "mcp.resolution.heading.targetWorkers")}`,
        ...formatMcpResolutionTargets(input).map((target) => `- ${target}`),
        ...(input.origin === undefined
            ? []
            : [
                "",
                `## ${(0, catalog_1.translate)(input.locale, "mcp.resolution.heading.origin")}`,
                input.origin,
            ]),
        "",
        buildMcpResolutionProcessSection({ locale: input.locale }),
        "",
        buildMcpResolutionDoneWhenSection({ locale: input.locale }),
    ].join("\n");
}
function isMcpResolutionIssueBody(body) {
    return body.trimStart().startsWith(exports.MCP_RESOLUTION_ISSUE_MARKER);
}
function isMcpResolutionIssueDraft(input) {
    const workflowSelection = input.workflowOptions?.workflowSelection;
    return (isMcpResolutionIssueBody(input.body) &&
        workflowSelection?.mode === "template" &&
        workflowSelection.templatePath === exports.MCP_RESOLUTION_SYSTEM_WORKFLOW_TEMPLATE);
}
function buildMcpResolutionProcessSection(input) {
    return [
        `## ${(0, catalog_1.translate)(input.locale, "mcp.resolution.heading.requiredAction")}`,
        ...buildMcpResolutionProcessLines({ locale: input.locale }),
    ].join("\n");
}
function buildMcpResolutionProcessLines(input) {
    return translateList(input.locale, MCP_RESOLUTION_PROCESS_KEYS);
}
function buildMcpResolutionDoneWhenSection(input) {
    return [
        `## ${(0, catalog_1.translate)(input.locale, "mcp.resolution.heading.doneWhen")}`,
        ...buildMcpResolutionDoneWhenLines({ locale: input.locale }),
    ].join("\n");
}
function buildMcpResolutionDoneWhenLines(input) {
    return translateList(input.locale, MCP_RESOLUTION_DONE_WHEN_KEYS);
}
const MCP_RESOLUTION_PROCESS_KEYS = [
    "mcp.resolution.process.inspectSkills",
    "mcp.resolution.process.useSkillWhenBetter",
    "mcp.resolution.process.inspectConfigured",
    "mcp.resolution.process.inspectCatalog",
    "mcp.resolution.process.search",
    "mcp.resolution.process.installSafe",
    "mcp.resolution.process.catalogFirst",
    "mcp.resolution.process.officialDocs",
    "mcp.resolution.process.providerHelp",
    "mcp.resolution.process.noSecrets",
    "mcp.resolution.process.envNamesOnly",
    "mcp.resolution.process.verify",
    "mcp.resolution.process.authHandoff",
    "mcp.resolution.process.updateWorkflow",
    "mcp.resolution.process.lint",
];
const MCP_RESOLUTION_DONE_WHEN_KEYS = [
    "mcp.resolution.doneWhen.capabilitySatisfied",
    "mcp.resolution.doneWhen.noSecrets",
    "mcp.resolution.doneWhen.safeInstall",
    "mcp.resolution.doneWhen.verified",
    "mcp.resolution.doneWhen.workflowRefs",
    "mcp.resolution.doneWhen.lint",
];
function translateList(locale, keys) {
    return keys.map((key) => (0, catalog_1.translate)(locale, key));
}
function formatMcpResolutionTargets(input) {
    return input.target === "all" ? [...input.configuredWorkers] : [input.target];
}
