Skip to content

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

handoff: stop an fx resume that names another directory

Claude7bff78c8db00
diff --git a/cli/beacon/internal/handoff/fx_test.go b/cli/beacon/internal/handoff/fx_test.go
index 1cb4f4bf..64bccb34 100644
--- a/cli/beacon/internal/handoff/fx_test.go
+++ b/cli/beacon/internal/handoff/fx_test.go
@@ -153,6 +153,8 @@ func TestPlanResumeRefusesToStartANewFxSession(t *testing.T) {
{"a new session requested", fxSession, PlanOptions{ForceNew: true}, ReasonRequested},
{"the session file is gone", gone, PlanOptions{}, ReasonSessionGone},
{"known only from the runtime log", fxSession, PlanOptions{FromRuntimeLog: true}, ReasonFromRuntimeLog},
+ // fx resumes only sessions of the workspace it starts in.
+ {"--cwd outside its workspace", fxSession, PlanOptions{Dir: t.TempDir()}, ReasonOtherDirectory},
} {
t.Run(tc.name, func(t *testing.T) {
tc.opts.BriefPath, tc.opts.LookPath = brief, allRuntimes
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 abbfd4ec..0bed6668 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
@@ -161,6 +164,8 @@ var runtimes = []Runtime{
// fx looks a session id up within the workspace it runs in; the plan starts it in the
// session's workspace root.
Resume: func(s Session) ([]string, bool) { return []string{"--resume", s.ID}, true },
+ // fx resumes only sessions of the workspace it is started in.
+ ResumesInSessionDir: true,
// No NewSession: fx has no interactive session that starts from a prompt (`fx ask` is
// one-shot), so it reopens its own sessions but cannot pick one up from a brief.
},
diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdx
index ff1497f7..9698295a 100644
--- a/docs/cli/handoff.mdx
+++ b/docs/cli/handoff.mdx
@@ -130,7 +130,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.
-fx has no interactive session that starts from a prompt (`fx ask` runs one request and exits), so it is not in the new-session table. Beacon reopens an fx session natively, and continues it in another runtime with `--agent`; `--agent fx` for another runtime's session, `--new` on an fx session, and an fx session whose files are gone stop with an error rather than launching anything. fx looks a session id up within the workspace it runs in, so Beacon starts it in the session's workspace; `--cwd` elsewhere won't find the session. fx's default permission mode is `auto`, where a reviewer resolves permission requests, and fx has no command-line flag to change it. Beacon passes none: it reopens your own session under whatever permission mode your fx configuration sets.
+fx has no interactive session that starts from a prompt (`fx ask` runs one request and exits), so it is not in the new-session table. Beacon reopens an fx session natively, and continues it in another runtime with `--agent`; `--agent fx` for another runtime's session, `--new` on an fx session, and an fx session whose files are gone stop with an error rather than launching anything. fx looks a session id up within the workspace it runs in, so Beacon starts it in the session's workspace, and `--cwd` naming another directory stops with an error too, since fx could not find the session there. fx's default permission mode is `auto`, where a reviewer resolves permission requests, and fx has no command-line flag to change it. Beacon passes none: it reopens your own session under whatever permission mode your fx configuration sets.
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.