File size: 2,243 Bytes
a3aed04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
 * 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,
  };
}