import { relative } from "node:path";
import { AdrService } from "../memory/adr/adr-service.js";
const FALLBACK_THREADSUITE_ADR_CANDIDATES = [
    {
        title: "ThreadSuite bootstrap",
        context: "ThreadSuite performed a bounded project inventory and generated durable project knowledge scaffolding.",
        decision: "Use ThreadSuite as the project bootstrap entrypoint for bounded inventory, continuity/context files, memory capsules, and ADR candidates.",
        consequences: "Threadwell can start future sessions from durable project knowledge before broad repository exploration. Generated facts remain inferred until reviewed.",
    },
    {
        title: "Complete ThreadSuite is the default bootstrap profile",
        context: "ThreadSuite supports complete and lite profiles.",
        decision: "Make bare `/threadsuite` run the complete profile and require `lite` for the intentionally smaller bootstrap.",
        consequences: "The default gives the agent the richest safe project intelligence. Users can still choose lite when they want less generated scaffolding.",
    },
];
export function bootstrapThreadSuiteAdrs(cwd, inventory, options, semanticDiscovery, synthesis) {
    if (options.profile === "lite")
        return [{ path: "docs/adr", action: "skipped", title: "ThreadSuite ADR bootstrap" }];
    const candidates = synthesis?.adrCandidates.length
        ? synthesis.adrCandidates.map((candidate) => ({
            title: candidate.title,
            context: `${candidate.context}\n\nEvidence: ${candidate.evidence.join(", ") || "none cited"}`,
            decision: candidate.decision,
            consequences: candidate.consequences,
            evidence: candidate.evidence,
        }))
        : FALLBACK_THREADSUITE_ADR_CANDIDATES.map((candidate) => ({
            ...candidate,
            context: `${candidate.context}\n${buildFallbackAdrContext(inventory, semanticDiscovery)}`,
        }));
    return writeAdrCandidates(cwd, options, candidates);
}
function writeAdrCandidates(cwd, options, candidates) {
    const adrService = new AdrService({ projectRoot: cwd });
    const existingRecords = Object.values(adrService.getIndex()).flat();
    return candidates.map((candidate) => {
        const existing = existingRecords.find((record) => record.title === candidate.title);
        if (existing && !options.reset) {
            return {
                path: existing.path ? relative(cwd, existing.path).replaceAll("\\", "/") : "docs/adr",
                action: "preserved",
                title: existing.title,
            };
        }
        const record = adrService.createProposedAdr({
            title: candidate.title,
            context: candidate.context,
            decision: `${candidate.decision} This ADR is proposed and must be reviewed before acceptance.`,
            consequences: candidate.consequences,
            links: ["CONTEXT.md", "STATE.md", "ACTIVE_QUEUE.md", "AUTONOMOUS_EXECUTION.md", ...(candidate.evidence ?? [])],
        });
        return {
            path: record.path ? relative(cwd, record.path).replaceAll("\\", "/") : "docs/adr",
            action: "created",
            title: record.title,
        };
    });
}
function buildFallbackAdrContext(inventory, semanticDiscovery) {
    return [
        `Detected project type: ${inventory.projectType}.`,
        `Project purpose: ${semanticDiscovery.projectPurpose.value}.`,
        "This decision is inferred from bootstrap behavior and should be reviewed by the user before acceptance.",
    ].join("\n");
}
//# sourceMappingURL=adr-bootstrap.js.map