The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(gitlink): preserve whitespace in worktree and evidence paths (#1112)
Rudy Mizrahi Celekli17a5c8d562b9
diff --git a/cli/beacon/cmd/handoff_resume.go b/cli/beacon/cmd/handoff_resume.goindex 05727d16..710b017e 100644--- a/cli/beacon/cmd/handoff_resume.go+++ b/cli/beacon/cmd/handoff_resume.go@@ -90,11 +90,11 @@ func runHandoffResume(cmd *cobra.Command, args []string) error {if err != nil {return fmt.Errorf("resolve brief directory: %w", err)}- cwd := strings.TrimSpace(opts.cwd)- if cwd != "" {- if cwd, err = filepath.Abs(cwd); err != nil {- return fmt.Errorf("resolve --cwd: %w", err)- }+ cwd := opts.cwd+ if strings.TrimSpace(cwd) == "" {+ cwd = ""+ } else if cwd, err = filepath.Abs(cwd); err != nil {+ return fmt.Errorf("resolve --cwd: %w", err)}plan, err := handoff.PlanResume(session, handoff.PlanOptions{Target: target,diff --git a/cli/beacon/cmd/share.go b/cli/beacon/cmd/share.goindex fe76a12d..63e72306 100644--- a/cli/beacon/cmd/share.go+++ b/cli/beacon/cmd/share.go@@ -441,8 +441,8 @@ func shareStoreDirs() (handoff.StoreDirs, error) {// shareDirectory is the directory --cwd names, absolute, or the current one.func shareDirectory() (string, error) {- dir := strings.TrimSpace(shareOpts.cwd)- if dir == "" {+ dir := shareOpts.cwd+ if strings.TrimSpace(dir) == "" {dir = "."}abs, err := filepath.Abs(dir)diff --git a/cli/beacon/internal/gitlink/evidence.go b/cli/beacon/internal/gitlink/evidence.goindex 116def5e..685a3873 100644--- a/cli/beacon/internal/gitlink/evidence.go+++ b/cli/beacon/internal/gitlink/evidence.go@@ -155,7 +155,7 @@ func scanLogFile(ctx context.Context, path string, repo Repo, since, until time.session = &SessionEvidence{Link: link}sessions[key] = session}- cwd := strings.TrimSpace(event.Session.WorkingDirectory)+ cwd := event.Session.WorkingDirectoryif session.WorkingDirectory == "" && filepath.IsAbs(cwd) {session.WorkingDirectory = filepath.Clean(cwd)}diff --git a/cli/beacon/internal/gitlink/git.go b/cli/beacon/internal/gitlink/git.goindex a6f20639..6df027db 100644--- a/cli/beacon/internal/gitlink/git.go+++ b/cli/beacon/internal/gitlink/git.go@@ -154,9 +154,9 @@ func OpenRepo(ctx context.Context, g Git) (Repo, error) {// A bare repository has no top level, and nothing in one was written by an agent.return Repo{}, fmt.Errorf("%w (no work tree): %s", ErrNotRepository, g.dir())}- root := filepath.Clean(strings.TrimSpace(lines[0]))- gitDir := filepath.Clean(strings.TrimSpace(lines[1]))- common := strings.TrimSpace(lines[2])+ root := filepath.Clean(lines[0])+ gitDir := filepath.Clean(lines[1])+ common := lines[2]if !filepath.IsAbs(common) {// --git-common-dir is relative to the directory git ran in, not to the top level.base, err := filepath.Abs(g.dir())@@ -187,7 +187,6 @@ func (r Repo) roots() []string {// path is not inside the work tree. A relative path is taken relative to base, which is where the// session that recorded it was running.func (r Repo) RelPath(path, base string) (string, bool) {- path = strings.TrimSpace(path)if path == "" {return "", false}diff --git a/cli/beacon/internal/gitlink/relpath_test.go b/cli/beacon/internal/gitlink/relpath_test.goindex a4beb022..237c5e08 100644--- a/cli/beacon/internal/gitlink/relpath_test.go+++ b/cli/beacon/internal/gitlink/relpath_test.go@@ -1,9 +1,13 @@package gitlinkimport (+ "context""net/url"+ "os""path/filepath"+ "runtime""testing"+ "time")// Editors and MCP tools report files as file: URIs. They name the same file as the plain path.@@ -21,3 +25,59 @@ func TestRelPathReadsFileURIs(t *testing.T) {t.Errorf("a file on another host was placed in the repository as %q", rel)}}++func TestRepoPreservesWhitespacePaths(t *testing.T) {+ if runtime.GOOS == "windows" {+ t.Skip("Windows normalizes trailing spaces in paths")+ }+ r := newTestRepo(t)+ root := r.root + " "+ if err := os.Rename(r.root, root); err != nil {+ t.Fatal(err)+ }+ r.root = root+ repo, err := OpenRepo(context.Background(), r.gitClient())+ if err != nil {+ t.Fatal(err)+ }+ canonical, err := filepath.EvalSymlinks(root)+ if err != nil {+ t.Fatal(err)+ }+ if repo.Root != canonical {+ t.Fatalf("Root = %q, want %q", repo.Root, canonical)+ }+ for _, name := range []string{" notes.md", "notes.md ", " docs / notes.md "} {+ r.write(name, "content")+ for _, path := range []string{name, filepath.Join(root, name)} {+ if rel, ok := repo.RelPath(path, root); !ok || rel != name {+ t.Errorf("RelPath(%q) = %q, %v; want %q", path, rel, ok, name)+ }+ }+ }+}++func TestReadEvidencePreservesWhitespaceWorkingDirectory(t *testing.T) {+ if runtime.GOOS == "windows" {+ t.Skip("Windows normalizes trailing spaces in paths")+ }+ r := newTestRepo(t)+ repo := r.open()+ cwd := filepath.Join(repo.Root, "sub ")+ if err := os.MkdirAll(cwd, 0o755); err != nil {+ t.Fatal(err)+ }+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")+ writeLog(t, logPath, logEvent{at: t0, harness: "codex", session: "s", cwd: cwd, action: "file.modified", filePath: " notes.md ", operation: "modify"})+ got, err := ReadEvidence(context.Background(), repo, logPath, t0.Add(-time.Minute), t0.Add(time.Minute))+ if err != nil {+ t.Fatal(err)+ }+ evidence := got["codex_cli/s"]+ if evidence == nil {+ t.Fatal("missing session evidence")+ }+ if _, ok := evidence.Files["sub / notes.md "]; !ok {+ t.Fatalf("recorded files = %v", evidence.Files)+ }+}diff --git a/cli/beacon/internal/handoff/resume.go b/cli/beacon/internal/handoff/resume.goindex b6a44023..8541f27c 100644--- a/cli/beacon/internal/handoff/resume.go+++ b/cli/beacon/internal/handoff/resume.go@@ -160,8 +160,8 @@ func nativeBlocker(session Session, target string, opts PlanOptions) string {// resumeDir is the directory the runtime starts in. A runtime reopens and scopes a session by its// directory, so a session whose directory is gone does not start anywhere else by accident.func resumeDir(session Session, override string) (string, error) {- dir := strings.TrimSpace(override)- if dir == "" {+ dir := override+ if strings.TrimSpace(dir) == "" {dir = session.Directory}if dir == "" {diff --git a/cli/beacon/internal/handoff/resume_test.go b/cli/beacon/internal/handoff/resume_test.goindex 3f240c2d..1a795125 100644--- a/cli/beacon/internal/handoff/resume_test.go+++ b/cli/beacon/internal/handoff/resume_test.go@@ -232,7 +232,11 @@ func TestPlanResumeErrors(t *testing.T) {func TestPlanResumeDirectory(t *testing.T) {session := resumableSession(t, HarnessCodex, "s-1")- other := t.TempDir()+ // A directory name may end in a space; --cwd names that directory, not its trimmed sibling.+ other := filepath.Join(t.TempDir(), "other ")+ if err := os.Mkdir(other, 0o755); err != nil {+ t.Fatal(err)+ }plan, err := PlanResume(session, PlanOptions{Dir: other, LookPath: allRuntimes})if err != nil || plan.Dir != other {t.Fatalf("--cwd override = %q, %v", plan.Dir, err)diff --git a/cli/beacon/internal/handoff/runtimelog.go b/cli/beacon/internal/handoff/runtimelog.goindex 40f04501..6eada240 100644--- a/cli/beacon/internal/handoff/runtimelog.go+++ b/cli/beacon/internal/handoff/runtimelog.go@@ -118,7 +118,7 @@ func LogSessions(logPath string, filter Filter) ([]Session, error) {order = append(order, key)}if session.Directory == "" {- session.Directory = strings.TrimSpace(event.Session.WorkingDirectory)+ session.Directory = event.Session.WorkingDirectory}if session.Branch == "" {session.Branch = strings.TrimSpace(event.Branch)diff --git a/cli/beacon/internal/handoff/runtimelog_test.go b/cli/beacon/internal/handoff/runtimelog_test.goindex bf02a789..ac6fc7cf 100644--- a/cli/beacon/internal/handoff/runtimelog_test.go+++ b/cli/beacon/internal/handoff/runtimelog_test.go@@ -68,3 +68,24 @@ func TestLogSessionsIgnoresBeaconBookkeepingForRecency(t *testing.T) {t.Fatalf("sessions = %+v", sessions)}}++// A directory name may end in a space; the session is listed under that directory, not its+// trimmed sibling, so `beacon share` run there finds it.+func TestLogSessionsKeepsWhitespaceInTheDirectory(t *testing.T) {+ dir := t.TempDir()+ logPath := filepath.Join(dir, "runtime.jsonl")+ project := filepath.Join(dir, "app ")+ event := schema.NewEvent(schema.NewEventOptions{Action: "prompt.submitted", Category: "prompt", Harness: schema.HarnessInfo{Name: "kiro"}})+ event.Timestamp = "2026-10-01T10:00:00.000000000Z"+ event.Session = &schema.SessionInfo{ID: "k1", WorkingDirectory: project}+ if _, err := writer.AppendEvent(event, writer.Options{Path: logPath, UserMode: true}); err != nil {+ t.Fatal(err)+ }+ sessions, err := LogSessions(logPath, Filter{Directory: project})+ if err != nil {+ t.Fatal(err)+ }+ if len(sessions) != 1 || sessions[0].Directory != project {+ t.Fatalf("sessions = %+v, want one in %q", sessions, project)+ }+}diff --git a/pkg/asymptoteobserve/share.go b/pkg/asymptoteobserve/share.goindex 44e68bba..0e6f1db7 100644--- a/pkg/asymptoteobserve/share.go+++ b/pkg/asymptoteobserve/share.go@@ -305,8 +305,8 @@ func ShareEventID(event Event) string {func BuildShareBundle(events []Event, opts ShareOptions) TraceBundleV1 {if opts.WorkingDirectory == "" {for _, event := range events {- if event.Session != nil && strings.TrimSpace(event.Session.WorkingDirectory) != "" {- opts.WorkingDirectory = strings.TrimSpace(event.Session.WorkingDirectory)+ if event.Session != nil && event.Session.WorkingDirectory != "" {+ opts.WorkingDirectory = event.Session.WorkingDirectorybreak}}@@ -422,7 +422,7 @@ func shareSummaryForPublication(summary *TraceSummaryV1, events []Event, opts Shvar remote, branch, ref, project, workDir stringfor _, event := range events {if workDir == "" && event.Session != nil {- workDir = strings.TrimSpace(event.Session.WorkingDirectory)+ workDir = event.Session.WorkingDirectory}if event.VCS != nil {if event.VCS.Repository != nil && event.VCS.Repository.URL != nil && remote == "" {@@ -490,7 +490,6 @@ func shareSummaryForPublication(summary *TraceSummaryV1, events []Event, opts Sh// shareProjectName is the last segment of a directory or repository name, unless it is the home// directory, whose name is the local account's.func shareProjectName(value, home string) string {- value = strings.TrimSpace(value)if value == "" || samePath(value, home) {return ""}@@ -551,7 +550,7 @@ type pathScrubber struct {func newPathScrubber(work, home string) pathScrubber {clean := func(p string) string {- p = strings.TrimRight(strings.TrimSpace(p), `/\`)+ p = strings.TrimRight(p, `/\`)// A root or a single short segment would rewrite unrelated text.if len(p) < 3 {return ""@@ -830,12 +829,12 @@ func ShareBranch(name string) string {}func samePath(a, b string) bool {- a, b = strings.TrimRight(strings.TrimSpace(a), `/\`), strings.TrimRight(strings.TrimSpace(b), `/\`)+ a, b = strings.TrimRight(a, `/\`), strings.TrimRight(b, `/\`)return a != "" && a == b}func lastPathSegment(value string) string {- value = strings.TrimRight(strings.TrimSpace(value), `/\`)+ value = strings.TrimRight(value, `/\`)if i := strings.LastIndexAny(value, `/\:`); i >= 0 {value = value[i+1:]}diff --git a/pkg/asymptoteobserve/share_test.go b/pkg/asymptoteobserve/share_test.goindex 9ffd2717..4dc336a0 100644--- a/pkg/asymptoteobserve/share_test.go+++ b/pkg/asymptoteobserve/share_test.go@@ -566,6 +566,21 @@ func TestPathScrubberReplacesWholePathsOnly(t *testing.T) {}}+// A directory name may end in a space. The work directory is that directory, not its trimmed+// sibling, so its files are shown relative to it and the project keeps its name.+func TestShareKeepsWhitespaceInTheWorkingDirectory(t *testing.T) {+ event := shareEventAt("2026-10-01T10:00:00Z", "claude_code", CollectionMethodHook, "file.modified", "file")+ event.Session.WorkingDirectory = "/src/repo "+ event.File = &FileInfo{Path: "/src/repo /x", Operation: "modify"}+ bundle := BuildShareBundle([]Event{event}, shareTestOpts)+ if len(bundle.Events) != 1 || bundle.Events[0].File == nil || bundle.Events[0].File.Path != "x" {+ t.Fatalf("events = %+v", bundle.Events)+ }+ if bundle.Summary.Project == nil || bundle.Summary.Project.Name != "repo " {+ t.Fatalf("project = %+v", bundle.Summary.Project)+ }+}+func TestShareMessagesKeepsRepeatedPhaselessCallsApart(t *testing.T) {// Cursor's beforeReadFile records file.read with a path and nothing else. Reading the same file// twice is two calls, not a call and its result.diff --git a/pkg/asymptoteobserve/tracebuild.go b/pkg/asymptoteobserve/tracebuild.goindex b60fca67..1bf6c158 100644--- a/pkg/asymptoteobserve/tracebuild.go+++ b/pkg/asymptoteobserve/tracebuild.go@@ -521,9 +521,9 @@ func (b *TraceBuilder) Fold(event Event, traceEvent TraceEventV1) {}}if a.summary.Project == nil {- dir := strings.TrimSpace(event.Repository)+ dir := event.Repositoryif dir == "" && event.Session != nil {- dir = strings.TrimSpace(event.Session.WorkingDirectory)+ dir = event.Session.WorkingDirectory}if name := traceProjectName(dir); name != "" {a.summary.Project = &TraceProjectV1{Name: name}