Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions pkg/cli/token_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,9 @@ func analyzeTokenUsage(runDir string, verbose bool) (*TokenUsageSummary, error)

filePath := findTokenUsageFile(runDir)
if filePath != "" {
if verbose {
fileInfo, _ := os.Stat(filePath)
if fileInfo != nil {
fmt.Fprintf(os.Stderr, " Found token usage file: %s (%d bytes)\n", filepath.Base(filePath), fileInfo.Size())
}
fileInfo, _ := os.Stat(filePath)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/zoom-out] os.Stat is now called unconditionally even when verbose=false — this is a subtle behavioral change from the original code where the stat was guarded by if verbose.

💡 Details and suggested fix

Since fileInfo is only used to format the log message, the syscall was previously skipped when not in verbose mode. The same pattern repeats at lines 461, 641, and 683.

The cleanest fix is to keep a verbose guard around both the os.Stat and the log call:

if verbose {
    if fileInfo, _ := os.Stat(filePath); fileInfo != nil {
        console.LogVerbose(verbose, fmt.Sprintf("  Found token usage file: %s (%d bytes)", filepath.Base(filePath), fileInfo.Size()))
    }
}

Alternatively, consider adding a LogVerbosef(verbose bool, format string, args ...any) helper to the console package. This would internalize the verbose gate so call sites never need the explicit if verbose wrapper — and it would allow lazy argument evaluation without adding syscalls in non-verbose paths.

if fileInfo != nil {
console.LogVerbose(verbose, fmt.Sprintf(" Found token usage file: %s (%d bytes)", filepath.Base(filePath), fileInfo.Size()))
}
Comment on lines +443 to 446

summary, err := parseTokenUsageFile(filePath)
Expand All @@ -460,11 +458,9 @@ func analyzeTokenUsage(runDir string, verbose bool) (*TokenUsageSummary, error)
if agentUsagePath == "" {
return nil, nil
}
if verbose {
fileInfo, _ := os.Stat(agentUsagePath)
if fileInfo != nil {
fmt.Fprintf(os.Stderr, " Found agent usage file: %s (%d bytes)\n", filepath.Base(agentUsagePath), fileInfo.Size())
}
agentFileInfo, _ := os.Stat(agentUsagePath)
if agentFileInfo != nil {
console.LogVerbose(verbose, fmt.Sprintf(" Found agent usage file: %s (%d bytes)", filepath.Base(agentUsagePath), agentFileInfo.Size()))
}
Comment on lines +461 to 464

summary, err := parseAgentUsageFile(agentUsagePath)
Expand Down Expand Up @@ -630,9 +626,7 @@ func analyzeTokenUsageAICOnly(runDir string, verbose bool) (*TokenUsageSummary,

usageJSONLFiles := findUsageJSONLFiles(runDir)
if len(usageJSONLFiles) > 0 {
if verbose {
fmt.Fprintf(os.Stderr, " Found usage JSONL files: %s\n", strings.Join(usageJSONLFiles, ", "))
}
console.LogVerbose(verbose, " Found usage JSONL files: "+strings.Join(usageJSONLFiles, ", "))
totalAIC, err := sumAICFromUsageJSONLFiles(usageJSONLFiles)
if err != nil {
return nil, err
Expand All @@ -642,11 +636,9 @@ func analyzeTokenUsageAICOnly(runDir string, verbose bool) (*TokenUsageSummary,

filePath := findTokenUsageFile(runDir)
if filePath != "" {
if verbose {
fileInfo, _ := os.Stat(filePath)
if fileInfo != nil {
fmt.Fprintf(os.Stderr, " Found token usage file: %s (%d bytes)\n", filepath.Base(filePath), fileInfo.Size())
}
fileInfo, _ := os.Stat(filePath)
if fileInfo != nil {
console.LogVerbose(verbose, fmt.Sprintf(" Found token usage file: %s (%d bytes)", filepath.Base(filePath), fileInfo.Size()))
}
Comment on lines +639 to 642

file, err := os.Open(filePath)
Expand Down Expand Up @@ -688,11 +680,9 @@ func analyzeTokenUsageAICOnly(runDir string, verbose bool) (*TokenUsageSummary,
if agentUsagePath == "" {
return nil, nil
}
if verbose {
fileInfo, _ := os.Stat(agentUsagePath)
if fileInfo != nil {
fmt.Fprintf(os.Stderr, " Found agent usage file: %s (%d bytes)\n", filepath.Base(agentUsagePath), fileInfo.Size())
}
agentFileInfo, _ := os.Stat(agentUsagePath)
if agentFileInfo != nil {
console.LogVerbose(verbose, fmt.Sprintf(" Found agent usage file: %s (%d bytes)", filepath.Base(agentUsagePath), agentFileInfo.Size()))
}
Comment on lines +683 to 686

data, err := os.ReadFile(filepath.Clean(agentUsagePath))
Expand Down
Loading