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: reopen a Grok session only from the directory it ran in
Claude9b2a2fd2e6f4
diff --git a/cli/beacon/internal/handoff/grok_test.go b/cli/beacon/internal/handoff/grok_test.goindex b3ea3235..c9876325 100644--- a/cli/beacon/internal/handoff/grok_test.go+++ b/cli/beacon/internal/handoff/grok_test.go@@ -172,6 +172,25 @@ func TestPlanResumeReopensAGrokSessionByItsID(t *testing.T) {}}+// Grok finds a session id under the directory it starts in, so --cwd elsewhere continues from a+// brief instead of reopening an id Grok cannot find there.+func TestPlanResumeReopensAGrokSessionOnlyInItsDirectory(t *testing.T) {+ session := resumableSession(t, HarnessGrok, grokSessionID)+ brief := filepath.Join(t.TempDir(), "brief.md")+ moved := t.TempDir()+ plan, err := PlanResume(session, PlanOptions{Dir: moved, BriefPath: brief, LookPath: installed("grok")})+ 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)+ }+ plan, err = PlanResume(session, PlanOptions{Dir: session.Directory, BriefPath: brief, LookPath: installed("grok")})+ if err != nil || plan.Mode != ModeNative {+ t.Fatalf("--cwd naming the session's own directory: plan = %+v, %v", plan, err)+ }+}+// Grok's config can make always-approve the default. No command Beacon runs may inherit it.func TestEveryGrokCommandAsksBeforeRunningTools(t *testing.T) {command, _ := commandFor(HarnessGrok)diff --git a/cli/beacon/internal/handoff/resume.go b/cli/beacon/internal/handoff/resume.goindex 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.goindex b1be5e35..cf355172 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@@ -170,6 +173,8 @@ var runtimes = []Runtime{return []string{"--permission-mode", "default", "--resume", s.ID}, true},NewSession: func(prompt string) []string { return []string{"--permission-mode", "default", prompt} },+ // Grok looks a session id up under the directory it is started in.+ ResumesInSessionDir: true,},},}diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdxindex 6875bf02..6df21834 100644--- a/docs/cli/handoff.mdx+++ b/docs/cli/handoff.mdx@@ -131,7 +131,7 @@ Claude Code, Cline, Prime Agent and Grok Build subagent sessions, and Cline's olCline 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.-Grok Build's configured permission mode can be always-approve. Beacon always passes `--permission-mode default`, the mode that asks before running tools, so a session Beacon starts or reopens never inherits always-approve from that config. You can still change the mode inside the Grok TUI. Grok looks a session id up under the directory it runs in, which is why the resume runs in the session's recorded directory.+Grok Build's configured permission mode can be always-approve. Beacon always passes `--permission-mode default`, the mode that asks before running tools, so a session Beacon starts or reopens never inherits always-approve from that config. You can still change the mode inside the Grok TUI. Grok looks a session id up under the directory it runs in, which is why the resume runs in the session's recorded directory. With `--cwd` naming another directory, a Grok session continues from a brief instead.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.