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
fix(cli): read the console user's remembered Harness² runs dirs in a system backfill
Claudedcc05ec81a4d
diff --git a/cli/beacon/cmd/endpoint_backfill.go b/cli/beacon/cmd/endpoint_backfill.goindex bff65718..6963110e 100644--- a/cli/beacon/cmd/endpoint_backfill.go+++ b/cli/beacon/cmd/endpoint_backfill.go@@ -136,7 +136,9 @@ var endpointBackfillRunners = func() []endpointBackfillRunner {return s.EventsEmitted, err}},{Name: "Harness²", Sync: "beacon endpoint harness2 sync", Run: func(r endpointBackfillRun) (int, error) {- s, err := harness2session.CollectOnce(harness2session.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveHarness2StatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})+ opts := harness2session.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveHarness2StatePath("", r.UserMode), Since: r.Since, Budget: r.Budget}+ opts.ExtraRoots = harness2BackfillExtraRoots(r.UserMode)+ s, err := harness2session.CollectOnce(opts)return s.EventsEmitted, err}},{Name: "OpenClaw Gateway", Sync: "beacon endpoint integrations openclaw sessions sync", Run: func(r endpointBackfillRun) (int, error) {@@ -146,6 +148,17 @@ var endpointBackfillRunners = func() []endpointBackfillRunner {}}+// harness2BackfillExtraRoots is the runs directories a backfill reads beyond its own cursor's. A+// system backfill keeps its cursor beside the system log, but a --runs-dir the console user named+// was remembered in their own cursor file, which the home the backfill runs under names; without it+// a checkout outside ~/harness2 would be read by the user's syncs and never by the system install.+func harness2BackfillExtraRoots(userMode bool) []string {+ if userMode {+ return nil+ }+ return harness2session.UserRememberedRoots(harness2session.DefaultStatePath())+}+// endpointBackfillScratchDir is where a system backfill copies SQLite stores it reads as root: under// the root-owned system base directory, on disk, rather than a /tmp that is often memory-backed. A// seam for tests.diff --git a/cli/beacon/cmd/endpoint_harness2_test.go b/cli/beacon/cmd/endpoint_harness2_test.goindex 3a0dcdfe..7e5efc8e 100644--- a/cli/beacon/cmd/endpoint_harness2_test.go+++ b/cli/beacon/cmd/endpoint_harness2_test.go@@ -229,3 +229,18 @@ func TestEndpointHarness2StatusReportsABrokenRootBesideTheRest(t *testing.T) {t.Fatalf("report = %+v", report)}}++// A system install's backfill keeps its own cursor beside the system log, yet must still read the+// runs directory the console user named with --runs-dir, which their own cursor file remembers.+func TestHarness2SystemBackfillReadsTheUsersRememberedRoots(t *testing.T) {+ f := newHarness2CommandFixture(t)+ // A user-mode sync with the default cursor path remembers the directory.+ endpointHarness2Opts.statePath = ""+ runHarness2(t, endpointHarness2SyncCmd, runEndpointHarness2Sync)+ if got := harness2BackfillExtraRoots(false); len(got) != 1 || got[0] != f.runsDir {+ t.Fatalf("system backfill extra roots = %v, want [%s]", got, f.runsDir)+ }+ if got := harness2BackfillExtraRoots(true); got != nil {+ t.Fatalf("user backfill extra roots = %v; its own cursor already remembers them", got)+ }+}diff --git a/cli/beacon/internal/harness2session/collect.go b/cli/beacon/internal/harness2session/collect.goindex 5487ece3..0477987d 100644--- a/cli/beacon/internal/harness2session/collect.go+++ b/cli/beacon/internal/harness2session/collect.go@@ -1,6 +1,7 @@package harness2sessionimport (+ "encoding/json""errors""fmt""io"@@ -11,6 +12,7 @@ import ("time""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/writer"+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/sessionfs""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/sessionsync""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/sessionwindow")@@ -99,13 +101,17 @@ func (s *State) remember(roots []string) {type CollectOptions struct {// RunsDirs are the runs directories to read. Empty reads DefaultRunsDirs and every directory an// earlier sweep was given; given, they are read and remembered for later sweeps.- RunsDirs []string- StatePath string- LogPath string- Write bool- UserMode bool- Print bool- Out io.Writer+ RunsDirs []string+ // ExtraRoots are read beside the defaults and the remembered roots when RunsDirs is empty, and+ // are not remembered. A system-mode backfill passes the roots the console user's own syncs+ // remembered (UserRememberedRoots), which live in that user's cursor file, not the system one.+ ExtraRoots []string+ StatePath string+ LogPath string+ Write bool+ UserMode bool+ Print bool+ Out io.Writer// Since, when set, limits the sweep to trajectories modified at or after it, newest first. Older// ones are not read and their cursors do not move, so a later sync still collects them. The// install-time backfill sets it; an ordinary sync leaves it zero.@@ -156,6 +162,21 @@ func Roots(runsDirs []string, state *State) ([]string, error) {return store.Roots, nil}+// UserRememberedRoots is the runs directories a user's own syncs remembered in the cursor file at+// statePath. It reads through sessionfs, because a system-mode backfill reads it as root from a+// home the user controls, and a file it cannot read or parse remembers nothing.+func UserRememberedRoots(statePath string) []string {+ data, err := sessionfs.ReadFile(statePath)+ if err != nil {+ return nil+ }+ var state State+ if err := json.Unmarshal(data, &state); err != nil || state.Version != StateVersion {+ return nil+ }+ return state.Roots+}+func CollectOnce(opts CollectOptions) (summary Summary, err error) {if opts.Print && !opts.Write {opts.StatePath = ""@@ -168,6 +189,13 @@ func CollectOnce(opts CollectOptions) (summary Summary, err error) {if err != nil {return summary, err}+ if len(opts.RunsDirs) == 0 && len(opts.ExtraRoots) > 0 {+ merged, err := NewStore(append(append([]string{}, roots...), opts.ExtraRoots...))+ if err != nil {+ return summary, err+ }+ roots = merged.Roots+ }summary.Roots = rootsstore := &Store{Roots: roots}// A root that cannot be read is an error for the sweep, not the end of it: the other roots,diff --git a/cli/beacon/internal/harness2session/collect_test.go b/cli/beacon/internal/harness2session/collect_test.goindex 3809d07a..6f95bb46 100644--- a/cli/beacon/internal/harness2session/collect_test.go+++ b/cli/beacon/internal/harness2session/collect_test.go@@ -331,3 +331,32 @@ func TestCollectOnceKeepsCollectingPastABrokenRoot(t *testing.T) {t.Fatal("the good root was not collected")}}++// Extra roots are read beside the defaults but never remembered: they belong to another cursor file.+func TestCollectOnceReadsExtraRootsWithoutRememberingThem(t *testing.T) {+ env := newSweepEnv(t)+ userState := filepath.Join(t.TempDir(), "user-harness2.json")+ if err := (&State{Version: StateVersion, Roots: []string{env.root}, Files: map[string]*Cursor{}}).Save(userState); err != nil {+ t.Fatal(err)+ }+ extra := UserRememberedRoots(userState)+ if len(extra) != 1 || extra[0] != env.root {+ t.Fatalf("UserRememberedRoots = %v", extra)+ }+ summary := env.sweep(t, func(o *CollectOptions) { o.RunsDirs, o.ExtraRoots = nil, extra })+ if summary.EventsEmitted != 21 {+ t.Fatalf("sweep with extra roots = %+v", summary)+ }+ state, err := LoadState(env.statePath)+ if err != nil {+ t.Fatal(err)+ }+ if len(state.Roots) != 0 {+ t.Fatalf("extra roots were remembered in this cursor: %v", state.Roots)+ }+ for _, bad := range []string{filepath.Join(t.TempDir(), "missing.json"), env.logPath} {+ if got := UserRememberedRoots(bad); got != nil {+ t.Fatalf("UserRememberedRoots(%s) = %v, want nothing", bad, got)+ }+ }+}