(fileLists: string[][], topK = 3)
| 41 | |
| 42 | /** Directories the user works in most, from the files their episodes touched (2-level). PURE. */ |
| 43 | export function favoriteAreas(fileLists: string[][], topK = 3): string[] { |
| 44 | const freq = new Map<string, number>(); |
| 45 | for (const files of fileLists) for (const f of files) { |
| 46 | const area = f.split('/').slice(0, 2).join('/'); |
| 47 | if (area) freq.set(area, (freq.get(area) ?? 0) + 1); |
| 48 | } |
| 49 | return [...freq.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, topK).map(([a]) => a); |
| 50 | } |
| 51 | |
| 52 | export function buildUserModel(input: { userFacts: string[]; episodes: { prompt: string; files?: string[] }[] }): UserModel { |
| 53 | const preferences = input.userFacts |
no test coverage detected