Skip to content

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

handoff: add Factory Droid

Claudec6d3b5829f32
diff --git a/cli/beacon/internal/factorysession/handoff_test.go b/cli/beacon/internal/factorysession/handoff_test.go
new file mode 100644
index 00000000..5b3151cb
--- /dev/null
+++ b/cli/beacon/internal/factorysession/handoff_test.go
@@ -0,0 +1,63 @@
+package factorysession
+
+import (
+ "encoding/json"
+ "testing"
+
+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"
+)
+
+func TestMapSessionRecordsAHandoffLink(t *testing.T) {
+ ref := SessionRef{ID: "new-1", Path: "/tmp/new-1.jsonl", CWD: "/work"}
+ prompt := "Continue the work.\n\n" + asymptoteobserve.HandoffMarker("claude_code", "src-1")
+ marked, err := json.Marshal(map[string]interface{}{"type": "message", "id": "u1", "message": map[string]interface{}{
+ "role": "user", "content": []interface{}{
+ map[string]interface{}{"type": "text", "text": "an unrelated block"},
+ map[string]interface{}{"type": "text", "text": prompt},
+ },
+ }})
+ if err != nil {
+ t.Fatal(err)
+ }
+ records := []Record{
+ mustRecord(t, 1, `{"type":"session_start","id":"new-1","cwd":"/work"}`),
+ mustRecord(t, 2, string(marked)),
+ mustRecord(t, 3, `{"type":"message","id":"u2","message":{"role":"user","content":[{"type":"text","text":"no marker here"}]}}`),
+ }
+ mapped := MapSession(ref, records, MapOptions{})
+ var links []MappedEvent
+ for _, m := range mapped {
+ if m.Event.Event.Action == "session.handoff" {
+ links = append(links, m)
+ }
+ }
+ if len(links) != 1 {
+ t.Fatalf("links = %d, want 1: %+v", len(links), mapped)
+ }
+ link := links[0]
+ if link.SourceLine != 2 || link.Event.Handoff == nil || link.Event.Handoff.SourceHarness != "claude_code" || link.Event.Handoff.SourceSessionID != "src-1" {
+ t.Fatalf("link = %+v handoff=%+v", link, link.Event.Handoff)
+ }
+ if link.Event.Session == nil || link.Event.Session.ID != "new-1" || link.Event.Session.WorkingDirectory != "/work" {
+ t.Fatalf("link session = %+v", link.Event.Session)
+ }
+ if link.Event.Harness.Name != Harness || link.Event.Harness.CollectionMethod != "poll" || link.Event.Event.Fidelity != "observed" {
+ t.Fatalf("link provenance = %+v %+v", link.Event.Harness, link.Event.Event)
+ }
+ if link.Event.Prompt != nil || link.Event.Content != nil || link.Event.GenAI != nil {
+ t.Fatalf("the link must not repeat the prompt: %+v", link.Event)
+ }
+ ids := map[string]bool{}
+ for _, m := range mapped {
+ if ids[m.Event.Event.ID] {
+ t.Fatalf("duplicate event id %s", m.Event.Event.ID)
+ }
+ ids[m.Event.Event.ID] = true
+ }
+ again := MapSession(ref, records, MapOptions{})
+ for i := range mapped {
+ if again[i].Event.Event.ID != mapped[i].Event.Event.ID {
+ t.Fatal("event ids must be deterministic, so a second sync never duplicates the link")
+ }
+ }
+}
diff --git a/cli/beacon/internal/factorysession/mapper.go b/cli/beacon/internal/factorysession/mapper.go
index 98c6e898..b870f109 100644
--- a/cli/beacon/internal/factorysession/mapper.go
+++ b/cli/beacon/internal/factorysession/mapper.go
@@ -112,6 +112,11 @@ func (m *mapper) emitMessage(record *Record) {
ev.Content = asymptoteobserve.RetainedContent(text, 0)
ev.GenAI = &schema.GenAIInfo{Input: &schema.GenAIInputInfo{Messages: asymptoteobserve.TextInputMessages(text)}}
m.append(record, fmt.Sprintf("prompt.%d", i), ev)
+ if info, ok := asymptoteobserve.ParseHandoffMarker(text); ok {
+ link := m.base(record, "session.handoff", "session", schema.SeverityInfo, "Session continued from a "+info.SourceHarness+" session")
+ link.Handoff = &info
+ m.append(record, fmt.Sprintf("prompt.%d.handoff", i), link)
+ }
}
case RoleAssistant:
blocks := messageBlocks(msg)
diff --git a/cli/beacon/internal/handoff/factory.go b/cli/beacon/internal/handoff/factory.go
new file mode 100644
index 00000000..550bb9d9
--- /dev/null
+++ b/cli/beacon/internal/handoff/factory.go
@@ -0,0 +1,72 @@
+package handoff
+
+import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/factorysession"
+)
+
+// Factory Droid keeps one JSONL transcript per session under a directory named for where it ran,
+// opened by a session_start record that carries its title and working directory.
+
+type factorySource struct{ dir string }
+
+func (s *factorySource) Harness() string { return HarnessFactory }
+
+// store reads dir as Factory's sessions directory, as `beacon endpoint factory sync --sessions-dir`
+// does.
+func (s *factorySource) store() (*factorysession.Store, error) {
+ return factorysession.NewStore(s.dir)
+}
+
+func (s *factorySource) List() ([]Session, error) {
+ store, err := s.store()
+ if err != nil {
+ return nil, err
+ }
+ if !store.Exists() {
+ return nil, nil
+ }
+ refs, err := store.List()
+ if err != nil {
+ return nil, err
+ }
+ sessions := make([]Session, 0, len(refs))
+ for _, ref := range refs {
+ sessions = append(sessions, Session{
+ Harness: HarnessFactory,
+ ID: ref.ID,
+ Title: oneLine(ref.Title),
+ Directory: ref.CWD,
+ SourcePath: ref.Path,
+ UpdatedAt: unixMS(ref.ModTimeUnixMS),
+ })
+ }
+ return sessions, nil
+}
+
+func (s *factorySource) Events(session Session) ([]schema.Event, error) {
+ store, err := s.store()
+ if err != nil {
+ return nil, err
+ }
+ refs, err := store.List()
+ if err != nil {
+ return nil, err
+ }
+ for _, ref := range refs {
+ if ref.ID != session.ID || ref.Path != session.SourcePath {
+ continue
+ }
+ records, _, err := store.Read(ref)
+ if err != nil {
+ return nil, err
+ }
+ mapped := factorysession.MapSession(ref, records, factorysession.MapOptions{})
+ events := make([]schema.Event, 0, len(mapped))
+ for _, m := range mapped {
+ events = append(events, m.Event)
+ }
+ return events, nil
+ }
+ return nil, errSessionGone(session)
+}
diff --git a/cli/beacon/internal/handoff/factory_test.go b/cli/beacon/internal/handoff/factory_test.go
new file mode 100644
index 00000000..ecc71b82
--- /dev/null
+++ b/cli/beacon/internal/handoff/factory_test.go
@@ -0,0 +1,108 @@
+package handoff
+
+import (
+ "errors"
+ "path/filepath"
+ "reflect"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
+)
+
+var factoryUpdated = time.Date(2026, 9, 24, 11, 0, 0, 0, time.UTC)
+
+// factoryFixture lays down a Factory Droid sessions directory in the layout droid writes: one
+// directory per working directory, holding each session's transcript and settings.
+func factoryFixture(t *testing.T) (StoreDirs, string) {
+ t.Helper()
+ testenv.SetHome(t, t.TempDir())
+ isolateRuntimeEnv(t)
+ dirs := StoreDirs{HarnessFactory: filepath.Join(t.TempDir(), "sessions")}
+
+ path := filepath.Join(dirs[HarnessFactory], "-work-cli", "factory-sess-1.jsonl")
+ writeFixture(t, path,
+ jsonLine(t, map[string]interface{}{"type": "session_start", "id": "factory-sess-1", "title": " Fix the\nflaky test ", "cwd": "/work/cli"})+
+ jsonLine(t, map[string]interface{}{"type": "message", "id": "u1", "timestamp": "2026-09-24T10:59:00.000Z", "message": map[string]interface{}{
+ "role": "user", "content": []interface{}{map[string]interface{}{"type": "text", "text": "<user_query>\nfix the flaky test\n</user_query>"}},
+ }})+
+ jsonLine(t, map[string]interface{}{"type": "message", "id": "a1", "timestamp": "2026-09-24T10:59:30.000Z", "message": map[string]interface{}{
+ "role": "assistant", "content": []interface{}{map[string]interface{}{"type": "text", "text": "Fixed."}},
+ }}))
+ writeFixture(t, filepath.Join(dirs[HarnessFactory], "-work-cli", "factory-sess-1.settings.json"), `{"model":"gpt-5"}`)
+ setModTime(t, path, factoryUpdated)
+ return dirs, path
+}
+
+func TestListReadsFactorySessions(t *testing.T) {
+ dirs, path := factoryFixture(t)
+ sessions, err := List(DefaultSources(dirs), Filter{Harness: HarnessFactory})
+ if err != nil {
+ t.Fatalf("List: %v", err)
+ }
+ want := []Session{{Harness: HarnessFactory, ID: "factory-sess-1", Title: "Fix the flaky test", Directory: "/work/cli", SourcePath: path, UpdatedAt: factoryUpdated}}
+ if !reflect.DeepEqual(sessions, want) {
+ t.Fatalf("sessions = %+v\nwant %+v", sessions, want)
+ }
+}
+
+func TestParseHarnessNamesFactoryDroid(t *testing.T) {
+ for _, name := range []string{"factory", "droid", "Factory-Droid"} {
+ if got, err := ParseHarness(name); err != nil || got != HarnessFactory {
+ t.Errorf("ParseHarness(%q) = %q, %v; want %s", name, got, err, HarnessFactory)
+ }
+ }
+}
+
+func TestFactorySessionBuildsABrief(t *testing.T) {
+ dirs, _ := factoryFixture(t)
+ sources := DefaultSources(dirs)
+ // A unique prefix finds the session too.
+ session, err := Find(sources, HarnessFactory, "factory-sess")
+ if err != nil {
+ t.Fatalf("Find: %v", err)
+ }
+ events, err := Events(sources, session)
+ if err != nil {
+ t.Fatalf("Events: %v", err)
+ }
+ brief := BuildBrief(session, events, FromSessionStore, time.Now())
+ if brief.Prompts != 1 || brief.FirstRequest != "fix the flaky test" {
+ t.Fatalf("brief prompts=%d first=%q", brief.Prompts, brief.FirstRequest)
+ }
+ if !strings.Contains(brief.Render(), "Factory Droid") {
+ t.Fatalf("the brief should name Factory Droid:\n%s", brief.Render())
+ }
+}
+
+func TestFactorySessionGoneFromItsStore(t *testing.T) {
+ dirs, path := factoryFixture(t)
+ session := Session{Harness: HarnessFactory, ID: "factory-sess-1", SourcePath: path + ".moved"}
+ if _, err := Events(DefaultSources(dirs), session); !errors.Is(err, ErrNotFound) {
+ t.Fatalf("Events = %v, want ErrNotFound", err)
+ }
+}
+
+func TestPlanResumeReopensAFactorySessionByItsID(t *testing.T) {
+ session := resumableSession(t, HarnessFactory, "factory-1")
+ plan, err := PlanResume(session, PlanOptions{LookPath: installed("droid")})
+ if err != nil {
+ t.Fatalf("PlanResume: %v", err)
+ }
+ if plan.Mode != ModeNative || plan.Executable != "/bin/droid" || !reflect.DeepEqual(plan.Args, []string{"--resume", "factory-1"}) || len(plan.Env) != 0 {
+ t.Fatalf("plan = %+v", plan)
+ }
+
+ gone := session
+ gone.SourcePath = filepath.Join(t.TempDir(), "missing.jsonl")
+ brief := filepath.Join(t.TempDir(), "brief.md")
+ plan, err = PlanResume(gone, PlanOptions{BriefPath: brief, LookPath: installed("droid")})
+ if err != nil {
+ t.Fatalf("PlanResume: %v", err)
+ }
+ // The prompt is droid's only argument: no --auto, so the new session keeps asking.
+ if plan.Mode != ModeNewSession || plan.Reason != ReasonSessionGone || !reflect.DeepEqual(plan.Args, []string{NewSessionPrompt(gone, brief)}) {
+ t.Fatalf("plan = %+v", plan)
+ }
+}
diff --git a/cli/beacon/internal/handoff/resume_test.go b/cli/beacon/internal/handoff/resume_test.go
index 54ed8c2d..c03f4ac0 100644
--- a/cli/beacon/internal/handoff/resume_test.go
+++ b/cli/beacon/internal/handoff/resume_test.go
@@ -24,7 +24,7 @@ func installed(names ...string) func(string) (string, error) {
}
}
-var allRuntimes = installed("claude", "codex", "opencode", "cline", "pi", "prime-agent")
+var allRuntimes = installed("claude", "codex", "opencode", "cline", "pi", "prime-agent", "droid")
// resumableSession is a session whose directory and session file both exist.
func resumableSession(t *testing.T, harness, id string) Session {
@@ -48,6 +48,7 @@ func TestPlanResumeReopensEachRuntimeNatively(t *testing.T) {
{HarnessCodex, "codex", []string{"resume", "s-1"}},
{HarnessOpenCode, "opencode", []string{"--session", "s-1"}},
{HarnessCline, "cline", []string{"--tui", "--auto-approve", "false", "--id", "s-1"}},
+ {HarnessFactory, "droid", []string{"--resume", "s-1"}},
} {
t.Run(tc.harness, func(t *testing.T) {
session := resumableSession(t, tc.harness, "s-1")
@@ -80,6 +81,7 @@ func TestPlanResumeStartsANewSessionInEachRuntime(t *testing.T) {
{HarnessCline, "cline", []string{"--tui", "--auto-approve", "false"}},
{HarnessPi, "pi", []string{"--"}},
{HarnessPrime, "prime-agent", []string{"--"}},
+ {HarnessFactory, "droid", nil},
} {
t.Run(tc.target, func(t *testing.T) {
source := HarnessCodex
diff --git a/cli/beacon/internal/handoff/runtimes.go b/cli/beacon/internal/handoff/runtimes.go
index 76162102..0d30b0b8 100644
--- a/cli/beacon/internal/handoff/runtimes.go
+++ b/cli/beacon/internal/handoff/runtimes.go
@@ -7,6 +7,7 @@ import (
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/claudesession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/clinesession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/codexsession"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/factorysession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/opencodesession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/pisession"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/primesession"
@@ -53,6 +54,7 @@ const (
HarnessCline = clinesession.Harness
HarnessPi = pisession.Harness
HarnessPrime = primesession.Harness
+ HarnessFactory = factorysession.Harness
)
// runtimes lists every runtime handoff supports, in display order.
@@ -149,6 +151,21 @@ var runtimes = []Runtime{
NewSession: func(prompt string) []string { return []string{"--", prompt} },
},
},
+ {
+ Harness: HarnessFactory,
+ Label: "Factory Droid",
+ Aliases: []string{"droid", "factory-droid"},
+ NewSource: func(dir string) Source { return &factorySource{dir: dir} },
+ // Droid's interactive mode asks before it acts. Beacon never passes --auto, so a session it
+ // starts keeps asking.
+ Command: &runtimeCommand{
+ Executable: "droid",
+ Resume: func(s Session) ([]string, bool) { return []string{"--resume", s.ID}, true },
+ // The prompt is droid's positional argument. It starts with a word that is neither an
+ // option nor one of droid's subcommands, so it is read as the prompt.
+ NewSession: func(prompt string) []string { return []string{prompt} },
+ },
+ },
}
// Harnesses lists the runtimes handoff supports, in display order.
diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdx
index 4b458e2b..83bda689 100644
--- a/docs/cli/handoff.mdx
+++ b/docs/cli/handoff.mdx
@@ -25,10 +25,11 @@ Sessions come from each runtime's own local session store, not from Beacon's run
| Cline | `~/.cline/data` | `cline` |
| Pi | `~/.pi/agent/sessions` (or under `PI_CODING_AGENT_DIR`) | `pi` |
| Prime Agent | `~/.prime/agent`, both `sessions` and `session-artifacts` (or `PRIME_AGENT_CODING_AGENT_DIR`) | `prime` |
+| Factory Droid | `~/.factory/sessions` | `droid` |
When a Codex thread has more than one rollout file, `beacon handoff` lists it once, under its newest file. Cline can hold the same task both as a CLI session and in its older task history; the CLI session is the copy that is listed. Cline kanban cards are not sessions and are not listed. Prime Agent subagent transcripts, under `session-artifacts`, are listed as subagents of the session that started them.
-`--store-dir <runtime>=<path>` takes the location in the table: for Pi its sessions directory, as `beacon endpoint pi sync --sessions-dir` does, and for Prime Agent the agent directory holding both of its roots.
+`--store-dir <runtime>=<path>` takes the location in the table: for Pi its sessions directory, as `beacon endpoint pi sync --sessions-dir` does, and for Prime Agent the agent directory holding both of its roots. For Factory Droid it is the sessions directory, as `beacon endpoint factory sync --sessions-dir` does.
## `beacon handoff list`
@@ -110,6 +111,7 @@ There are two ways to resume:
| Cline | `cline --tui --auto-approve false --id <id>` |
| Pi | `pi --session <session file>` |
| Prime Agent | `prime-agent --resume <session file>` |
+ | Factory Droid | `droid --resume <id>` |
- **Start a new session from a brief.** Otherwise, or with `--agent` naming another runtime or with `--new`, Beacon writes a brief (see `export`) and starts a new session. The first message of that session points at the brief:
@@ -121,6 +123,7 @@ There are two ways to resume:
| Cline | `cline --tui --auto-approve false "<prompt>"` |
| Pi | `pi -- "<prompt>"` |
| Prime Agent | `prime-agent -- "<prompt>"` |
+ | Factory Droid | `droid "<prompt>"` |
The prompt names the brief by its path and asks the agent to read it, then confirm the task before changing anything. The brief is never inlined into the command line, because a command line is visible to every local user through the process table. The prompt ends with a handoff marker (see below).
@@ -132,7 +135,7 @@ The runtime runs in this terminal, in the session's recorded directory. If that
| Flag | Description |
|------|-------------|
-| `--agent` | Runtime to continue in: `claude`, `codex`, `opencode`, `cline`, `pi` or `prime`. Defaults to the session's own runtime. |
+| `--agent` | Runtime to continue in: `claude`, `codex`, `opencode`, `cline`, `pi`, `prime` or `droid`. Defaults to the session's own runtime. |
| `--new` | Start a new session from a brief even when the session could be reopened. |
| `--cwd` | Directory to start the runtime in. |
| `--print` | Show the plan and command without writing a brief or launching anything. |
@@ -163,7 +166,7 @@ The link event keeps the new session's id, workspace and harness, and leaves the
Two paths record the link:
- **Live hooks.** The prompt hook for Claude Code and the Cline and OpenCode plugins record it as the prompt is sent (`harness.collection_method: hook`).
-- **Session-store sync.** `beacon endpoint claude sync`, `codex sync`, `opencode sync`, `cline sync`, `pi sync` and `prime sync` record it when they read the prompt back from the runtime's store (`harness.collection_method: poll`).
+- **Session-store sync.** `beacon endpoint claude sync`, `codex sync`, `opencode sync`, `cline sync`, `pi sync`, `prime sync` and `factory sync` record it when they read the prompt back from the runtime's store (`harness.collection_method: poll`).
Codex CLI prompts reach Beacon over OTLP and through `beacon endpoint codex sync`, not a prompt hook, so a session continued in Codex is linked by the sync. For a runtime that also has a prompt hook or plugin, a sync can record the same link the hook already did; the two carry different `collection_method` values, as every other event those runtimes report through both paths does. A sync's link has a deterministic `event.id`, so syncing again never duplicates it.