diff --git a/internal/agent/loop_detection_test.go b/internal/agent/loop_detection_test.go index deb1a639ff19f7246c844a312e96466cd078b9bc..9e0405e09c91103846ae8fddf0f10fda5a4bf3c2 100644 --- a/internal/agent/loop_detection_test.go +++ b/internal/agent/loop_detection_test.go @@ -80,7 +80,7 @@ func TestHasRepeatedToolCalls(t *testing.T) { t.Run("exact repeat at threshold not detected", func(t *testing.T) { // maxRepeats=5 means > 5 is needed, so exactly 5 should return false steps := make([]fantasy.StepResult, 10) - for i := 0; i < 5; i++ { + for i := range 5 { steps[i] = makeToolStep("read", `{"file":"a.go"}`, "content") } for i := 5; i < 10; i++ { @@ -95,7 +95,7 @@ func TestHasRepeatedToolCalls(t *testing.T) { t.Run("loop detected", func(t *testing.T) { // 6 identical steps in a window of 10 with maxRepeats=5 → detected steps := make([]fantasy.StepResult, 10) - for i := 0; i < 6; i++ { + for i := range 6 { steps[i] = makeToolStep("read", `{"file":"a.go"}`, "content") } for i := 6; i < 10; i++ { @@ -110,7 +110,7 @@ func TestHasRepeatedToolCalls(t *testing.T) { t.Run("steps without tool calls are skipped", func(t *testing.T) { // Mix of tool steps and empty steps — empty ones should not affect counts steps := make([]fantasy.StepResult, 10) - for i := 0; i < 4; i++ { + for i := range 4 { steps[i] = makeToolStep("read", `{"file":"a.go"}`, "content") } for i := 4; i < 8; i++ { diff --git a/internal/cmd/session.go b/internal/cmd/session.go index 2d3793aec05d1701c67278e2dca08d8216398347..0a1020f9daaac77b1ee32818c255265522c41f09 100644 --- a/internal/cmd/session.go +++ b/internal/cmd/session.go @@ -171,10 +171,7 @@ func runSessionList(cmd *cobra.Command, _ []string) error { width = tw } // 7 (hash) + 1 (space) + 25 (RFC3339 date) + 1 (space) = 34 chars prefix. - titleWidth := width - 34 - if titleWidth < 10 { - titleWidth = 10 - } + titleWidth := max(width-34, 10) var writeErr error for _, s := range list { diff --git a/internal/shell/background.go b/internal/shell/background.go index cbcf7d3fe62005c7ee7af83831134a2c42d1bf84..55f85b6ce2781faae78dfa8df9e6c34e77e25eef 100644 --- a/internal/shell/background.go +++ b/internal/shell/background.go @@ -56,7 +56,7 @@ type BackgroundShell struct { stderr *syncBuffer done chan struct{} exitErr error - completedAt int64 // Unix timestamp when job completed (0 if still running) + completedAt atomic.Int64 // Unix timestamp when job completed (0 if still running) } // BackgroundShellManager manages background shell instances. @@ -122,7 +122,7 @@ func (m *BackgroundShellManager) Start(ctx context.Context, workingDir string, b err := shell.ExecStream(shellCtx, command, bgShell.stdout, bgShell.stderr) bgShell.exitErr = err - atomic.StoreInt64(&bgShell.completedAt, time.Now().Unix()) + bgShell.completedAt.Store(time.Now().Unix()) }() return bgShell, nil @@ -178,7 +178,7 @@ func (m *BackgroundShellManager) Cleanup() int { var toRemove []string for shell := range m.shells.Seq() { - completedAt := atomic.LoadInt64(&shell.completedAt) + completedAt := shell.completedAt.Load() if completedAt > 0 && now-completedAt > retentionSeconds { toRemove = append(toRemove, shell.ID) } diff --git a/internal/ui/anim/anim.go b/internal/ui/anim/anim.go index 3e159b102324a68bb93b8f9cbd3e128bf60dcf0f..deddbff2f0b88681a05120b3f85debc4b1a5404e 100644 --- a/internal/ui/anim/anim.go +++ b/internal/ui/anim/anim.go @@ -57,10 +57,10 @@ var ( // Internal ID management. Used during animating to ensure that frame messages // are received only by spinner components that sent them. -var lastID int64 +var lastID atomic.Int64 func nextID() int { - return int(atomic.AddInt64(&lastID, 1)) + return int(lastID.Add(1)) } // Cache for expensive animation calculations diff --git a/internal/ui/completions/completions.go b/internal/ui/completions/completions.go index b819e8b974513971e9ddfdc7f04d068b433d685a..0a63e789b040f3b17b671c1f6ddb5c8be0f12f1c 100644 --- a/internal/ui/completions/completions.go +++ b/internal/ui/completions/completions.go @@ -257,14 +257,9 @@ func namePriorityTier(path, queryLower string) int { } func hasPathSegment(pathLower, queryLower string) bool { - for _, part := range strings.FieldsFunc(pathLower, func(r rune) bool { + return slices.Contains(strings.FieldsFunc(pathLower, func(r rune) bool { return r == '/' || r == '\\' - }) { - if part == queryLower { - return true - } - } - return false + }), queryLower) } func (c *Completions) updateSize() {