const FORBIDDEN_HISTORY_PATTERNS = /\b(npm run|stack trace|today I|current task|todo|temporary|raw output|password|secret|token)\b/i;
export function diagnoseContextDocument(document) {
    const diagnostics = [];
    const seenTerms = new Map();
    for (const term of document.terms) {
        const key = term.name.toLowerCase();
        const existing = seenTerms.get(key);
        if (existing && existing !== term.meaning) {
            diagnostics.push({
                severity: "warning",
                code: "duplicate-term-conflict",
                term: term.name,
                message: `Term "${term.name}" has multiple meanings.`,
                suggestion: "Merge the duplicate entries or clarify aliases/related terms.",
            });
        }
        seenTerms.set(key, term.meaning);
        if (FORBIDDEN_HISTORY_PATTERNS.test(`${term.name} ${term.meaning}`)) {
            diagnostics.push({
                severity: "warning",
                code: "ephemeral-or-sensitive-term",
                term: term.name,
                message: `Term "${term.name}" looks ephemeral, task-history-like, or sensitive.`,
                suggestion: "Remove raw progress, validation output, secrets, or task history from CONTEXT.md.",
            });
        }
    }
    if (!document.purpose.trim()) {
        diagnostics.push({
            severity: "info",
            code: "missing-purpose",
            message: "CONTEXT.md has no project purpose.",
            suggestion: "Add a stable project purpose in the Purpose section.",
        });
    }
    return diagnostics;
}
export function renderContextDiagnostics(diagnostics) {
    if (diagnostics.length === 0)
        return "CONTEXT.md diagnostics: OK";
    return [
        "CONTEXT.md diagnostics:",
        ...diagnostics.map((diagnostic) => {
            const term = diagnostic.term ? ` (${diagnostic.term})` : "";
            const suggestion = diagnostic.suggestion ? `\n  suggestion: ${diagnostic.suggestion}` : "";
            return `- ${diagnostic.severity} ${diagnostic.code}${term}: ${diagnostic.message}${suggestion}`;
        }),
    ].join("\n");
}
//# sourceMappingURL=context-diagnostics.js.map