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
21 changes: 8 additions & 13 deletions pkg/cli/audit_cross_run_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func renderCrossRunReportMarkdown(report *CrossRunAuditReport) {
fmt.Printf("| Avg | Min | Max |\n")
fmt.Printf("|-----|-----|-----|\n")
fmt.Printf("| %s | %s | %s |\n",
formatDurationNs(mt.AvgDurationNs),
formatDurationNs(mt.MinDurationNs),
formatDurationNs(mt.MaxDurationNs))
timeutil.FormatDurationNs(mt.AvgDurationNs),
timeutil.FormatDurationNs(mt.MinDurationNs),
timeutil.FormatDurationNs(mt.MaxDurationNs))
fmt.Println()
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func renderCrossRunReportMarkdown(report *CrossRunAuditReport) {
}
durStr := "—"
if run.Duration > 0 {
durStr = formatDurationNs(int64(run.Duration))
durStr = timeutil.FormatDurationNs(int64(run.Duration))
}
fmt.Printf("| %d | %s | %s | %s | %s | %s | %s | %s | %d | %d |\n",
run.RunID, run.WorkflowName, run.Conclusion, durStr,
Expand Down Expand Up @@ -249,9 +249,9 @@ func renderCrossRunReportPretty(report *CrossRunAuditReport) {
}
if mt.AvgDurationNs > 0 {
fmt.Fprintf(os.Stderr, " Duration: avg=%s min=%s max=%s\n",
formatDurationNs(mt.AvgDurationNs),
formatDurationNs(mt.MinDurationNs),
formatDurationNs(mt.MaxDurationNs))
timeutil.FormatDurationNs(mt.AvgDurationNs),
timeutil.FormatDurationNs(mt.MinDurationNs),
timeutil.FormatDurationNs(mt.MaxDurationNs))
}
fmt.Fprintln(os.Stderr)
}
Expand Down Expand Up @@ -339,7 +339,7 @@ func renderCrossRunReportPretty(report *CrossRunAuditReport) {
}
durStr := ""
if run.Duration > 0 {
durStr = " dur=" + formatDurationNs(int64(run.Duration))
durStr = " dur=" + timeutil.FormatDurationNs(int64(run.Duration))
}
if !run.HasData {
fmt.Fprintf(os.Stderr, " Run #%-12d %-30s %-10s (no firewall data)%s%s%s mcp_errors=%d errors=%d\n",
Expand Down Expand Up @@ -387,11 +387,6 @@ func formatRunIDs(ids []int64) string {
return strings.Join(parts, ", ")
}

// formatDurationNs formats a nanosecond duration as a human-readable string.
func formatDurationNs(ns int64) string {
return timeutil.FormatDurationNs(ns)
}

// safePercent returns percentage of part/total, returning 0 when total is 0.
func safePercent(part, total int) float64 {
if total == 0 {
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/audit_report_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/github/gh-aw/pkg/console"
"github.com/github/gh-aw/pkg/sliceutil"
"github.com/github/gh-aw/pkg/stringutil"
"github.com/github/gh-aw/pkg/timeutil"
)

// renderJSON outputs the audit data as JSON
Expand Down Expand Up @@ -1062,7 +1063,7 @@ func renderTokenUsage(summary *TokenUsageSummary) {
console.FormatNumber(summary.TotalOutputTokens),
console.FormatNumber(cacheTokens))
fmt.Fprintf(os.Stderr, " Requests: %d (avg %s)\n",
summary.TotalRequests, FormatDurationMs(summary.AvgDurationMs()))
summary.TotalRequests, timeutil.FormatDurationMs(summary.AvgDurationMs()))
if summary.CacheEfficiency > 0 {
fmt.Fprintf(os.Stderr, " Cache hit: %.1f%%\n", summary.CacheEfficiency*100)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/logs_github_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"fmt"
"os"
"os/exec"
"slices"
"strconv"
"strings"

"github.com/github/gh-aw/pkg/console"
"github.com/github/gh-aw/pkg/logger"
"github.com/github/gh-aw/pkg/sliceutil"
"github.com/github/gh-aw/pkg/workflow"
)

Expand Down Expand Up @@ -283,7 +283,7 @@ func listWorkflowRunsWithPagination(opts ListWorkflowRunsOptions) ([]WorkflowRun
}

for _, run := range runs {
if sliceutil.Contains(agenticWorkflowNames, run.WorkflowName) {
if slices.Contains(agenticWorkflowNames, run.WorkflowName) {
agenticRuns = append(agenticRuns, run)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/mcp_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"errors"
"fmt"
"slices"
"strings"
"time"

"github.com/github/gh-aw/pkg/sliceutil"
"github.com/github/gh-aw/pkg/workflow"
"github.com/modelcontextprotocol/go-sdk/jsonrpc"
)
Expand Down Expand Up @@ -89,7 +89,7 @@ func validateMCPWorkflowName(workflowName string) error {

// Check if it's a valid GitHub Actions workflow name
agenticWorkflowNames, nameErr := getAgenticWorkflowNames(false)
if nameErr == nil && sliceutil.Contains(agenticWorkflowNames, workflowName) {
if nameErr == nil && slices.Contains(agenticWorkflowNames, workflowName) {
mcpLog.Printf("Workflow name is valid GitHub Actions workflow name: %s", workflowName)
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/mcp_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package cli

import (
"encoding/json"
"slices"
"testing"
"time"

"github.com/github/gh-aw/pkg/sliceutil"
"github.com/google/jsonschema-go/jsonschema"
)

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestGenerateSchema(t *testing.T) {
// Check that items is an array type
// In v0.4.0+, nullable slices use Types []string with ["null", "array"]
// instead of Type string with "array"
isArray := itemsProp.Type == "array" || sliceutil.Contains(itemsProp.Types, "array")
isArray := itemsProp.Type == "array" || slices.Contains(itemsProp.Types, "array")
if !isArray {
t.Errorf("Expected items to be an array type, got Type='%s', Types=%v", itemsProp.Type, itemsProp.Types)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/cli/mcp_tool_schemas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ package cli

import (
"encoding/json"
"slices"
"testing"

"github.com/github/gh-aw/pkg/sliceutil"
)

// TestMCPToolOutputSchemas verifies that output schemas are correctly generated for MCP tools
Expand Down Expand Up @@ -102,7 +101,7 @@ func TestMCPToolOutputSchemas(t *testing.T) {
// This will be an array schema
// In v0.4.0+, nullable arrays use Types []string with ["null", "array"]
// instead of Type string with "array"
isArray := schema.Type == "array" || sliceutil.Contains(schema.Types, "array")
isArray := schema.Type == "array" || slices.Contains(schema.Types, "array")
if !isArray {
t.Errorf("Expected schema to be an array type, got Type='%s', Types=%v", schema.Type, schema.Types)
}
Expand Down
8 changes: 1 addition & 7 deletions pkg/cli/token_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,6 @@ func (s *TokenUsageSummary) AvgDurationMs() int {
return s.TotalDurationMs / s.TotalRequests
}

// FormatDurationMs formats milliseconds as a human-readable string.
// Deprecated: Use timeutil.FormatDurationMs instead.
func FormatDurationMs(ms int) string {
return timeutil.FormatDurationMs(ms)
}

// ModelRows returns the by-model data as sorted rows for console rendering
func (s *TokenUsageSummary) ModelRows() []ModelTokenUsageRow {
rows := make([]ModelTokenUsageRow, 0, len(s.ByModel))
Expand All @@ -287,7 +281,7 @@ func (s *TokenUsageSummary) ModelRows() []ModelTokenUsageRow {
CacheWriteTokens: usage.CacheWriteTokens,
EffectiveTokens: usage.EffectiveTokens,
Requests: usage.Requests,
AvgDuration: FormatDurationMs(avgDur),
AvgDuration: timeutil.FormatDurationMs(avgDur),
})
}
// Sort by total tokens descending
Expand Down
3 changes: 2 additions & 1 deletion pkg/cli/token_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/github/gh-aw/pkg/testutil"
"github.com/github/gh-aw/pkg/timeutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -230,7 +231,7 @@ func TestFormatDurationMs(t *testing.T) {

for _, tt := range tests {
t.Run(tt.expected, func(t *testing.T) {
assert.Equal(t, tt.expected, FormatDurationMs(tt.ms), "FormatDurationMs(%d)", tt.ms)
assert.Equal(t, tt.expected, timeutil.FormatDurationMs(tt.ms), "FormatDurationMs(%d)", tt.ms)
})
}
}
Expand Down
18 changes: 0 additions & 18 deletions pkg/mathutil/mathutil.go

This file was deleted.

Loading
Loading