// Layer 7: Folder Intelligence Engine // Detects projection / stereo / passthrough / fisheye patterns in folder paths. import { FOLDER_PATTERNS, LayerResult, Projection, Stereo, LensType } from "../types"; export interface FolderAnalysis { projection: Projection | null; stereo: Stereo | null; lens: LensType | null; passthrough: boolean; matchedFolders: string[]; } export function analyzeFolder(folderPath: string): LayerResult { const lower = folderPath.toLowerCase(); const segments = lower.split("/").filter(Boolean); const matched: string[] = []; // Boundary-aware matcher for short tokens (ar, mr, ou, tb). const boundaryMatch = (text: string, token: string): boolean => { if (token.length <= 3) { const re = new RegExp(`(^|[^a-z0-9])${token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^a-z0-9]|$)`, "i"); return re.test(text); } return text.includes(token); }; let projection: Projection | null = null; let stereo: Stereo | null = null; let lens: LensType | null = null; let passthrough = false; for (const seg of segments) { if (FOLDER_PATTERNS.passthrough.some((p) => boundaryMatch(seg, p))) { passthrough = true; matched.push(`passthrough:${seg}`); } if (FOLDER_PATTERNS.vr180.some((p) => boundaryMatch(seg, p)) && !projection) { projection = "vr180"; matched.push(`projection:${seg}`); } if (FOLDER_PATTERNS.vr360.some((p) => boundaryMatch(seg, p)) && !projection) { projection = "vr360"; matched.push(`projection:${seg}`); } if (FOLDER_PATTERNS.sbs.some((p) => boundaryMatch(seg, p)) && !stereo) { stereo = "sbs"; matched.push(`stereo:${seg}`); } if (FOLDER_PATTERNS.ou.some((p) => boundaryMatch(seg, p)) && !stereo) { stereo = "ou"; matched.push(`stereo:${seg}`); } if ( FOLDER_PATTERNS.fisheye.some((p) => boundaryMatch(seg, p)) && !lens ) { // Dual fisheye if the folder explicitly says "dual" lens = seg.includes("dual") ? "dual_fisheye" : "fisheye"; matched.push(`lens:${seg}`); } } const categoryCount = [ projection !== null, stereo !== null, lens !== null, passthrough, ].filter(Boolean).length; const confidence = Math.min(0.4 + categoryCount * 0.1, 0.75); return { layer: 7, name: "Folder Intelligence", confidence, source: "folder", data: { projection, stereo, lens, passthrough, matchedFolders: matched }, notes: matched.length > 0 ? `Matched: ${matched.join(", ")}` : "No folder patterns matched", }; }