File size: 1,089 Bytes
2ab3016 | 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 | import fs from "fs";
import path from "path";
import { safeResolve } from "./safePaths";
const allowedExtensions = [".md", ".txt", ".json", ".ts", ".tsx", ".js", ".prisma"];
const blockedFilenames = [".env", ".env.local", ".env.production"];
const blockedExtensions = [".pem", ".key", ".p12", ".sqlite", ".db"];
export function loadProjectMemory(memoryRoot: string, requestedFiles: string[]): string {
let memoryContent = "";
for (const file of requestedFiles) {
const ext = path.extname(file);
if (!allowedExtensions.includes(ext)) continue;
const normalizedFile = path.normalize(file).replace(/\\/g, "/");
const basename = path.basename(normalizedFile);
const extname = path.extname(normalizedFile);
if (blockedFilenames.includes(basename) || blockedExtensions.includes(extname)) continue;
const filePath = safeResolve(memoryRoot, file);
if (fs.existsSync(filePath)) {
const fileContent = fs.readFileSync(filePath, "utf8");
if (fileContent.length <= 1024 * 1024) memoryContent += fileContent + "\n\n";
}
}
return memoryContent;
} |