MCPcopy Create free account
hub / github.com/PatrickSys/codebase-context / track

Method track

src/utils/usage-tracker.ts:255–308  ·  view source on GitHub ↗
(
    category: string,
    patternName: string,
    example?: { file: string; snippet: string },
    fileDate?: Date
  )

Source from the content-addressed store, hash-verified

253 }
254
255 track(
256 category: string,
257 patternName: string,
258 example?: { file: string; snippet: string },
259 fileDate?: Date
260 ): void {
261 if (!this.patterns.has(category)) {
262 this.patterns.set(category, new Map());
263 }
264
265 const categoryPatterns = this.patterns.get(category)!;
266 categoryPatterns.set(patternName, (categoryPatterns.get(patternName) || 0) + 1);
267
268 // Track file dates for P90 robust trend analysis
269 if (fileDate) {
270 const dateKey = `${category}:${patternName}`;
271 const dates = this.patternFileDates.get(dateKey);
272 if (dates) {
273 dates.push(fileDate.getTime());
274 } else {
275 this.patternFileDates.set(dateKey, [fileDate.getTime()]);
276 }
277 }
278
279 // Smart Canonical Example Selection
280 const exampleKey = `${category}:${patternName}`;
281
282 if (example) {
283 if (!this.canonicalExamples.has(exampleKey)) {
284 this.canonicalExamples.set(exampleKey, example);
285 } else {
286 // Check if new example is better
287 const existing = this.canonicalExamples.get(exampleKey)!;
288
289 // Priority 1: Core/Shared directories (likely definitive)
290 const isCoreOrShared = (f: string) => f.includes('core/') || f.includes('shared/');
291 const newIsPriority = isCoreOrShared(example.file);
292 const oldIsPriority = isCoreOrShared(existing.file);
293
294 if (newIsPriority && !oldIsPriority) {
295 this.canonicalExamples.set(exampleKey, example);
296 } else if (newIsPriority === oldIsPriority) {
297 // Priority 2: Concise length (but not too short)
298 const newLen = example.snippet.length;
299 const oldLen = existing.snippet.length;
300
301 // If current is very long (>200 chars) and new is shorter but substantial (>50), take new
302 if (oldLen > 200 && newLen < oldLen && newLen > 50) {
303 this.canonicalExamples.set(exampleKey, example);
304 }
305 }
306 }
307 }
308 }
309
310 /**
311 * Track a file as a potential "Golden File" - a file that demonstrates multiple modern patterns

Callers 2

detectFromCodeMethod · 0.95
indexMethod · 0.95

Calls 3

hasMethod · 0.80
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected