(dir, depth)
| 91 | const entries = []; |
| 92 | |
| 93 | function walk(dir, depth) { |
| 94 | if (depth > maxDepth || entries.length >= maxCollect) return; |
| 95 | let listing; |
| 96 | try { listing = fs.readdirSync(dir, { withFileTypes: true }); } |
| 97 | catch { return; } |
| 98 | |
| 99 | for (const ent of listing) { |
| 100 | if (entries.length >= maxCollect) break; |
| 101 | const name = ent.name; |
| 102 | |
| 103 | if (ent.isDirectory()) { |
| 104 | if (SKIP_DIRS.has(name)) continue; |
| 105 | // Skip most dot-dirs but allow .marrow (MarrowScript source) |
| 106 | if (name.startsWith('.') && name !== '.marrow') continue; |
| 107 | walk(path.join(dir, name), depth + 1); |
| 108 | } else if (ent.isFile()) { |
| 109 | const full = path.join(dir, name); |
| 110 | const rel = path.relative(rootDir, full); |
| 111 | const ext = path.extname(name).toLowerCase(); |
| 112 | const base = name.toLowerCase(); |
| 113 | |
| 114 | let score = 0; |
| 115 | |
| 116 | // Extension scoring |
| 117 | if (SOURCE_EXTS.has(ext)) score += 2; |
| 118 | |
| 119 | // Config files |
| 120 | if (CONFIG_FILES.has(name)) score += 1; |
| 121 | |
| 122 | // Test files |
| 123 | if (/^test_|\.test\.|\.spec\.|_test\./i.test(name)) score += 1; |
| 124 | |
| 125 | // Generated output penalty |
| 126 | if (GENERATED_PATTERNS.some(p => p.test(name))) score -= 2; |
| 127 | |
| 128 | // Recent modification bonus |
| 129 | let mtime = 0; |
| 130 | try { |
| 131 | const stat = fs.statSync(full); |
| 132 | mtime = stat.mtimeMs; |
| 133 | const ageMs = now - mtime; |
| 134 | if (ageMs < 86400000) score += 3; // < 24h |
| 135 | else if (ageMs < 604800000) score += 2; // < 7d |
| 136 | else if (ageMs < 2592000000) score += 1; // < 30d |
| 137 | } catch {} |
| 138 | |
| 139 | // Task keyword bonus |
| 140 | if (taskTokens.length > 0) { |
| 141 | const relLower = rel.toLowerCase(); |
| 142 | const hits = taskTokens.filter(t => relLower.includes(t)).length; |
| 143 | score += Math.min(hits * 2, 4); // cap at +4 |
| 144 | } |
| 145 | |
| 146 | entries.push({ rel, full, name, ext, score, mtime }); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 |
no test coverage detected