Skip to content

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

handoff: describe runtimes in one registry

Claude1411d0833f48
diff --git a/cli/beacon/cmd/handoff.go b/cli/beacon/cmd/handoff.go
index d4c8c66b..a286dfb7 100644
--- a/cli/beacon/cmd/handoff.go
+++ b/cli/beacon/cmd/handoff.go
@@ -25,7 +25,11 @@ type handoffOptions struct {
directory string
includeSubagents bool
limit int
- dirs handoff.StoreDirs
+ claudeDir string
+ codexDir string
+ openCodeDir string
+ clineDir string
+ storeDirs []string
print bool
outputDir string
logPath string
@@ -83,7 +87,11 @@ func resolveHandoffSession(id string) (handoffSubject, error) {
if err != nil {
return handoffSubject{}, err
}
- session, findErr := handoff.Find(handoffSources(handoffOpts.dirs), harness, id)
+ dirs, err := handoffStoreDirs()
+ if err != nil {
+ return handoffSubject{}, err
+ }
+ session, findErr := handoff.Find(handoffSources(dirs), harness, id)
if findErr == nil {
return handoffSubject{session: session}, nil
}
@@ -128,7 +136,11 @@ func (subject handoffSubject) brief() (handoff.Brief, error) {
return handoff.BuildBrief(subject.session, subject.logEvents, handoff.FromRuntimeLog, handoffNow()), nil
}
session := subject.session
- events, err := handoff.Events(handoffSources(handoffOpts.dirs), session)
+ dirs, err := handoffStoreDirs()
+ if err != nil {
+ return handoff.Brief{}, err
+ }
+ events, err := handoff.Events(handoffSources(dirs), session)
if err == nil {
return handoff.BuildBrief(session, events, handoff.FromSessionStore, handoffNow()), nil
}
@@ -231,7 +243,11 @@ func runHandoffList(cmd *cobra.Command, args []string) error {
}
filter.Directory = abs
}
- sessions, listErr := handoff.List(handoffSources(handoffOpts.dirs), filter)
+ dirs, err := handoffStoreDirs()
+ if err != nil {
+ return err
+ }
+ sessions, listErr := handoff.List(handoffSources(dirs), filter)
out := cmd.OutOrStdout()
if handoffOpts.jsonOutput {
result := handoffListResult{Sessions: sessions}
@@ -304,13 +320,42 @@ func truncateRunes(s string, max int) string {
return string(runes[:max-1]) + "…"
}
+// handoffStoreDirs collects the store directory overrides. --store-dir names any runtime; the
+// per-runtime flags predate it and win over it for their runtime.
+func handoffStoreDirs() (handoff.StoreDirs, error) {
+ dirs := handoff.StoreDirs{}
+ for _, entry := range handoffOpts.storeDirs {
+ name, dir, ok := strings.Cut(entry, "=")
+ if !ok || strings.TrimSpace(name) == "" || dir == "" {
+ return nil, fmt.Errorf("--store-dir %q: want <runtime>=<path>", entry)
+ }
+ harness, err := handoff.ParseHarness(name)
+ if err != nil {
+ return nil, fmt.Errorf("--store-dir %q: %w", entry, err)
+ }
+ dirs[harness] = dir
+ }
+ for harness, dir := range map[string]string{
+ handoff.HarnessClaude: handoffOpts.claudeDir,
+ handoff.HarnessCodex: handoffOpts.codexDir,
+ handoff.HarnessOpenCode: handoffOpts.openCodeDir,
+ handoff.HarnessCline: handoffOpts.clineDir,
+ } {
+ if dir != "" {
+ dirs[harness] = dir
+ }
+ }
+ return dirs, nil
+}
+
func addHandoffStoreFlags(cmd *cobra.Command) {
f := cmd.Flags()
- f.StringVar(&handoffOpts.harness, "harness", "", "Only this runtime: claude, codex, opencode or cline")
- f.StringVar(&handoffOpts.dirs.ClaudeProjects, "claude-projects-dir", "", "Claude projects directory (default ~/.claude/projects)")
- f.StringVar(&handoffOpts.dirs.Codex, "codex-dir", "", "Codex directory (default ~/.codex)")
- f.StringVar(&handoffOpts.dirs.OpenCode, "opencode-dir", "", "OpenCode data directory or opencode.db path")
- f.StringVar(&handoffOpts.dirs.Cline, "cline-dir", "", "Cline directory (default ~/.cline)")
+ f.StringVar(&handoffOpts.harness, "harness", "", "Only this runtime: "+strings.Join(handoff.RuntimeNames(), ", "))
+ f.StringArrayVar(&handoffOpts.storeDirs, "store-dir", nil, "Read a runtime's sessions from this directory, as <runtime>=<path> (repeatable)")
+ f.StringVar(&handoffOpts.claudeDir, "claude-projects-dir", "", "Claude projects directory (default ~/.claude/projects)")
+ f.StringVar(&handoffOpts.codexDir, "codex-dir", "", "Codex directory (default ~/.codex)")
+ f.StringVar(&handoffOpts.openCodeDir, "opencode-dir", "", "OpenCode data directory or opencode.db path")
+ f.StringVar(&handoffOpts.clineDir, "cline-dir", "", "Cline directory (default ~/.cline)")
}
func init() {
diff --git a/cli/beacon/cmd/handoff_resume.go b/cli/beacon/cmd/handoff_resume.go
index 7627d965..5ecd330a 100644
--- a/cli/beacon/cmd/handoff_resume.go
+++ b/cli/beacon/cmd/handoff_resume.go
@@ -171,7 +171,7 @@ func init() {
handoffCmd.AddCommand(handoffResumeCmd)
addHandoffStoreFlags(handoffResumeCmd)
f := handoffResumeCmd.Flags()
- f.StringVar(&handoffResumeOpts.agent, "agent", "", "Runtime to continue in: claude, codex, opencode or cline (default the session's own)")
+ f.StringVar(&handoffResumeOpts.agent, "agent", "", "Runtime to continue in: "+strings.Join(handoff.StartableNames(), ", ")+" (default the session's own)")
f.BoolVar(&handoffResumeOpts.newOnly, "new", false, "Start a new session from a brief even when the session could be reopened")
f.StringVar(&handoffResumeOpts.cwd, "cwd", "", "Directory to start the runtime in (default the session's directory)")
f.BoolVar(&handoffResumeOpts.print, "print", false, "Show what would run without writing a brief or launching anything")
diff --git a/cli/beacon/cmd/handoff_test.go b/cli/beacon/cmd/handoff_test.go
index 1b13574e..e313584b 100644
--- a/cli/beacon/cmd/handoff_test.go
+++ b/cli/beacon/cmd/handoff_test.go
@@ -6,6 +6,7 @@ import (
"errors"
"os"
"path/filepath"
+ "reflect"
"strings"
"testing"
"time"
@@ -50,6 +51,12 @@ func runHandoff(t *testing.T, args ...string) (string, string, error) {
handoffResumeOpts = handoffResumeOptions{}
for _, cmd := range handoffCmd.Commands() {
cmd.Flags().VisitAll(func(f *pflag.Flag) {
+ if slice, ok := f.Value.(pflag.SliceValue); ok {
+ // Set on a slice flag appends; start it empty again instead.
+ _ = slice.Replace(nil)
+ f.Changed = false
+ return
+ }
_ = f.Value.Set(f.DefValue)
f.Changed = false
})
@@ -225,7 +232,7 @@ func TestHandoffListWarnsAboutUnreadableStores(t *testing.T) {
func TestHandoffListRejectsUnknownRuntime(t *testing.T) {
stubHandoffSources(t)
- if _, _, err := runHandoff(t, "list", "--harness", "cursor"); err == nil || !strings.Contains(err.Error(), "unsupported runtime") {
+ if _, _, err := runHandoff(t, "list", "--harness", "no-such-runtime"); err == nil || !strings.Contains(err.Error(), "unsupported runtime") {
t.Fatalf("err = %v", err)
}
}
@@ -235,12 +242,32 @@ func TestHandoffListPassesStoreDirectories(t *testing.T) {
if _, _, err := runHandoff(t, "list", "--claude-projects-dir", "/c", "--codex-dir", "/x", "--opencode-dir", "/o", "--cline-dir", "/l"); err != nil {
t.Fatal(err)
}
- want := handoff.StoreDirs{ClaudeProjects: "/c", Codex: "/x", OpenCode: "/o", Cline: "/l"}
- if *seen != want {
+ want := handoff.StoreDirs{handoff.HarnessClaude: "/c", handoff.HarnessCodex: "/x", handoff.HarnessOpenCode: "/o", handoff.HarnessCline: "/l"}
+ if !reflect.DeepEqual(*seen, want) {
t.Fatalf("store dirs = %+v, want %+v", *seen, want)
}
}
+func TestHandoffStoreDirFlag(t *testing.T) {
+ seen := stubHandoffSources(t)
+ // --store-dir takes any name the runtime answers to; a per-runtime flag wins for its runtime.
+ if _, _, err := runHandoff(t, "list", "--store-dir", "claude-code=/generic", "--store-dir", "codex=/x=y", "--claude-projects-dir", "/c"); err != nil {
+ t.Fatal(err)
+ }
+ want := handoff.StoreDirs{handoff.HarnessClaude: "/c", handoff.HarnessCodex: "/x=y"}
+ if !reflect.DeepEqual(*seen, want) {
+ t.Fatalf("store dirs = %+v, want %+v", *seen, want)
+ }
+ for _, bad := range []string{"claude", "=/x", "claude=", "no-such-runtime=/x"} {
+ if _, _, err := runHandoff(t, "list", "--store-dir", bad); err == nil || !strings.Contains(err.Error(), "--store-dir") {
+ t.Fatalf("--store-dir %q: err = %v", bad, err)
+ }
+ }
+ if _, _, err := runHandoff(t, "export", "claude-1", "--store-dir", "bogus"); err == nil || !strings.Contains(err.Error(), "--store-dir") {
+ t.Fatalf("export with a bad --store-dir: err = %v", err)
+ }
+}
+
func TestHandoffAge(t *testing.T) {
now := time.Date(2026, 9, 25, 12, 0, 0, 0, time.UTC)
for _, tc := range []struct {
diff --git a/cli/beacon/internal/handoff/brief.go b/cli/beacon/internal/handoff/brief.go
index fda1a3d7..900ab0f3 100644
--- a/cli/beacon/internal/handoff/brief.go
+++ b/cli/beacon/internal/handoff/brief.go
@@ -249,21 +249,6 @@ func contains(values []string, value string) bool {
return false
}
-// RuntimeLabel is how a brief names a runtime to a reader.
-func RuntimeLabel(harness string) string {
- switch harness {
- case HarnessClaude:
- return "Claude Code"
- case HarnessCodex:
- return "Codex CLI"
- case HarnessOpenCode:
- return "OpenCode"
- case HarnessCline:
- return "Cline"
- }
- return harness
-}
-
// Render writes the brief as Markdown no larger than BriefMaxBytes, dropping the oldest
// recent-activity entries first when it would be larger.
func (b Brief) Render() string {
diff --git a/cli/beacon/internal/handoff/claude_test.go b/cli/beacon/internal/handoff/claude_test.go
index d465aa97..18cb639e 100644
--- a/cli/beacon/internal/handoff/claude_test.go
+++ b/cli/beacon/internal/handoff/claude_test.go
@@ -44,11 +44,11 @@ func TestClaudeSessionWithoutIndexUsesTheTranscriptCWD(t *testing.T) {
func TestClaudeIndexProjectPathWinsOverTheTranscript(t *testing.T) {
f := newStoreFixture(t)
- path := filepath.Join(f.dirs.ClaudeProjects, "-work-api", "claude-sess-1.jsonl")
+ path := filepath.Join(f.dirs[HarnessClaude], "-work-api", "claude-sess-1.jsonl")
// The index says /work/api; a transcript cwd of a subdirectory the agent moved into must not
// override it.
writeFixture(t, path, claudeLine(t, map[string]interface{}{"type": "user", "cwd": "/work/api/cmd", "message": map[string]interface{}{"role": "user", "content": "hi"}}))
- sessions, err := (&claudeSource{dir: f.dirs.ClaudeProjects}).List()
+ sessions, err := (&claudeSource{dir: f.dirs[HarnessClaude]}).List()
if err != nil {
t.Fatal(err)
}
diff --git a/cli/beacon/internal/handoff/fixtures_test.go b/cli/beacon/internal/handoff/fixtures_test.go
index dacf1edc..ab743558 100644
--- a/cli/beacon/internal/handoff/fixtures_test.go
+++ b/cli/beacon/internal/handoff/fixtures_test.go
@@ -33,10 +33,10 @@ func newStoreFixture(t *testing.T) storeFixture {
f := storeFixture{
root: root,
dirs: StoreDirs{
- ClaudeProjects: filepath.Join(root, ".claude", "projects"),
- Codex: filepath.Join(root, ".codex"),
- OpenCode: filepath.Join(root, "opencode"),
- Cline: filepath.Join(root, ".cline"),
+ HarnessClaude: filepath.Join(root, ".claude", "projects"),
+ HarnessCodex: filepath.Join(root, ".codex"),
+ HarnessOpenCode: filepath.Join(root, "opencode"),
+ HarnessCline: filepath.Join(root, ".cline"),
},
}
f.writeClaude(t)
@@ -48,7 +48,7 @@ func newStoreFixture(t *testing.T) storeFixture {
func (f storeFixture) writeClaude(t *testing.T) {
t.Helper()
- project := filepath.Join(f.dirs.ClaudeProjects, "-work-api")
+ project := filepath.Join(f.dirs[HarnessClaude], "-work-api")
main := filepath.Join(project, "claude-sess-1.jsonl")
writeFixture(t, main, jsonLine(t, map[string]interface{}{
"type": "user", "uuid": "u1", "sessionId": "claude-sess-1", "cwd": "/work/api", "gitBranch": "feat/health",
@@ -75,8 +75,8 @@ func (f storeFixture) writeClaude(t *testing.T) {
func (f storeFixture) writeCodex(t *testing.T) {
t.Helper()
// A thread with two rollout files, both carrying the thread id.
- older := filepath.Join(f.dirs.Codex, "sessions", "2026", "09", "20", "rollout-2026-09-20T09-00-00-codex-thread-1.jsonl")
- newer := filepath.Join(f.dirs.Codex, "sessions", "2026", "09", "21", "rollout-2026-09-21T09-00-00-codex-thread-1.jsonl")
+ older := filepath.Join(f.dirs[HarnessCodex], "sessions", "2026", "09", "20", "rollout-2026-09-20T09-00-00-codex-thread-1.jsonl")
+ newer := filepath.Join(f.dirs[HarnessCodex], "sessions", "2026", "09", "21", "rollout-2026-09-21T09-00-00-codex-thread-1.jsonl")
for _, path := range []string{older, newer} {
writeFixture(t, path, jsonLine(t, map[string]interface{}{
"timestamp": "2026-09-21T09:00:00.000Z", "type": "session_meta",
@@ -85,17 +85,17 @@ func (f storeFixture) writeCodex(t *testing.T) {
}
setModTime(t, older, codexUpdated.Add(-24*time.Hour))
setModTime(t, newer, codexUpdated)
- writeFixture(t, filepath.Join(f.dirs.Codex, "session_index.jsonl"), jsonLine(t, map[string]interface{}{
+ writeFixture(t, filepath.Join(f.dirs[HarnessCodex], "session_index.jsonl"), jsonLine(t, map[string]interface{}{
"id": "codex-thread-1", "thread_name": "Fix the login form",
}))
}
func (f storeFixture) writeOpenCode(t *testing.T) {
t.Helper()
- if err := os.MkdirAll(f.dirs.OpenCode, 0o755); err != nil {
+ if err := os.MkdirAll(f.dirs[HarnessOpenCode], 0o755); err != nil {
t.Fatal(err)
}
- db, err := sql.Open("sqlite", filepath.Join(f.dirs.OpenCode, "opencode.db"))
+ db, err := sql.Open("sqlite", filepath.Join(f.dirs[HarnessOpenCode], "opencode.db"))
if err != nil {
t.Fatal(err)
}
@@ -120,7 +120,7 @@ func (f storeFixture) writeOpenCode(t *testing.T) {
func (f storeFixture) writeCline(t *testing.T) {
t.Helper()
- sessionDir := filepath.Join(f.dirs.Cline, "data", "sessions", "cline-task-1")
+ sessionDir := filepath.Join(f.dirs[HarnessCline], "data", "sessions", "cline-task-1")
writeFixture(t, filepath.Join(sessionDir, "cline-task-1.json"), mustJSON(t, map[string]interface{}{
"task": "Write the release notes", "workspacePath": "/work/docs",
}))
@@ -131,7 +131,7 @@ func (f storeFixture) writeCline(t *testing.T) {
setModTime(t, messages, clineUpdated)
// The same task id in the older task history must not list twice.
- history := filepath.Join(f.dirs.Cline, "data", "tasks", "cline-task-1", "api_conversation_history.json")
+ history := filepath.Join(f.dirs[HarnessCline], "data", "tasks", "cline-task-1", "api_conversation_history.json")
writeFixture(t, history, mustJSON(t, []interface{}{
map[string]interface{}{"role": "user", "content": "Write the release notes", "ts": clineUpdated.Add(time.Hour).UnixMilli()},
}))
@@ -172,7 +172,7 @@ func jsonLine(t *testing.T, value interface{}) string {
// second turn in the thread's newer Codex rollout file.
func (f storeFixture) writeTranscripts(t *testing.T) {
t.Helper()
- claudeMain := filepath.Join(f.dirs.ClaudeProjects, "-work-api", "claude-sess-1.jsonl")
+ claudeMain := filepath.Join(f.dirs[HarnessClaude], "-work-api", "claude-sess-1.jsonl")
writeFixture(t, claudeMain, jsonLine(t, map[string]interface{}{
"type": "user", "uuid": "u1", "sessionId": "claude-sess-1", "cwd": "/work/api", "timestamp": "2026-09-23T08:59:00.000Z",
"message": map[string]interface{}{"role": "user", "content": "add a health endpoint"},
@@ -196,14 +196,14 @@ func (f storeFixture) writeTranscripts(t *testing.T) {
"payload": map[string]interface{}{"type": "message", "role": "assistant", "content": []interface{}{map[string]interface{}{"type": "output_text", "text": reply}}},
})
}
- older := filepath.Join(f.dirs.Codex, "sessions", "2026", "09", "20", "rollout-2026-09-20T09-00-00-codex-thread-1.jsonl")
- newer := filepath.Join(f.dirs.Codex, "sessions", "2026", "09", "21", "rollout-2026-09-21T09-00-00-codex-thread-1.jsonl")
+ older := filepath.Join(f.dirs[HarnessCodex], "sessions", "2026", "09", "20", "rollout-2026-09-20T09-00-00-codex-thread-1.jsonl")
+ newer := filepath.Join(f.dirs[HarnessCodex], "sessions", "2026", "09", "21", "rollout-2026-09-21T09-00-00-codex-thread-1.jsonl")
writeFixture(t, older, codexTurn("fix the login form", "Working on it."))
writeFixture(t, newer, codexTurn("also check the signup form", "The form validates now."))
setModTime(t, older, codexUpdated.Add(-24*time.Hour))
setModTime(t, newer, codexUpdated)
- db, err := sql.Open("sqlite", filepath.Join(f.dirs.OpenCode, "opencode.db"))
+ db, err := sql.Open("sqlite", filepath.Join(f.dirs[HarnessOpenCode], "opencode.db"))
if err != nil {
t.Fatal(err)
}
@@ -225,7 +225,7 @@ func (f storeFixture) writeTranscripts(t *testing.T) {
}
}
- messages := filepath.Join(f.dirs.Cline, "data", "sessions", "cline-task-1", "cline-task-1.messages.json")
+ messages := filepath.Join(f.dirs[HarnessCline], "data", "sessions", "cline-task-1", "cline-task-1.messages.json")
writeFixture(t, messages, mustJSON(t, map[string]interface{}{"messages": []interface{}{
map[string]interface{}{"role": "user", "content": "Write the release notes", "ts": clineUpdated.Add(-time.Minute).UnixMilli()},
map[string]interface{}{"role": "assistant", "content": []interface{}{map[string]interface{}{"type": "text", "text": "Release notes drafted."}}, "ts": clineUpdated.UnixMilli()},
diff --git a/cli/beacon/internal/handoff/link_test.go b/cli/beacon/internal/handoff/link_test.go
index 9a28469b..6c210183 100644
--- a/cli/beacon/internal/handoff/link_test.go
+++ b/cli/beacon/internal/handoff/link_test.go
@@ -15,14 +15,14 @@ import (
// writes for a new session continuing a Claude Code session.
func (f storeFixture) writeHandoffPrompts(t *testing.T, prompt string) {
t.Helper()
- claudeMain := filepath.Join(f.dirs.ClaudeProjects, "-work-api", "claude-sess-1.jsonl")
+ claudeMain := filepath.Join(f.dirs[HarnessClaude], "-work-api", "claude-sess-1.jsonl")
writeFixture(t, claudeMain, jsonLine(t, map[string]interface{}{
"type": "user", "uuid": "u1", "sessionId": "claude-sess-1", "cwd": "/work/api", "timestamp": "2026-09-23T08:59:00.000Z",
"message": map[string]interface{}{"role": "user", "content": prompt},
}))
setModTime(t, claudeMain, claudeUpdated)
- newer := filepath.Join(f.dirs.Codex, "sessions", "2026", "09", "21", "rollout-2026-09-21T09-00-00-codex-thread-1.jsonl")
+ newer := filepath.Join(f.dirs[HarnessCodex], "sessions", "2026", "09", "21", "rollout-2026-09-21T09-00-00-codex-thread-1.jsonl")
writeFixture(t, newer, jsonLine(t, map[string]interface{}{
"timestamp": "2026-09-21T09:00:00.000Z", "type": "session_meta",
"payload": map[string]interface{}{"id": "codex-thread-1", "session_id": "codex-thread-1", "cwd": "/work/web"},
@@ -32,7 +32,7 @@ func (f storeFixture) writeHandoffPrompts(t *testing.T, prompt string) {
}))
setModTime(t, newer, codexUpdated)
- db, err := sql.Open("sqlite", filepath.Join(f.dirs.OpenCode, "opencode.db"))
+ db, err := sql.Open("sqlite", filepath.Join(f.dirs[HarnessOpenCode], "opencode.db"))
if err != nil {
t.Fatal(err)
}
@@ -49,7 +49,7 @@ func (f storeFixture) writeHandoffPrompts(t *testing.T, prompt string) {
t.Fatal(err)
}
- messages := filepath.Join(f.dirs.Cline, "data", "sessions", "cline-task-1", "cline-task-1.messages.json")
+ messages := filepath.Join(f.dirs[HarnessCline], "data", "sessions", "cline-task-1", "cline-task-1.messages.json")
writeFixture(t, messages, mustJSON(t, map[string]interface{}{"messages": []interface{}{
map[string]interface{}{"role": "user", "content": prompt, "ts": clineUpdated.UnixMilli()},
}}))
diff --git a/cli/beacon/internal/handoff/resume.go b/cli/beacon/internal/handoff/resume.go
index 918a30be..81e40d36 100644
--- a/cli/beacon/internal/handoff/resume.go
+++ b/cli/beacon/internal/handoff/resume.go
@@ -7,7 +7,6 @@ import (
"path/filepath"
"strings"
- "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/clinesession"
"github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"
)
@@ -28,59 +27,6 @@ const (
ReasonFromRuntimeLog = "runtime_log_only"
)
-// runtimeCommand is how Beacon starts one runtime's CLI. Every argument vector was checked against
-// that CLI's own --help.
-type runtimeCommand struct {
- Executable string
- // Resume returns the arguments that reopen session, or ok=false when this runtime's CLI cannot
- // reopen it.
- Resume func(session Session) (args []string, ok bool)
- // NewSession returns the arguments that start an interactive session with prompt as its first
- // message.
- NewSession func(prompt string) []string
-}
-
-var runtimeCommands = map[string]runtimeCommand{
- HarnessClaude: {
- Executable: "claude",
- Resume: func(s Session) ([]string, bool) {
- // A subagent transcript is a sidechain of its parent; `claude --resume` reopens
- // top-level sessions only.
- if s.Subagent {
- return nil, false
- }
- return []string{"--resume", s.ID}, true
- },
- NewSession: func(prompt string) []string { return []string{prompt} },
- },
- HarnessCodex: {
- Executable: "codex",
- Resume: func(s Session) ([]string, bool) { return []string{"resume", s.ID}, true },
- NewSession: func(prompt string) []string { return []string{prompt} },
- },
- HarnessOpenCode: {
- Executable: "opencode",
- Resume: func(s Session) ([]string, bool) { return []string{"--session", s.ID}, true },
- NewSession: func(prompt string) []string { return []string{"--prompt", prompt} },
- },
- HarnessCline: {
- // Cline approves every tool call unless told otherwise. A session Beacon starts never
- // gains that on Beacon's say-so; the user can still turn it on inside the TUI.
- Executable: "cline",
- Resume: func(s Session) ([]string, bool) {
- // `cline --id` reopens CLI sessions; the older task history and subagent threads are
- // not sessions it can load.
- if s.Store != clinesession.SourceMessages || s.Subagent {
- return nil, false
- }
- return []string{"--tui", "--auto-approve", "false", "--id", s.ID}, true
- },
- NewSession: func(prompt string) []string {
- return []string{"--tui", "--auto-approve", "false", prompt}
- },
- },
-}
-
// Plan is a resolved resume: what will run, where, and why.
type Plan struct {
Mode string `json:"mode"`
@@ -122,9 +68,9 @@ func PlanResume(session Session, opts PlanOptions) (Plan, error) {
if opts.Target != "" {
target = opts.Target
}
- targetCommand, ok := runtimeCommands[target]
+ targetCommand, ok := commandFor(target)
if !ok {
- return Plan{}, fmt.Errorf("%s sessions cannot be started by beacon handoff (supported: claude, codex, opencode, cline)", target)
+ return Plan{}, fmt.Errorf("%s sessions cannot be started by beacon handoff (supported: %s)", target, strings.Join(StartableNames(), ", "))
}
dir, err := resumeDir(session, opts.Dir)
if err != nil {
@@ -151,11 +97,14 @@ func PlanResume(session Session, opts PlanOptions) (Plan, error) {
}
plan.Mode, plan.Reason = ModeNewSession, reason
plan.BriefPath = opts.BriefPath
+ if targetCommand.NewSession == nil {
+ return Plan{}, fmt.Errorf("%s cannot start a new session from a brief (%s)", RuntimeLabel(target), ReasonText(reason))
+ }
plan.Args = targetCommand.NewSession(NewSessionPrompt(session, opts.BriefPath))
return plan, nil
}
-func nativeArgs(command runtimeCommand, session Session) []string {
+func nativeArgs(command *runtimeCommand, session Session) []string {
args, _ := command.Resume(session)
return args
}
@@ -170,7 +119,11 @@ func nativeBlocker(session Session, target string, opts PlanOptions) string {
case opts.FromRuntimeLog:
return ReasonFromRuntimeLog
}
- if _, ok := runtimeCommands[target].Resume(session); !ok {
+ command, _ := commandFor(target)
+ if command.Resume == nil {
+ return ReasonNotResumable
+ }
+ if _, ok := command.Resume(session); !ok {
return ReasonNotResumable
}
if session.SourcePath == "" {
@@ -231,3 +184,14 @@ func ReasonText(reason string) string {
}
return reason
}
+
+// StartableNames names the runtimes Beacon can start, for messages.
+func StartableNames() []string {
+ var names []string
+ for i, r := range runtimes {
+ if r.Command != nil {
+ names = append(names, RuntimeNames()[i])
+ }
+ }
+ return names
+}
diff --git a/cli/beacon/internal/handoff/resume_test.go b/cli/beacon/internal/handoff/resume_test.go
index 95993d9e..17fdbb09 100644
--- a/cli/beacon/internal/handoff/resume_test.go
+++ b/cli/beacon/internal/handoff/resume_test.go
@@ -183,7 +183,7 @@ func TestPlanResumeClineOnlyReopensCLISessions(t *testing.T) {
// Every command Beacon builds for Cline must turn auto-approve off, because Cline defaults to
// approving every tool call.
func TestEveryClineCommandTurnsAutoApproveOff(t *testing.T) {
- command := runtimeCommands[HarnessCline]
+ command, _ := commandFor(HarnessCline)
resume, _ := command.Resume(Session{ID: "x", Store: "messages"})
for _, args := range [][]string{resume, command.NewSession("p")} {
joined := strings.Join(args, " ")
diff --git a/cli/beacon/internal/handoff/runtimes.go b/cli/beacon/internal/handoff/runtimes.go
new file mode 100644
index 00000000..46a42f50
--- /dev/null
+++ b/cli/beacon/internal/handoff/runtimes.go
@@ -0,0 +1,204 @@
+package handoff
+
+import (
+ "fmt"
+ "strings"
+
+ "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/opencodesession"
+ "github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"
+)
+
+// Runtime is everything handoff knows about one agent runtime. Adding a runtime is adding one entry
+// to runtimes: how to name it, where its sessions are stored, and how to start its CLI.
+type Runtime struct {
+ // Harness is the name the endpoint event schema uses.
+ Harness string
+ // Label names the runtime to a person.
+ Label string
+ // Aliases are the extra names --harness and --agent accept, besides Harness itself.
+ Aliases []string
+ // NewSource builds the runtime's session source, reading its store from dir, or from the
+ // runtime's default location when dir is empty. nil when Beacon reads no local store for the
+ // runtime; its sessions can then still be exported from the runtime log.
+ NewSource func(dir string) Source
+ // Command starts the runtime's CLI. nil when Beacon cannot start the runtime.
+ Command *runtimeCommand
+}
+
+// runtimeCommand is how Beacon starts one runtime's CLI. Every argument vector is checked against
+// that CLI's own --help.
+type runtimeCommand struct {
+ Executable string
+ // Resume returns the arguments that reopen session, or ok=false when this runtime's CLI cannot
+ // reopen it. nil when the CLI has no way to reopen a session by id.
+ Resume func(session Session) (args []string, ok bool)
+ // NewSession returns the arguments that start an interactive session with prompt as its first
+ // message.
+ NewSession func(prompt string) []string
+}
+
+// Harness names, as the endpoint event schema spells them.
+const (
+ HarnessClaude = claudesession.Harness
+ HarnessCodex = codexsession.Harness
+ HarnessOpenCode = opencodesession.Harness
+ HarnessCline = clinesession.Harness
+)
+
+// runtimes lists every runtime handoff supports, in display order.
+var runtimes = []Runtime{
+ {
+ Harness: HarnessClaude,
+ Label: "Claude Code",
+ Aliases: []string{"claude", "claude-code"},
+ NewSource: func(dir string) Source { return &claudeSource{dir: dir} },
+ Command: &runtimeCommand{
+ Executable: "claude",
+ Resume: func(s Session) ([]string, bool) {
+ // A subagent transcript is a sidechain of its parent; `claude --resume` reopens
+ // top-level sessions only.
+ if s.Subagent {
+ return nil, false
+ }
+ return []string{"--resume", s.ID}, true
+ },
+ NewSession: func(prompt string) []string { return []string{prompt} },
+ },
+ },
+ {
+ Harness: HarnessCodex,
+ Label: "Codex CLI",
+ Aliases: []string{"codex", "codex-cli"},
+ NewSource: func(dir string) Source { return &codexSource{dir: dir} },
+ Command: &runtimeCommand{
+ Executable: "codex",
+ Resume: func(s Session) ([]string, bool) { return []string{"resume", s.ID}, true },
+ NewSession: func(prompt string) []string { return []string{prompt} },
+ },
+ },
+ {
+ Harness: HarnessOpenCode,
+ Label: "OpenCode",
+ NewSource: func(dir string) Source { return &openCodeSource{dir: dir} },
+ Command: &runtimeCommand{
+ Executable: "opencode",
+ Resume: func(s Session) ([]string, bool) { return []string{"--session", s.ID}, true },
+ NewSession: func(prompt string) []string { return []string{"--prompt", prompt} },
+ },
+ },
+ {
+ Harness: HarnessCline,
+ Label: "Cline",
+ NewSource: func(dir string) Source { return &clineSource{dir: dir} },
+ // Cline approves every tool call unless told otherwise. A session Beacon starts never gains
+ // that on Beacon's say-so; the user can still turn it on inside the TUI.
+ Command: &runtimeCommand{
+ Executable: "cline",
+ Resume: func(s Session) ([]string, bool) {
+ // `cline --id` reopens CLI sessions; the older task history and subagent threads are
+ // not sessions it can load.
+ if s.Store != clinesession.SourceMessages || s.Subagent {
+ return nil, false
+ }
+ return []string{"--tui", "--auto-approve", "false", "--id", s.ID}, true
+ },
+ NewSession: func(prompt string) []string {
+ return []string{"--tui", "--auto-approve", "false", prompt}
+ },
+ },
+ },
+}
+
+// Harnesses lists the runtimes handoff supports, in display order.
+var Harnesses = func() []string {
+ names := make([]string, 0, len(runtimes))
+ for _, r := range runtimes {
+ names = append(names, r.Harness)
+ }
+ return names
+}()
+
+// LookupRuntime returns the registry entry for harness.
+func LookupRuntime(harness string) (Runtime, bool) {
+ for _, r := range runtimes {
+ if r.Harness == harness {
+ return r, true
+ }
+ }
+ return Runtime{}, false
+}
+
+// ParseHarness resolves a user-supplied runtime name to its harness name. An empty name stays
+// empty, meaning every runtime. A name the event schema normalises to a supported harness is
+// accepted too.
+func ParseHarness(name string) (string, error) {
+ name = strings.ToLower(strings.TrimSpace(name))
+ if name == "" {
+ return "", nil
+ }
+ for _, r := range runtimes {
+ if name == r.Harness {
+ return r.Harness, nil
+ }
+ for _, alias := range r.Aliases {
+ if name == alias {
+ return r.Harness, nil
+ }
+ }
+ }
+ if normalized := asymptoteobserve.NormalizeHarnessName(name); normalized != "" {
+ if _, ok := LookupRuntime(normalized); ok {
+ return normalized, nil
+ }
+ }
+ return "", fmt.Errorf("unsupported runtime %q (supported: %s)", name, strings.Join(RuntimeNames(), ", "))
+}
+
+// RuntimeNames is the shortest name each runtime answers to, for messages.
+func RuntimeNames() []string {
+ names := make([]string, 0, len(runtimes))
+ for _, r := range runtimes {
+ name := r.Harness
+ for _, alias := range r.Aliases {
+ if len(alias) < len(name) {
+ name = alias
+ }
+ }
+ names = append(names, name)
+ }
+ return names
+}
+
+// RuntimeLabel is how a brief names a runtime to a reader.
+func RuntimeLabel(harness string) string {
+ if r, ok := LookupRuntime(harness); ok {
+ return r.Label
+ }
+ return harness
+}
+
+// StoreDirs overrides where runtimes' session stores are read from, keyed by harness. A runtime
+// with no entry reads its store from its default location.
+type StoreDirs map[string]string
+
+// DefaultSources returns a source for every runtime whose store Beacon reads.
+func DefaultSources(dirs StoreDirs) []Source {
+ var sources []Source
+ for _, r := range runtimes {
+ if r.NewSource != nil {
+ sources = append(sources, r.NewSource(dirs[r.Harness]))
+ }
+ }
+ return sources
+}
+
+func commandFor(harness string) (*runtimeCommand, bool) {
+ r, ok := LookupRuntime(harness)
+ if !ok || r.Command == nil {
+ return nil, false
+ }
+ return r.Command, true
+}
diff --git a/cli/beacon/internal/handoff/session_test.go b/cli/beacon/internal/handoff/session_test.go
index 34339d88..7036bb01 100644
--- a/cli/beacon/internal/handoff/session_test.go
+++ b/cli/beacon/internal/handoff/session_test.go
@@ -62,7 +62,7 @@ func TestListCarriesEachRuntimesMetadata(t *testing.T) {
if !claude.UpdatedAt.Equal(claudeUpdated) {
t.Fatalf("claude updated = %s, want %s", claude.UpdatedAt, claudeUpdated)
}
- if claude.SourcePath != filepath.Join(f.dirs.ClaudeProjects, "-work-api", "claude-sess-1.jsonl") {
+ if claude.SourcePath != filepath.Join(f.dirs[HarnessClaude], "-work-api", "claude-sess-1.jsonl") {
t.Fatalf("claude source = %q", claude.SourcePath)
}
@@ -144,10 +144,10 @@ func TestListToleratesMissingStores(t *testing.T) {
testenv.SetHome(t, t.TempDir())
empty := t.TempDir()
sources := DefaultSources(StoreDirs{
- ClaudeProjects: filepath.Join(empty, "claude"),
- Codex: filepath.Join(empty, "codex"),
- OpenCode: filepath.Join(empty, "opencode"),
- Cline: filepath.Join(empty, "cline"),
+ HarnessClaude: filepath.Join(empty, "claude"),
+ HarnessCodex: filepath.Join(empty, "codex"),
+ HarnessOpenCode: filepath.Join(empty, "opencode"),
+ HarnessCline: filepath.Join(empty, "cline"),
})
sessions, err := List(sources, Filter{})
if err != nil || len(sessions) != 0 {
diff --git a/cli/beacon/internal/handoff/sources.go b/cli/beacon/internal/handoff/sources.go
index 7207598a..d26990d8 100644
--- a/cli/beacon/internal/handoff/sources.go
+++ b/cli/beacon/internal/handoff/sources.go
@@ -1,7 +1,6 @@
package handoff
import (
- "fmt"
"sort"
"strings"
"time"
@@ -12,60 +11,6 @@ import (
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/opencodesession"
)
-// Harness names, as the endpoint event schema spells them.
-const (
- HarnessClaude = claudesession.Harness
- HarnessCodex = codexsession.Harness
- HarnessOpenCode = opencodesession.Harness
- HarnessCline = clinesession.Harness
-)
-
-// Harnesses lists the runtimes handoff supports, in display order.
-var Harnesses = []string{HarnessClaude, HarnessCodex, HarnessOpenCode, HarnessCline}
-
-var harnessAliases = map[string]string{
- "claude": HarnessClaude,
- "claude-code": HarnessClaude,
- "claude_code": HarnessClaude,
- "codex": HarnessCodex,
- "codex-cli": HarnessCodex,
- "codex_cli": HarnessCodex,
- "opencode": HarnessOpenCode,
- "cline": HarnessCline,
-}
-
-// ParseHarness resolves a user-supplied runtime name to its harness name. An empty name stays
-// empty, meaning every runtime.
-func ParseHarness(name string) (string, error) {
- name = strings.ToLower(strings.TrimSpace(name))
- if name == "" {
- return "", nil
- }
- if harness, ok := harnessAliases[name]; ok {
- return harness, nil
- }
- return "", fmt.Errorf("unsupported runtime %q (supported: claude, codex, opencode, cline)", name)
-}
-
-// StoreDirs overrides where each runtime's session store is read from. An empty field means the
-// runtime's default location.
-type StoreDirs struct {
- ClaudeProjects string
- Codex string
- OpenCode string
- Cline string
-}
-
-// DefaultSources returns a source for every supported runtime.
-func DefaultSources(dirs StoreDirs) []Source {
- return []Source{
- &claudeSource{dir: dirs.ClaudeProjects},
- &codexSource{dir: dirs.Codex},
- &openCodeSource{dir: dirs.OpenCode},
- &clineSource{dir: dirs.Cline},
- }
-}
-
func unixMS(ms int64) time.Time {
if ms <= 0 {
return time.Time{}
diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdx
index 2abe676d..a4da50a8 100644
--- a/docs/cli/handoff.mdx
+++ b/docs/cli/handoff.mdx
@@ -45,7 +45,8 @@ beacon handoff list --json
| `--subagents` | Include subagent sessions. They are hidden by default, because resuming one resumes a fragment of its parent's task. |
| `--limit` | Maximum sessions to list. Default `25`; `0` lists all. |
| `--json` | Print `{"sessions": [...], "warnings": [...]}`. |
-| `--claude-projects-dir`, `--codex-dir`, `--opencode-dir`, `--cline-dir` | Read a runtime's store from a non-default location. |
+| `--store-dir <runtime>=<path>` | Read a runtime's store from a non-default location. Repeatable. |
+| `--claude-projects-dir`, `--codex-dir`, `--opencode-dir`, `--cline-dir` | The same for one runtime; each wins over `--store-dir` for its runtime. |
A store that cannot be read is reported as a warning (on stderr, or under `warnings` in JSON), and the sessions from the other runtimes are still listed.
@@ -80,7 +81,7 @@ Briefs are written to `~/.beacon/endpoint/handoffs`. The directory is `0700` and
| `--output-dir` | Directory to write the brief into. |
| `--log-path` | Runtime log to fall back to. Defaults to the local runtime log. |
| `--json` | Print `{"path", "from", "session"}`. `from` is `session_store` or `runtime_log`. |
-| `--harness` and the `--*-dir` flags | As for `list`. |
+| `--harness`, `--store-dir` and the `--*-dir` flags | As for `list`. |
## `beacon handoff resume`
@@ -129,7 +130,7 @@ The runtime runs in this terminal, in the session's recorded directory. If that
| `--print` | Show the plan and command without writing a brief or launching anything. |
| `--json` | With `--print`, describe the plan as JSON (`mode`, `reason`, `target`, `executable`, `args`, `dir`, `brief_path`). |
| `--yes` | Launch without asking. |
-| `--output-dir`, `--log-path`, `--harness`, and the `--*-dir` flags | As for `export`. |
+| `--output-dir`, `--log-path`, `--harness`, `--store-dir`, and the `--*-dir` flags | As for `export`. |
## Linking a new session to the one it continues