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
Refuse a session id whose BEACON_HARNESS is missing or unknown
Claude036882dd5b13
diff --git a/cli/beacon/cmd/share.go b/cli/beacon/cmd/share.goindex 1b376a66..1271b9a2 100644--- a/cli/beacon/cmd/share.go+++ b/cli/beacon/cmd/share.go@@ -535,7 +535,8 @@ func resolveShareID(sources []handoff.Source, harness, id string) (shareSubject,// 1. BEACON_SESSION_ID (with BEACON_HARNESS), which the Claude Code hook exports to the agent's// shell. Skipped under --cwd, which names another directory, and when --harness names another// runtime (a Codex started from a Claude Code shell inherits Claude's variables). An id that is-// set but cannot be found is an error rather than a reason to share some other session.+// set but cannot be found, or set with a missing or unknown BEACON_HARNESS, is an error rather+// than a reason to share some other session.// 2. The session a Beacon hook last saw in the directory, from the active-session record.// 3. The most recent session in the directory.func resolveShareCurrent(sources []handoff.Source, harness string) (shareSubject, error) {@@ -545,11 +546,18 @@ func resolveShareCurrent(sources []handoff.Source, harness string) (shareSubject}if strings.TrimSpace(shareOpts.cwd) == "" {if id := strings.TrimSpace(shareGetenv(shareSessionEnv)); id != "" {- envHarness, herr := handoff.ParseHarness(shareGetenv(shareHarnessEnv))- if herr == nil && (harness == "" || envHarness == "" || envHarness == harness) {- if envHarness == "" {- envHarness = harness- }+ // The two variables name one session together. A runtime name that is missing or+ // unknown is an error, never a reason to share some other session; only --harness naming+ // a different runtime passes over them on purpose.+ rawHarness := strings.TrimSpace(shareGetenv(shareHarnessEnv))+ if rawHarness == "" {+ return shareSubject{}, fmt.Errorf("%s=%s is set but %s is not; set both, or name the session with --session", shareSessionEnv, id, shareHarnessEnv)+ }+ envHarness, herr := handoff.ParseHarness(rawHarness)+ if herr != nil {+ return shareSubject{}, fmt.Errorf("%s=%q: %w", shareHarnessEnv, rawHarness, herr)+ }+ if harness == "" || envHarness == harness {subject, err := resolveShareID(sources, envHarness, id)if err != nil {return shareSubject{}, fmt.Errorf("%s=%s names this session, but it cannot be read yet: %w", shareSessionEnv, id, err)diff --git a/cli/beacon/cmd/share_current_test.go b/cli/beacon/cmd/share_current_test.goindex a690fa24..72133b45 100644--- a/cli/beacon/cmd/share_current_test.go+++ b/cli/beacon/cmd/share_current_test.go@@ -7,6 +7,7 @@ import ("testing""time"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/account""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/writer""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/handoff"@@ -72,8 +73,11 @@ func TestShareCurrentPrefersTheSessionEnvironment(t *testing.T) {// An env id that cannot be found is an error, never some other session.shareGetenv = func(key string) string {- if key == shareSessionEnv {+ switch key {+ case shareSessionEnv:return "missing-session"+ case shareHarnessEnv:+ return "gemini_cli"}return ""}@@ -82,6 +86,48 @@ func TestShareCurrentPrefersTheSessionEnvironment(t *testing.T) {}}+func TestShareCurrentRefusesAnUnusableHarnessVariable(t *testing.T) {+ env := shareCurrentEnv(t)+ t.Chdir(env.projectDir)+ srv := newFakeShareServer(t)+ srv.signIn(account.ScopeTracesWrite)+ for _, tc := range []struct{ harness, want string }{+ {"kimi_kode", `BEACON_HARNESS="kimi_kode"`},+ {"", "BEACON_HARNESS is not"},+ } {+ shareGetenv = func(key string) string {+ switch key {+ case shareSessionEnv:+ return "gem-session-1"+ case shareHarnessEnv:+ return tc.harness+ }+ return ""+ }+ _, _, err := runShareCommand(t, "--log-path", env.logPath)+ if err == nil || !strings.Contains(err.Error(), tc.want) {+ t.Errorf("BEACON_HARNESS=%q: err = %v, want %q", tc.harness, err, tc.want)+ }+ }+ if len(srv.requests) != 0 {+ t.Fatalf("requests = %v", srv.requests)+ }+ // --harness naming another valid runtime passes over the variables on purpose.+ shareGetenv = func(key string) string {+ switch key {+ case shareSessionEnv:+ return "gem-session-1"+ case shareHarnessEnv:+ return "gemini_cli"+ }+ return ""+ }+ stdout, _, err := runShareCommand(t, "--harness", "claude", "--print", "--log-path", env.logPath)+ if err != nil || sharePrintedExternalID(t, stdout) != "claude_code:"+shareTestSession {+ t.Fatalf("--harness claude: err = %v\n%s", err, stdout)+ }+}+func TestShareCurrentUsesTheActiveSessionRecord(t *testing.T) {env := shareCurrentEnv(t)t.Chdir(env.projectDir)diff --git a/docs/cli/share.mdx b/docs/cli/share.mdxindex 8b9fb181..1e4bd5a9 100644--- a/docs/cli/share.mdx+++ b/docs/cli/share.mdx@@ -52,7 +52,7 @@ Sessions are read the way [`beacon handoff`](/cli/handoff) reads them: from theAn agent asked to "share this session" runs `beacon share` from its own shell, where it does not know its session id. `--current`, which is also what `beacon share` does with no selector, finds it in this order:-1. **`BEACON_SESSION_ID`** (with `BEACON_HARNESS`). Beacon's Claude Code `SessionStart` hook appends `export BEACON_SESSION_ID=<id>` and `export BEACON_HARNESS=claude_code` to the file Claude Code names in `CLAUDE_ENV_FILE`, which Claude Code runs before each shell command of the session, so every command the agent runs carries its session id. Any other launcher may set the two variables too. The step is skipped under `--cwd`, and when `--harness` names another runtime, because a runtime started from a Claude Code shell inherits Claude Code's variables. An id that is set but cannot be read is an error, never a reason to share another session.+1. **`BEACON_SESSION_ID`** (with `BEACON_HARNESS`). Beacon's Claude Code `SessionStart` hook appends `export BEACON_SESSION_ID=<id>` and `export BEACON_HARNESS=claude_code` to the file Claude Code names in `CLAUDE_ENV_FILE`, which Claude Code runs before each shell command of the session, so every command the agent runs carries its session id. Any other launcher may set the two variables too. The step is skipped under `--cwd`, and when `--harness` names another runtime, because a runtime started from a Claude Code shell inherits Claude Code's variables. An id that is set but cannot be read is an error, never a reason to share another session, and so is an id set without `BEACON_HARNESS` or with a `BEACON_HARNESS` that names no runtime Beacon knows: set both, or name the session with `--session`.2. **The active-session record.** Every Beacon hook notes, per runtime and working directory, the session it last saw, in `~/.beacon/endpoint/active-sessions.json` (0600 under a 0700 directory). The record holds session ids, runtime names, directories and times, never content, and nothing in it leaves the machine. It keeps at most 256 entries and drops any not seen for 14 days; `--current` uses an entry seen within the last day, and only when it was seen at least as recently as the directory's newest session was updated: only hooks write the record, so a runtime Beacon sees only through OTLP or its session store (GitHub Copilot CLI, fx) never updates it, and its newer session wins over an older entry.3. **The most recent session** that ran in the directory.