Skip to content

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

handoff: reopen a Cursor chat only from the directory it ran in

Clauded485a870c7a8
diff --git a/cli/beacon/internal/handoff/cursor_test.go b/cli/beacon/internal/handoff/cursor_test.go
index 0536f9b6..fe63187f 100644
--- a/cli/beacon/internal/handoff/cursor_test.go
+++ b/cli/beacon/internal/handoff/cursor_test.go
@@ -262,4 +262,25 @@ func TestPlanResumeReopensOnlyCursorCLIChats(t *testing.T) {
if plan.Mode != ModeNewSession || plan.Reason != ReasonSessionGone {
t.Fatalf("plan = %+v", plan)
}
+
+ // cursor-agent finds the chat from the directory it starts in, so --cwd elsewhere cannot reopen
+ // it; the same directory by another path still can.
+ moved := t.TempDir()
+ plan, err = PlanResume(session, PlanOptions{Dir: moved, BriefPath: brief, LookPath: installed("cursor-agent")})
+ if err != nil {
+ t.Fatalf("PlanResume: %v", err)
+ }
+ if plan.Mode != ModeNewSession || plan.Reason != ReasonOtherDirectory || plan.Dir != moved {
+ t.Fatalf("--cwd elsewhere: plan = %+v", plan)
+ }
+ if testenv.HasPOSIXFileModes() {
+ link := filepath.Join(t.TempDir(), "workspace-link")
+ if err := os.Symlink(f.workspace, link); err != nil {
+ t.Fatal(err)
+ }
+ plan, err = PlanResume(session, PlanOptions{Dir: link, BriefPath: brief, LookPath: installed("cursor-agent")})
+ if err != nil || plan.Mode != ModeNative {
+ t.Fatalf("--cwd through a symlink to the session's directory: plan = %+v, %v", plan, err)
+ }
+ }
}
diff --git a/cli/beacon/internal/handoff/resume.go b/cli/beacon/internal/handoff/resume.go
index 2b30824d..bafdced4 100644
--- a/cli/beacon/internal/handoff/resume.go
+++ b/cli/beacon/internal/handoff/resume.go
@@ -25,6 +25,7 @@ const (
ReasonNotResumable = "not_resumable"
ReasonSessionGone = "session_file_missing"
ReasonFromRuntimeLog = "runtime_log_only"
+ ReasonOtherDirectory = "other_directory"
)
// Plan is a resolved resume: what will run, where, and why.
@@ -135,6 +136,9 @@ func nativeBlocker(session Session, target string, opts PlanOptions) string {
if _, ok := command.Resume(session); !ok {
return ReasonNotResumable
}
+ if command.ResumesInSessionDir && opts.Dir != "" && !sameDirectory(opts.Dir, session.Directory) {
+ return ReasonOtherDirectory
+ }
if session.SourcePath == "" {
return ReasonSessionGone
}
@@ -190,6 +194,8 @@ func ReasonText(reason string) string {
return "the session file is no longer on this machine"
case ReasonFromRuntimeLog:
return "the session is known only from Beacon's runtime log"
+ case ReasonOtherDirectory:
+ return "its runtime reopens it only from the directory it ran in"
}
return reason
}
@@ -204,3 +210,15 @@ func StartableNames() []string {
}
return names
}
+
+// sameDirectory reports whether a and b name one directory, symlinks resolved.
+func sameDirectory(a, b string) bool {
+ if a == "" || b == "" {
+ return false
+ }
+ ra, rb := resolveExisting(a), resolveExisting(b)
+ if ra == "" || rb == "" {
+ return filepath.Clean(a) == filepath.Clean(b)
+ }
+ return ra == rb
+}
diff --git a/cli/beacon/internal/handoff/runtimes.go b/cli/beacon/internal/handoff/runtimes.go
index 2276ff3c..814bd483 100644
--- a/cli/beacon/internal/handoff/runtimes.go
+++ b/cli/beacon/internal/handoff/runtimes.go
@@ -41,6 +41,9 @@ type runtimeCommand struct {
// NewSession returns the arguments that start an interactive session with prompt as its first
// message.
NewSession func(prompt string) []string
+ // ResumesInSessionDir marks a CLI that finds a session by the directory it is started in, so
+ // a native reopen from any other directory (--cwd) would not find it.
+ ResumesInSessionDir bool
// Env overrides the runtime's environment: a variable set to a value is set, one set to "" is
// removed. It holds switches only, never credentials, because the plan prints it.
Env map[string]string
@@ -167,6 +170,8 @@ var runtimes = []Runtime{
return []string{"--resume", s.ID}, true
},
NewSession: func(prompt string) []string { return []string{prompt} },
+ // cursor-agent looks a chat id up under a hash of the directory it is started in.
+ ResumesInSessionDir: true,
},
},
}
diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdx
index dfc1b432..7180f4e0 100644
--- a/docs/cli/handoff.mdx
+++ b/docs/cli/handoff.mdx
@@ -129,7 +129,7 @@ There are two ways to resume:
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.
+`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, and only from that directory: with `--cwd` pointing elsewhere, it continues from a brief. 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.