Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Fix five bugs in Cursor session polling collector

Cursor Agent8d4ea20afae7
diff --git a/cli/beacon/internal/cursorsession/collect.go b/cli/beacon/internal/cursorsession/collect.go
index 8efc64dd..d056b0d7 100644
--- a/cli/beacon/internal/cursorsession/collect.go
+++ b/cli/beacon/internal/cursorsession/collect.go
@@ -150,7 +150,7 @@ func CollectOnce(opts CollectOptions) (summary Summary, err error) {
func collectTrace(store *Store, ref TraceRef, state *State, opts CollectOptions, summary *Summary) (bool, error) {
cursor := state.cursor(ref)
- if ref.UpdatedAtUnixMS > 0 && ref.UpdatedAtUnixMS <= cursor.UpdatedAtMS {
+ if ref.UpdatedAtUnixMS > 0 && ref.UpdatedAtUnixMS < cursor.UpdatedAtMS {
return false, nil
}
records, err := store.Read(ref)
diff --git a/cli/beacon/internal/cursorsession/parse.go b/cli/beacon/internal/cursorsession/parse.go
index d4149d28..56c75cd1 100644
--- a/cli/beacon/internal/cursorsession/parse.go
+++ b/cli/beacon/internal/cursorsession/parse.go
@@ -10,6 +10,7 @@ import (
"os"
"path/filepath"
"regexp"
+ "runtime"
"strconv"
"strings"
"time"
@@ -689,7 +690,8 @@ func resolveDashEncodedProjectDirectory(name string) string {
}
seen[key] = true
for end := len(parts); end > idx; end-- {
- candidate := filepath.Join(append([]string{root}, parts[idx:end]...)...)
+ component := strings.Join(parts[idx:end], "-")
+ candidate := filepath.Join(root, component)
info, err := os.Stat(candidate)
if err != nil || !info.IsDir() {
continue
@@ -703,8 +705,18 @@ func resolveDashEncodedProjectDirectory(name string) string {
}
return ""
}
- if resolved := walk(string(filepath.Separator), 0); resolved != "" {
- return resolved
+ roots := []string{string(filepath.Separator)}
+ if runtime.GOOS == "windows" && len(parts) > 0 && len(parts[0]) == 1 {
+ roots = append(roots, strings.ToUpper(parts[0])+`:\`)
+ }
+ for _, root := range roots {
+ start := 0
+ if root != string(filepath.Separator) {
+ start = 1
+ }
+ if resolved := walk(root, start); resolved != "" {
+ return resolved
+ }
}
return name
}
diff --git a/cli/beacon/internal/cursorsession/store.go b/cli/beacon/internal/cursorsession/store.go
index 094e79e2..d31416c9 100644
--- a/cli/beacon/internal/cursorsession/store.go
+++ b/cli/beacon/internal/cursorsession/store.go
@@ -73,14 +73,15 @@ func (s *Store) Exists() bool {
func (s *Store) List() ([]TraceRef, error) {
var refs []TraceRef
+ var errs []error
global, err := s.listGlobalStorage()
if err != nil {
- return refs, err
+ errs = append(errs, err)
}
refs = append(refs, global...)
transcripts, err := s.listTranscripts()
if err != nil {
- return refs, err
+ errs = append(errs, err)
}
refs = append(refs, transcripts...)
sort.SliceStable(refs, func(i, j int) bool {
@@ -89,6 +90,9 @@ func (s *Store) List() ([]TraceRef, error) {
}
return refs[i].ID < refs[j].ID
})
+ if len(refs) == 0 && len(errs) > 0 {
+ return refs, errors.Join(errs...)
+ }
return refs, nil
}
@@ -426,7 +430,11 @@ func (s *Store) readTranscript(ref TraceRef) ([]Record, error) {
}
func openSQLiteReadOnly(path string) (*sql.DB, error) {
- u := url.URL{Scheme: "file", Path: path}
+ uriPath := filepath.ToSlash(path)
+ if !strings.HasPrefix(uriPath, "/") {
+ uriPath = "/" + uriPath
+ }
+ u := url.URL{Scheme: "file", Path: uriPath}
q := u.Query()
q.Set("mode", "ro")
q.Set("_pragma", "busy_timeout(1000)")
diff --git a/cli/beacon/internal/cursorsession/types.go b/cli/beacon/internal/cursorsession/types.go
index 141575d8..6c2ef273 100644
--- a/cli/beacon/internal/cursorsession/types.go
+++ b/cli/beacon/internal/cursorsession/types.go
@@ -140,6 +140,9 @@ type jsonTimeOrNumber struct {
}
func (t *jsonTimeOrNumber) UnmarshalJSON(data []byte) error {
+ if string(data) == "null" {
+ return nil
+ }
var n float64
if err := json.Unmarshal(data, &n); err == nil {
t.Millis = int64(n)