"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_AGENT_ENTRYPOINT_SOURCE_PATH = exports.DEFAULT_AGENT_ENTRYPOINT_PATH = void 0;
exports.scaffoldAgentEntrypoint = scaffoldAgentEntrypoint;
exports.renderDefaultAgentEntrypoint = renderDefaultAgentEntrypoint;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const cli_constants_1 = require("../config/cli-constants");
const runtime_contract_1 = require("../runtime/runtime-contract");
const default_assets_1 = require("./default-assets");
exports.DEFAULT_AGENT_ENTRYPOINT_PATH = node_path_1.default.posix.join(runtime_contract_1.DAY_SHIFT_DIRECTORY_NAME, runtime_contract_1.AGENT_ENTRYPOINT_FILE_NAME);
exports.DEFAULT_AGENT_ENTRYPOINT_SOURCE_PATH = node_path_1.default.posix.join(runtime_contract_1.DAY_SHIFT_DIRECTORY_NAME, "scaffolds", "agents.init.md");
function scaffoldAgentEntrypoint(options) {
    const scaffoldAgentEntrypoint = options.scaffoldAgentEntrypoint ?? true;
    const agentEntrypointPath = exports.DEFAULT_AGENT_ENTRYPOINT_PATH;
    const absolutePath = node_path_1.default.join(options.repositoryRoot, agentEntrypointPath);
    if (!scaffoldAgentEntrypoint) {
        return {
            agentEntrypointPath,
            created: false,
            skippedReason: "disabled"
        };
    }
    if (node_fs_1.default.existsSync(absolutePath)) {
        return {
            agentEntrypointPath,
            created: false,
            skippedReason: "exists"
        };
    }
    node_fs_1.default.writeFileSync(absolutePath, renderDefaultAgentEntrypoint(), "utf8");
    return {
        agentEntrypointPath,
        created: true,
        skippedReason: null
    };
}
function renderDefaultAgentEntrypoint(options = {}) {
    const fallbackContents = [
        "# Day Shift Agent Entrypoint",
        "",
        "Use Day Shift artifacts in this repository to plan and execute work with clear traceability.",
        "",
        "## Planning Root",
        "",
        "- `.day-shift/planning/basic/`",
        "- `.day-shift/planning/structured/`",
        "- `.day-shift/planning/governed/`",
        "",
        "## Core Shared Paths",
        "",
        "- `.day-shift/prompts/`",
        "- `.day-shift/templates/`",
        "- `.day-shift/workflows/`",
        `- \`${cli_constants_1.CLI_SPEC_INDEX_PATH}\``,
        ""
    ].join("\n");
    const packageRoot = options.packageRoot ?? (0, default_assets_1.resolvePackageRootFromWorkspaceInitModuleDirectory)(__dirname);
    for (const relativePath of [exports.DEFAULT_AGENT_ENTRYPOINT_SOURCE_PATH, exports.DEFAULT_AGENT_ENTRYPOINT_PATH]) {
        const absolutePath = node_path_1.default.join(packageRoot, ...relativePath.split("/"));
        if (node_fs_1.default.existsSync(absolutePath) && node_fs_1.default.statSync(absolutePath).isFile()) {
            return node_fs_1.default.readFileSync(absolutePath, "utf8");
        }
    }
    return fallbackContents;
}
