/** * TIA-∞ Drift Detector * Identifies structural inconsistencies, version drift, naming mismatches, * outdated modules, and evolution gaps within the QGTNL ecosystem. */ import { LineageNode, LineageReport } from "./lineage"; export interface DriftIssue { path: string; type: string; description: string; } export interface DriftReport { generatedAt: number; issues: DriftIssue[]; } function detectNamingDrift(node: LineageNode, issues: DriftIssue[]) { const p = node.path.toLowerCase(); if (p.includes("inde.x")) { issues.push({ path: node.path, type: "naming-drift", description: "Suspicious filename detected (inde.x). Expected: index.ts", }); } if (p.endsWith(".ts") && p.includes(" ")) { issues.push({ path: node.path, type: "invalid-filename", description: "Filename contains spaces, which may break imports.", }); } } function detectStructuralDrift(node: LineageNode, issues: DriftIssue[]) { if (node.inferredRole === "processing-layer" && !node.children) { issues.push({ path: node.path, type: "incomplete-engine", description: "Engine module appears incomplete or missing components.", }); } if (node.inferredRole === "presentation-layer" && !node.children) { issues.push({ path: node.path, type: "incomplete-ui", description: "UI module appears incomplete or missing components.", }); } } function detectVersionDrift(node: LineageNode, issues: DriftIssue[]) { if (node.path.toLowerCase().includes("old") || node.path.toLowerCase().includes("backup")) { issues.push({ path: node.path, type: "version-drift", description: "Legacy or backup module detected. May require merging or cleanup.", }); } } function walk(node: LineageNode, issues: DriftIssue[]) { detectNamingDrift(node, issues); detectStructuralDrift(node, issues); detectVersionDrift(node, issues); if (node.children) { node.children.forEach((child) => walk(child, issues)); } } export function generateDriftReport(report: LineageReport): DriftReport { const issues: DriftIssue[] = []; walk(report.root, issues); return { generatedAt: Date.now(), issues, }; }