Detailed changes
@@ -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++ {
@@ -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 {
@@ -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)
}
@@ -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
@@ -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() {