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
handoff: add Cursor
Claudea1a8c5e41273
diff --git a/cli/beacon/cmd/handoff_resume_test.go b/cli/beacon/cmd/handoff_resume_test.goindex 049de73a..e976aea6 100644--- a/cli/beacon/cmd/handoff_resume_test.go+++ b/cli/beacon/cmd/handoff_resume_test.go@@ -238,7 +238,7 @@ func TestHandoffResumeErrors(t *testing.T) {if _, _, err := runResume(t, f, "claude-1", "--agent", "opencode", "--yes"); !errors.Is(err, handoff.ErrRuntimeNotInstalled) {t.Fatalf("uninstalled target err = %v", err)}- if _, _, err := runResume(t, f, "claude-1", "--agent", "cursor"); err == nil || !strings.Contains(err.Error(), "--agent") {+ if _, _, err := runResume(t, f, "claude-1", "--agent", "no-such-runtime"); err == nil || !strings.Contains(err.Error(), "--agent") {t.Fatalf("unsupported --agent err = %v", err)}handoffLaunch = func(handoff.Plan, io.Reader, io.Writer, io.Writer) (int, error) {@@ -254,9 +254,9 @@ func TestHandoffResumeErrors(t *testing.T) {func TestHandoffResumeFromTheRuntimeLogStartsANewSession(t *testing.T) {f := newResumeFixture(t)- logPath := handoffLog(t, "cursor", "cursor-conv-1", "rename the module")+ logPath := handoffLog(t, "gemini_cli", "gemini-conv-1", "rename the module")dir := t.TempDir()- _, _, err := runResume(t, f, "cursor-conv-1", "--log-path", logPath, "--agent", "claude", "--cwd", dir, "--yes")+ _, _, err := runResume(t, f, "gemini-conv-1", "--log-path", logPath, "--agent", "claude", "--cwd", dir, "--yes")if err != nil {t.Fatalf("resume: %v", err)}diff --git a/cli/beacon/cmd/handoff_test.go b/cli/beacon/cmd/handoff_test.goindex b193e800..a79aca8c 100644--- a/cli/beacon/cmd/handoff_test.go+++ b/cli/beacon/cmd/handoff_test.go@@ -411,8 +411,8 @@ func TestHandoffExportDefaultsUnderTheBeaconDirectory(t *testing.T) {func TestHandoffExportFallsBackToTheRuntimeLog(t *testing.T) {stubHandoffClock(t)stubHandoffSources(t, stubHandoffSource{harness: handoff.HarnessClaude})- logPath := handoffLog(t, "cursor", "cursor-conv-1", "rename the module")- out, stderr, err := runHandoff(t, "export", "cursor-conv-1", "--log-path", logPath, "--output-dir", t.TempDir())+ logPath := handoffLog(t, "gemini_cli", "gemini-conv-1", "rename the module")+ out, stderr, err := runHandoff(t, "export", "gemini-conv-1", "--log-path", logPath, "--output-dir", t.TempDir())if err != nil {t.Fatalf("export: %v", err)}@@ -423,9 +423,19 @@ func TestHandoffExportFallsBackToTheRuntimeLog(t *testing.T) {if !strings.Contains(string(data), "rename the module") || !strings.Contains(string(data), "comes from Beacon's runtime log") {t.Fatalf("log brief:\n%s", data)}- if !strings.Contains(stderr, "beacon handoff does not read cursor session stores") {+ if !strings.Contains(stderr, "beacon handoff does not read gemini_cli session stores") {t.Fatalf("stderr should say why the brief came from the log: %q", stderr)}++ // A runtime whose store Beacon reads, but which no longer has the session, says so instead.+ cursorLog := handoffLog(t, "cursor", "cursor-conv-1", "rename the module")+ _, stderr, err = runHandoff(t, "export", "cursor-conv-1", "--log-path", cursorLog, "--output-dir", t.TempDir())+ if err != nil {+ t.Fatalf("export: %v", err)+ }+ if !strings.Contains(stderr, "cursor session cursor-conv-1 is no longer in its runtime's store") {+ t.Fatalf("stderr should say the store lost the session: %q", stderr)+ }}func TestHandoffExportRefusesTheLogWhenTheSessionsStoreIsUnreadable(t *testing.T) {@@ -438,8 +448,8 @@ func TestHandoffExportRefusesTheLogWhenTheSessionsStoreIsUnreadable(t *testing.T}// Another runtime's session in the log is unaffected by the unreadable Claude store.- cursorLog := handoffLog(t, "cursor", "cursor-conv-1", "rename the module")- out, _, err := runHandoff(t, "export", "cursor-conv-1", "--print", "--log-path", cursorLog)+ geminiLog := handoffLog(t, "gemini_cli", "gemini-conv-1", "rename the module")+ out, _, err := runHandoff(t, "export", "gemini-conv-1", "--print", "--log-path", geminiLog)if err != nil || !strings.Contains(out, "rename the module") {t.Fatalf("export = %v\n%s", err, out)}@@ -486,8 +496,8 @@ func TestHandoffExportErrors(t *testing.T) {t.Fatalf("unknown session err = %v", err)}- logPath := handoffLog(t, "cursor", "cursor-conv-1", "x")- if _, _, err := runHandoff(t, "export", "cursor-conv-1", "--harness", "codex", "--log-path", logPath); !errors.Is(err, handoff.ErrNotFound) {+ logPath := handoffLog(t, "gemini_cli", "gemini-conv-1", "x")+ if _, _, err := runHandoff(t, "export", "gemini-conv-1", "--harness", "codex", "--log-path", logPath); !errors.Is(err, handoff.ErrNotFound) {t.Fatalf("--harness must also scope the log fallback, got %v", err)}@@ -506,9 +516,9 @@ func TestHandoffExportErrors(t *testing.T) {func TestHandoffExportFindsALogSessionByPrefix(t *testing.T) {stubHandoffClock(t)stubHandoffSources(t, stubHandoffSource{harness: handoff.HarnessClaude})- logPath := handoffLog(t, "cursor", "cursor-conv-1234", "rename the module")- out, _, err := runHandoff(t, "export", "cursor-conv", "--print", "--log-path", logPath)- if err != nil || !strings.Contains(out, "rename the module") || !strings.Contains(out, "`cursor-conv-1234`") {+ logPath := handoffLog(t, "gemini_cli", "gemini-conv-1234", "rename the module")+ out, _, err := runHandoff(t, "export", "gemini-conv", "--print", "--log-path", logPath)+ if err != nil || !strings.Contains(out, "rename the module") || !strings.Contains(out, "`gemini-conv-1234`") {t.Fatalf("export by prefix = %v\n%s", err, out)}}diff --git a/cli/beacon/internal/cursorsession/handoff_test.go b/cli/beacon/internal/cursorsession/handoff_test.gonew file mode 100644index 00000000..80119c16--- /dev/null+++ b/cli/beacon/internal/cursorsession/handoff_test.go@@ -0,0 +1,63 @@+package cursorsession++import (+ "testing"++ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"+)++func TestMapTraceRecordsAHandoffLink(t *testing.T) {+ ref := TraceRef{ID: "new-1", Kind: SourceTranscript, SourcePath: "/tmp/new-1.jsonl", Workspace: "/work"}+ prompt := "Continue the work.\n\n" + asymptoteobserve.HandoffMarker("claude_code", "src-1")+ records := []Record{+ {Order: 1, NativeID: "u1", Type: "user_message", Content: prompt},+ {Order: 2, NativeID: "a1", Type: "agent_text", Content: "Reading the brief."},+ {Order: 3, NativeID: "u2", Type: "user_message", Content: "no marker here"},+ }+ mapped := MapTrace(ref, records, MapOptions{})+ var links []MappedEvent+ for _, m := range mapped {+ if m.Event.Event.Action == "session.handoff" {+ links = append(links, m)+ }+ }+ if len(links) != 1 {+ t.Fatalf("links = %d, want 1: %+v", len(links), mapped)+ }+ link := links[0]+ if link.SourceOrder != 1 || link.Event.Handoff == nil || link.Event.Handoff.SourceHarness != "claude_code" || link.Event.Handoff.SourceSessionID != "src-1" {+ t.Fatalf("link = %+v handoff=%+v", link, link.Event.Handoff)+ }+ if link.Event.Session == nil || link.Event.Session.ID != "new-1" || link.Event.Session.WorkingDirectory != "/work" {+ t.Fatalf("link session = %+v", link.Event.Session)+ }+ if link.Event.Harness.Name != Harness || link.Event.Harness.CollectionMethod != "poll" || link.Event.Event.Fidelity != "observed" {+ t.Fatalf("link provenance = %+v %+v", link.Event.Harness, link.Event.Event)+ }+ if link.Event.Prompt != nil || link.Event.Content != nil || (link.Event.GenAI != nil && link.Event.GenAI.Input != nil) {+ t.Fatalf("the link must not repeat the prompt: %+v", link.Event)+ }+ // The prompt is still recorded, from the same record, ahead of its link.+ if mapped[0].Event.Event.Action != "prompt.submitted" || mapped[0].SourceOrder != 1 || mapped[1].Event.Event.Action != "session.handoff" {+ t.Fatalf("mapped = %+v", mapped)+ }+ ids := map[string]bool{}+ for _, m := range mapped {+ if ids[m.Event.Event.ID] {+ t.Fatalf("duplicate event id %s", m.Event.Event.ID)+ }+ ids[m.Event.Event.ID] = true+ }+ again := MapTrace(ref, records, MapOptions{})+ for i := range mapped {+ if again[i].Event.Event.ID != mapped[i].Event.Event.ID {+ t.Fatal("event ids must be deterministic, so a second sync never duplicates the link")+ }+ }+ // A sync that already read the prompt's record emits neither the prompt nor its link again.+ for _, m := range MapTrace(ref, records, MapOptions{MinOrder: 1}) {+ if m.Event.Event.Action == "session.handoff" {+ t.Fatal("the link belongs to the record it came from")+ }+ }+}diff --git a/cli/beacon/internal/cursorsession/mapper.go b/cli/beacon/internal/cursorsession/mapper.goindex d8b87f5c..f5e4a8cf 100644--- a/cli/beacon/internal/cursorsession/mapper.go+++ b/cli/beacon/internal/cursorsession/mapper.go@@ -34,12 +34,33 @@ func MapTrace(ref TraceRef, records []Record, opts MapOptions) []MappedEvent {if !ok {continue}- ev.Event.ID = cursorEventID(fmt.Sprintf("%s:%s:%d:%s:%s", ref.Kind, ref.ID, record.Order, record.NativeID, record.Type))+ key := fmt.Sprintf("%s:%s:%d:%s:%s", ref.Kind, ref.ID, record.Order, record.NativeID, record.Type)+ ev.Event.ID = cursorEventID(key)out = append(out, MappedEvent{SourceOrder: record.Order, Event: ev})+ // The link shares its prompt's record, so a sync that resumes from that record's order+ // never splits the pair.+ if link, ok := handoffLink(ref, record); ok {+ link.Event.ID = cursorEventID(key + ":handoff")+ out = append(out, MappedEvent{SourceOrder: record.Order, Event: link})+ }}return out}+// handoffLink is the session.handoff event for a prompt that carries the handoff marker.+func handoffLink(ref TraceRef, record Record) (schema.Event, bool) {+ if record.Type != "user_message" {+ return schema.Event{}, false+ }+ info, ok := asymptoteobserve.ParseHandoffMarker(record.Content)+ if !ok {+ return schema.Event{}, false+ }+ link := baseEvent(ref, record, "session.handoff", "session", schema.SeverityInfo, schema.FidelityObserved, "Session continued from a "+info.SourceHarness+" session")+ link.Handoff = &info+ return link, true+}+func mapRecord(ref TraceRef, record Record) (schema.Event, bool) {ev := baseEvent(ref, record, "tool.completed", "tool", schema.SeverityInfo, schema.FidelityObserved, "Cursor session event")switch record.Type {diff --git a/cli/beacon/internal/handoff/brief_test.go b/cli/beacon/internal/handoff/brief_test.goindex 55e3bd27..a5fee14f 100644--- a/cli/beacon/internal/handoff/brief_test.go+++ b/cli/beacon/internal/handoff/brief_test.go@@ -335,7 +335,7 @@ func TestEventsForASessionThatIsGone(t *testing.T) {if _, err := Events(sources, session); err == nil || !strings.Contains(err.Error(), "no longer in its store") {t.Fatalf("err = %v", err)}- if _, err := Events(sources, Session{Harness: "cursor"}); err == nil {+ if _, err := Events(sources, Session{Harness: "gemini_cli"}); err == nil {t.Fatal("an unsupported runtime must be an error")}if _, err := Events([]Source{fakeSource{harness: HarnessClaude}}, Session{Harness: HarnessClaude}); err == nil {@@ -354,8 +354,8 @@ func actionList(events []schema.Event) string {func TestLogSession(t *testing.T) {logPath := filepath.Join(t.TempDir(), "runtime.jsonl")lines := []string{- `{"timestamp":"2026-09-25T09:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"prompt.submitted","category":"prompt"},"severity":"info","endpoint":{"hostname":"h","os":"linux"},"harness":{"name":"cursor"},"session":{"id":"cur-1","working_directory":"/work/x"},"branch":"dev","prompt":{"text":"rename the module"}}`,- `{"timestamp":"2026-09-25T09:05:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"prompt.submitted","category":"prompt"},"severity":"info","endpoint":{"hostname":"h","os":"linux"},"harness":{"name":"cursor"},"session":{"id":"other"},"prompt":{"text":"unrelated"}}`,+ `{"timestamp":"2026-09-25T09:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"prompt.submitted","category":"prompt"},"severity":"info","endpoint":{"hostname":"h","os":"linux"},"harness":{"name":"gemini_cli"},"session":{"id":"cur-1","working_directory":"/work/x"},"branch":"dev","prompt":{"text":"rename the module"}}`,+ `{"timestamp":"2026-09-25T09:05:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"prompt.submitted","category":"prompt"},"severity":"info","endpoint":{"hostname":"h","os":"linux"},"harness":{"name":"gemini_cli"},"session":{"id":"other"},"prompt":{"text":"unrelated"}}`,}writeFixture(t, logPath, strings.Join(lines, "\n")+"\n")@@ -363,14 +363,14 @@ func TestLogSession(t *testing.T) {if err != nil || !found {t.Fatalf("LogSession = %v, %v", found, err)}- if session.Harness != "cursor" || session.Directory != "/work/x" || session.Branch != "dev" || len(events) != 1 {+ if session.Harness != "gemini_cli" || session.Directory != "/work/x" || session.Branch != "dev" || len(events) != 1 {t.Fatalf("session = %+v, %d events", session, len(events))}if !session.UpdatedAt.Equal(time.Date(2026, 9, 25, 9, 0, 0, 0, time.UTC)) {t.Fatalf("updated = %s", session.UpdatedAt)}brief := BuildBrief(session, events, FromRuntimeLog, briefNow)- if brief.FirstRequest != "rename the module" || !strings.Contains(brief.Render(), "a cursor session") {+ if brief.FirstRequest != "rename the module" || !strings.Contains(brief.Render(), "a gemini_cli session") {t.Fatalf("log brief = %+v", brief)}if _, _, found, err := LogSession(logPath, "missing", ""); found || err != nil {diff --git a/cli/beacon/internal/handoff/cursor.go b/cli/beacon/internal/handoff/cursor.gonew file mode 100644index 00000000..e8172abd--- /dev/null+++ b/cli/beacon/internal/handoff/cursor.go@@ -0,0 +1,137 @@+package handoff++import (+ "crypto/md5"+ "encoding/hex"+ "os"+ "path/filepath"+ "sort"+ "strings"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/cursorsession"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"+)++// Cursor keeps sessions in two stores: Composer conversations in its global storage SQLite+// database, and agent transcripts under ~/.cursor/projects, which the IDE and the cursor-agent CLI+// both write. One conversation can be in both under the same id.++type cursorSource struct{ dir string }++func (s *cursorSource) Harness() string { return HarnessCursor }++// store reads dir as Cursor's projects directory, as `beacon endpoint cursor sync --projects-dir`+// does. The global storage database is always read from its default location.+func (s *cursorSource) store() (*cursorsession.Store, error) {+ return cursorsession.NewStore("", s.dir)+}++func (s *cursorSource) List() ([]Session, error) {+ store, err := s.store()+ if err != nil {+ return nil, err+ }+ if !store.Exists() {+ return nil, nil+ }+ // Cursor has two stores; List returns what it could read alongside any error.+ refs, err := store.List()+ byID := map[string]Session{}+ for _, ref := range refs {+ session := Session{+ Harness: HarnessCursor,+ ID: ref.ID,+ Title: oneLine(firstNonEmpty(ref.Title, ref.Preview)),+ Directory: ref.Workspace,+ SourcePath: ref.SourcePath,+ Store: string(ref.Kind),+ UpdatedAt: unixMS(ref.UpdatedAtUnixMS),+ Subagent: ref.RelationshipType == "subagent",+ ParentID: relatedParent(ref.RelationshipType, ref.RelatedTo),+ }+ // A conversation stored twice is listed once: as the transcript when cursor-agent can+ // reopen it, else as the Composer record, which is Cursor's own conversation store.+ if prev, ok := byID[ref.ID]; ok && !cursorPrefer(session, prev) {+ continue+ }+ byID[ref.ID] = session+ }+ sessions := make([]Session, 0, len(byID))+ for _, session := range byID {+ sessions = append(sessions, session)+ }+ sort.Slice(sessions, func(i, j int) bool { return sessions[i].ID < sessions[j].ID })+ return sessions, err+}++func cursorPrefer(candidate, current Session) bool {+ if cursorCLIChat(current) {+ return false+ }+ return cursorCLIChat(candidate) || candidate.Store == string(cursorsession.SourceGlobalStorage)+}++func (s *cursorSource) Events(session Session) ([]schema.Event, error) {+ store, err := s.store()+ if err != nil {+ return nil, err+ }+ refs, listErr := store.List()+ for _, ref := range refs {+ if ref.ID != session.ID || ref.SourcePath != session.SourcePath {+ continue+ }+ records, err := store.Read(ref)+ if err != nil {+ return nil, err+ }+ mapped := cursorsession.MapTrace(ref, records, cursorsession.MapOptions{})+ events := make([]schema.Event, 0, len(mapped))+ for _, m := range mapped {+ events = append(events, m.Event)+ }+ return events, nil+ }+ if listErr != nil {+ return nil, listErr+ }+ return nil, errSessionGone(session)+}++// cursorCLIChat reports whether session is a chat cursor-agent can reopen with --resume. The CLI+// keeps each chat it started in chats/<md5 of the directory it ran in>/<chat id>/store.db under its+// config directory, and resumes a chat id from the directory it is started in. IDE conversations+// have no such store, so only a transcript with one is resumable.+func cursorCLIChat(session Session) bool {+ if session.Store != string(cursorsession.SourceTranscript) || session.Subagent || session.ID == "" || session.Directory == "" {+ return false+ }+ root := cursorConfigDir()+ if root == "" {+ return false+ }+ // The CLI hashes its working directory as the operating system reports it, symlinks resolved.+ dir := session.Directory+ if resolved, err := filepath.EvalSymlinks(dir); err == nil {+ dir = resolved+ }+ sum := md5.Sum([]byte(dir))+ info, err := os.Stat(filepath.Join(root, "chats", hex.EncodeToString(sum[:]), session.ID, "store.db"))+ return err == nil && info.Mode().IsRegular()+}++// cursorConfigDir is cursor-agent's config directory: CURSOR_CONFIG_DIR, else+// $XDG_CONFIG_HOME/cursor, else ~/.cursor.+func cursorConfigDir() string {+ if dir := strings.TrimSpace(os.Getenv("CURSOR_CONFIG_DIR")); dir != "" {+ return dir+ }+ if xdg := strings.TrimSpace(os.Getenv("XDG_CONFIG_HOME")); xdg != "" {+ return filepath.Join(xdg, "cursor")+ }+ home, err := os.UserHomeDir()+ if err != nil || strings.TrimSpace(home) == "" {+ return ""+ }+ return filepath.Join(home, ".cursor")+}diff --git a/cli/beacon/internal/handoff/cursor_test.go b/cli/beacon/internal/handoff/cursor_test.gonew file mode 100644index 00000000..0536f9b6--- /dev/null+++ b/cli/beacon/internal/handoff/cursor_test.go@@ -0,0 +1,265 @@+package handoff++import (+ "crypto/md5"+ "database/sql"+ "encoding/hex"+ "errors"+ "os"+ "path/filepath"+ "reflect"+ "regexp"+ "runtime"+ "strings"+ "testing"+ "time"++ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/cursorsession"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"+)++var cursorUpdated = time.Date(2026, 9, 24, 11, 0, 0, 0, time.UTC)++type cursorStores struct {+ dirs StoreDirs+ workspace string+ cliPath string+ idePath string+}++// cursorWorkspace is a directory Cursor's dash-encoded project name decodes back to. The decoding+// splits on dashes, so the path may hold no other punctuation, which rules out macOS and Windows+// temporary directories.+func cursorWorkspace(t *testing.T) string {+ t.Helper()+ if runtime.GOOS == "windows" {+ t.Skip("Windows temporary paths do not survive Cursor's project-name encoding")+ }+ root, err := os.MkdirTemp("/tmp", "beaconcursor")+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { os.RemoveAll(root) })+ dir := filepath.Join(root, "work", "api")+ if err := os.MkdirAll(dir, 0o755); err != nil {+ t.Fatal(err)+ }+ return dir+}++// cursorProjectName encodes a workspace path the way Cursor names its project directories.+func cursorProjectName(path string) string {+ return strings.Trim(regexp.MustCompile(`[^a-zA-Z0-9]+`).ReplaceAllString(path, "-"), "-")+}++// writeCursorChatStore lays down the chat store cursor-agent keeps for a chat it started in dir.+func writeCursorChatStore(t *testing.T, dir, id string) {+ t.Helper()+ resolved, err := filepath.EvalSymlinks(dir)+ if err != nil {+ t.Fatal(err)+ }+ sum := md5.Sum([]byte(resolved))+ writeFixture(t, filepath.Join(cursorConfigDir(), "chats", hex.EncodeToString(sum[:]), id, "store.db"), "sqlite")+}++// cursorFixture lays down both of Cursor's stores in the layout Cursor writes: Composer records in+// the global storage database, and agent transcripts under the projects directory. cli-1 is a chat+// cursor-agent started, ide-2 an IDE conversation with a subagent, and composer-1 a Composer+// conversation. cli-1 and ide-2 are in the global storage database too.+func cursorFixture(t *testing.T) cursorStores {+ t.Helper()+ testenv.SetHome(t, t.TempDir())+ isolateRuntimeEnv(t)+ ws := cursorWorkspace(t)+ f := cursorStores{dirs: StoreDirs{HarnessCursor: filepath.Join(t.TempDir(), "projects")}, workspace: ws}++ transcripts := filepath.Join(f.dirs[HarnessCursor], cursorProjectName(ws), "agent-transcripts")+ f.cliPath = filepath.Join(transcripts, "cli-1", "cli-1.jsonl")+ writeFixture(t, f.cliPath,+ jsonLine(t, map[string]interface{}{"type": "user_message", "id": "u1", "text": " tidy the\nrouter ", "timestamp": "2026-09-24T10:58:00Z"})++ jsonLine(t, map[string]interface{}{"type": "message", "id": "a1", "message": map[string]interface{}{"role": "assistant", "content": []interface{}{map[string]interface{}{"type": "text", "text": "Done."}}}, "timestamp": "2026-09-24T10:59:00Z"}))+ setModTime(t, f.cliPath, cursorUpdated)+ writeCursorChatStore(t, ws, "cli-1")++ f.idePath = filepath.Join(transcripts, "ide-2.jsonl")+ writeFixture(t, f.idePath, jsonLine(t, map[string]interface{}{"type": "user_message", "id": "u1", "text": "plot the latency"}))+ setModTime(t, f.idePath, cursorUpdated.Add(-time.Hour))+ sub := filepath.Join(transcripts, "ide-2", "subagents", "sub-1.jsonl")+ writeFixture(t, sub, jsonLine(t, map[string]interface{}{"type": "user_message", "id": "u1", "text": "read the csv"}))+ setModTime(t, sub, cursorUpdated.Add(-30*time.Minute))++ dbPath := cursorsession.DefaultGlobalDBPath()+ if err := os.MkdirAll(filepath.Dir(dbPath), 0o755); err != nil {+ t.Fatal(err)+ }+ db, err := sql.Open("sqlite", dbPath)+ if err != nil {+ t.Fatal(err)+ }+ defer db.Close()+ if _, err := db.Exec(`CREATE TABLE cursorDiskKV (key TEXT PRIMARY KEY, value BLOB)`); err != nil {+ t.Fatal(err)+ }+ composer := func(id, name string, updated time.Time) string {+ return mustJSON(t, map[string]interface{}{+ "composerId": id, "name": name, "lastUpdatedAt": updated.UnixMilli(),+ "context": map[string]interface{}{"path": ws},+ "fullConversationHeadersOnly": []interface{}{map[string]interface{}{"bubbleId": "b1", "type": 1}},+ })+ }+ for key, value := range map[string]string{+ "composerData:composer-1": composer("composer-1", "Investigate the build", cursorUpdated.Add(-2*time.Hour)),+ "bubbleId:composer-1:b1": `{"type":1,"text":"why is the build red"}`,+ "composerData:cli-1": composer("cli-1", "Tidy the router", cursorUpdated),+ "bubbleId:cli-1:b1": `{"type":1,"text":"tidy the router"}`,+ "composerData:ide-2": composer("ide-2", "Plot the latency", cursorUpdated.Add(-time.Hour)),+ "bubbleId:ide-2:b1": `{"type":1,"text":"plot the latency"}`,+ } {+ if _, err := db.Exec(`INSERT INTO cursorDiskKV(key, value) VALUES (?, ?)`, key, []byte(value)); err != nil {+ t.Fatal(err)+ }+ }+ return f+}++func TestListReadsCursorSessions(t *testing.T) {+ f := cursorFixture(t)+ sessions, err := List(DefaultSources(f.dirs), Filter{Harness: HarnessCursor, IncludeSubagents: true})+ if err != nil {+ t.Fatalf("List: %v", err)+ }+ byID := map[string]Session{}+ for _, s := range sessions {+ byID[s.ID] = s+ }+ if len(sessions) != 4 {+ t.Fatalf("sessions = %v, want each conversation once", sessionKeys(sessions))+ }+ // A chat cursor-agent can reopen is listed as its transcript.+ want := Session{Harness: HarnessCursor, ID: "cli-1", Title: "tidy the router", Directory: f.workspace, SourcePath: f.cliPath, Store: string(cursorsession.SourceTranscript), UpdatedAt: cursorUpdated}+ if !reflect.DeepEqual(byID["cli-1"], want) {+ t.Fatalf("cli session = %+v\nwant %+v", byID["cli-1"], want)+ }+ // An IDE conversation stored twice is listed as its Composer record.+ ide := byID["ide-2"]+ if ide.Store != string(cursorsession.SourceGlobalStorage) || ide.SourcePath != "global:ide-2" || ide.Title != "Plot the latency" || ide.Directory != f.workspace {+ t.Fatalf("ide session = %+v", ide)+ }+ if comp := byID["composer-1"]; comp.Store != string(cursorsession.SourceGlobalStorage) || comp.Title != "Investigate the build" || comp.Subagent {+ t.Fatalf("composer session = %+v", comp)+ }+ if sub := byID["sub-1"]; !sub.Subagent || sub.ParentID != "ide-2" || sub.Title != "read the csv" {+ t.Fatalf("subagent = %+v, want a subagent of ide-2", sub)+ }++ top, err := List(DefaultSources(f.dirs), Filter{Harness: HarnessCursor})+ if err != nil {+ t.Fatal(err)+ }+ if got := strings.Join(sessionKeys(top), ","); got != "cursor/cli-1,cursor/ide-2,cursor/composer-1" {+ t.Fatalf("top-level sessions = %s, want newest first without the subagent", got)+ }+}++func TestCursorSessionsBuildABrief(t *testing.T) {+ f := cursorFixture(t)+ sources := DefaultSources(f.dirs)+ for _, tc := range []struct{ id, request string }{+ {"cli-1", "tidy the"},+ // A unique prefix finds the session too.+ {"compose", "why is the build red"},+ {"sub-1", "read the csv"},+ } {+ t.Run(tc.id, func(t *testing.T) {+ session, err := Find(sources, HarnessCursor, tc.id)+ if err != nil {+ t.Fatalf("Find: %v", err)+ }+ events, err := Events(sources, session)+ if err != nil {+ t.Fatalf("Events: %v", err)+ }+ brief := BuildBrief(session, events, FromSessionStore, time.Now())+ if brief.Prompts != 1 || !strings.Contains(brief.FirstRequest, tc.request) {+ t.Fatalf("brief prompts=%d first=%q", brief.Prompts, brief.FirstRequest)+ }+ if !strings.Contains(brief.Render(), "Cursor") {+ t.Fatalf("the brief should name Cursor:\n%s", brief.Render())+ }+ })+ }+ if session, err := Find(sources, HarnessCursor, "comp"); err == nil {+ t.Fatalf("a prefix under %d characters must not match, got %s", MinPrefixLength, session.ID)+ }+ if session, err := Find(sources, "", "cli-1"); err != nil || session.SourcePath != f.cliPath {+ t.Fatalf("a conversation in both stores must not be ambiguous: %+v, %v", session, err)+ }+}++func TestCursorSessionGoneFromItsStore(t *testing.T) {+ f := cursorFixture(t)+ for _, session := range []Session{+ {Harness: HarnessCursor, ID: "cli-1", SourcePath: f.cliPath + ".moved", Store: string(cursorsession.SourceTranscript)},+ {Harness: HarnessCursor, ID: "gone-1", SourcePath: "global:gone-1", Store: string(cursorsession.SourceGlobalStorage)},+ } {+ if _, err := Events(DefaultSources(f.dirs), session); !errors.Is(err, ErrNotFound) {+ t.Fatalf("Events(%s) = %v, want ErrNotFound", session.SourcePath, err)+ }+ }+}++func TestPlanResumeReopensOnlyCursorCLIChats(t *testing.T) {+ f := cursorFixture(t)+ sources := DefaultSources(f.dirs)+ session, err := Find(sources, HarnessCursor, "cli-1")+ if err != nil {+ t.Fatal(err)+ }+ plan, err := PlanResume(session, PlanOptions{LookPath: installed("cursor-agent")})+ if err != nil {+ t.Fatalf("PlanResume: %v", err)+ }+ if plan.Mode != ModeNative || plan.Executable != "/bin/cursor-agent" || plan.Dir != f.workspace || !reflect.DeepEqual(plan.Args, []string{"--resume", "cli-1"}) {+ t.Fatalf("plan = %+v", plan)+ }++ // IDE conversations, whichever store they are read from, and subagent transcripts continue from+ // a brief.+ ide, err := Find(sources, HarnessCursor, "ide-2")+ if err != nil {+ t.Fatal(err)+ }+ ideTranscript := Session{Harness: HarnessCursor, ID: "ide-2", Directory: f.workspace, SourcePath: f.idePath, Store: string(cursorsession.SourceTranscript)}+ sub, err := Find(sources, HarnessCursor, "sub-1")+ if err != nil {+ t.Fatal(err)+ }+ // A chat id cursor-agent keeps for another directory does not resume here.+ elsewhere := session+ elsewhere.Directory = t.TempDir()+ for name, s := range map[string]Session{"global storage": ide, "ide transcript": ideTranscript, "subagent": sub, "other directory": elsewhere} {+ t.Run(name, func(t *testing.T) {+ brief := filepath.Join(t.TempDir(), "brief.md")+ plan, err := PlanResume(s, PlanOptions{BriefPath: brief, LookPath: installed("cursor-agent")})+ if err != nil {+ t.Fatalf("PlanResume: %v", err)+ }+ if plan.Mode != ModeNewSession || plan.Reason != ReasonNotResumable || !reflect.DeepEqual(plan.Args, []string{NewSessionPrompt(s, brief)}) {+ t.Fatalf("plan = %+v", plan)+ }+ })+ }++ // A chat whose transcript is gone continues from a brief too.+ gone := session+ gone.SourcePath = filepath.Join(t.TempDir(), "missing.jsonl")+ brief := filepath.Join(t.TempDir(), "brief.md")+ plan, err = PlanResume(gone, PlanOptions{BriefPath: brief, LookPath: installed("cursor-agent")})+ if err != nil {+ t.Fatalf("PlanResume: %v", err)+ }+ if plan.Mode != ModeNewSession || plan.Reason != ReasonSessionGone {+ t.Fatalf("plan = %+v", plan)+ }+}diff --git a/cli/beacon/internal/handoff/fixtures_test.go b/cli/beacon/internal/handoff/fixtures_test.goindex e9c90e3f..84315508 100644--- a/cli/beacon/internal/handoff/fixtures_test.go+++ b/cli/beacon/internal/handoff/fixtures_test.go@@ -24,7 +24,7 @@ var (// runtime the fixture leaves at its default reads only the test's HOME.func isolateRuntimeEnv(t *testing.T) {t.Helper()- for _, name := range []string{"PI_CODING_AGENT_DIR", "PRIME_AGENT_CODING_AGENT_DIR"} {+ for _, name := range []string{"PI_CODING_AGENT_DIR", "PRIME_AGENT_CODING_AGENT_DIR", "XDG_CONFIG_HOME", "APPDATA", "CURSOR_CONFIG_DIR"} {t.Setenv(name, "")}}diff --git a/cli/beacon/internal/handoff/resume_test.go b/cli/beacon/internal/handoff/resume_test.goindex 54ed8c2d..625b4930 100644--- a/cli/beacon/internal/handoff/resume_test.go+++ b/cli/beacon/internal/handoff/resume_test.go@@ -24,7 +24,7 @@ func installed(names ...string) func(string) (string, error) {}}-var allRuntimes = installed("claude", "codex", "opencode", "cline", "pi", "prime-agent")+var allRuntimes = installed("claude", "codex", "opencode", "cline", "pi", "prime-agent", "cursor-agent")// resumableSession is a session whose directory and session file both exist.func resumableSession(t *testing.T, harness, id string) Session {@@ -80,6 +80,7 @@ func TestPlanResumeStartsANewSessionInEachRuntime(t *testing.T) {{HarnessCline, "cline", []string{"--tui", "--auto-approve", "false"}},{HarnessPi, "pi", []string{"--"}},{HarnessPrime, "prime-agent", []string{"--"}},+ {HarnessCursor, "cursor-agent", nil},} {t.Run(tc.target, func(t *testing.T) {source := HarnessCodex@@ -204,10 +205,10 @@ func TestPlanResumeErrors(t *testing.T) {if _, err := PlanResume(session, PlanOptions{Target: HarnessCodex, BriefPath: filepath.Join(t.TempDir(), "b.md"), LookPath: installed("claude")}); !errors.Is(err, ErrRuntimeNotInstalled) {t.Fatalf("missing target runtime err = %v", err)}- if _, err := PlanResume(session, PlanOptions{Target: "cursor", LookPath: allRuntimes}); err == nil || !strings.Contains(err.Error(), "cannot be started") {+ if _, err := PlanResume(session, PlanOptions{Target: "gemini_cli", LookPath: allRuntimes}); err == nil || !strings.Contains(err.Error(), "cannot be started") {t.Fatalf("unsupported target err = %v", err)}- if _, err := PlanResume(Session{Harness: "cursor", ID: "x", Directory: t.TempDir()}, PlanOptions{LookPath: allRuntimes}); err == nil {+ if _, err := PlanResume(Session{Harness: "gemini_cli", ID: "x", Directory: t.TempDir()}, PlanOptions{LookPath: allRuntimes}); err == nil {t.Fatal("a session from an unsupported runtime needs --agent")}if _, err := PlanResume(session, PlanOptions{ForceNew: true, LookPath: allRuntimes}); err == nil || !strings.Contains(err.Error(), "brief path") {diff --git a/cli/beacon/internal/handoff/runtimes.go b/cli/beacon/internal/handoff/runtimes.goindex 76162102..2276ff3c 100644--- a/cli/beacon/internal/handoff/runtimes.go+++ b/cli/beacon/internal/handoff/runtimes.go@@ -7,6 +7,7 @@ import ("github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudesession""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/clinesession""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/codexsession"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/cursorsession""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/opencodesession""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/pisession""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/primesession"@@ -53,6 +54,7 @@ const (HarnessCline = clinesession.HarnessHarnessPi = pisession.HarnessHarnessPrime = primesession.Harness+ HarnessCursor = cursorsession.Harness)// runtimes lists every runtime handoff supports, in display order.@@ -149,6 +151,24 @@ var runtimes = []Runtime{NewSession: func(prompt string) []string { return []string{"--", prompt} },},},+ {+ Harness: HarnessCursor,+ Label: "Cursor",+ NewSource: func(dir string) Source { return &cursorSource{dir: dir} },+ // cursor-agent asks before running commands unless given --force; Beacon never passes it.+ Command: &runtimeCommand{+ Executable: "cursor-agent",+ Resume: func(s Session) ([]string, bool) {+ // --resume takes a CLI chat id. IDE conversations and subagent transcripts are not+ // chats the CLI can load.+ if !cursorCLIChat(s) {+ return nil, false+ }+ return []string{"--resume", s.ID}, true+ },+ NewSession: func(prompt string) []string { return []string{prompt} },+ },+ },}// Harnesses lists the runtimes handoff supports, in display order.diff --git a/cli/beacon/internal/handoff/session_test.go b/cli/beacon/internal/handoff/session_test.goindex 8bc4277b..e1307422 100644--- a/cli/beacon/internal/handoff/session_test.go+++ b/cli/beacon/internal/handoff/session_test.go@@ -274,7 +274,7 @@ func TestParseHarness(t *testing.T) {t.Fatalf("ParseHarness(%q) = %q, %v; want %q", in, got, err, want)}}- if _, err := ParseHarness("cursor"); err == nil || !strings.Contains(err.Error(), "supported") {+ if _, err := ParseHarness("no-such-runtime"); err == nil || !strings.Contains(err.Error(), "supported") {t.Fatalf("unsupported runtime err = %v", err)}}diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdxindex 4b458e2b..dfc1b432 100644--- a/docs/cli/handoff.mdx+++ b/docs/cli/handoff.mdx@@ -25,10 +25,11 @@ Sessions come from each runtime's own local session store, not from Beacon's run| Cline | `~/.cline/data` | `cline` || Pi | `~/.pi/agent/sessions` (or under `PI_CODING_AGENT_DIR`) | `pi` || Prime Agent | `~/.prime/agent`, both `sessions` and `session-artifacts` (or `PRIME_AGENT_CODING_AGENT_DIR`) | `prime` |+| Cursor | `~/.cursor/projects` (agent transcripts) and Cursor's global storage `state.vscdb` (Composer conversations) | `cursor` |-When a Codex thread has more than one rollout file, `beacon handoff` lists it once, under its newest file. Cline can hold the same task both as a CLI session and in its older task history; the CLI session is the copy that is listed. Cline kanban cards are not sessions and are not listed. Prime Agent subagent transcripts, under `session-artifacts`, are listed as subagents of the session that started them.+When a Codex thread has more than one rollout file, `beacon handoff` lists it once, under its newest file. Cline can hold the same task both as a CLI session and in its older task history; the CLI session is the copy that is listed. Cline kanban cards are not sessions and are not listed. Prime Agent subagent transcripts, under `session-artifacts`, are listed as subagents of the session that started them. A Cursor conversation can be stored both as a transcript and as a Composer record under one id; it is listed once, as the transcript when `cursor-agent` can reopen it and as the Composer record otherwise. Cursor subagent transcripts are listed as subagents of the conversation that started them.-`--store-dir <runtime>=<path>` takes the location in the table: for Pi its sessions directory, as `beacon endpoint pi sync --sessions-dir` does, and for Prime Agent the agent directory holding both of its roots.+`--store-dir <runtime>=<path>` takes the location in the table: for Pi its sessions directory, as `beacon endpoint pi sync --sessions-dir` does, for Prime Agent the agent directory holding both of its roots, and for Cursor the projects directory, as `beacon endpoint cursor sync --projects-dir` does. Cursor's global storage database is always read from its default location.## `beacon handoff list`@@ -43,7 +44,7 @@ beacon handoff list --json| Flag | Description ||------|-------------|-| `--harness` | Only this runtime: `claude`, `codex`, `opencode`, or `cline`. |+| `--harness` | Only this runtime: `claude`, `codex`, `opencode`, `cline`, `pi`, `prime` or `cursor`. || `--here` | Only sessions that ran in the current directory or below it. || `--dir` | Only sessions that ran in this directory or below it. || `--subagents` | Include subagent sessions. They are hidden by default, because resuming one resumes a fragment of its parent's task. |@@ -110,6 +111,7 @@ There are two ways to resume:| Cline | `cline --tui --auto-approve false --id <id>` || Pi | `pi --session <session file>` || Prime Agent | `prime-agent --resume <session file>` |+ | Cursor | `cursor-agent --resume <chat id>` (chats `cursor-agent` started only) |- **Start a new session from a brief.** Otherwise, or with `--agent` naming another runtime or with `--new`, Beacon writes a brief (see `export`) and starts a new session. The first message of that session points at the brief:@@ -121,18 +123,21 @@ There are two ways to resume:| Cline | `cline --tui --auto-approve false "<prompt>"` || Pi | `pi -- "<prompt>"` || Prime Agent | `prime-agent -- "<prompt>"` |+ | Cursor | `cursor-agent "<prompt>"` |The prompt names the brief by its path and asks the agent to read it, then confirm the task before changing anything. The brief is never inlined into the command line, because a command line is visible to every local user through the process table. The prompt ends with a handoff marker (see below).Claude Code, Cline and Prime Agent subagent sessions, and Cline's older task history, can't be reopened by their CLIs, so they always continue from a brief. A session known only from Beacon's runtime log also continues from a brief, and it needs `--agent` if its own runtime isn't one Beacon can start.+`cursor-agent --resume` reopens only chats the CLI itself started, which it keeps under `~/.cursor/chats` (or `CURSOR_CONFIG_DIR`, or `$XDG_CONFIG_HOME/cursor`) keyed by the directory the chat ran in. Beacon reopens a Cursor session natively only when that chat store exists for the session's recorded directory. Conversations from the Cursor IDE, Composer records, and subagent transcripts continue from a brief. Beacon never passes `--force` or `--yolo`, so `cursor-agent` still asks before running commands.+Cline approves every tool call by default. Beacon always passes `--auto-approve false`, so a session Beacon starts never gets auto-approval on Beacon's say-so. You can still turn it on inside the Cline TUI.The runtime runs in this terminal, in the session's recorded directory. If that directory no longer exists, Beacon stops rather than starting somewhere else; pass `--cwd` to choose a directory. Beacon prints the plan and asks `Continue? [Y/n]` before launching. Without a terminal, it launches only with `--yes`. `beacon handoff resume` exits with the runtime's own exit code.| Flag | Description ||------|-------------|-| `--agent` | Runtime to continue in: `claude`, `codex`, `opencode`, `cline`, `pi` or `prime`. Defaults to the session's own runtime. |+| `--agent` | Runtime to continue in: `claude`, `codex`, `opencode`, `cline`, `pi`, `prime` or `cursor`. Defaults to the session's own runtime. || `--new` | Start a new session from a brief even when the session could be reopened. || `--cwd` | Directory to start the runtime in. || `--print` | Show the plan and command without writing a brief or launching anything. |@@ -163,7 +168,7 @@ The link event keeps the new session's id, workspace and harness, and leaves theTwo paths record the link:- **Live hooks.** The prompt hook for Claude Code and the Cline and OpenCode plugins record it as the prompt is sent (`harness.collection_method: hook`).-- **Session-store sync.** `beacon endpoint claude sync`, `codex sync`, `opencode sync`, `cline sync`, `pi sync` and `prime sync` record it when they read the prompt back from the runtime's store (`harness.collection_method: poll`).+- **Session-store sync.** `beacon endpoint claude sync`, `codex sync`, `opencode sync`, `cline sync`, `pi sync`, `prime sync` and `cursor sync` record it when they read the prompt back from the runtime's store (`harness.collection_method: poll`).Codex CLI prompts reach Beacon over OTLP and through `beacon endpoint codex sync`, not a prompt hook, so a session continued in Codex is linked by the sync. For a runtime that also has a prompt hook or plugin, a sync can record the same link the hook already did; the two carry different `collection_method` values, as every other event those runtimes report through both paths does. A sync's link has a deterministic `event.id`, so syncing again never duplicates it.