"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PROMPT_RENDER_LANE_ORDER = void 0;
exports.collectPromptRenderingEvidence = collectPromptRenderingEvidence;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const canonical_policy_1 = require("./canonical-policy");
const trust_lanes_1 = require("./trust-lanes");
exports.PROMPT_RENDER_LANE_ORDER = [
    "generated context",
    "agent entrypoint guidance",
    "warnings",
    "prompt instructions"
];
function collectPromptRenderingEvidence(options) {
    const agentEntrypointPath = ".day-shift/agents.md";
    const agentEntrypointAbsolutePath = node_path_1.default.join(options.repositoryRoot, agentEntrypointPath);
    const agentEntrypointPresent = node_fs_1.default.existsSync(agentEntrypointAbsolutePath);
    const missingAgentEntrypoint = options.requireAgentEntrypoint && !agentEntrypointPresent && !options.degradedNoAgent
        ? `Agent entrypoint '${agentEntrypointPath}' is missing.`
        : null;
    const degradedMode = options.degradedNoAgent
        ? "Agent entrypoint guidance omitted by explicit --no-agent degraded mode."
        : null;
    return {
        surfaceMode: "reporting",
        visibleLaneOrder: exports.PROMPT_RENDER_LANE_ORDER,
        trustLanes: [
            { surfaceLane: "generated context", source: (0, trust_lanes_1.getTrustLane)("generated-evidence") },
            { surfaceLane: "agent entrypoint guidance", source: (0, trust_lanes_1.getTrustLane)("product-policy") },
            { surfaceLane: "warnings", source: (0, trust_lanes_1.getTrustLane)("generated-evidence") },
            { surfaceLane: "prompt instructions", source: (0, trust_lanes_1.getTrustLane)("product-policy") }
        ],
        generatedContext: {
            requestedPromptPath: options.requestedPromptPath,
            resolvedPromptPath: options.resolvedPromptPath,
            resolvedLayer: options.resolvedLayer,
            sourceFamily: options.sourceFamily
                ?? (options.resolvedLayer === "packaged-default" ? "package" : "workspace"),
            fallbackTrace: options.fallbackTrace,
            userLayerDestinationPath: options.userLayerDestinationPath
                ?? options.requestedPromptPath,
            canonicalPolicy: (0, canonical_policy_1.composeCanonicalPolicy)({
                ruleIds: options.policyRuleIds ?? canonical_policy_1.DEFAULT_PROMPT_POLICY_RULE_IDS,
                taskDelta: options.taskPolicyDelta
            })
        },
        agentEntrypointGuidance: {
            path: agentEntrypointPath,
            present: agentEntrypointPresent,
            requiredForSurface: options.requireAgentEntrypoint,
            missingBehavior: "fail-by-default-when-required"
        },
        warnings: {
            promptResolution: options.promptResolutionWarning,
            missingAgentEntrypoint,
            degradedMode
        },
        promptInstructions: {
            path: options.promptInstructionsPath
        },
        degradedMode: {
            requested: options.degradedNoAgent,
            explicitFlag: "--no-agent",
            allowedOnlyWhenExplicit: true
        },
        unresolvedTokenPattern: "{{[a-z_][a-z0-9_]*}}"
    };
}
