"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderDedicatedPromptHeader = renderDedicatedPromptHeader;
exports.renderDedicatedPromptEnvelope = renderDedicatedPromptEnvelope;
exports.renderDedicatedWorkspaceFields = renderDedicatedWorkspaceFields;
exports.renderDedicatedPromptInputLines = renderDedicatedPromptInputLines;
exports.renderDedicatedUserPromptBlock = renderDedicatedUserPromptBlock;
exports.renderStructuredSummary = renderStructuredSummary;
const render_1 = require("../system-prompts/render");
const prompt_contract_section_1 = require("./prompt-contract-section");
const prompt_text_1 = require("./prompt-text");
function renderDedicatedPromptHeader(input) {
    const subagentLines = input.allowSubagents === false
        ? []
        : [
            prompt_text_1.PROMPT_TEXT.subagentCommon,
            input.workerName === "codex"
                ? prompt_text_1.PROMPT_TEXT.subagentCodex
                : prompt_text_1.PROMPT_TEXT.subagentClaude,
        ];
    return [
        prompt_text_1.PROMPT_TEXT.sectionAuthoritativeInstructions,
        prompt_text_1.PROMPT_TEXT.introOperating,
        input.runDescription,
        ...input.instructionLines,
        prompt_text_1.PROMPT_TEXT.introNoWorkerCommitOrPush,
        ...subagentLines,
        prompt_text_1.PROMPT_TEXT.introReturnDecision,
        ...(0, render_1.renderSystemPromptGuidance)({
            prompts: input.systemPrompts,
            names: input.systemPromptNames ?? [],
        }),
        "",
    ];
}
function renderDedicatedPromptEnvelope(input) {
    return [
        ...input.preambleLines,
        ...renderDedicatedRepairSection(input.repairLines),
        ...input.inputLines,
        "",
        ...renderDedicatedPromptContractSection(input.contract),
    ].join("\n");
}
function renderDedicatedRepairSection(repairLines) {
    return repairLines
        ? [prompt_text_1.PROMPT_TEXT.sectionRepairAttempt, ...repairLines, ""]
        : [];
}
function renderDedicatedWorkspaceFields(input) {
    return [
        `- Repository root: ${input.repositoryRoot}`,
        `- Workspace path: ${input.workspacePath}`,
        `- Output language: ${input.outputLanguage}`,
    ];
}
function renderDedicatedPromptInputLines(input) {
    return [
        input.heading,
        ...renderDedicatedUserPromptBlock(input.prompt),
        ...renderDedicatedWorkspaceFields(input.workspace),
    ];
}
function renderDedicatedUserPromptBlock(prompt) {
    return ["- User prompt:", "```text", prompt || prompt_text_1.PROMPT_TEXT.empty, "```"];
}
function renderStructuredSummary(summary) {
    if (summary.trim().length === 0 || summary === prompt_text_1.PROMPT_TEXT.none) {
        return [`  ${prompt_text_1.PROMPT_TEXT.none}`];
    }
    return ["```json", ...summary.split("\n"), "```"];
}
function renderDedicatedPromptContractSection(input) {
    return (0, prompt_contract_section_1.renderPromptContractSection)({
        ...input,
        trailingBlankLine: true,
    });
}
