{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../../../src/core/workspace/classify.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,cAAc,GACvB,QAAQ,GACR,MAAM,GACN,eAAe,GACf,eAAe,GACf,QAAQ,GACR,WAAW,GACX,OAAO,GACP,WAAW,GACX,QAAQ,GACR,QAAQ,GACR,kBAAkB,GAClB,UAAU,GACV,SAAS,CAAC;AAgGb,MAAM,WAAW,oBAAoB;IACpC,cAAc,EAAE,cAAc,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAqBD,wBAAgB,YAAY,CAAC,qBAAqB,EAAE,MAAM,GAAG,oBAAoB,CA8DhF","sourcesContent":["/**\n * File classification and sensitive-file policy.\n */\n\nexport type Classification =\n\t| \"source\"\n\t| \"test\"\n\t| \"documentation\"\n\t| \"configuration\"\n\t| \"schema\"\n\t| \"migration\"\n\t| \"build\"\n\t| \"generated\"\n\t| \"vendor\"\n\t| \"binary\"\n\t| \"secret-sensitive\"\n\t| \"lockfile\"\n\t| \"unknown\";\n\nconst LANGUAGE_BY_EXT: Record<string, string> = {\n\t\".ts\": \"typescript\",\n\t\".tsx\": \"typescript\",\n\t\".mts\": \"typescript\",\n\t\".cts\": \"typescript\",\n\t\".js\": \"javascript\",\n\t\".jsx\": \"javascript\",\n\t\".mjs\": \"javascript\",\n\t\".cjs\": \"javascript\",\n\t\".py\": \"python\",\n\t\".pyi\": \"python\",\n\t\".cs\": \"csharp\",\n\t\".java\": \"java\",\n\t\".go\": \"go\",\n\t\".rs\": \"rust\",\n\t\".json\": \"json\",\n\t\".yaml\": \"yaml\",\n\t\".yml\": \"yaml\",\n\t\".toml\": \"toml\",\n\t\".md\": \"markdown\",\n\t\".mdx\": \"markdown\",\n\t\".sh\": \"shell\",\n\t\".bash\": \"shell\",\n\t\".zsh\": \"shell\",\n\t\".ps1\": \"powershell\",\n\t\".psm1\": \"powershell\",\n\t\".sql\": \"sql\",\n\t\".css\": \"css\",\n\t\".scss\": \"scss\",\n\t\".less\": \"less\",\n\t\".html\": \"html\",\n\t\".xml\": \"xml\",\n\t\".proto\": \"proto\",\n\t\".graphql\": \"graphql\",\n\t\".gql\": \"graphql\",\n\t\".txt\": \"text\",\n\t\".rst\": \"markdown\",\n};\n\nconst SENSITIVE_FILE_PATTERNS: RegExp[] = [\n\t/(^|[/\\\\])\\.env([^/\\\\]*)?$/i,\n\t/(^|[/\\\\])\\.pem$/i,\n\t/(^|[/\\\\])\\.key$/i,\n\t/(^|[/\\\\])\\.p12$/i,\n\t/(^|[/\\\\])\\.pfx$/i,\n\t/(^|[/\\\\])id_rsa($|[.])/i,\n\t/(^|[/\\\\])id_ed25519($|[.])/i,\n\t/(^|[/\\\\])credentials\\.json$/i,\n\t/(^|[/\\\\])service-account[^/\\\\]*\\.json$/i,\n\t/(^|[/\\\\])\\.netrc$/i,\n\t/(^|[/\\\\])\\.npmrc$/i,\n\t/(^|[/\\\\])\\.htpasswd$/i,\n\t/(^|[/\\\\])secrets\\.[^/\\\\]*$/i,\n\t/(^|[/\\\\])\\.ssh[/\\\\]/i,\n\t/(^|[/\\\\])awscredentials$/i,\n\t/(^|[/\\\\])\\.aws[/\\\\](credentials|config)$/i,\n];\n\nconst BINARY_EXT: Set<string> = new Set([\n\t\".png\",\n\t\".jpg\",\n\t\".jpeg\",\n\t\".gif\",\n\t\".webp\",\n\t\".ico\",\n\t\".svg\",\n\t\".pdf\",\n\t\".zip\",\n\t\".gz\",\n\t\".tar\",\n\t\".7z\",\n\t\".exe\",\n\t\".dll\",\n\t\".so\",\n\t\".dylib\",\n\t\".wasm\",\n\t\".woff\",\n\t\".woff2\",\n\t\".ttf\",\n\t\".otf\",\n\t\".mp3\",\n\t\".mp4\",\n\t\".avi\",\n\t\".mov\",\n\t\".pickle\",\n\t\".bin\",\n\t\".class\",\n\t\".o\",\n\t\".a\",\n\t\".jar\",\n\t\".node\",\n\t\".map\",\n]);\n\nexport interface ClassificationResult {\n\tclassification: Classification;\n\tlanguageId?: string;\n\tisBinary: boolean;\n\tisGenerated: boolean;\n\tisSensitive: boolean;\n\tignoredByVendor?: boolean;\n\tignoredByCache?: boolean;\n}\n\nconst GENERATED_PATTERNS: RegExp[] = [\n\t/(^|[/\\\\])(dist|build|out|coverage|\\.next|\\.nuxt|\\.svelte-kit|\\.turbo)([/\\\\]|$)/i,\n\t/(^|[/\\\\])build[/\\\\]/i,\n\t/\\.(min|bundle|chunk)\\.(js|css)$/i,\n\t/(^|[/\\\\])generated[/\\\\]/i,\n\t/(^|[/\\\\])\\.cache[/\\\\]/i,\n];\n\nconst VENDOR_PATTERNS: RegExp[] = [\n\t/(^|[/\\\\])node_modules([/\\\\]|$)/i,\n\t/(^|[/\\\\])vendor([/\\\\]|$)/i,\n\t/(^|[/\\\\])\\.venv([/\\\\]|$)/i,\n\t/(^|[/\\\\])venv([/\\\\]|$)/i,\n\t/(^|[/\\\\])site-packages([/\\\\]|$)/i,\n\t/(^|[/\\\\])\\.git([/\\\\]|$)/i,\n\t/(^|[/\\\\])Pods([/\\\\]|$)/i,\n\t/(^|[/\\\\])(Cargo|go|pip|pnpm|npm|yarn)\\.lock$/i,\n];\n\nexport function classifyPath(workspaceRelativePath: string): ClassificationResult {\n\tconst rel = workspaceRelativePath.replace(/\\\\/g, \"/\");\n\tconst lower = rel.toLowerCase();\n\tconst ext = extOf(rel);\n\n\tconst isSensitive = SENSITIVE_FILE_PATTERNS.some((re) => re.test(rel));\n\tconst isBinaryExt = BINARY_EXT.has(ext);\n\tconst isGenerated = GENERATED_PATTERNS.some((re) => re.test(rel));\n\tconst isVendor = VENDOR_PATTERNS.some((re) => re.test(rel));\n\tconst isCache = /([/\\\\])\\.?(_|node_modules|__pycache__|\\.git)([/\\\\]|$)/.test(rel);\n\tconst isLockfile =\n\t\t/(^|[/\\\\])(package-lock|pnpm-lock|yarn\\.lock|Cargo\\.lock|go\\.sum|poetry\\.lock|Pipfile\\.lock)(\\.|$)/i.test(rel);\n\n\tlet classification: Classification = \"unknown\";\n\tconst segs = rel.split(\"/\");\n\tconst _base = segs[segs.length - 1] ?? \"\";\n\n\tif (isSensitive) {\n\t\tclassification = \"secret-sensitive\";\n\t} else if (/\\.(test|spec)\\./.test(lower) || /(^|\\/)(test|tests|__tests__|spec|specs)(\\/|$)/i.test(rel)) {\n\t\tclassification = \"test\";\n\t} else if (isLockfile) {\n\t\tclassification = \"lockfile\";\n\t} else if (isVendor) {\n\t\tclassification = \"vendor\";\n\t} else if (isGenerated) {\n\t\tclassification = \"generated\";\n\t} else if (/(^|\\/)(docs|documentation)(\\/|$)/i.test(rel) || /\\.(md|mdx|rst|txt)$/i.test(lower)) {\n\t\tclassification = \"documentation\";\n\t} else if (/\\.(json|ya?ml|toml|ini|conf|cfg|properties)$/i.test(lower)) {\n\t\tclassification = \"configuration\";\n\t} else if (/\\.(proto|graphql|gql)$/i.test(lower)) {\n\t\tclassification = \"schema\";\n\t} else if (/(^|[/\\\\])migrations?([/\\\\]|$)/i.test(rel)) {\n\t\tclassification = \"migration\";\n\t} else if (/\\.(d\\.ts)$/i.test(lower)) {\n\t\tclassification = \"source\";\n\t} else if (LANGUAGE_BY_EXT[ext]) {\n\t\tclassification = /\\.(css|scss|less|html|xml|js|jsx|mjs|cjs|ts|tsx|mts|cts)$/i.test(lower)\n\t\t\t? \"source\"\n\t\t\t: LANGUAGE_BY_EXT[ext] === \"markdown\"\n\t\t\t\t? \"documentation\"\n\t\t\t\t: \"source\";\n\t}\n\n\tif (classification === \"unknown\") {\n\t\tif (isBinaryExt) classification = \"binary\";\n\t\telse if (LANGUAGE_BY_EXT[ext]) classification = \"source\";\n\t\telse classification = \"unknown\";\n\t}\n\n\tconst languageId = LANGUAGE_BY_EXT[ext];\n\n\treturn {\n\t\tclassification,\n\t\tlanguageId,\n\t\tisBinary: isBinaryExt,\n\t\tisGenerated,\n\t\tisSensitive,\n\t\tignoredByVendor: isVendor,\n\t\tignoredByCache: isCache,\n\t};\n}\n\nfunction extOf(rel: string): string {\n\tconst base = rel.split(\"/\").pop() ?? \"\";\n\tconst idx = base.lastIndexOf(\".\");\n\tif (idx <= 0) return \"\";\n\tconst ext = base.slice(idx);\n\t// handle .d.ts\n\tif (base.toLowerCase().endsWith(\".d.ts\")) return \".d.ts\";\n\treturn ext.toLowerCase();\n}\n"]}