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
beacon-hooks: link handoffs from every prompt path
Claudede14846140c3
diff --git a/cli/beacon-hooks/cmd/handoff_link_test.go b/cli/beacon-hooks/cmd/handoff_link_test.goindex 58caa337..afee9183 100644--- a/cli/beacon-hooks/cmd/handoff_link_test.go+++ b/cli/beacon-hooks/cmd/handoff_link_test.go@@ -1,6 +1,8 @@package cmdimport (+ "encoding/json"+ "os""path/filepath""testing"@@ -133,3 +135,90 @@ func TestOpenCodePromptRecordsAHandoffLink(t *testing.T) {t.Fatalf("a prompt without a marker yields only the prompt event, got %+v", plain)}}++// assertLinkedEvents checks a mapper's output for a marker prompt: the prompt event, then the link,+// with the prompt event's own fields left intact.+func assertLinkedEvents(t *testing.T, events []normalizedEvent) {+ t.Helper()+ if len(events) != 2 || events[0].action != "prompt.submitted" || events[1].action != "session.handoff" {+ t.Fatalf("events = %+v, want prompt.submitted then session.handoff", events)+ }+ handoff, _ := events[1].fields["handoff"].(map[string]interface{})+ if handoff["source_harness"] != "claude_code" || handoff["source_session_id"] != "src-session-1" {+ t.Fatalf("handoff = %#v", events[1].fields["handoff"])+ }+ if _, ok := events[1].fields["prompt"]; ok {+ t.Fatal("the link must not repeat the prompt")+ }+ if _, ok := events[0].fields["prompt"]; !ok {+ t.Fatal("building the link must not strip the prompt event's own fields")+ }+}++func TestPiFamilyPromptRecordsAHandoffLink(t *testing.T) {+ for _, runtime := range []piFamily{piRuntime, ompRuntime, primeRuntime, omoRuntime} {+ t.Run(runtime.platform, func(t *testing.T) {+ events := runtime.endpointEvents(map[string]interface{}{+ "type": "input", "text": handoffTestPrompt, "sessionId": "pi-new-1",+ }, "pi-new-1")+ assertLinkedEvents(t, events)+ plain := runtime.endpointEvents(map[string]interface{}{"type": "input", "text": "hello"}, "pi-new-1")+ if len(plain) != 1 {+ t.Fatalf("a prompt without a marker yields only the prompt event, got %+v", plain)+ }+ })+ }++ // End to end through the hook, so the link carries the runtime's harness and session.+ logPath := piTestLog(t)+ runHookWithInput(t, runPiEvent, map[string]interface{}{+ "type": "input", "text": handoffTestPrompt, "sessionId": "pi-new-1", "cwd": "/repo",+ })+ links := eventsWithAction(t, logPath, "session.handoff")+ if len(links) != 1 {+ t.Fatalf("actions = %v, want one session.handoff", piEventActions(t, logPath))+ }+ assertHandoffLink(t, links[0], "pi-new-1", "pi_cli")+}++func TestOpenClawPromptRecordsAHandoffLink(t *testing.T) {+ assertLinkedEvents(t, openClawEvents(t, "message_received", map[string]interface{}{+ "content": handoffTestPrompt, "from": "U42",+ }, nil))+ if got := openClawEvents(t, "message_received", map[string]interface{}{"content": "deploy staging"}, nil); len(got) != 1 {+ t.Fatalf("a prompt without a marker yields only the prompt event, got %+v", got)+ }+}++// Antigravity's prompt hook does not always fire; pre-tool then recovers the prompt from the+// transcript, and that recovered prompt must link too.+func TestAntigravityTranscriptPromptRecordsAHandoffLink(t *testing.T) {+ setupHookConfigDirs(t)+ platformFlag = "antigravity"+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)+ transcriptPath := filepath.Join(t.TempDir(), "transcript.jsonl")+ line, err := json.Marshal(map[string]interface{}{+ "source": "USER_EXPLICIT", "type": "USER_INPUT",+ "content": "<USER_REQUEST>\n" + handoffTestPrompt + "\n</USER_REQUEST>",+ })+ if err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(transcriptPath, append(line, '\n'), 0o600); err != nil {+ t.Fatal(err)+ }+ input := map[string]interface{}{+ "conversationId": "ag-new-1",+ "transcriptPath": transcriptPath,+ "toolCall": map[string]interface{}{"name": "list_dir", "args": map[string]interface{}{}},+ }+ runHookWithInput(t, runPreTool, input)+ runHookWithInput(t, runPreTool, input)++ links := eventsWithAction(t, logPath, "session.handoff")+ if len(links) != 1 {+ t.Fatalf("session.handoff events = %d, want 1 however many tools run", len(links))+ }+ assertHandoffLink(t, links[0], "ag-new-1", "antigravity_cli")+}diff --git a/cli/beacon-hooks/cmd/openclaw_event.go b/cli/beacon-hooks/cmd/openclaw_event.goindex d8c95cee..d5efc0ff 100644--- a/cli/beacon-hooks/cmd/openclaw_event.go+++ b/cli/beacon-hooks/cmd/openclaw_event.go@@ -357,10 +357,14 @@ func openClawPromptEvents(input, event, fields map[string]interface{}) []normaliif len(extra) > 0 {fields["raw"] = mergeNested(fields["raw"], extra)}- return []normalizedEvent{{+ events := []normalizedEvent{{action: "prompt.submitted", category: "prompt", severity: "info",message: "Prompt submitted to OpenClaw", fields: fields,}}+ if link, ok := handoffLinkEvent(fields, prompt); ok {+ events = append(events, link)+ }+ return events}// openClawLlmOutputEvents records what a finished model response reports: its token usage, and thediff --git a/cli/beacon-hooks/cmd/pi_family.go b/cli/beacon-hooks/cmd/pi_family.goindex 707a4f89..fabf94ff 100644--- a/cli/beacon-hooks/cmd/pi_family.go+++ b/cli/beacon-hooks/cmd/pi_family.go@@ -108,7 +108,11 @@ func (f piFamily) endpointEvents(input map[string]interface{}, sessionID string)if prompt == "" {return nil}- return []normalizedEvent{f.promptEvent(fields, prompt, getFirstStr(input, "source"))}+ events := []normalizedEvent{f.promptEvent(fields, prompt, getFirstStr(input, "source"))}+ if link, ok := handoffLinkEvent(fields, prompt); ok {+ events = append(events, link)+ }+ return eventscase "tool_call":// The pre-execution half of a tool call: the runtime has decided to run it and named itsdiff --git a/cli/beacon-hooks/cmd/pre_tool.go b/cli/beacon-hooks/cmd/pre_tool.goindex 79a6719a..be91f1f5 100644--- a/cli/beacon-hooks/cmd/pre_tool.go+++ b/cli/beacon-hooks/cmd/pre_tool.go@@ -242,6 +242,9 @@ func emitAntigravityPromptFromTranscript(logger *logging.Logger, input map[strin})fields["content"] = retainedContentFields(prompt)emitHookEvent(logger, "prompt.submitted", "prompt", "info", "Prompt submitted to agent", input, fields)+ if link, ok := handoffLinkEvent(fields, prompt); ok {+ emitHookEvent(logger, link.action, link.category, link.severity, link.message, input, link.fields)+ }if err := st.SetPromptEmitted(); err != nil {logger.Warn("Failed to persist prompt state", "error", err.Error())}diff --git a/docs/cli/handoff.mdx b/docs/cli/handoff.mdxindex 2abe676d..291a97eb 100644--- a/docs/cli/handoff.mdx+++ b/docs/cli/handoff.mdx@@ -153,7 +153,7 @@ The link event keeps the new session's id, workspace and harness, and leaves theTwo 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`).+- **Live hooks and plugins.** Every runtime whose prompts Beacon captures as they are sent records it: the shared prompt hook (Claude Code, Cursor, Factory Droid, Gemini CLI, Qwen Code, Kiro, Kimi Code, Devin, Muse Code, OpenHands, Grok Build, DeepSeek Harness, Hermes Agent, VS Code), Antigravity (including the prompt it recovers from its transcript when the prompt hook does not fire), the Cline, OpenCode and OpenClaw plugins, and the Pi, Oh My Pi, Prime Agent and Senpi extensions (`harness.collection_method` `hook` or `plugin`).- **Session-store sync.** `beacon endpoint claude sync`, `codex sync`, `opencode sync` and `cline 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 the other three runtimes, a sync can record the same link a 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.