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
Share no sessions on push when the pushed refs are unknown
Claudea8da85fded07
diff --git a/cli/beacon/cmd/git_share.go b/cli/beacon/cmd/git_share.goindex b7d5b4f3..a291f1d7 100644--- a/cli/beacon/cmd/git_share.go+++ b/cli/beacon/cmd/git_share.go@@ -131,14 +131,15 @@ func runGitHookPrePush(cmd *cobra.Command, args []string) error {repo.Git = repo.Git.WithExtraEnv("GIT_TERMINAL_PROMPT=0")// git's stdin (the refs being pushed) is read only when sessions are shared, and only when// Beacon's hook block passed a copy in (it replays the original to the rest of the hook).- // Called any other way, stdin belongs to whatever runs after Beacon, so the pushed commits are- // worked out from HEAD and the remote's tracking branches instead.+ // Called any other way, stdin belongs to whatever runs after Beacon, and without it Beacon+ // cannot know which refs are being pushed (another branch, --tags, --delete), so it shares no+ // sessions at all rather than guess: only the notes ref is pushed.if enabled, visibility := gitlink.ShareSessionsConfig(ctx, repo); enabled {stdin := ""if os.Getenv(gitlink.HookStdinEnv) == "1" {stdin = readHookStdin(cmd.InOrStdin())} else {- stdin = gitlink.HeadPushLine(ctx, repo, args[0])+ fmt.Fprintln(cmd.ErrOrStderr(), "beacon: sessions are shared on push only through the hook `beacon git setup` installs; this push shares commit links only")}if stdin != "" {// Sharing sessions gets the budget less what pushing the notes ref needs, so the linksdiff --git a/cli/beacon/cmd/git_share_sessions_test.go b/cli/beacon/cmd/git_share_sessions_test.goindex 07364e60..4aa28529 100644--- a/cli/beacon/cmd/git_share_sessions_test.go+++ b/cli/beacon/cmd/git_share_sessions_test.go@@ -63,6 +63,7 @@ func TestGitHookPostCommitWritesAKnownShareURL(t *testing.T) {}func TestGitPrePushSharesLinkedSessions(t *testing.T) {+ t.Setenv(gitlink.HookStdinEnv, "1") // as Beacon's hook block runs itroot, remote := gitCommandTeam(t)env := newShareEnv(t)srv := newFakeShareServer(t)@@ -118,6 +119,7 @@ func TestGitPrePushSharesLinkedSessions(t *testing.T) {}func TestGitPrePushWithoutCredentialsSharesNothingQuietly(t *testing.T) {+ t.Setenv(gitlink.HookStdinEnv, "1") // as Beacon's hook block runs itroot, remote := gitCommandTeam(t)env := newShareEnv(t) // signed out, and any request fails the testprevOpts := shareOpts@@ -168,9 +170,10 @@ func TestGitSetupShareSessionsRules(t *testing.T) {}// Called straight from a hook manager (gitlink.HookCall), without Beacon's block to copy and-// replay stdin, the pre-push hook must leave stdin to the steps after it (`git lfs pre-push`),-// and still finds the pushed commits from HEAD and the remote's tracking branches.-func TestGitPrePushWithoutTheBlockLeavesStdinAlone(t *testing.T) {+// replay stdin, the pre-push hook must leave stdin to the steps after it (`git lfs pre-push`).+// Without the refs it cannot know what is being pushed (another branch, --tags, --delete), so it+// shares no sessions, says so once, and still pushes the commit links.+func TestGitPrePushWithoutTheBlockLeavesStdinAloneAndSharesNothing(t *testing.T) {root, remote := gitCommandTeam(t)env := newShareEnv(t)srv := newFakeShareServer(t)@@ -192,15 +195,21 @@ func TestGitPrePushWithoutTheBlockLeavesStdinAlone(t *testing.T) {rootCmd.SetIn(reader)t.Cleanup(func() { rootCmd.SetIn(nil) })var stderr bytes.Buffer- if _, err := runGitStderr(t, &stderr, "hook", "pre-push", "--cwd", root, "origin", remote); err != nil || stderr.Len() != 0 {- t.Fatalf("pre-push: %v %q", err, stderr.String())+ before := len(srv.requests)+ if _, err := runGitStderr(t, &stderr, "hook", "pre-push", "--cwd", root, "origin", remote); err != nil {+ t.Fatalf("pre-push: %v", err)}if reader.Len() != len(stdin) {t.Fatalf("the hook read %d bytes of stdin that the next step needs", len(stdin)-reader.Len())}- want := "beacon:claude_code/" + shareTestSession + " https://beacon.sh/s/k3xabc"- if note := mustGit(t, remote, "notes", "--ref="+gitlink.NotesRef, "show", sha); note != want {- t.Fatalf("remote note %q, want the session shared from HEAD", note)+ if len(srv.requests) != before {+ t.Fatalf("shared sessions without knowing the pushed refs: %v", srv.requests[before:])+ }+ if !strings.Contains(stderr.String(), "commit links only") {+ t.Fatalf("stderr %q, want the hint", stderr.String())+ }+ if note := mustGit(t, remote, "notes", "--ref="+gitlink.NotesRef, "show", sha); note != "beacon:claude_code/"+shareTestSession {+ t.Fatalf("remote note %q, want the bare link pushed and nothing shared", note)}}diff --git a/cli/beacon/internal/gitlink/share.go b/cli/beacon/internal/gitlink/share.goindex cc9fe106..20ccb8f3 100644--- a/cli/beacon/internal/gitlink/share.go+++ b/cli/beacon/internal/gitlink/share.go@@ -355,22 +355,6 @@ func PushedCommits(ctx context.Context, repo Repo, remote string, stdin string,return out, nil}-// HeadPushLine stands in for a pre-push hook's stdin when Beacon was not given it: one line pushing-// HEAD to a new branch, so PushedCommits returns the commits on HEAD that none of the remote's-// tracking branches has. It is "" when remote is not a configured remote (there would be nothing-// to exclude) or HEAD has no commit.-func HeadPushLine(ctx context.Context, repo Repo, remote string) string {- if !isRemote(ctx, repo, remote) {- return ""- }- head, err := repo.Git.Run(ctx, nil, "rev-parse", "--verify", "--quiet", "HEAD^{commit}")- head = strings.TrimSpace(head)- if err != nil || !isSHA(head) {- return ""- }- return "HEAD " + head + " HEAD " + strings.Repeat("0", len(head))-}-// hasCommit reports whether sha names a commit present in this repository.func hasCommit(ctx context.Context, repo Repo, sha string) bool {_, err := repo.Git.Run(ctx, nil, "cat-file", "-e", sha+"^{commit}")diff --git a/docs/cli/git.mdx b/docs/cli/git.mdxindex 2c3f9cd6..568eacf8 100644--- a/docs/cli/git.mdx+++ b/docs/cli/git.mdx@@ -129,7 +129,7 @@ beacon git setup --share-sessions # new traces are direcbeacon git setup --share-sessions --share-visibility private```-With `--share-sessions`, the pre-push hook also shares the sessions linked to the commits being pushed that have no share URL in their note yet, then writes their URLs into the notes before pushing `refs/notes/beacon`. A session already shared from this machine only gets its URL written. A session this machine does not have (a teammate's) is skipped. It is the same upload as [`beacon share`](/cli/share#what-is-uploaded), with the same redaction, and an existing trace keeps its visibility.+With `--share-sessions`, the pre-push hook also shares the sessions linked to the commits being pushed that have no share URL in their note yet, then writes their URLs into the notes before pushing `refs/notes/beacon`. A session already shared from this machine only gets its URL written. A session this machine does not have (a teammate's) is skipped. It is the same upload as [`beacon share`](/cli/share#what-is-uploaded), with the same redaction, and an existing trace keeps its visibility. Which commits are being pushed comes from the refs git hands the hook on stdin. Beacon's hook block copies them for Beacon and replays them to the rest of the repository's hook, so `git lfs pre-push` and similar steps still see them. Called through the `beacon git hook pre-push "$@" || true` line added to a hook manager or a hook in another language, Beacon leaves stdin alone and shares no sessions (it cannot tell which refs are being pushed); it still shares the commit links and prints a one-line note.- It runs only during a push you started, and reads at most 100 pushed commits and shares at most 10 sessions per push.- It uses your `beacon login` sign-in (with `traces:write`) or `BEACON_API_KEY`. Without either it shares nothing and prints nothing.