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
Link a merge only to the files it changed itself
Claudea5ecb55c1ed4
diff --git a/CLAUDE.md b/CLAUDE.mdindex 1ae501b2..f89adb65 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -66,7 +66,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.- 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.-- Commit-to-session links via `beacon git 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. 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.+- Commit-to-session links via `beacon git 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.- 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`.Current non-goals unless explicitly requested:diff --git a/cli/beacon/internal/gitlink/commit.go b/cli/beacon/internal/gitlink/commit.goindex 14b44ed7..b2997ace 100644--- a/cli/beacon/internal/gitlink/commit.go+++ b/cli/beacon/internal/gitlink/commit.go@@ -52,18 +52,42 @@ func ResolveCommit(ctx context.Context, g Git, rev string) (Commit, error) {return commit, nil}-// ChangedFiles returns the repository-relative paths commit changes, compared with its first-// parent. A rename or copy contributes both its source and its destination: an agent that moved a-// file edited the path it moved from as much as the one it moved to.-func ChangedFiles(ctx context.Context, g Git, commit string) ([]string, error) {- out, err := g.RunRaw(ctx, "diff-tree", "--no-commit-id", "--name-status", "-r", "-z", "-M", "--root",- "--diff-merges=first-parent", commit, "--")+// ChangedFiles returns the repository-relative paths commit changes. A rename or copy+// contributes both its source and its destination: an agent that moved a file edited the path it+// moved from as much as the one it moved to.+//+// For a merge it returns only the paths where the result differs from every parent -- conflict+// resolutions and edits made while merging. The files a merge merely brought in from the other+// side were written by that side's commits, and linking them again here would make every pull or+// merge claim the work of whoever wrote the branch. A clean merge therefore changes nothing.+func ChangedFiles(ctx context.Context, g Git, commit Commit) ([]string, error) {+ args := []string{"diff-tree", "--no-commit-id", "--name-status", "-r", "-z", "-M", "--root", commit.SHA, "--"}+ if len(commit.Parents) > 1 {+ // Combined diff: one status letter per parent and one path, no rename pairs.+ args = []string{"diff-tree", "--no-commit-id", "--name-status", "-r", "-z", "--cc", commit.SHA, "--"}+ }+ out, err := g.RunRaw(ctx, args...)if err != nil {- return nil, fmt.Errorf("list files changed by %s: %w", commit, err)+ return nil, fmt.Errorf("list files changed by %s: %w", commit.SHA, err)+ }+ if len(commit.Parents) > 1 {+ return parseCombinedNameStatusZ(out), nil}return parseNameStatusZ(out), nil}+// parseCombinedNameStatusZ reads `--cc --name-status -z` output: pairs of status and path.+func parseCombinedNameStatusZ(out []byte) []string {+ fields := strings.Split(string(out), "\x00")+ var paths []string+ for i := 0; i+1 < len(fields); i += 2 {+ if fields[i+1] != "" {+ paths = append(paths, fields[i+1])+ }+ }+ return paths+}+// parseNameStatusZ reads `--name-status -z` output: a status field and then one path, or two for a// rename (R) or copy (C).func parseNameStatusZ(out []byte) []string {diff --git a/cli/beacon/internal/gitlink/link.go b/cli/beacon/internal/gitlink/link.goindex 60536fb8..5332b162 100644--- a/cli/beacon/internal/gitlink/link.go+++ b/cli/beacon/internal/gitlink/link.go@@ -99,7 +99,7 @@ func Attribute(ctx context.Context, repo Repo, opts Options) (Result, error) {since, until := Window(commit, opts.MinLookback, opts.MaxLookback)result := Result{Commit: commit, RepoRoot: repo.Root, Since: since, Until: until, DryRun: opts.DryRun}- changed, err := ChangedFiles(ctx, repo.Git, commit.SHA)+ changed, err := ChangedFiles(ctx, repo.Git, commit)if err != nil {return Result{}, err}diff --git a/cli/beacon/internal/gitlink/notes_test.go b/cli/beacon/internal/gitlink/notes_test.goindex 38f2dbed..292acbbd 100644--- a/cli/beacon/internal/gitlink/notes_test.go+++ b/cli/beacon/internal/gitlink/notes_test.go@@ -74,37 +74,61 @@ func TestChangedFilesCoversRenamesRootAndMerges(t *testing.T) {ctx := context.Background()r.write("a.go", "package a\n\nfunc A() {}\n")r.write("dir/b.go", "package b\n")- root := r.commitAt("root", t0)- got, err := ChangedFiles(ctx, r.gitClient(), root)- if err != nil {- t.Fatal(err)+ r.commitAt("root", t0)+ changed := func() []string {+ t.Helper()+ c, err := ResolveCommit(ctx, r.gitClient(), "HEAD")+ if err != nil {+ t.Fatal(err)+ }+ files, err := ChangedFiles(ctx, r.gitClient(), c)+ if err != nil {+ t.Fatal(err)+ }+ sort.Strings(files)+ return files}- sort.Strings(got)+ got := changed()if !reflect.DeepEqual(got, []string{"a.go", "dir/b.go"}) {t.Fatalf("root commit files %q", got)}r.git("mv", "a.go", "renamed.go")r.write("dir/b.go", "package b\n\nvar X = 1\n")- rename := r.commitAt("rename", t0.Add(time.Minute))- got, _ = ChangedFiles(ctx, r.gitClient(), rename)- sort.Strings(got)+ r.commitAt("rename", t0.Add(time.Minute))+ got = changed()if !reflect.DeepEqual(got, []string{"a.go", "dir/b.go", "renamed.go"}) {t.Fatalf("rename commit files %q", got)}- // A merge is compared with its first parent: the files the merge brought in.+ // A clean merge changes nothing it did not bring in from a parent.r.git("checkout", "-q", "-b", "side")r.write("side.txt", "side")+ r.write("conflict.txt", "side\n")r.commitAt("side", t0.Add(2*time.Minute))r.git("checkout", "-q", "main")r.write("main.txt", "main")r.commitAt("main", t0.Add(3*time.Minute))+ r.git("checkout", "-q", "-b", "clean")r.git("merge", "-q", "--no-ff", "--no-edit", "side")- merge := r.git("rev-parse", "HEAD")- got, _ = ChangedFiles(ctx, r.gitClient(), merge)- if !reflect.DeepEqual(got, []string{"side.txt"}) {- t.Fatalf("merge commit files %q", got)+ if got := changed(); len(got) != 0 {+ t.Fatalf("clean merge files %q", got)+ }++ // A conflicted merge changes the resolution and any edit made while merging, not the files+ // either side brought.+ r.git("checkout", "-q", "main")+ r.write("conflict.txt", "main\n")+ r.commitAt("main conflict", t0.Add(4*time.Minute))+ cmd := r.gitClient()+ if _, err := cmd.Run(ctx, nil, "merge", "-q", "--no-edit", "side"); err == nil {+ t.Fatal("expected a conflict")+ }+ r.write("conflict.txt", "resolved\n")+ r.write("dir/b.go", "package b\n\n// edited while merging\n")+ r.commitAt("merge", t0.Add(5*time.Minute))+ if got := changed(); !reflect.DeepEqual(got, []string{"conflict.txt", "dir/b.go"}) {+ t.Fatalf("conflicted merge files %q", got)}}@@ -115,8 +139,12 @@ func TestChangedFilesKeepsUnusualNames(t *testing.T) {t.Skip("name not representable on this filesystem")}r.write(name, "x")- sha := r.commitAt("odd", t0)- got, err := ChangedFiles(context.Background(), r.gitClient(), sha)+ r.commitAt("odd", t0)+ c, err := ResolveCommit(context.Background(), r.gitClient(), "HEAD")+ if err != nil {+ t.Fatal(err)+ }+ got, err := ChangedFiles(context.Background(), r.gitClient(), c)if err != nil {t.Fatal(err)}diff --git a/docs/cli/git.mdx b/docs/cli/git.mdxindex 9881a74f..bdce3326 100644--- a/docs/cli/git.mdx+++ b/docs/cli/git.mdx@@ -20,7 +20,9 @@ Beacon already records every file a supported runtime writes, so matching a comm1. **Window.** Beacon reads the log from the parent commit's time up to the commit. The window always covers at least `--min-lookback` (2 hours) and never more than `--max-lookback` (24 hours) before the commit. Events after the commit are ignored, because they cannot have produced it.2. **Evidence.** A session wrote a file when the log has, for that session, a `file.created`, `file.modified` or `file.deleted` event, a tool event whose `file.operation` is a write, a shell command whose target is plain to read (`rm`, `mv`, `cp`, `touch`, `tee`, `sed -i`, `git mv`, output redirection), or an `apply_patch` envelope. Reads do not count.-3. **Overlap.** Beacon compares those paths with the files the commit changes against its first parent, counting both sides of a rename. A session that wrote at least one of them is linked. Sessions are ordered by how many of the commit's files they wrote, then by how recently.+3. **Overlap.** Beacon compares those paths with the files the commit changes, counting both sides of a rename. A session that wrote at least one of them is linked. Sessions are ordered by how many of the commit's files they wrote, then by how recently.++For a merge commit, only files where the result differs from every parent count: conflict resolutions and edits made while merging. The files a merge brings in were written by the other side's commits, so a clean merge or a `git pull` links nothing.A link is an inference, not an observation. A session that edited a file a person then rewrote by hand is still linked, and a session that wrote nothing the commit kept is not.