From 5aa7473e1407e97c9ac115c3dbb59bf0090b1681 Mon Sep 17 00:00:00 2001 From: dj-oyu <68707227+dj-oyu@users.noreply.github.com> Date: Sun, 22 Feb 2026 06:11:12 +0900 Subject: [PATCH] fix: strip trailing slash from workspace path in status display Paths like `/home/user/project/` caused empty project name because LastIndex found the trailing slash. TrimRight ensures correct extraction. Co-Authored-By: Claude Opus 4.6 --- pkg/agent/loop.go | 10 +++++----- pkg/agent/loop_test.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 0e4a5e22f..7f42a62fd 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -1152,11 +1152,11 @@ func buildRichStatus(task *activeTask, isBackground bool, workspace string) stri // Workspace: always emit for fixed height (show project name only) sb.WriteString("\U0001F4C1 ") if workspace != "" { - project := workspace - if idx := strings.LastIndex(workspace, "/"); idx >= 0 { - project = workspace[idx+1:] - } else if idx := strings.LastIndex(workspace, "\\"); idx >= 0 { - project = workspace[idx+1:] + project := strings.TrimRight(workspace, "/\\") + if idx := strings.LastIndex(project, "/"); idx >= 0 { + project = project[idx+1:] + } else if idx := strings.LastIndex(project, "\\"); idx >= 0 { + project = project[idx+1:] } sb.WriteString(project) } diff --git a/pkg/agent/loop_test.go b/pkg/agent/loop_test.go index 8b7d2a83e..5200ad7ad 100644 --- a/pkg/agent/loop_test.go +++ b/pkg/agent/loop_test.go @@ -1569,6 +1569,23 @@ func TestBuildRichStatus(t *testing.T) { } } +func TestBuildRichStatus_TrailingSlash(t *testing.T) { + task := &activeTask{ + Iteration: 1, + MaxIter: 10, + toolLog: []toolLogEntry{ + {Name: "exec", ArgsSnip: "ls", Result: "✓ 0.1s"}, + }, + } + // Trailing slash should not break project name extraction + for _, ws := range []string{"/home/user/terra-py-form/", "/home/user/terra-py-form", "C:\\Users\\dev\\terra-py-form\\"} { + got := buildRichStatus(task, false, ws) + if !strings.Contains(got, "terra-py-form") { + t.Errorf("workspace %q: expected 'terra-py-form' in output, got:\n%s", ws, got) + } + } +} + func TestBuildRichStatus_FixedHeight(t *testing.T) { // Test that output has the same number of lines regardless of entry count countLines := func(s string) int {