MCPcopy Index your code
hub / github.com/codeaashu/claude-code / pickDiverseCoreFiles

Function pickDiverseCoreFiles

src/utils/exampleCommands.ts:56–84  ·  view source on GitHub ↗
(
  sortedPaths: string[],
  want: number,
)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 7

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

Tested by

no test coverage detected