Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Compare auto-share project paths the filesystem's way; global disable turns projects off

Claudea7e5cd26ab07
diff --git a/cli/beacon/cmd/share_auto.go b/cli/beacon/cmd/share_auto.go
index bf5bcb77..4011cf62 100644
--- a/cli/beacon/cmd/share_auto.go
+++ b/cli/beacon/cmd/share_auto.go
@@ -115,6 +115,8 @@ type shareAutoStatus struct {
CloudConnected bool `json:"cloud_connected"`
CloudPrivacyMode string `json:"cloud_privacy_mode,omitempty"`
Warnings []string `json:"warnings,omitempty"`
+ // ProjectsTurnedOff are the project entries a user-wide disable turned off with it.
+ ProjectsTurnedOff []string `json:"projects_turned_off,omitempty"`
}
func runShareAutoSet(cmd *cobra.Command, enable bool) error {
@@ -148,6 +150,7 @@ func shareAutoSet(cmd *cobra.Command, enable bool) error {
return fmt.Errorf("read %s: %w (fix or remove it, then retry)", path, err)
}
project := ""
+ var turnedOff []string
if strings.TrimSpace(shareAutoOpts.project) != "" {
project, err = filepath.Abs(shareAutoOpts.project)
if err != nil {
@@ -157,7 +160,7 @@ func shareAutoSet(cmd *cobra.Command, enable bool) error {
entry := shareauto.Project{Path: project, Enabled: enable, Visibility: visibility}
replaced := false
for i, p := range settings.Projects {
- if filepath.Clean(p.Path) == project {
+ if shareauto.SamePath(p.Path, project) {
settings.Projects[i] = entry
replaced = true
}
@@ -169,6 +172,16 @@ func shareAutoSet(cmd *cobra.Command, enable bool) error {
settings.Auto.Enabled = enable
if enable {
settings.Auto.Visibility = visibility
+ } else {
+ // Off for every new session means every project too: a project entry is checked
+ // before the user-wide switch, so one left enabled would keep publishing. The entries
+ // stay, turned off, so `enable --project` can bring one back.
+ for i := range settings.Projects {
+ if settings.Projects[i].Enabled {
+ settings.Projects[i].Enabled = false
+ turnedOff = append(turnedOff, settings.Projects[i].Path)
+ }
+ }
}
}
if err := shareauto.Save(path, settings); err != nil {
@@ -184,6 +197,7 @@ func shareAutoSet(cmd *cobra.Command, enable bool) error {
dir, _ = filepath.Abs(".")
}
status := buildShareAutoStatus(path, settings, dir)
+ status.ProjectsTurnedOff = turnedOff
return printShareAutoResult(cmd, status, enable, project)
}
@@ -244,6 +258,9 @@ func printShareAutoResult(cmd *cobra.Command, status shareAutoStatus, enable boo
fmt.Fprintln(out, "Sessions that are already running are shared on their next event; earlier sessions are not. Use `beacon share` for those.")
} else {
fmt.Fprintf(out, "Auto-share is off for %s. Traces already published stay published; delete them on beacon.sh.\n", scope)
+ for _, p := range status.ProjectsTurnedOff {
+ fmt.Fprintf(out, "Turned off for the project %s too.\n", p)
+ }
}
if project != "" {
fmt.Fprintf(out, "Recorded in %s and %s.\n", status.SettingsPath, shareauto.MarkerPath(project))
diff --git a/cli/beacon/cmd/share_auto_test.go b/cli/beacon/cmd/share_auto_test.go
index c9c41606..57374915 100644
--- a/cli/beacon/cmd/share_auto_test.go
+++ b/cli/beacon/cmd/share_auto_test.go
@@ -136,3 +136,36 @@ func TestShareAutoProjectScopeAndStatus(t *testing.T) {
t.Fatal("marker still enabled")
}
}
+
+// A user-wide disable turns off projects enabled with --project too: their entries are checked
+// before the user-wide switch, so leaving one on would keep publishing after "off for every new
+// session".
+func TestShareAutoGlobalDisableTurnsOffProjects(t *testing.T) {
+ path := shareAutoTestEnv(t, true, managedprivacy.Standard)
+ project := t.TempDir()
+ if _, _, err := runShareAuto(t, "enable", "--project", project); err != nil {
+ t.Fatalf("enable --project: %v", err)
+ }
+ if !shareauto.ForHook(path, project).Enabled {
+ t.Fatal("the project is not enabled")
+ }
+ stdout, _, err := runShareAuto(t, "disable")
+ if err != nil {
+ t.Fatalf("disable: %v", err)
+ }
+ if !strings.Contains(stdout, "Auto-share is off for every new session") || !strings.Contains(stdout, "Turned off for the project "+project) {
+ t.Fatalf("stdout = %q", stdout)
+ }
+ settings, _ := shareauto.Load(path)
+ if entry, ok := settings.Project(project); !ok || entry.Enabled {
+ t.Fatalf("project entry = %+v %v, want kept and off", entry, ok)
+ }
+ // What the hook adapter decides: no session.share_requested is written in the project.
+ if d := shareauto.ForHook(path, filepath.Join(project, "sub")); d.Enabled {
+ t.Fatalf("hook decision after a global disable = %+v", d)
+ }
+ stdout, _, err = runShareAuto(t, "status", "--project", project)
+ if err != nil || !strings.Contains(stdout, "Auto-share in "+project+": off") {
+ t.Fatalf("status = %q (%v)", stdout, err)
+ }
+}
diff --git a/docs/cli/share.mdx b/docs/cli/share.mdx
index fcbb419c..fa1dcf04 100644
--- a/docs/cli/share.mdx
+++ b/docs/cli/share.mdx
@@ -132,7 +132,7 @@ beacon share auto status
beacon share auto disable
```
-`enable` warns when the endpoint is not connected to Beacon Cloud, because then nothing is published (the event is written and stays local), and when forwarding is in metadata-only mode, because the trace then has no prompts, answers, reasoning or tool output. `--visibility public` lists every new session in Discover; it asks first, and without a terminal it is refused unless you pass `--yes`. Sessions already running are requested on their next event; earlier sessions are not, so share those with `beacon share`. Turning auto-share off stops new requests; traces already published stay until you delete them on beacon.sh.
+`enable` warns when the endpoint is not connected to Beacon Cloud, because then nothing is published (the event is written and stays local), and when forwarding is in metadata-only mode, because the trace then has no prompts, answers, reasoning or tool output. `--visibility public` lists every new session in Discover; it asks first, and without a terminal it is refused unless you pass `--yes`. Sessions already running are requested on their next event; earlier sessions are not, so share those with `beacon share`. Turning auto-share off stops new requests; traces already published stay until you delete them on beacon.sh. `disable` without `--project` turns it off everywhere, including every project you enabled with `--project` (the entries are kept, turned off, and named in the output); `disable --project <dir>` turns off only that project.
The setting is in `~/.beacon/endpoint/share.json` (0600). `--project <dir>` applies the choice to one project: it is recorded there for you by path, and `<dir>/.beacon/share.json` records it in the repository so it can be committed. A project file can turn auto-share off on its own, but it turns it on only for someone who ran `beacon share auto enable --project` in that project, and the visibility always comes from that person's own setting. A cloned repository can never publish your sessions. The nearest project with a choice decides; elsewhere, the setting for every session does. `status` shows which applies in the current directory (or `--project`), why, and the forwarding state; `--json` prints it as a document.
diff --git a/pkg/asymptoteobserve/shareauto/shareauto.go b/pkg/asymptoteobserve/shareauto/shareauto.go
index 5ce79f0a..f7b2b734 100644
--- a/pkg/asymptoteobserve/shareauto/shareauto.go
+++ b/pkg/asymptoteobserve/shareauto/shareauto.go
@@ -21,6 +21,7 @@ import (
"errors"
"os"
"path/filepath"
+ "runtime"
"strings"
)
@@ -145,11 +146,13 @@ func (s Settings) anyEnabled() bool {
return false
}
-// Project returns the user's entry for dir.
+// Project returns the user's entry for dir. Paths are compared the way the filesystem names them
+// (see pathKey), so an entry written with a symlink, another case on Windows, or a short 8.3 name
+// still matches.
func (s Settings) Project(dir string) (Project, bool) {
- dir = filepath.Clean(dir)
+ key := pathKey(dir)
for _, p := range s.Projects {
- if filepath.Clean(p.Path) == dir {
+ if pathKey(p.Path) == key {
return p, true
}
}
@@ -162,9 +165,17 @@ func (s Settings) Project(dir string) (Project, bool) {
func Resolve(s Settings, workDir string) Decision {
var d Decision
dir := filepath.Clean(workDir)
- if workDir != "" && filepath.IsAbs(dir) {
+ if workDir != "" && rooted(dir) {
+ projects := make(map[string]Project, len(s.Projects))
+ for _, p := range s.Projects {
+ if k := pathKey(p.Path); k != "" {
+ if _, dup := projects[k]; !dup {
+ projects[k] = p
+ }
+ }
+ }
for i := 0; i < maxWalk; i++ {
- if p, ok := s.Project(dir); ok {
+ if p, ok := projects[pathKey(dir)]; ok {
return Decision{Enabled: p.Enabled, Visibility: p.Visibility, Source: "project", Project: dir}
}
if m, ok := LoadMarker(dir); ok {
@@ -188,6 +199,40 @@ func Resolve(s Settings, workDir string) Decision {
return d
}
+// SamePath reports whether a and b name the same directory, compared as Project and Resolve
+// compare them.
+func SamePath(a, b string) bool {
+ ka := pathKey(a)
+ return ka != "" && ka == pathKey(b)
+}
+
+// rooted is true for a path that names a directory from the top of a filesystem. On Windows that
+// includes a path rooted on the current drive (`\work\project`, `/work/project`), which a runtime
+// may report without a drive letter.
+func rooted(p string) bool {
+ if filepath.IsAbs(p) {
+ return true
+ }
+ return runtime.GOOS == "windows" && (strings.HasPrefix(p, `\`) || strings.HasPrefix(p, "/"))
+}
+
+// pathKey is the form two paths are compared in: cleaned, with symlinks resolved when the path
+// exists (which on Windows also expands 8.3 short names and normalizes the drive letter), and on
+// Windows case-folded, because its filesystems ignore case.
+func pathKey(p string) string {
+ if strings.TrimSpace(p) == "" {
+ return ""
+ }
+ p = filepath.Clean(p)
+ if resolved, err := filepath.EvalSymlinks(p); err == nil {
+ p = resolved
+ }
+ if runtime.GOOS == "windows" {
+ p = strings.ToLower(p)
+ }
+ return p
+}
+
// ForHook is Resolve for the hook path: it reads the user file and returns a disabled decision at
// the cost of one failed read when nothing could enable auto-share.
func ForHook(path, workDir string) Decision {
diff --git a/pkg/asymptoteobserve/shareauto/shareauto_test.go b/pkg/asymptoteobserve/shareauto/shareauto_test.go
index 4b3f0d5b..b0f2ee3d 100644
--- a/pkg/asymptoteobserve/shareauto/shareauto_test.go
+++ b/pkg/asymptoteobserve/shareauto/shareauto_test.go
@@ -3,6 +3,8 @@ package shareauto
import (
"os"
"path/filepath"
+ "runtime"
+ "strings"
"testing"
)
@@ -72,3 +74,32 @@ func TestForHookAndSave(t *testing.T) {
t.Fatal("damaged file enabled")
}
}
+
+// Project entries match the directory however its path is spelled: through a symlink, with a
+// trailing separator, or (on Windows) in another case or rooted on the current drive.
+func TestResolveMatchesEquivalentPaths(t *testing.T) {
+ real := t.TempDir()
+ work := filepath.Join(real, "sub")
+ if err := os.MkdirAll(work, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ s := Settings{Auto: Auto{Enabled: true}, Projects: []Project{{Path: real + string(filepath.Separator), Enabled: false}}}
+ if d := Resolve(s, work); d.Enabled || d.Source != "project" {
+ t.Fatalf("trailing separator: %+v", d)
+ }
+ link := filepath.Join(t.TempDir(), "link")
+ if err := os.Symlink(real, link); err == nil {
+ if d := Resolve(s, filepath.Join(link, "sub")); d.Enabled || d.Source != "project" {
+ t.Fatalf("through a symlink: %+v", d)
+ }
+ }
+ if runtime.GOOS == "windows" {
+ if d := Resolve(s, strings.ToUpper(work)); d.Enabled || d.Source != "project" {
+ t.Fatalf("other case: %+v", d)
+ }
+ }
+ rootedOnly := Settings{Auto: Auto{Enabled: true}, Projects: []Project{{Path: "/work/project", Enabled: false}}}
+ if d := Resolve(rootedOnly, "/work/project"); d.Enabled {
+ t.Fatalf("rooted path: %+v", d)
+ }
+}