import * as fs from "fs"; import * as path from "path"; export interface MarkdownFile { path: string; content: string; } const FILENAMES = ["LLMTUNE.md", "CLAUDE.md", ".llmtune", ".claude"]; export function loadProjectInstructions( workspaceRoot: string, cwd: string ): MarkdownFile[] { const files: MarkdownFile[] = []; const seen = new Set(); const dirsToCheck = [cwd]; let current = cwd; while (current !== workspaceRoot && current !== path.dirname(current)) { current = path.dirname(current); dirsToCheck.push(current); } dirsToCheck.push(workspaceRoot); for (const dir of dirsToCheck) { for (const filename of FILENAMES) { const filePath = path.join(dir, filename); const resolved = path.resolve(filePath); if (seen.has(resolved)) continue; try { const stat = fs.statSync(filePath); if (stat.isFile()) { const content = fs.readFileSync(filePath, "utf-8"); if (content.trim()) { seen.add(resolved); files.push({ path: resolved, content: content.trim() }); } } } catch { // file doesn't exist, skip } } } return files; }