(scored: ScoredChunk[], maxFiles: number)
| 323 | * at files is more useful to the model than pointing at arbitrary 30-line windows. |
| 324 | */ |
| 325 | export function aggregateToFiles(scored: ScoredChunk[], maxFiles: number): RankedFile[] { |
| 326 | const best = new Map<string, { score: number; startLine: number; endLine: number; text: string }>(); |
| 327 | for (const { chunk, score } of scored) { |
| 328 | const cur = best.get(chunk.file); |
| 329 | if (!cur || score > cur.score) { |
| 330 | best.set(chunk.file, { score, startLine: chunk.startLine, endLine: chunk.endLine, text: chunk.text }); |
| 331 | } |
| 332 | } |
| 333 | return [...best.entries()] |
| 334 | .map(([file, v]) => ({ file, score: v.score, bestLines: `${v.startLine}-${v.endLine}`, text: v.text })) |
| 335 | .sort((a, b) => b.score - a.score) |
| 336 | .slice(0, maxFiles); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Expand a ranked file list with import-graph neighbors of the top hits, so the |
no test coverage detected