TIA / lineage.ts
DJ-Goanna-Coding's picture
Add TIA backend
a3aed04 verified
/**
* TIA-∞ Lineage Mapper
* Interprets the scanned QGTNL structure and reconstructs ancestry,
* drift, missing links, and module evolution patterns.
*/
import { ScanResult } from "./scanner";
export interface LineageNode {
path: string;
type: "file" | "directory";
depth: number;
children?: LineageNode[];
inferredRole?: string;
anomalies?: string[];
}
export interface LineageReport {
generatedAt: number;
root: LineageNode;
anomalies: string[];
}
function inferRole(node: ScanResult): string | undefined {
const p = node.path.toLowerCase();
if (p.includes("tia")) return "core-intelligence";
if (p.includes("aion")) return "temporal-engine";
if (p.includes("oracle")) return "predictive-engine";
if (p.includes("citadel")) return "infrastructure";
if (p.includes("holo3d")) return "visual-engine";
if (p.includes("api")) return "interface-layer";
if (p.includes("engine")) return "processing-layer";
if (p.includes("ui")) return "presentation-layer";
return undefined;
}
function detectAnomalies(node: ScanResult): string[] {
const issues: string[] = [];
if (node.type === "file" && node.size === 0) {
issues.push("empty-file");
}
if (node.type === "directory" && (!node.children || node.children.length === 0)) {
issues.push("empty-directory");
}
return issues;
}
function mapLineage(node: ScanResult, depth = 0): LineageNode {
const lineageNode: LineageNode = {
path: node.path,
type: node.type,
depth,
inferredRole: inferRole(node),
anomalies: detectAnomalies(node),
};
if (node.children) {
lineageNode.children = node.children.map((child) =>
mapLineage(child, depth + 1)
);
}
return lineageNode;
}
export function generateLineageReport(structure: ScanResult): LineageReport {
const root = mapLineage(structure);
const anomalies: string[] = [];
function collect(node: LineageNode) {
if (node.anomalies && node.anomalies.length > 0) {
anomalies.push(...node.anomalies.map((a) => `${node.path}: ${a}`));
}
if (node.children) {
node.children.forEach(collect);
}
}
collect(root);
return {
generatedAt: Date.now(),
root,
anomalies,
};
}