| 40 | } |
| 41 | |
| 42 | async function findNearestInstructionFile(startDir: string): Promise<string | null> { |
| 43 | let currentDir = startDir |
| 44 | |
| 45 | while (true) { |
| 46 | const candidates = [ |
| 47 | `${currentDir}/AGENTS.md`, |
| 48 | `${currentDir}/NCODE.md`, |
| 49 | `${currentDir}/CLAUDE.md`, |
| 50 | `${currentDir}/.ncode/NCODE.md`, |
| 51 | `${currentDir}/.claude/CLAUDE.md`, |
| 52 | ] |
| 53 | |
| 54 | for (const candidate of candidates) { |
| 55 | if (await fileExists(candidate)) { |
| 56 | return candidate |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | const parentDir = dirname(currentDir) |
| 61 | if (parentDir === currentDir) { |
| 62 | return null |
| 63 | } |
| 64 | currentDir = parentDir |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | function extractUpSection(markdown: string): Section | null { |
| 69 | const lines = markdown.split(/\r?\n/) |