Skip to content

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

Merge handoff 2/5 into handoff 3/5

Claudee1b08de1be23
diff --cc cli/beacon/cmd/handoff.go
index 88f32379,791468f7..d4c8c66b
--- a/cli/beacon/cmd/handoff.go
+++ b/cli/beacon/cmd/handoff.go
@@@ -70,38 -70,48 +70,42 @@@ var
handoffNow = time.Now
)
-// loadHandoffBrief builds the brief for id from the runtime's session store, or from the runtime log
-// when the store no longer has the session.
-func loadHandoffBrief(id string) (handoff.Brief, error) {
+// handoffSubject is the session a handoff command acts on, found in its runtime's store or, when
+// the store no longer has it, in Beacon's runtime log.
+type handoffSubject struct {
+ session handoff.Session
+ fromLog bool
+ logEvents []schema.Event
+}
+
+func resolveHandoffSession(id string) (handoffSubject, error) {
harness, err := handoff.ParseHarness(handoffOpts.harness)
if err != nil {
- return handoff.Brief{}, err
+ return handoffSubject{}, err
}
- sources := handoffSources(handoffOpts.dirs)
- session, findErr := handoff.Find(sources, harness, id)
- var notFound *handoff.NotFoundError
- switch {
- case findErr == nil:
- events, err := handoff.Events(sources, session)
- if err == nil {
- return handoff.BuildBrief(session, events, handoff.FromSessionStore, handoffNow()), nil
- }
- if !errors.Is(err, handoff.ErrNotFound) {
- return handoff.Brief{}, fmt.Errorf("read %s session %s: %w", session.Harness, session.ID, err)
- }
- id = session.ID
- case !errors.As(findErr, &notFound):
- return handoff.Brief{}, findErr
+ session, findErr := handoff.Find(handoffSources(handoffOpts.dirs), harness, id)
+ if findErr == nil {
+ return handoffSubject{session: session}, nil
}
- logSession, events, err := loadHandoffLogSession(id, harness, notFound)
- if err != nil {
- return handoff.Brief{}, err
+ var notFound *handoff.NotFoundError
+ if !errors.As(findErr, &notFound) {
+ return handoffSubject{}, findErr
}
- return handoff.BuildBrief(logSession, events, handoff.FromRuntimeLog, handoffNow()), nil
+ return resolveHandoffLogSession(id, harness, notFound)
}
-// loadHandoffLogSession finds id in the runtime log. It refuses a session whose own store could not
-// be read: that session may well still be there, and a brief from the log would keep less of it
+// resolveHandoffLogSession finds id in the runtime log. It refuses a session whose own store could
+// not be read: that session may well still be there, and a brief from the log would keep less of it
// than the store does.
-func loadHandoffLogSession(id, harness string, notFound *handoff.NotFoundError) (handoff.Session, []schema.Event, error) {
+func resolveHandoffLogSession(id, harness string, notFound *handoff.NotFoundError) (handoffSubject, error) {
logPath := handoffRuntimeLogPath()
- session, events, found, err := handoff.LogSession(logPath, id)
+ session, events, found, err := handoff.LogSession(logPath, id, harness)
+ var ambiguous *handoff.AmbiguousError
+ if errors.As(err, &ambiguous) {
- return handoff.Session{}, nil, fmt.Errorf("in the runtime log %s: %w", logPath, err)
++ return handoffSubject{}, fmt.Errorf("in the runtime log %s: %w", logPath, err)
+ }
if err != nil {
- return handoff.Session{}, nil, fmt.Errorf("read runtime log %s: %w", logPath, err)
+ return handoffSubject{}, fmt.Errorf("read runtime log %s: %w", logPath, err)
}
if !found || (harness != "" && session.Harness != harness) {
if notFound == nil {