Skip to content
Merged
Show file tree
Hide file tree
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
40 changes: 14 additions & 26 deletions pkg/cli/compile_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"github.com/github/gh-aw/pkg/logger"
"github.com/github/gh-aw/pkg/sliceutil"
"github.com/github/gh-aw/pkg/stringutil"
)

Expand Down Expand Up @@ -78,34 +79,21 @@ func sanitizeValidationResults(results []ValidationResult) []ValidationResult {

compileConfigLog.Printf("Sanitizing validation results: workflow_count=%d", len(results))

sanitized := make([]ValidationResult, len(results))
for i, result := range results {
sanitized[i] = ValidationResult{
sanitizeError := func(e CompileValidationError) CompileValidationError {
return CompileValidationError{
Type: e.Type,
Message: stringutil.SanitizeErrorMessage(e.Message),
Line: e.Line,
}
}

return sliceutil.Map(results, func(result ValidationResult) ValidationResult {
return ValidationResult{
Workflow: result.Workflow,
Valid: result.Valid,
CompiledFile: result.CompiledFile,
Errors: make([]CompileValidationError, len(result.Errors)),
Warnings: make([]CompileValidationError, len(result.Warnings)),
}

// Sanitize all error messages
for j, err := range result.Errors {
sanitized[i].Errors[j] = CompileValidationError{
Type: err.Type,
Message: stringutil.SanitizeErrorMessage(err.Message),
Line: err.Line,
}
Errors: sliceutil.Map(result.Errors, sanitizeError),
Warnings: sliceutil.Map(result.Warnings, sanitizeError),
}

// Sanitize all warning messages
for j, warn := range result.Warnings {
sanitized[i].Warnings[j] = CompileValidationError{
Type: warn.Type,
Message: stringutil.SanitizeErrorMessage(warn.Message),
Line: warn.Line,
}
}
}

return sanitized
})
}
15 changes: 6 additions & 9 deletions pkg/cli/health_command.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cli

import (
"cmp"
"encoding/json"
"fmt"
"os"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -202,15 +204,10 @@ func displayHealthSummary(runs []WorkflowRun, config HealthConfig) error {
workflowHealths = append(workflowHealths, health)
}

// Sort by success rate (lowest first to highlight issues)
// Using a simple bubble sort for simplicity
for i := 0; i < len(workflowHealths); i++ {
for j := i + 1; j < len(workflowHealths); j++ {
if workflowHealths[i].SuccessRate > workflowHealths[j].SuccessRate {
workflowHealths[i], workflowHealths[j] = workflowHealths[j], workflowHealths[i]
}
}
}
// Sort by success rate ascending (lowest first to highlight issues)
slices.SortFunc(workflowHealths, func(a, b WorkflowHealth) int {
return cmp.Compare(a.SuccessRate, b.SuccessRate)
})

// Calculate summary
summary := CalculateHealthSummary(workflowHealths, fmt.Sprintf("Last %d Days", config.Days), config.Threshold)
Expand Down
36 changes: 18 additions & 18 deletions pkg/cli/logs_report.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package cli

import (
"cmp"
"encoding/json"
"fmt"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -368,8 +368,8 @@ func buildToolUsageSummary(processedRuns []ProcessedRun) []ToolUsageSummary {
}

// Sort by total calls descending
sort.Slice(result, func(i, j int) bool {
return result[i].TotalCalls > result[j].TotalCalls
slices.SortFunc(result, func(a, b ToolUsageSummary) int {
return cmp.Compare(b.TotalCalls, a.TotalCalls)
})

return result
Expand Down Expand Up @@ -453,8 +453,8 @@ func buildMissingToolsSummary(processedRuns []ProcessedRun) []MissingToolSummary
)

// Sort by count descending
sort.Slice(result, func(i, j int) bool {
return result[i].Count > result[j].Count
slices.SortFunc(result, func(a, b MissingToolSummary) int {
return cmp.Compare(b.Count, a.Count)
})

return result
Expand Down Expand Up @@ -496,8 +496,8 @@ func buildMissingDataSummary(processedRuns []ProcessedRun) []MissingDataSummary
)

// Sort by count descending
sort.Slice(result, func(i, j int) bool {
return result[i].Count > result[j].Count
slices.SortFunc(result, func(a, b MissingDataSummary) int {
return cmp.Compare(b.Count, a.Count)
})

return result
Expand Down Expand Up @@ -537,8 +537,8 @@ func buildMCPFailuresSummary(processedRuns []ProcessedRun) []MCPFailureSummary {
)

// Sort by count descending
sort.Slice(result, func(i, j int) bool {
return result[i].Count > result[j].Count
slices.SortFunc(result, func(a, b MCPFailureSummary) int {
return cmp.Compare(b.Count, a.Count)
})

return result
Expand Down Expand Up @@ -587,12 +587,12 @@ func convertDomainsToSortedSlices(allowedMap, blockedMap map[string]bool) (allow
for domain := range allowedMap {
allowed = append(allowed, domain)
}
sort.Strings(allowed)
slices.Sort(allowed)

for domain := range blockedMap {
blocked = append(blocked, domain)
}
sort.Strings(blocked)
slices.Sort(blocked)

return allowed, blocked
}
Expand Down Expand Up @@ -704,7 +704,7 @@ func buildRedactedDomainsSummary(processedRuns []ProcessedRun) *RedactedDomainsL
for domain := range allDomainsSet {
allDomains = append(allDomains, domain)
}
sort.Strings(allDomains)
slices.Sort(allDomains)

return &RedactedDomainsLogSummary{
TotalDomains: len(allDomains),
Expand Down Expand Up @@ -825,16 +825,16 @@ func buildMCPToolUsageSummary(processedRuns []ProcessedRun) *MCPToolUsageSummary
}

// Sort summaries by server name, then tool name
sort.Slice(summaries, func(i, j int) bool {
if summaries[i].ServerName != summaries[j].ServerName {
return summaries[i].ServerName < summaries[j].ServerName
slices.SortFunc(summaries, func(a, b MCPToolSummary) int {
if a.ServerName != b.ServerName {
return cmp.Compare(a.ServerName, b.ServerName)
}
return summaries[i].ToolName < summaries[j].ToolName
return cmp.Compare(a.ToolName, b.ToolName)
})

// Sort servers by name
sort.Slice(servers, func(i, j int) bool {
return servers[i].ServerName < servers[j].ServerName
slices.SortFunc(servers, func(a, b MCPServerStats) int {
return cmp.Compare(a.ServerName, b.ServerName)
})

reportLog.Printf("Built MCP tool usage summary: %d tool summaries, %d servers, %d total tool calls",
Expand Down