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
Let a repository's opt-out marker win over the user's entry
Claude642cb896a611
diff --git a/CLAUDE.md b/CLAUDE.mdindex e822829e..553d4bbc 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -69,7 +69,7 @@ Supported runtime surfaces today:- Token usage and runtime-reported cost capture across spans, logs, and metric datapoints, normalized into `gen_ai.usage`, with attribution rollups served by the dashboard token view (`/api/tokens`) and the `beacon token-usage` report command for local and CI logs. Every report row carries three costs (`cli/beacon/internal/tokens/cost.go`): `cost_usd` (runtime-reported, unchanged), `estimated_cost_usd` (list price of every priced token, from `internal/pricing`, computed after dedup and cumulative resolution) and `effective_cost_usd` with `cost_source` (per endpoint/harness/session scope, reported cost wins wholesale when the scope has any; otherwise the estimate; session-less events per event), plus `unpriced_events`/`unpriced_tokens` and a report-level `pricing` block (catalog provenance, per-model key, match, base rates, bands applied, fallbacks, unpriced models). Long-context bands apply only to events `requestScoped` classifies as one model request; it defaults to aggregate, so a new capture path is priced at base rates until it is added there with a test. Lens data (`LensDataV1`) carries no estimate.- Local threat detection via `beacon scan`, which runs the open Threat Rules format (`spec/threat-rules`; CEL match conditions over the endpoint event schema, with embedded conformance fixtures) over the runtime JSONL. The engine (`pkg/asymptoteobserve/threatrules`) ships in the binary; the rule corpus is external data loaded from a local store (`~/.beacon/endpoint/rules`) managed by `beacon rules`, so the corpus can grow without enlarging the binary. `scan` is read-only and offline; only the explicit, user-initiated `beacon rules pull <url>` reaches the network. A small frozen baseline is embedded so `scan` works before any rules are installed.- Session handoff via `beacon handoff list|export|resume` (`cli/beacon/internal/handoff`, `cli/beacon/cmd/handoff*.go`; docs in `docs/cli/handoff.mdx` and `docs/concepts/session-handoff.mdx`). Every runtime is one entry in the registry in `cli/beacon/internal/handoff/runtimes.go`: its session source, the names it answers to, and the commands that reopen it or start it from a brief; `TestRegistryIsConsistent` checks the entries. Handoff reads the session stores of Claude Code, Codex CLI, OpenCode, Cline, Pi, Prime Agent, Factory Droid, GitHub Copilot CLI, Hermes Agent, DeepSeek Harness, fx, Grok Build, OpenClaw Gateway and Cursor read-only and never touches the network. Oh My Pi, Gemini CLI, Qwen Code, Kiro, Antigravity CLI, Devin CLI, Muse Code, OpenHands and goose have no store Beacon reads: their sessions come from the runtime log, and they take a brief as the target of `--agent`. `resume` reopens a session natively with its runtime's own command when it can, and otherwise writes a brief to `~/.beacon/endpoint/handoffs` (0700/0600) and starts a new session pointed at it. DeepSeek Harness cannot be started, and Hermes Agent and fx only reopen their own sessions, so their sessions continue in another runtime. fx, Grok Build and Cursor find a session by the directory they run in, so they are reopened natively only in the session's own directory. The brief is passed by absolute path, never inlined on a command line. Every launch keeps the runtime's approvals on: Beacon never passes a flag that turns them off, names the approval mode that asks where a CLI takes one (Cline always gets `--auto-approve false`, because Cline defaults to approving every tool call), and removes or overrides environment switches that would approve everything (`COPILOT_ALLOW_ALL`, `COPILOT_PLAN_THEN_AUTOPILOT`, `HERMES_YOLO_MODE`, `GOOSE_MODE`); `--print` shows them under `env`. Briefs run every event through `SanitizeEvent`, and quoted content goes in fences longer than any backtick run it contains, with inline fields reduced to one line, so quoted content cannot forge brief structure. A new session's first prompt ends with the `[beacon-handoff from=<harness> session=<id>]` marker (`pkg/asymptoteobserve/handoff.go`). The hook and plugin prompt paths and the session-store mappers record a `session.handoff` event with `handoff.{source_harness,source_session_id}` when they see it; that is an observed claim, not a verified identity.-- Session sharing via `beacon share` and `beacon share refresh` (`cli/beacon/cmd/share.go`; docs in `docs/cli/share.mdx`). It publishes one session the person names (or the most recent in a directory) to beacon.sh as a shared trace that is a `beacon.trace.v1` trace, the projection the dashboard uses: `BuildShareBundle` (sanitize, scrub, then `TraceEventFromEvent`/`TraceBuilder`), the wire types (`ShareTraceV1` summary body, `ShareEventsBatchV1` of `TraceEventV1`s, `ShareTraceStateV1` with `last_event_id`), `ShareExternalID` (`<harness>:<session-id>`, or a sha256 form), `ShareRelation` and `ShareEventsAfter` live in `pkg/asymptoteobserve/share.go`, and the client in `cli/beacon/internal/account/share.go` (`PUT /v1/traces/{external_id}`, `POST .../events/batch` capped at `ShareMaxEventsPerBatch`, `GET`). The chat view is derived on beacon.sh with `TraceMessages` (`pkg/asymptoteobserve/tracemessages.go`), which pairs a tool invocation and its completion by `tool_call_id` and writes a call reported twice once; messages are never uploaded. Sessions resolve through the handoff registry (store first, then the runtime log). Every event goes through `SanitizeEvent` and session-directory/home paths are rewritten in every projected field before projection, and the shared summary drops the working directory and repository path and names the project by `project.name`. `--print` shows the exact `{external_id, trace, events}` payload with no network, `public` needs confirmation (refused without a terminal unless `--yes`), a re-share upserts by stable event id, and a refresh sends only `ShareEventsAfter` the server's `last_event_id` (re-sending it and any tool call still open). After an upload it writes one `session.shared` event (`event.fidelity=inferred`, no collection method) carrying `shared_url`, `visibility`, `shared_at`/`last_refreshed_at` in raw, which the trace list reads as the sharing state; the projection skips that event. It never runs from hooks or in the background. With no selector (or `--current`) it shares the session it runs inside: `BEACON_SESSION_ID`/`BEACON_HARNESS` (the Claude Code SessionStart hook appends both as `export` lines to `$CLAUDE_ENV_FILE`, plain identifiers only; a child runtime inherits them, so without `--harness` they are refused, naming both sessions, when the named session ran outside this directory and its parents or another runtime worked here more recently: `shareEnvContradiction`), then the active-session record (only when the entry was seen at least as recently as the directory's newest session, since OTLP-only and poll runtimes never write it), then the directory's most recent session. The record is `pkg/asymptoteobserve/activesession` (`~/.beacon/endpoint/active-sessions.json`, 0600 under 0700, atomic and locked, at most 256 entries, 14-day prune, an unchanged entry rewritten at most once a minute), written by the hook logger after every endpoint event with a session id, working directory and harness; it holds identifiers and paths only, never content, and hooks write it silently and never touch the network for it. Hook tests point `BEACON_ACTIVE_SESSIONS_FILE` at a temp file in `TestMain`. Auto-share (`beacon share auto enable|disable|status`, `cli/beacon/cmd/share_auto.go`, settings in `pkg/asymptoteobserve/shareauto`) is server-side publishing: when it applies to a session's working directory, the hook logger writes ONE local `session.share_requested` event per session (`event.fidelity=inferred`, `share.visibility`; deduplicated under the active-session record's lock) and Beacon Cloud forwarding ships it; beacon.sh builds and refreshes the trace with the same `BuildShareBundle` projection and `ShareExternalID`. Hooks never upload. The user file `~/.beacon/endpoint/share.json` (0600, CLI-written) holds the user-wide switch, three-state (unset, on, or off as a kill switch over every project; `auto.state`, with `auto.enabled` kept in step so older files read) and per-project choices by path, which a user-wide enable or disable never rewrites; a project marker `<repo>/.beacon/share.json` may disable on its own but enables only when the user's file trusts that project, with the user's visibility, so a cloned repository can never publish someone's sessions. `ForHook` costs one failed read when nothing is enabled. Hook tests point `BEACON_SHARE_SETTINGS_FILE` at a temp file. The share projection and `handoff.LogSessions` recency skip `session.share_requested`.+- Session sharing via `beacon share` and `beacon share refresh` (`cli/beacon/cmd/share.go`; docs in `docs/cli/share.mdx`). It publishes one session the person names (or the most recent in a directory) to beacon.sh as a shared trace that is a `beacon.trace.v1` trace, the projection the dashboard uses: `BuildShareBundle` (sanitize, scrub, then `TraceEventFromEvent`/`TraceBuilder`), the wire types (`ShareTraceV1` summary body, `ShareEventsBatchV1` of `TraceEventV1`s, `ShareTraceStateV1` with `last_event_id`), `ShareExternalID` (`<harness>:<session-id>`, or a sha256 form), `ShareRelation` and `ShareEventsAfter` live in `pkg/asymptoteobserve/share.go`, and the client in `cli/beacon/internal/account/share.go` (`PUT /v1/traces/{external_id}`, `POST .../events/batch` capped at `ShareMaxEventsPerBatch`, `GET`). The chat view is derived on beacon.sh with `TraceMessages` (`pkg/asymptoteobserve/tracemessages.go`), which pairs a tool invocation and its completion by `tool_call_id` and writes a call reported twice once; messages are never uploaded. Sessions resolve through the handoff registry (store first, then the runtime log). Every event goes through `SanitizeEvent` and session-directory/home paths are rewritten in every projected field before projection, and the shared summary drops the working directory and repository path and names the project by `project.name`. `--print` shows the exact `{external_id, trace, events}` payload with no network, `public` needs confirmation (refused without a terminal unless `--yes`), a re-share upserts by stable event id, and a refresh sends only `ShareEventsAfter` the server's `last_event_id` (re-sending it and any tool call still open). After an upload it writes one `session.shared` event (`event.fidelity=inferred`, no collection method) carrying `shared_url`, `visibility`, `shared_at`/`last_refreshed_at` in raw, which the trace list reads as the sharing state; the projection skips that event. It never runs from hooks or in the background. With no selector (or `--current`) it shares the session it runs inside: `BEACON_SESSION_ID`/`BEACON_HARNESS` (the Claude Code SessionStart hook appends both as `export` lines to `$CLAUDE_ENV_FILE`, plain identifiers only; a child runtime inherits them, so without `--harness` they are refused, naming both sessions, when the named session ran outside this directory and its parents or another runtime worked here more recently: `shareEnvContradiction`), then the active-session record (only when the entry was seen at least as recently as the directory's newest session, since OTLP-only and poll runtimes never write it), then the directory's most recent session. The record is `pkg/asymptoteobserve/activesession` (`~/.beacon/endpoint/active-sessions.json`, 0600 under 0700, atomic and locked, at most 256 entries, 14-day prune, an unchanged entry rewritten at most once a minute), written by the hook logger after every endpoint event with a session id, working directory and harness; it holds identifiers and paths only, never content, and hooks write it silently and never touch the network for it. Hook tests point `BEACON_ACTIVE_SESSIONS_FILE` at a temp file in `TestMain`. Auto-share (`beacon share auto enable|disable|status`, `cli/beacon/cmd/share_auto.go`, settings in `pkg/asymptoteobserve/shareauto`) is server-side publishing: when it applies to a session's working directory, the hook logger writes ONE local `session.share_requested` event per session (`event.fidelity=inferred`, `share.visibility`; deduplicated under the active-session record's lock) and Beacon Cloud forwarding ships it; beacon.sh builds and refreshes the trace with the same `BuildShareBundle` projection and `ShareExternalID`. Hooks never upload. The user file `~/.beacon/endpoint/share.json` (0600, CLI-written) holds the user-wide switch, three-state (unset, on, or off as a kill switch over every project; `auto.state`, with `auto.enabled` kept in step so older files read) and per-project choices by path, which a user-wide enable or disable never rewrites; a project marker `<repo>/.beacon/share.json` may disable on its own (and an off marker wins over the user's entry for the same directory; the closest directory with an entry or marker decides) but enables only when the user's file trusts that project, with the user's visibility, so a cloned repository can never publish someone's sessions. `ForHook` costs one failed read when nothing is enabled. Hook tests point `BEACON_SHARE_SETTINGS_FILE` at a temp file. The share projection and `handoff.LogSessions` recency skip `session.share_requested`.- Commit-to-session links via `beacon git setup|status|remove|link|notes` (`cli/beacon/internal/gitlink`, `cli/beacon/cmd/git*.go`; docs in `docs/cli/git.mdx`). A link is a `beacon:<harness>/<session-id>` line in a git note under `refs/notes/beacon`; it carries identifiers only, never content, because notes can be pushed. Which sessions to link is inferred from the local runtime log: a session is linked when, between the parent commit and the commit (at least two hours, at most 24), it wrote a file the commit changes (for a merge, only files that differ from every parent, so a clean merge or pull links nothing). Evidence is file write events, write-type `file.operation`s, plainly readable shell targets, and `apply_patch` envelopes; reads never count. Note updates are a compare-and-swap on the notes ref through a private `refs/notes/beacon-tx/` working ref, and every existing note line, a teammate's or a person's, is kept verbatim. `setup` installs post-commit (links HEAD in the foreground with a 3 s budget, silent, never fails the commit, skips rebase/cherry-pick/revert) and post-rewrite (normalizes the note git concatenates on amend) as standalone `beacon-<hook>` scripts called from a marked block inserted after the shebang of the repository's own hook; only shell hooks are edited, `core.hooksPath` is refused without `--hooks-path`, and `notes.rewriteRef` carries links through amend and rebase. `BEACON_GIT_HOOKS=0` disables the hooks for one command. Every link a run adds is also written to the runtime log as one `session.commit_linked` event in the linked session's timeline (`event.fidelity=inferred`, no collection method), with commit id, branch and credential-stripped remote in the OTel-shaped `vcs` block and overlap counts in `vcs.attribution`; the event deliberately carries no file, command or tool fields so it can never become attribution evidence. Sharing is opt-in (`setup --share-notes`, off by default): a non-destructive fetch refspec `+refs/notes/beacon:refs/notes/beacon-remotes/<remote>` so git's own fetch brings teammates' links into a read-only tracking ref that `beacon git notes` unions with the local one (never force-fetch into `refs/notes/beacon`: it would destroy unpushed links), and a pre-push hook that fetches, merges with `cat_sort_uniq` through the same CAS, and pushes only the notes ref with `--no-verify`, within a 10 s budget and never failing the push. That pre-push hook is the only Beacon git hook that touches the network, and only during a push the person started; `beacon git notes push|fetch` do the same by hand.- Beacon Cloud MCP registration via `beacon mcp connect|disconnect|status` (`cli/beacon/internal/mcpconnect`, `cli/beacon/cmd/mcp_connect.go`; docs in `docs/cli/mcp-connect.mdx`). It registers the Beacon Cloud MCP server as `beacon-managed`, a different name from the local stdio server `beacon`, in the user-level config of Claude Code, Codex CLI, Cursor, VS Code, Gemini CLI and OpenCode. It prints manual steps for runtimes without confirmed MCP OAuth support. OAuth is the default and writes only the URL; `--token-env` writes a reference to an environment variable in each harness's own syntax, never a value. `connect` never reads or copies the account token and never writes a token; minting one is the separate, explicit `beacon mcp token create`. It is explicit and interactive: never run by an unattended install; the onboarding wizard runs it only after the person chose Beacon Cloud and left "Beacon Cloud MCP" selected (that screen is the confirmation), and otherwise the install only suggests it. It is refused as root, and refused in CI or without a terminal unless `--yes` is given. Its one network request is the RFC 9728 resource-metadata check of the URL, which `--dry-run` skips. Configs are edited like the Kimi Code writer: never re-serialized, spliced as text, parsed back and compared before an atomic replace, backed up first. What was written is recorded in `~/.beacon/mcp/connections.json`, and `disconnect` removes only entries recorded there that still point at the recorded URL. `cmd/mcp_connect_e2e_test.go` runs the real harness CLIs when they are installed; re-run it when a harness changes its MCP config format.- An optional, off-by-default policy seam in the hook path (`cli/beacon-hooks/internal/policy`) governed by the stable contract in `pkg/asymptoteobserve/policycontract`. When `BEACON_POLICY_PROVIDER` names an executable, the `pre-tool` and `permission-request` hooks send it a JSON request describing the imminent tool call and honor an allow/deny response, returning the runtime's native deny shape and `policy.enforcement=enforce` telemetry on a deny. The seam is inert when unset and fail-open on any error (timeout, non-zero exit, malformed output), so the open build ships no enforcement of its own; all audit/enforce decision logic lives in the external provider. `rules/agent-control/agent-permission-bypass-spawn.rule.yaml` is the open detect twin that flags the same pattern in `beacon scan`.diff --git a/cli/beacon/cmd/share_auto.go b/cli/beacon/cmd/share_auto.goindex 3d8281f0..e302aea6 100644--- a/cli/beacon/cmd/share_auto.go+++ b/cli/beacon/cmd/share_auto.go@@ -110,7 +110,8 @@ type shareAutoStatus struct {Source string `json:"source,omitempty"`Project string `json:"project,omitempty"`UntrustedMarker string `json:"untrusted_marker,omitempty"`- // Overridden is the project whose enabled entry the user-wide off switch overrides here.+ // Overridden is the project whose enabled entry is overridden here: by the off switch for+ // every session (source "user") or by the repository's opt-out file (source "marker").Overridden string `json:"overridden,omitempty"`UserEnabled bool `json:"user_enabled"`UserState string `json:"user_state"`@@ -341,7 +342,11 @@ func runShareAutoStatus(cmd *cobra.Command, args []string) error {case "project":fmt.Fprintf(out, " decided by your setting for the project %s\n", status.Project)case "marker":- fmt.Fprintf(out, " turned off by %s\n", shareauto.MarkerPath(status.Project))+ if status.Overridden != "" {+ fmt.Fprintf(out, " disabled by the repository file %s, which overrides your setting for this project\n", shareauto.MarkerPath(status.Project))+ } else {+ fmt.Fprintf(out, " disabled by the repository file %s\n", shareauto.MarkerPath(status.Project))+ }case "user":if status.Overridden != "" {fmt.Fprintf(out, " turned off for every session, which overrides your setting for the project %s\n", status.Overridden)diff --git a/cli/beacon/cmd/share_auto_test.go b/cli/beacon/cmd/share_auto_test.goindex dc98a1f6..8139d1a7 100644--- a/cli/beacon/cmd/share_auto_test.go+++ b/cli/beacon/cmd/share_auto_test.go@@ -198,3 +198,24 @@ func TestShareAutoProjectEnableClearsTheOffSwitch(t *testing.T) {t.Fatal("want the project on and other directories off")}}++// A repository's committed opt-out holds for someone who had enabled the project, and status says+// the repository opted out.+func TestShareAutoRepositoryOptOutOverridesAProjectEnable(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)+ }+ // A teammate commits an opt-out, which the pull brings in.+ if err := shareauto.SaveMarker(project, shareauto.Marker{Auto: shareauto.Auto{Enabled: false}}); err != nil {+ t.Fatal(err)+ }+ if d := shareauto.ForHook(path, project); d.Enabled {+ t.Fatalf("hook decision = %+v, want the repository's opt-out", d)+ }+ stdout, _, err := runShareAuto(t, "status", "--project", project)+ if err != nil || !strings.Contains(stdout, ": off") || !strings.Contains(stdout, "disabled by the repository file") || !strings.Contains(stdout, "overrides your setting") {+ t.Fatalf("status = %q (%v)", stdout, err)+ }+}diff --git a/docs/cli/share.mdx b/docs/cli/share.mdxindex d4750788..05d8a9fa 100644--- a/docs/cli/share.mdx+++ b/docs/cli/share.mdx@@ -135,7 +135,7 @@ 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. `disable` without `--project` turns it off everywhere: it overrides every project you enabled with `--project`, which it names, without changing their settings, so a later `enable` brings back exactly what was on before. `disable --project <dir>` turns off only that project. `enable --project <dir>` while it is off everywhere clears that switch (other sessions stay off) and says so.-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`) and why, the setting for every session (on, off or not set), each project you set and whether the off switch overrides it, and the forwarding state; `--json` prints it as a document.+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, and an off file wins over your own setting for the same directory, so a repository that opts out stays out for everyone; it turns auto-share 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 directory with a choice (yours or the repository's) decides, so a setting you made for a subdirectory applies there even under a parent repository's opt-out; elsewhere, the setting for every session does. The off switch for every session overrides all of it. `status` shows which applies in the current directory (or `--project`) and why, the setting for every session (on, off or not set), each project you set and whether the off switch overrides it, and the forwarding state; `--json` prints it as a document.The `session.share_requested` event is marked `event.fidelity=inferred` because Beacon originated it rather than a runtime reporting it, and it is not itself part of any shared trace.diff --git a/pkg/asymptoteobserve/shareauto/shareauto.go b/pkg/asymptoteobserve/shareauto/shareauto.goindex 3fa38f72..3c151705 100644--- a/pkg/asymptoteobserve/shareauto/shareauto.go+++ b/pkg/asymptoteobserve/shareauto/shareauto.go@@ -91,7 +91,8 @@ type Decision struct {Source string// Project is the project directory the decision came from, when it came from one.Project string- // Overridden is the project whose enabled entry the user-wide off switch overrides here.+ // Overridden is the project whose enabled user entry this decision overrides: by the user-wide+ // off switch (Source "user") or by the repository's opt-out marker (Source "marker").Overridden string// UntrustedMarker is a marker that asks for auto-share in a project the user has not opted in.UntrustedMarker string@@ -195,9 +196,13 @@ func (s Settings) Project(dir string) (Project, bool) {// Resolve decides whether auto-share applies in workDir. The user-wide switch turned off is a kill// switch: nothing applies anywhere, and the project entry it overrides is reported. Otherwise the-// nearest enclosing directory that has a user entry or a marker decides; a marker that asks for-// auto-share without a user entry is reported and otherwise ignored. With neither, the user-wide-// switch decides (on, or unset meaning off).+// nearest enclosing directory that has a user entry or a marker decides, walking from workDir+// outward. At that directory a marker that says off wins over the user's entry (the repository+// opted out; the overridden entry is reported); otherwise the user's entry decides. A marker that+// asks for auto-share without a user entry is reported and otherwise ignored. A closer directory+// decides over a farther one, whichever kind each is: a user entry for a subdirectory enables it+// even when a parent's marker says off. With neither, the user-wide switch decides (on, or unset+// meaning off).func Resolve(s Settings, workDir string) Decision {d := resolveProjects(s, workDir)if s.Global() == GlobalOff {@@ -223,17 +228,24 @@ func resolveProjects(s Settings, workDir string) Decision {}}for i := 0; i < maxWalk; i++ {- if p, ok := projects[pathKey(dir)]; ok {- return Decision{Enabled: p.Enabled, Visibility: p.Visibility, Source: "project", Project: dir}- }+ p, hasEntry := projects[pathKey(dir)]if m, ok := LoadMarker(dir); ok {if !m.Auto.Enabled {- return Decision{Source: "marker", Project: dir}+ // The repository opted out, and that wins over the user's own entry for the+ // same directory: a committed opt-out must hold for everyone who opens it.+ off := Decision{Source: "marker", Project: dir, UntrustedMarker: d.UntrustedMarker}+ if hasEntry && p.Enabled {+ off.Overridden = dir+ }+ return off}- if d.UntrustedMarker == "" {+ if !hasEntry && d.UntrustedMarker == "" {d.UntrustedMarker = dir}}+ if hasEntry {+ return Decision{Enabled: p.Enabled, Visibility: p.Visibility, Source: "project", Project: dir, UntrustedMarker: d.UntrustedMarker}+ }parent := filepath.Dir(dir)if parent == dir {breakdiff --git a/pkg/asymptoteobserve/shareauto/shareauto_test.go b/pkg/asymptoteobserve/shareauto/shareauto_test.goindex 4db445e6..cad2d907 100644--- a/pkg/asymptoteobserve/shareauto/shareauto_test.go+++ b/pkg/asymptoteobserve/shareauto/shareauto_test.go@@ -155,3 +155,43 @@ func TestLoadReadsTheOldFormat(t *testing.T) {}}}++// A repository's opt-out marker wins over the user's own entry for the same directory. A closer+// directory decides over a farther one: a user entry for a subdirectory enables it even when a+// parent's marker says off, and a subdirectory's off marker disables it under a parent's entry.+func TestMarkerOffWinsAtItsDirectoryAndTheClosestDecides(t *testing.T) {+ path := filepath.Join(t.TempDir(), FileName)+ repo := t.TempDir()+ sub := filepath.Join(repo, "service")+ if err := os.MkdirAll(sub, 0o755); err != nil {+ t.Fatal(err)+ }+ s := Settings{Projects: []Project{{Path: repo, Enabled: true}}}+ if err := SaveMarker(repo, Marker{Auto: Auto{Enabled: false}}); err != nil {+ t.Fatal(err)+ }+ if d := Resolve(s, repo); d.Enabled || d.Source != "marker" || d.Overridden != repo {+ t.Fatalf("user entry plus off marker = %+v", d)+ }+ if err := Save(path, s); err != nil {+ t.Fatal(err)+ }+ if d := ForHook(path, sub); d.Enabled {+ t.Fatalf("hook decision under the repository's opt-out = %+v", d)+ }+ // A user entry for the subdirectory is closer than the parent's marker.+ child := Settings{Projects: []Project{{Path: sub, Enabled: true}}}+ if d := Resolve(child, sub); !d.Enabled || d.Source != "project" || d.Project != sub {+ t.Fatalf("child entry under a parent's off marker = %+v", d)+ }+ // And a subdirectory's off marker is closer than the parent's entry.+ if err := os.Remove(MarkerPath(repo)); err != nil {+ t.Fatal(err)+ }+ if err := SaveMarker(sub, Marker{Auto: Auto{Enabled: false}}); err != nil {+ t.Fatal(err)+ }+ if d := Resolve(s, sub); d.Enabled || d.Source != "marker" || d.Project != sub {+ t.Fatalf("child off marker under a parent's entry = %+v", d)+ }+}