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
Match handoff directories through symlinks and platform path aliases
Claudec181daf81a47
diff --git a/cli/beacon/cmd/handoff_test.go b/cli/beacon/cmd/handoff_test.goindex 85e7692f..04a0df12 100644--- a/cli/beacon/cmd/handoff_test.go+++ b/cli/beacon/cmd/handoff_test.go@@ -138,18 +138,29 @@ func TestHandoffListJSONIsAnEmptyArrayNotNull(t *testing.T) {}func TestHandoffListFilters(t *testing.T) {- stubHandoffSources(t, handoffFixtureSessions()...)- out, _, err := runHandoff(t, "list", "--harness", "codex")- if err != nil || !strings.Contains(out, "codex-1") || strings.Contains(out, "claude-1") {- t.Fatalf("--harness codex = %v\n%s", err, out)- }- out, _, err = runHandoff(t, "list", "--dir", "/work/api")- if err != nil || !strings.Contains(out, "claude-1") || strings.Contains(out, "codex-1") {- t.Fatalf("--dir /work/api = %v\n%s", err, out)- }- out, _, err = runHandoff(t, "list", "--limit", "1")- if err != nil || strings.Count(strings.TrimSpace(out), "\n") != 1 {- t.Fatalf("--limit 1 = %v\n%s", err, out)+ api, web := t.TempDir(), t.TempDir()+ now := time.Now()+ stubHandoffSources(t,+ stubHandoffSource{harness: handoff.HarnessClaude, sessions: []handoff.Session{+ {Harness: handoff.HarnessClaude, ID: "claude-1", Directory: api, UpdatedAt: now.Add(-time.Minute)},+ }},+ stubHandoffSource{harness: handoff.HarnessCodex, sessions: []handoff.Session{+ {Harness: handoff.HarnessCodex, ID: "codex-1", Directory: web, UpdatedAt: now.Add(-time.Hour)},+ }},+ )+ for _, tc := range []struct {+ args []string+ want, without string+ }{+ {[]string{"--harness", "codex"}, "codex-1", "claude-1"},+ {[]string{"--dir", api}, "claude-1", "codex-1"},+ {[]string{"--dir", web}, "codex-1", "claude-1"},+ {[]string{"--limit", "1"}, "claude-1", "codex-1"},+ } {+ out, _, err := runHandoff(t, append([]string{"list"}, tc.args...)...)+ if err != nil || !strings.Contains(out, tc.want) || strings.Contains(out, tc.without) {+ t.Fatalf("list %q = %v (opts %+v)\n%s", tc.args, err, handoffOpts, out)+ }}}diff --git a/cli/beacon/internal/handoff/session.go b/cli/beacon/internal/handoff/session.goindex e2a23128..9765bdf0 100644--- a/cli/beacon/internal/handoff/session.go+++ b/cli/beacon/internal/handoff/session.go@@ -61,6 +61,7 @@ func (e *SourceError) Unwrap() error { return e.Err }func List(sources []Source, filter Filter) ([]Session, error) {var sessions []Sessionvar errs []error+ within := directoryMatcher(filter.Directory)for _, source := range sources {if filter.Harness != "" && source.Harness() != filter.Harness {continue@@ -76,7 +77,7 @@ func List(sources []Source, filter Filter) ([]Session, error) {if session.Subagent && !filter.IncludeSubagents {continue}- if filter.Directory != "" && !withinDirectory(session.Directory, filter.Directory) {+ if filter.Directory != "" && !within(session.Directory) {continue}sessions = append(sessions, session)@@ -152,7 +153,37 @@ func Find(sources []Source, harness, id string) (Session, error) {}}-// withinDirectory reports whether a session recorded in dir ran in root or below it.+// directoryMatcher returns a test for whether a session directory is root or below it. A runtime+// records the directory it resolved, and a shell reports the one the user typed: on macOS /var and+// /tmp are symlinks into /private, Windows has short 8.3 names, and home directories are often+// symlinked. When the paths do not match as written, both are compared with symlinks resolved.+func directoryMatcher(root string) func(dir string) bool {+ if root == "" {+ return func(string) bool { return true }+ }+ resolvedRoot, err := filepath.EvalSymlinks(root)+ if err != nil {+ resolvedRoot = ""+ }+ return func(dir string) bool {+ if dir == "" {+ return false+ }+ if withinDirectory(dir, root) {+ return true+ }+ if resolvedRoot == "" {+ return false+ }+ if withinDirectory(dir, resolvedRoot) {+ return true+ }+ resolved, err := filepath.EvalSymlinks(dir)+ return err == nil && withinDirectory(resolved, resolvedRoot)+ }+}++// withinDirectory reports whether dir is root or below it, comparing the paths as written.func withinDirectory(dir, root string) bool {if dir == "" {return falsediff --git a/cli/beacon/internal/handoff/session_test.go b/cli/beacon/internal/handoff/session_test.goindex f269a8c1..0978d700 100644--- a/cli/beacon/internal/handoff/session_test.go+++ b/cli/beacon/internal/handoff/session_test.go@@ -2,7 +2,9 @@ package handoffimport ("errors"+ "os""path/filepath"+ "sort""strings""testing""time"@@ -294,3 +296,43 @@ func TestWithinDirectory(t *testing.T) {}}}++// A runtime records the directory it resolved and a shell reports the one the user typed. On macOS+// /var and /tmp are symlinks into /private, so the two differ for the same place.+func TestListDirectoryFilterFollowsSymlinks(t *testing.T) {+ base := t.TempDir()+ real := filepath.Join(base, "real")+ if err := os.MkdirAll(filepath.Join(real, "pkg"), 0o755); err != nil {+ t.Fatal(err)+ }+ link := filepath.Join(base, "link")+ if err := os.Symlink(real, link); err != nil {+ t.Skipf("symlinks unavailable: %v", err)+ }+ other := t.TempDir()+ sources := []Source{fakeSource{harness: HarnessClaude, sessions: []Session{+ {Harness: HarnessClaude, ID: "recorded-real", Directory: filepath.Join(real, "pkg")},+ {Harness: HarnessClaude, ID: "recorded-link", Directory: link},+ {Harness: HarnessClaude, ID: "elsewhere", Directory: other},+ {Harness: HarnessClaude, ID: "gone", Directory: filepath.Join(base, "deleted")},+ }}}+ for _, tc := range []struct {+ root, want string+ }{+ {link, "claude_code/recorded-link,claude_code/recorded-real"},+ {real, "claude_code/recorded-link,claude_code/recorded-real"},+ {filepath.Join(link, "pkg"), "claude_code/recorded-real"},+ {other, "claude_code/elsewhere"},+ {filepath.Join(base, "missing-root"), ""},+ } {+ sessions, err := List(sources, Filter{Directory: tc.root})+ if err != nil {+ t.Fatal(err)+ }+ keys := sessionKeys(sessions)+ sort.Strings(keys)+ if got := strings.Join(keys, ","); got != tc.want {+ t.Fatalf("--dir %s = %q, want %q", tc.root, got, tc.want)+ }+ }+}