TIA / resurrection.ts
DJ-Goanna-Coding's picture
Add TIA backend
a3aed04 verified
/**
* TIA-∞ Resurrection Engine
* Analyzes lineage data to detect fragments, partial modules,
* abandoned structures, and missing siblings. Produces a safe,
* non-destructive proposal list for Guided Builder mode.
*/
import { LineageNode, LineageReport } from "./lineage";
export interface ResurrectionProposal {
path: string;
issue: string;
recommendedAction: string;
}
export interface ResurrectionPlan {
generatedAt: number;
proposals: ResurrectionProposal[];
}
function analyzeNode(node: LineageNode, proposals: ResurrectionProposal[]) {
// Detect empty files
if (node.anomalies?.includes("empty-file")) {
proposals.push({
path: node.path,
issue: "empty-file",
recommendedAction: "rebuild-file",
});
}
// Detect empty directories
if (node.anomalies?.includes("empty-directory")) {
proposals.push({
path: node.path,
issue: "empty-directory",
recommendedAction: "populate-directory",
});
}
// Detect missing siblings (heuristic)
if (node.inferredRole === "processing-layer" && !node.children) {
proposals.push({
path: node.path,
issue: "missing-engine-components",
recommendedAction: "reconstruct-engine-module",
});
}
// Detect suspicious naming drift
if (node.path.toLowerCase().includes("inde.x")) {
proposals.push({
path: node.path,
issue: "naming-drift",
recommendedAction: "rename-to-index.ts",
});
}
// Recurse
if (node.children) {
node.children.forEach((child) => analyzeNode(child, proposals));
}
}
export function generateResurrectionPlan(report: LineageReport): ResurrectionPlan {
const proposals: ResurrectionProposal[] = [];
analyzeNode(report.root, proposals);
return {
generatedAt: Date.now(),
proposals,
};
}