MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / pickDiverseCoreFiles

Function pickDiverseCoreFiles

source code/utils/exampleCommands.ts:58–86  ·  view source on GitHub ↗
(
  sortedPaths: string[],
  want: number,
)

Source from the content-addressed store, hash-verified

56 * Returns empty array if fewer than `want` core files are available.
57 */
58export function pickDiverseCoreFiles(
59 sortedPaths: string[],
60 want: number,
61): string[] {
62 const picked: string[] = []
63 const seenBasenames = new Set<string>()
64 const dirTally = new Map<string, number>()
65
66 // Greedy: on each pass allow +1 file per directory. Keeps the
67 // top-5 from collapsing into a single hot folder while still
68 // letting a dominant folder contribute multiple files if the
69 // repo is narrow.
70 for (let cap = 1; picked.length < want && cap <= want; cap++) {
71 for (const p of sortedPaths) {
72 if (picked.length >= want) break
73 if (!isCoreFile(p)) continue
74 const lastSep = Math.max(p.lastIndexOf('/'), p.lastIndexOf('\\'))
75 const base = lastSep >= 0 ? p.slice(lastSep + 1) : p
76 if (!base || seenBasenames.has(base)) continue
77 const dir = lastSep >= 0 ? p.slice(0, lastSep) : '.'
78 if ((dirTally.get(dir) ?? 0) >= cap) continue
79 picked.push(base)
80 seenBasenames.add(base)
81 dirTally.set(dir, (dirTally.get(dir) ?? 0) + 1)
82 }
83 }
84
85 return picked.length >= want ? picked : []
86}
87
88async function getFrequentlyModifiedFiles(): Promise<string[]> {
89 if (process.env.NODE_ENV === 'test') return []

Callers 1

Calls 6

isCoreFileFunction · 0.85
maxMethod · 0.80
setMethod · 0.80
hasMethod · 0.45
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected