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
Keep self-hosted share URLs through post-rewrite normalization
Claude9ba1f198acb0
diff --git a/cli/beacon/cmd/git_hooks.go b/cli/beacon/cmd/git_hooks.goindex 65424f14..b5c0b845 100644--- a/cli/beacon/cmd/git_hooks.go+++ b/cli/beacon/cmd/git_hooks.go@@ -327,6 +327,9 @@ func runGitHookPostRewrite(cmd *cobra.Command, _ []string) error {if err != nil {return nil}+ // Normalizing reads the share URLs in notes; a self-hosted or staging Beacon's links must+ // count as URLs here as they do everywhere else.+ gitAllowShareHosts()scanner := bufio.NewScanner(cmd.InOrStdin())for scanner.Scan() {fields := strings.Fields(scanner.Text())diff --git a/cli/beacon/cmd/git_hooks_test.go b/cli/beacon/cmd/git_hooks_test.goindex e80372e9..03f512ec 100644--- a/cli/beacon/cmd/git_hooks_test.go+++ b/cli/beacon/cmd/git_hooks_test.go@@ -8,8 +8,10 @@ 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/gitlink"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv")func writeRuntimeEvent(t *testing.T, logPath, top, session, file string) {@@ -221,3 +223,27 @@ func TestGitHookPostCommitRecordsTheLinkEvent(t *testing.T) {t.Fatalf("events %+v", got)}}++// A self-hosted Beacon's share URL survives post-rewrite normalization: the hook registers the+// configured host before it reads notes, and merging keeps a link's line with trailing fields over+// the bare one cat_sort_uniq sorts first.+func TestGitHookPostRewriteKeepsSelfHostedShareURLs(t *testing.T) {+ t.Setenv(account.BaseURLEnv, "https://beacon.rewrite-test.example")+ testenv.SetHome(t, t.TempDir())+ root := gitCommandRepo(t)+ mustGit(t, root, "commit", "-q", "--allow-empty", "-m", "c")+ sha := mustGit(t, root, "rev-parse", "HEAD")+ url := "https://beacon.rewrite-test.example/s/abc123"+ mustGit(t, root, "notes", "--ref="+gitlink.NotesRef, "add", "-m", "beacon:codex_cli/a\nbeacon:codex_cli/a "+url, sha)+ rootCmd.SetIn(strings.NewReader("0000000000000000000000000000000000000000 " + sha + "\n"))+ t.Cleanup(func() { rootCmd.SetIn(nil) })+ if _, err := runGit(t, "hook", "post-rewrite", "amend", "--cwd", root); err != nil {+ t.Fatal(err)+ }+ if note := mustGit(t, root, "notes", "--ref="+gitlink.NotesRef, "show", sha); note != "beacon:codex_cli/a "+url {+ t.Fatalf("note %q", note)+ }+ if !gitlink.ValidShareURL(url) {+ t.Fatal("post-rewrite did not register the configured Beacon host")+ }+}diff --git a/cli/beacon/internal/gitlink/note.go b/cli/beacon/internal/gitlink/note.goindex aaaafa04..9bfffb09 100644--- a/cli/beacon/internal/gitlink/note.go+++ b/cli/beacon/internal/gitlink/note.go@@ -179,8 +179,8 @@ func ParseNote(note string) []Link {// links a note already has returns it unchanged apart from that normalization.//// The one exception to "the first line wins" is the share URL: when the kept line is the bare-// `beacon:<harness>/<id>` and a repeat (or a new link) carries a URL, the line with the URL takes-// its place. Git's cat_sort_uniq merge sorts the bare line first, and without this a teammate's+// `beacon:<harness>/<id>` and a repeat carries trailing fields (a URL, valid here or not), or a new+// link carries a valid URL, that line takes its place. Git's cat_sort_uniq merge sorts the bare line first, and without this a teammate's// URL would be dropped by the next normalization.//// Links are never removed here. A note is shared history, and a teammate's link on the same commit@@ -196,7 +196,11 @@ func MergeNote(note string, links []Link) string {}if link, ok := ParseLine(line); ok {if i, seen := index[link.Key()]; seen {- if link.URL != "" && bare(i, link) {+ // Any trailing fields beat the bare line, whether or not this process can+ // validate the URL in them (a self-hosted Beacon this process was not told+ // about, or a field a newer version writes): merging never loses data, and+ // validation applies only when a URL is shown or used.+ if bare(i, link) && strings.TrimSpace(line) != linePrefix+link.Key() {lines[i] = line}continuediff --git a/cli/beacon/internal/gitlink/note_test.go b/cli/beacon/internal/gitlink/note_test.goindex d5dfbdb2..3e1ac940 100644--- a/cli/beacon/internal/gitlink/note_test.go+++ b/cli/beacon/internal/gitlink/note_test.go@@ -133,3 +133,21 @@ func TestMergeNoteAndSetLinkURLsKeepTheURL(t *testing.T) {t.Fatalf("ParseNote = %+v", links)}}++// Merging keeps a link's line with trailing fields over the bare line even when this process+// cannot validate the URL in it: merging never loses data.+func TestMergeNoteKeepsAnUnvalidatedURLOverTheBareLine(t *testing.T) {+ url := "https://beacon.unknown-host.example/s/abc"+ if ValidShareURL(url) {+ t.Fatal("the test host must not be allowed")+ }+ got := MergeNote("beacon:cursor/s1\nbeacon:cursor/s1 "+url+"\n", nil)+ if got != "beacon:cursor/s1 "+url+"\n" {+ t.Fatalf("merged %q", got)+ }+ // The first line with fields still wins over a later one.+ got = MergeNote("beacon:cursor/s1 "+url+"\nbeacon:cursor/s1 https://beacon.sh/s/x\n", nil)+ if got != "beacon:cursor/s1 "+url+"\n" {+ t.Fatalf("merged %q", got)+ }+}