// engine/dependency-detector.ts — Auto-detect SPEC-NNN cross-references from spec content.
// Parses text to find explicit SPEC-ID mentions instead of relying on manual declarations.
/** Pattern that matches SPEC-NNN references (word-boundary anchored). */
const SPEC_REF_PATTERN = /\bSPEC-(\d+)\b/g;
/**
 * Extract all SPEC-NNN references found in the given text content.
 * Deduplicates results — each ID appears at most once.
 */
export function detectSpecReferences(content) {
    const matches = new Set();
    for (const match of content.matchAll(SPEC_REF_PATTERN)) {
        // match[1] is the captured group (the digits), always defined here
        const digits = match[1];
        if (digits !== undefined) {
            matches.add(`SPEC-${digits}`);
        }
    }
    return Array.from(matches);
}
/**
 * Given a spec's content, find which other existing specs it references.
 * Self-references and references to unknown specs are filtered out.
 * Returns only specs that actually exist in allSpecIds.
 */
export function suggestDependencies(specId, specContent, technicalContent, allSpecIds) {
    const combined = `${specContent} ${technicalContent}`;
    const refs = detectSpecReferences(combined);
    return refs
        .filter((id) => id !== specId && allSpecIds.includes(id))
        .map((id) => ({ specId: id, confidence: 'explicit' }));
}
//# sourceMappingURL=dependency-detector.js.map