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
Never let the implicit share-hook repair block a plain setup
Claudee4c545d6dce6
diff --git a/cli/beacon/internal/gitlink/hooks.go b/cli/beacon/internal/gitlink/hooks.goindex a77ab556..d5f63c92 100644--- a/cli/beacon/internal/gitlink/hooks.go+++ b/cli/beacon/internal/gitlink/hooks.go@@ -133,9 +133,13 @@ func InstallHooks(ctx context.Context, repo Repo, opts InstallOptions) (InstallRhooks := append([]string{}, ManagedHooks...)if opts.ShareNotes != nil && *opts.ShareNotes {hooks = append(hooks, ShareHook)- } else if opts.ShareNotes == nil && hookPresent(loc.Dir, ShareHook) {+ } else if opts.ShareNotes == nil && hookPresent(loc.Dir, ShareHook) &&+ checkHookEditable(filepath.Join(loc.Dir, ShareHook)) == nil {// Refresh -- or repair, when only the block or only the script survived -- along with the- // others: status says to run setup to fix a broken install, and sharing is part of it.+ // others: status says to run setup to fix a broken install, and sharing is part of it. Only+ // when it can, though: a pre-push since replaced by a hook in another language is left+ // alone, because a repair nobody asked for must never stop linking from being installed.+ // An explicit --share-notes still refuses, and says so.hooks = append(hooks, ShareHook)}// Check every hook before writing any, so a refusal leaves the repository as it was.diff --git a/cli/beacon/internal/gitlink/share_test.go b/cli/beacon/internal/gitlink/share_test.goindex 365c0b7a..cd70814d 100644--- a/cli/beacon/internal/gitlink/share_test.go+++ b/cli/beacon/internal/gitlink/share_test.go@@ -322,3 +322,38 @@ func TestShareNotesRefusesAForeignPrePushAndNamesIt(t *testing.T) {t.Fatalf("HookCall(pre-push) = %q", got)}}++func TestPlainSetupIgnoresALeftoverShareScriptBesideAForeignPrePush(t *testing.T) {+ tm := newTeam(t)+ ctx := context.Background()+ bin, _ := fakeBeacon(t, filepath.Join(t.TempDir(), "bin"))+ bob := tm.bob.open()+ on := true+ if _, err := InstallHooks(ctx, bob, InstallOptions{BeaconPath: bin, ShareNotes: &on}); err != nil {+ t.Fatal(err)+ }+ loc, _ := ResolveHooks(ctx, bob)+ // Someone replaced pre-push with a Node hook, leaving Beacon's script behind.+ node := "#!/usr/bin/env node\nconsole.log('theirs')\n"+ if err := os.WriteFile(filepath.Join(loc.Dir, "pre-push"), []byte(node), 0o755); err != nil {+ t.Fatal(err)+ }+ res, err := InstallHooks(ctx, bob, InstallOptions{BeaconPath: bin})+ if err != nil {+ t.Fatalf("plain setup must not be blocked by a repair nobody asked for: %v", err)+ }+ if len(res.Reports) != len(ManagedHooks) {+ t.Fatalf("reports %+v", res.Reports)+ }+ if data, _ := os.ReadFile(filepath.Join(loc.Dir, "pre-push")); string(data) != node {+ t.Fatal("the Node hook was modified")+ }+ if st, _ := HookStatus(ctx, bob); !st.Installed() {+ t.Fatal("linking is not installed")+ }+ // Asking for sharing explicitly still refuses, naming pre-push.+ var foreign *ForeignHookError+ if _, err := InstallHooks(ctx, bob, InstallOptions{BeaconPath: bin, ShareNotes: &on}); !errors.As(err, &foreign) || foreign.Hook != ShareHook {+ t.Fatalf("explicit share: %v", err)+ }+}