on main help sign in
refactor: modernize (#2548)
commite3df84efb4067f61a0fcb8359308782ace5d9b1a authorBruno Krugel <brunokrugel@gmail.com> dateThu 2 Apr 2026, 10:24 (7 months ago) parentde04fc2
5 files changed+11−19
internal/agent/loop_detection_test.go+3−3 internal/cmd/session.go+1−4 internal/shell/background.go+3−3 internal/ui/anim/anim.go+2−2 internal/ui/completions/completions.go+2−7
internal/agent/loop_detection_test.go+3−3
@@ -80,7 +80,7 @@ func TestHasRepeatedToolCalls(t *testing.T) {
8080 t.Run("exact repeat at threshold not detected", func(t *testing.T) {
8181 // maxRepeats=5 means > 5 is needed, so exactly 5 should return false
8282 steps := make([]fantasy.StepResult, 10)
83− for i := 0; i < 5; i++ {
83+ for i := range 5 {
8484 steps[i] = makeToolStep("read", `{"file":"a.go"}`, "content")
8585 }
8686 for i := 5; i < 10; i++ {
@@ -95,7 +95,7 @@ func TestHasRepeatedToolCalls(t *testing.T) {
9595 t.Run("loop detected", func(t *testing.T) {
9696 // 6 identical steps in a window of 10 with maxRepeats=5 → detected
9797 steps := make([]fantasy.StepResult, 10)
98− for i := 0; i < 6; i++ {
98+ for i := range 6 {
9999 steps[i] = makeToolStep("read", `{"file":"a.go"}`, "content")
100100 }
101101 for i := 6; i < 10; i++ {
@@ -110,7 +110,7 @@ func TestHasRepeatedToolCalls(t *testing.T) {
110110 t.Run("steps without tool calls are skipped", func(t *testing.T) {
111111 // Mix of tool steps and empty steps — empty ones should not affect counts
112112 steps := make([]fantasy.StepResult, 10)
113− for i := 0; i < 4; i++ {
113+ for i := range 4 {
114114 steps[i] = makeToolStep("read", `{"file":"a.go"}`, "content")
115115 }
116116 for i := 4; i < 8; i++ {
internal/cmd/session.go+1−4
@@ -171,10 +171,7 @@ func runSessionList(cmd *cobra.Command, _ []string) error {
171171 width = tw
172172 }
173173 // 7 (hash) + 1 (space) + 25 (RFC3339 date) + 1 (space) = 34 chars prefix.
174− titleWidth := width - 34
175− if titleWidth < 10 {
176− titleWidth = 10
177− }
174+ titleWidth := max(width-34, 10)
178175
179176 var writeErr error
180177 for _, s := range list {
internal/shell/background.go+3−3
@@ -56,7 +56,7 @@ type BackgroundShell struct {
5656 stderr *syncBuffer
5757 done chan struct{}
5858 exitErr error
59− completedAt int64 // Unix timestamp when job completed (0 if still running)
59+ completedAt atomic.Int64 // Unix timestamp when job completed (0 if still running)
6060}
6161
6262// BackgroundShellManager manages background shell instances.
@@ -122,7 +122,7 @@ func (m *BackgroundShellManager) Start(ctx context.Context, workingDir string, b
122122 err := shell.ExecStream(shellCtx, command, bgShell.stdout, bgShell.stderr)
123123
124124 bgShell.exitErr = err
125− atomic.StoreInt64(&bgShell.completedAt, time.Now().Unix())
125+ bgShell.completedAt.Store(time.Now().Unix())
126126 }()
127127
128128 return bgShell, nil
@@ -178,7 +178,7 @@ func (m *BackgroundShellManager) Cleanup() int {
178178
179179 var toRemove []string
180180 for shell := range m.shells.Seq() {
181− completedAt := atomic.LoadInt64(&shell.completedAt)
181+ completedAt := shell.completedAt.Load()
182182 if completedAt > 0 && now-completedAt > retentionSeconds {
183183 toRemove = append(toRemove, shell.ID)
184184 }
internal/ui/anim/anim.go+2−2
@@ -57,10 +57,10 @@ var (
5757
5858// Internal ID management. Used during animating to ensure that frame messages
5959// are received only by spinner components that sent them.
60−var lastID int64
60+var lastID atomic.Int64
6161
6262func nextID() int {
63− return int(atomic.AddInt64(&lastID, 1))
63+ return int(lastID.Add(1))
6464}
6565
6666// Cache for expensive animation calculations
internal/ui/completions/completions.go+2−7
@@ -257,14 +257,9 @@ func namePriorityTier(path, queryLower string) int {
257257}
258258
259259func hasPathSegment(pathLower, queryLower string) bool {
260− for _, part := range strings.FieldsFunc(pathLower, func(r rune) bool {
260+ return slices.Contains(strings.FieldsFunc(pathLower, func(r rune) bool {
261261 return r == '/' || r == '\\'
262− }) {
263− if part == queryLower {
264− return true
265− }
266− }
267− return false
262+ }), queryLower)
268263}
269264
270265func (c *Completions) updateSize() {