MCPcopy Index your code
hub / github.com/github/gh-aw / findAgentUsageFile

Function findAgentUsageFile

pkg/cli/token_usage.go:349–378  ·  view source on GitHub ↗

findAgentUsageFile searches for agent_usage.json in the run directory.

(runDir string)

Source from the content-addressed store, hash-verified

347
348// findAgentUsageFile searches for agent_usage.json in the run directory.
349func findAgentUsageFile(runDir string) string {
350 primary := filepath.Join(runDir, agentUsageJSONPath)
351 if fileutil.FileExists(primary) {
352 tokenUsageLog.Printf("Found agent usage file at primary path: %s", primary)
353 return primary
354 }
355
356 var found string
357 if walkErr := filepath.Walk(runDir, func(path string, info os.FileInfo, err error) error {
358 if err != nil {
359 tokenUsageLog.Printf("walk error at %s: %v", path, err)
360 return nil
361 }
362 if info == nil || info.IsDir() {
363 return nil
364 }
365 if info.Name() == agentUsageJSONPath {
366 found = path
367 return filepath.SkipAll
368 }
369 return nil
370 }); walkErr != nil && !errors.Is(walkErr, filepath.SkipAll) {
371 fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("filesystem error walking %s: %v", runDir, walkErr)))
372 }
373
374 if found != "" {
375 tokenUsageLog.Printf("Found agent usage file via walk: %s", found)
376 }
377 return found
378}
379
380// agentUsageEntry is the JSON structure written by parse_token_usage.cjs to
381// /tmp/gh-aw/agent_usage.json. It aggregates the total token counts for a run

Callers 2

analyzeTokenUsageFunction · 0.85
analyzeTokenUsageAICOnlyFunction · 0.85

Calls 3

FileExistsFunction · 0.92
FormatWarningMessageFunction · 0.92
PrintfMethod · 0.45

Tested by

no test coverage detected