Skip to content

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

Add Senpi (oh-my-openagent standalone edition) telemetry capture

Claude2a4ec2fae5a4
diff --git a/cli/beacon-hooks/cmd/helpers.go b/cli/beacon-hooks/cmd/helpers.go
index eaaf3869..4ff5adfa 100644
--- a/cli/beacon-hooks/cmd/helpers.go
+++ b/cli/beacon-hooks/cmd/helpers.go
@@ -137,10 +137,11 @@ func resolveSessionID(input map[string]interface{}, platform string) string {
// the handler context's session manager per event. The snake_case spellings are a fallback for
// a payload that reached this command by some other route.
//
- // Oh My Pi and Prime Agent share this reader because they share the envelope: both extensions
- // are built from the same contract. Some Oh My Pi events -- the approval pair -- also carry a
- // `sessionId` of their own, which lands on the same key and needs no separate spelling.
- case "pi", "omp", "prime":
+ // Oh My Pi, Prime Agent and Senpi (omo) share this reader because they share the envelope: all
+ // four extensions are built from the same contract. Some Oh My Pi events -- the approval pair --
+ // also carry a `sessionId` of their own, which lands on the same key and needs no separate
+ // spelling.
+ case "pi", "omp", "prime", "omo":
return getFirstStr(input, "sessionId", "session_id", "sessionID")
// The Beacon plugin lifts OpenClaw's session id onto the envelope from the hook context,
// falling back to the event's own when the context did not carry one. `sessionKey` is
@@ -273,7 +274,7 @@ func resolveCwd(input map[string]interface{}, platform string) string {
return cwd
}
}
- if platform == "pi" || platform == "omp" || platform == "prime" {
+ if platform == "pi" || platform == "omp" || platform == "prime" || platform == "omo" {
// The extension lifts the runtime's cwd onto the envelope, preferring the handler context's
// own cwd and falling back to the session manager's. An event that carried its own cwd --
// user_bash does, and so does Oh My Pi's user_python -- wins over both, because the
diff --git a/cli/beacon-hooks/cmd/omo_event.go b/cli/beacon-hooks/cmd/omo_event.go
new file mode 100644
index 00000000..9f113456
--- /dev/null
+++ b/cli/beacon-hooks/cmd/omo_event.go
@@ -0,0 +1,64 @@
+package cmd
+
+import (
+ "github.com/spf13/cobra"
+)
+
+// omo-event is the single entry point for every Senpi (oh-my-openagent standalone edition)
+// lifecycle payload.
+//
+// Senpi loads Beacon as a TypeScript extension whose handlers all fire in the same process, so one
+// command receiving a typed envelope fits the runtime the way it does for Pi, Oh My Pi, Prime
+// Agent, opencode and Cline, rather than the command-per-hook shape used by runtimes that exec a
+// separate hook per event.
+//
+// It is a separate command from pi-event, not a flag on it, for the reason omp-event and
+// prime-event are: the runtimes are separately installed products, they are recorded under
+// separate harness names, and a running install must not change which runtime it attributes events
+// to. The event *mapping* is shared (see pi_family.go) precisely because Senpi is an in-flight fork
+// of pi-mono that kept its payload shapes.
+var omoEventCmd = &cobra.Command{
+ Use: "omo-event",
+ Short: "Record Senpi (oh-my-openagent) hook telemetry",
+ Long: `omo-event receives raw Beacon Senpi extension payloads and writes local endpoint telemetry.`,
+ Run: runOmoEvent,
+}
+
+func init() {
+ rootCmd.AddCommand(omoEventCmd)
+}
+
+func runOmoEvent(cmd *cobra.Command, args []string) {
+ runPiFamilyEvent(omoRuntime)
+}
+
+// supportedOmoEventTypes lists every Senpi event type this mapper handles.
+//
+// Like supportedPiEventTypes and supportedPrimeEventTypes, this is the contract between the
+// managed extension's subscription list and the mapper: a typo on either side produces no
+// telemetry rather than an error, so both sides pin the list and a test asserts each entry still
+// maps to an event.
+//
+// The list is Pi's exactly, and that is a finding rather than a copy. Senpi's ExtensionEvent union
+// has more than thirty members -- provider-request and response internals, streaming message and
+// tool-execution updates, compaction, model-select, turn bookkeeping and TUI plumbing among them --
+// and of the ones that describe an agent action rather than how the runtime got its work done,
+// these seven are what Beacon's extension subscribes to.
+//
+// Two absences are Senpi's own rather than a choice made here. It has no `user_python`: that is Oh
+// My Pi's own addition, a `$` operator prefix Senpi's fork never added. And it has no approval
+// event at all -- its `tool_call` handler can block, but that is an extension deciding rather than
+// an operator being asked, and its permission-system builtin owns the real approval prompt without
+// publishing it as an extension event -- so Beacon records tool activity and leaves approval
+// telemetry empty, exactly as it does for Pi and Prime Agent.
+func supportedOmoEventTypes() []string {
+ return []string{
+ "session_start",
+ "session_shutdown",
+ "input",
+ "tool_call",
+ "tool_result",
+ "user_bash",
+ "message_end",
+ }
+}
diff --git a/cli/beacon-hooks/cmd/omo_event_test.go b/cli/beacon-hooks/cmd/omo_event_test.go
new file mode 100644
index 00000000..dacc2aa2
--- /dev/null
+++ b/cli/beacon-hooks/cmd/omo_event_test.go
@@ -0,0 +1,331 @@
+package cmd
+
+import (
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// omoTestLog puts a Senpi extension run in a temp endpoint log and returns its path.
+func omoTestLog(t *testing.T) string {
+ t.Helper()
+ setupHookConfigDirs(t)
+ platformFlag = "omo"
+ logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
+ t.Setenv("BEACON_ENDPOINT_MODE", "1")
+ t.Setenv("BEACON_ENDPOINT_LOG", logPath)
+ t.Setenv("BEACON_CONTENT_RETENTION", "full")
+ return logPath
+}
+
+func omoEventActions(t *testing.T, logPath string) []string {
+ t.Helper()
+ var actions []string
+ for _, event := range endpointEvents(t, logPath) {
+ meta, _ := event["event"].(map[string]interface{})
+ actions = append(actions, meta["action"].(string))
+ }
+ return actions
+}
+
+func omoEventWithAction(t *testing.T, logPath, action string) map[string]interface{} {
+ t.Helper()
+ for _, event := range endpointEvents(t, logPath) {
+ meta, _ := event["event"].(map[string]interface{})
+ if meta["action"] == action {
+ return event
+ }
+ }
+ t.Fatalf("no %s event in log; got %v", action, omoEventActions(t, logPath))
+ return nil
+}
+
+// omoPayloads returns one payload per supported event type, each carrying the minimum its branch
+// needs to emit. The tool fixtures use `bash`, Senpi's ordinary default tool -- unlike Prime Agent,
+// Senpi kept pi-mono's built-in tool set (bash, read, edit, write, grep, find, ls) rather than
+// routing everything through a single kernel tool.
+func omoPayloads() map[string]map[string]interface{} {
+ return map[string]map[string]interface{}{
+ "session_start": {"type": "session_start", "reason": "startup"},
+ "session_shutdown": {"type": "session_shutdown", "reason": "quit"},
+ "input": {"type": "input", "text": "do the thing", "source": "interactive"},
+ "tool_call": {"type": "tool_call", "toolName": "bash", "toolCallId": "c1",
+ "input": map[string]interface{}{"command": "ls"}},
+ "tool_result": {"type": "tool_result", "toolName": "bash", "toolCallId": "c1",
+ "input": map[string]interface{}{"command": "ls"}},
+ "user_bash": {"type": "user_bash", "command": "git status", "cwd": "/repo"},
+ "message_end": {"type": "message_end", "message": map[string]interface{}{
+ "role": "assistant",
+ "usage": map[string]interface{}{"input": float64(10), "output": float64(5)},
+ }},
+ }
+}
+
+// Every type the managed extension subscribes to must map to at least one event. These strings are
+// the contract between the extension's subscription list and this mapper, and a typo on either side
+// produces no telemetry rather than an error -- so the list is walked rather than trusted.
+func TestOmoEventEverySupportedTypeProducesTelemetry(t *testing.T) {
+ payloads := omoPayloads()
+ for _, name := range supportedOmoEventTypes() {
+ payload, ok := payloads[name]
+ if !ok {
+ t.Fatalf("no fixture for supported Senpi event type %q; the mapper claims to handle it", name)
+ }
+ if events := omoRuntime.endpointEvents(cloneFields(payload), "sess-1"); len(events) == 0 {
+ t.Fatalf("supported Senpi event type %q produced no telemetry", name)
+ }
+ }
+}
+
+// An unrecognized type is silent rather than generic. Senpi publishes more than thirty event types
+// -- provider request/response internals, streaming message and tool-execution updates, turn
+// bookkeeping, compaction, model-select and TUI plumbing -- and a future one becoming an
+// undifferentiated row would fill the log with records no investigation asks for.
+func TestOmoEventUnknownTypeProducesNothing(t *testing.T) {
+ for _, name := range []string{
+ "message_update", "message_start", "before_provider_request", "after_provider_response",
+ "tool_execution_start", "tool_execution_update", "tool_execution_end", "turn_start", "turn_end",
+ "agent_start", "agent_end", "agent_settled", "model_select", "resources_discover",
+ "thinking_level_select", "session_compact", "session_abort", "input_disposition",
+ "", "totally_new",
+ } {
+ events := omoRuntime.endpointEvents(map[string]interface{}{"type": name}, "sess-1")
+ if len(events) != 0 {
+ t.Fatalf("Senpi event type %q produced %d events, want none", name, len(events))
+ }
+ }
+}
+
+// Senpi, Pi, Oh My Pi and Prime Agent are separately installed products that one machine can run
+// side by side. Sharing the mapper must not mean sharing identity: every event has to name the
+// runtime that produced it, in the harness name, in the message, and in the `raw` block an operator
+// reads.
+func TestOmoEventIsAttributedToOmoSenpiNotPi(t *testing.T) {
+ logPath := omoTestLog(t)
+
+ runHookWithInput(t, runOmoEvent, map[string]interface{}{
+ "type": "session_start", "reason": "startup", "sessionId": "sess-1",
+ })
+
+ event := omoEventWithAction(t, logPath, "session.started")
+
+ // The `--platform` is `omo`; the harness name events are written under is `omo_senpi`.
+ // Normalizing at write time is what keeps one Senpi session from being split across two
+ // spellings in any query that groups by harness.name -- and from being merged into Pi's, Oh My
+ // Pi's or Prime Agent's.
+ harness := nested(t, event, "harness")
+ if harness["name"] != "omo_senpi" {
+ t.Fatalf("harness.name = %v, want omo_senpi", harness["name"])
+ }
+
+ if event["message"] != "Senpi session started" {
+ t.Fatalf("message = %v, want it to name Senpi", event["message"])
+ }
+
+ raw := nested(t, event, "raw")
+ if _, ok := raw["omo"]; !ok {
+ t.Fatalf("raw = %v, want the verbatim payload under an omo key", raw)
+ }
+ for _, other := range []string{"pi", "omp", "prime"} {
+ if _, ok := raw[other]; ok {
+ t.Fatalf("raw = %v, want no %s key on a Senpi event", raw, other)
+ }
+ }
+ if raw["omo_session_reason"] != "startup" {
+ t.Fatalf("raw.omo_session_reason = %v, want startup", raw["omo_session_reason"])
+ }
+}
+
+// One shared shape, four identities. The shared core in pi_family.go must never start hardcoding
+// one runtime's name -- which is the way a refactor like that goes wrong silently.
+func TestPiAndOmoProduceTheSameShapeUnderDifferentIdentities(t *testing.T) {
+ shared := map[string]bool{}
+ for _, name := range supportedPiEventTypes() {
+ shared[name] = true
+ }
+ for name, payload := range omoPayloads() {
+ if !shared[name] {
+ continue
+ }
+ t.Run(name, func(t *testing.T) {
+ piEvents := piRuntime.endpointEvents(cloneFields(payload), "sess-1")
+ omoEvents := omoRuntime.endpointEvents(cloneFields(payload), "sess-1")
+
+ if len(piEvents) != len(omoEvents) {
+ t.Fatalf("pi produced %d events and omo %d for %q; the shared mapper should emit "+
+ "the same events for the same payload", len(piEvents), len(omoEvents), name)
+ }
+ for i := range piEvents {
+ if piEvents[i].action != omoEvents[i].action {
+ t.Fatalf("action[%d] = %q (pi) vs %q (omo)", i, piEvents[i].action, omoEvents[i].action)
+ }
+ if piEvents[i].message == omoEvents[i].message {
+ t.Fatalf("event[%d] message %q is identical for both runtimes; a reader could "+
+ "not tell which one produced it", i, piEvents[i].message)
+ }
+ if _, ok := omoEvents[i].fields["raw"].(map[string]interface{})["omo"]; !ok {
+ t.Fatalf("omo event[%d] raw block is not keyed by omo: %v", i, omoEvents[i].fields["raw"])
+ }
+ }
+ })
+ }
+}
+
+// Beacon ships and versions the extension file Senpi loads, so its events are plugin-collected, not
+// hook-collected. `event.fidelity` stays observed because every action here was named by the
+// runtime rather than derived by Beacon.
+func TestOmoEventCarriesPluginProvenance(t *testing.T) {
+ logPath := omoTestLog(t)
+
+ runHookWithInput(t, runOmoEvent, map[string]interface{}{
+ "type": "input", "text": "hello", "sessionId": "sess-1",
+ })
+
+ event := omoEventWithAction(t, logPath, "prompt.submitted")
+ if method := nested(t, event, "harness")["collection_method"]; method != "plugin" {
+ t.Fatalf("harness.collection_method = %v, want plugin", method)
+ }
+ if fidelity := nested(t, event, "event")["fidelity"]; fidelity != "observed" {
+ t.Fatalf("event.fidelity = %v, want observed", fidelity)
+ }
+}
+
+// Senpi exposes no approval event at all. Its tool_call handler can block, but that is an extension
+// deciding rather than an operator being asked, and its permission-system builtin owns the real
+// approval prompt without publishing it as an extension event. This is the Pi and Prime Agent
+// posture, and it is what separates Senpi from Oh My Pi, which does report real ones.
+func TestOmoEventNeverSynthesizesAnApproval(t *testing.T) {
+ for _, name := range supportedOmoEventTypes() {
+ if strings.Contains(name, "approval") {
+ t.Fatalf("supportedOmoEventTypes includes %q; Senpi publishes no approval event", name)
+ }
+ }
+
+ logPath := omoTestLog(t)
+ runHookWithInput(t, runOmoEvent, map[string]interface{}{
+ "type": "tool_call", "toolName": "bash", "toolCallId": "call-1",
+ "input": map[string]interface{}{"command": "rm -rf /tmp/x"}, "sessionId": "sess-1",
+ })
+
+ event := omoEventWithAction(t, logPath, "tool.invoked")
+ if _, ok := event["approval"]; ok {
+ t.Fatalf("tool.invoked carries an approval block: %v", event)
+ }
+}
+
+// The `!` prefix is Senpi's operator shell surface, and no tool event covers it. It is the one
+// command shape here the agent did not originate, so it is marked rather than merged in with
+// agent-run commands.
+func TestOmoEventUserBashIsMarkedOperatorInitiated(t *testing.T) {
+ logPath := omoTestLog(t)
+
+ runHookWithInput(t, runOmoEvent, map[string]interface{}{
+ "type": "user_bash", "command": "git push --force", "cwd": "/repo", "sessionId": "sess-1",
+ })
+
+ event := omoEventWithAction(t, logPath, "command.executed")
+ if command := nested(t, event, "command"); command["command"] != "git push --force" {
+ t.Fatalf("command.command = %v, want the operator's command", command["command"])
+ }
+ if raw := nested(t, event, "raw"); raw["omo_user_initiated"] != true {
+ t.Fatalf("raw.omo_user_initiated = %v, want true", raw["omo_user_initiated"])
+ }
+}
+
+// bash is Senpi's ordinary command tool -- unlike Prime Agent, whose only default tool is a Python
+// kernel, so this is the shape the vast majority of Senpi's agent activity actually takes.
+func TestOmoEventBashToolResultIsRecordedAsACommand(t *testing.T) {
+ logPath := omoTestLog(t)
+
+ runHookWithInput(t, runOmoEvent, map[string]interface{}{
+ "type": "tool_result", "toolName": "bash", "toolCallId": "call-1",
+ "input": map[string]interface{}{"command": "rm -rf /tmp/x"},
+ "details": map[string]interface{}{"exitCode": float64(0), "output": "done\n"},
+ "isError": false, "sessionId": "sess-1",
+ })
+
+ event := omoEventWithAction(t, logPath, "command.executed")
+ command := nested(t, event, "command")
+ if command["command"] != "rm -rf /tmp/x" {
+ t.Fatalf("command.command = %v, want the bash command", command["command"])
+ }
+ if tool := nested(t, event, "tool"); tool["name"] != "bash" {
+ t.Fatalf("tool.name = %v, want bash", tool["name"])
+ }
+}
+
+// Beacon's edit-tool mapping is shared with Pi and Prime Agent, so this pins that Senpi's own edit
+// result reaches it: the runtime's unified patch is retained as content on the file.modified event,
+// the same shape TestPiEventEditResultRecordsTheUnifiedPatch already proves for Pi.
+func TestOmoEventEditResultRecordsTheUnifiedPatch(t *testing.T) {
+ logPath := omoTestLog(t)
+ patch := "@@ -1 +1 @@\n-old\n+new\n"
+
+ runHookWithInput(t, runOmoEvent, map[string]interface{}{
+ "type": "tool_result", "toolName": "edit", "toolCallId": "call-2",
+ "input": map[string]interface{}{"path": "/repo/a.ts"},
+ "details": map[string]interface{}{"patch": patch},
+ "isError": false,
+ "sessionId": "sess-1",
+ })
+
+ event := omoEventWithAction(t, logPath, "file.modified")
+ file := nested(t, event, "file")
+ if file["path"] != "/repo/a.ts" || file["operation"] != "modify" {
+ t.Fatalf("file = %v, want the edited path with a modify operation", file)
+ }
+ content := nested(t, event, "content")
+ if content["bytes"] != float64(len(patch)) {
+ t.Fatalf("content.bytes = %v, want the patch length %d", content["bytes"], len(patch))
+ }
+}
+
+// Usage and cost come off a finalized assistant message, the only place this family reports them,
+// and land in gen_ai.usage rather than in a parallel per-harness field.
+func TestOmoEventMessageEndReportsUsageAndReasoning(t *testing.T) {
+ logPath := omoTestLog(t)
+
+ runHookWithInput(t, runOmoEvent, map[string]interface{}{
+ "type": "message_end",
+ "sessionId": "sess-1",
+ "message": map[string]interface{}{
+ "role": "assistant",
+ "model": "claude-opus-5",
+ "content": []interface{}{
+ map[string]interface{}{"type": "thinking", "thinking": "consider the failing test"},
+ map[string]interface{}{"type": "text", "text": "Fixed it."},
+ },
+ "usage": map[string]interface{}{
+ "input": float64(120), "output": float64(30), "cacheRead": float64(8),
+ "cost": map[string]interface{}{"total": 0.0042},
+ },
+ },
+ })
+
+ usage := nested(t, nested(t, omoEventWithAction(t, logPath, "token.usage"), "gen_ai"), "usage")
+ if usage["input_tokens"] != float64(120) || usage["output_tokens"] != float64(30) {
+ t.Fatalf("gen_ai.usage = %v, want the reported input and output tokens", usage)
+ }
+ if cacheRead, ok := usage["cache_read"].(map[string]interface{}); !ok || cacheRead["input_tokens"] != float64(8) {
+ t.Fatalf("gen_ai.usage.cache_read = %v, want 8 input tokens", usage["cache_read"])
+ }
+ // Runtime-reported cost only; Beacon never derives it from a local pricing table.
+ if usage["cost_usd"] != 0.0042 {
+ t.Fatalf("gen_ai.usage.cost_usd = %v, want the runtime's reported cost", usage["cost_usd"])
+ }
+
+ reasoning := omoEventWithAction(t, logPath, "agent.reasoning")
+ output := nested(t, nested(t, reasoning, "gen_ai"), "output")
+ messages, _ := output["messages"].([]interface{})
+ if len(messages) != 1 {
+ t.Fatalf("gen_ai.output.messages = %v, want one reasoning message", output["messages"])
+ }
+ // The assistant's visible answer is not reasoning. Recording it as such would put the model's
+ // output where a reader looking for its private deliberation expects to find it.
+ first, _ := messages[0].(map[string]interface{})
+ parts, _ := first["parts"].([]interface{})
+ part, _ := parts[0].(map[string]interface{})
+ if part["content"] != "consider the failing test" {
+ t.Fatalf("reasoning part = %v, want only the thinking text", part)
+ }
+}
diff --git a/cli/beacon-hooks/cmd/pi_family.go b/cli/beacon-hooks/cmd/pi_family.go
index 07aebd2b..707a4f89 100644
--- a/cli/beacon-hooks/cmd/pi_family.go
+++ b/cli/beacon-hooks/cmd/pi_family.go
@@ -48,6 +48,17 @@ var (
// events are written under is still `prime_agent`; NormalizeHarnessName pins both spellings so
// one session cannot be recorded under two names.
primeRuntime = piFamily{platform: "prime", displayName: "Prime Agent"}
+ // Senpi is the standalone edition of oh-my-openagent: an in-flight fork of pi-mono
+ // (code-yeongyu/senpi) that OMO brands and bundles its own extension into, distributed as the
+ // `omo` command. Its ExtensionEvent union kept Pi's shape -- the same `type` discriminator, the
+ // same toolName/input/details tool events, the same usage object -- even where it added events
+ // Pi does not have, so the seven events Beacon's Senpi extension subscribes to map through this
+ // family unchanged. "omo" rather than "senpi" because that is the binary the operator runs and
+ // the directory Beacon installs into (~/.omo/agent); "senpi" is the upstream project name, not
+ // the product. The harness name events are written under is omo_senpi, not omo, because "omo"
+ // alone would not distinguish this edition from oh-my-openagent's OpenCode and Codex CLI
+ // editions if Beacon ever observes those too -- see asymptoteobserve.NormalizeHarnessName.
+ omoRuntime = piFamily{platform: "omo", displayName: "Senpi"}
)
// rawKey namespaces a runtime-specific detail inside the `raw` block.
diff --git a/cli/beacon-hooks/cmd/pi_family_subscription_test.go b/cli/beacon-hooks/cmd/pi_family_subscription_test.go
index 21aaa7e3..64c13f01 100644
--- a/cli/beacon-hooks/cmd/pi_family_subscription_test.go
+++ b/cli/beacon-hooks/cmd/pi_family_subscription_test.go
@@ -28,6 +28,7 @@ func TestManagedExtensionSubscriptionsMatchTheirMappers(t *testing.T) {
{"pi", filepath.Join("..", "..", "..", "plugins", "pi-beacon", "src", "beacon.ts"), supportedPiEventTypes()},
{"omp", filepath.Join("..", "..", "..", "plugins", "omp-beacon", "src", "beacon.ts"), supportedOmpEventTypes()},
{"prime", filepath.Join("..", "..", "..", "plugins", "prime-beacon", "src", "beacon.ts"), supportedPrimeEventTypes()},
+ {"omo", filepath.Join("..", "..", "..", "plugins", "omo-beacon", "src", "beacon.ts"), supportedOmoEventTypes()},
} {
t.Run(tc.runtime, func(t *testing.T) {
subscribed := subscribedEventTypes(t, tc.source)
@@ -62,6 +63,7 @@ func TestEverySubscribedTypeIsMappedToAnEvent(t *testing.T) {
{piRuntime, filepath.Join("..", "..", "..", "plugins", "pi-beacon", "src", "beacon.ts")},
{ompRuntime, filepath.Join("..", "..", "..", "plugins", "omp-beacon", "src", "beacon.ts")},
{primeRuntime, filepath.Join("..", "..", "..", "plugins", "prime-beacon", "src", "beacon.ts")},
+ {omoRuntime, filepath.Join("..", "..", "..", "plugins", "omo-beacon", "src", "beacon.ts")},
} {
t.Run(tc.runtime.platform, func(t *testing.T) {
for _, name := range subscribedEventTypes(t, tc.source) {
diff --git a/cli/beacon/internal/endpoint/hooks/assets/omo/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/omo/beacon.ts
new file mode 100644
index 00000000..ec37df67
--- /dev/null
+++ b/cli/beacon/internal/endpoint/hooks/assets/omo/beacon.ts
@@ -0,0 +1,285 @@
+// __BEACON_MANAGED_MARKER__
+// Beacon endpoint telemetry extension for Senpi (the standalone edition of oh-my-openagent).
+// Managed by beacon endpoint hooks install --harness omo.
+
+// The argv Beacon's installer writes, as an array rather than a command line.
+//
+// An argv array is passed straight to the OS with no shell in between, which sidesteps quoting
+// entirely -- the same reason the Cline plugin uses one. Senpi runs as a Bun-compiled binary or
+// under Node depending on how it was installed, and on Windows as readily as on macOS, so there is
+// no one shell whose quoting rules would hold.
+const beaconArgv: string[] = ["__BEACON_ARGV__"]
+
+const debugEnabled = process.env.BEACON_OMO_DEBUG === "1"
+
+// A send that has not finished in this long is abandoned. Senpi awaits event handlers before
+// continuing the agent loop, so this is the worst case Beacon can add to a tool call.
+const sendTimeoutMs = 2000
+
+// How deep into an event the serializer will walk before giving up.
+const maxDepth = 8
+
+// Senpi's own event objects, narrowed to the fields Beacon reads.
+//
+// Declared here rather than imported from @earendil-works/pi-coding-agent on purpose -- and Senpi
+// really does publish under that name, because it is an in-flight fork of badlogic/pi-mono
+// (code-yeongyu/senpi) that kept the upstream package name. The installed file sits in
+// ~/.omo/agent/extensions with no node_modules beside it, and Senpi loads third-party extensions
+// through Bun's own importer or jiti, neither of which resolves a type-only import. A value import
+// would fail at load; a type import would resolve for nobody. Local structural types cost the
+// compile-time link to Senpi's definitions and buy a file that loads wherever Senpi does.
+type OmoEvent = Record<string, unknown> & { type: string }
+
+interface OmoSessionManager {
+ getSessionId?: () => string
+}
+
+interface OmoContext {
+ cwd?: string
+ sessionManager?: OmoSessionManager
+ model?: { id?: string; name?: string; provider?: string } | undefined
+ hasUI?: boolean
+}
+
+// The events Beacon subscribes to, and nothing else.
+//
+// Senpi's ExtensionEvent union has more than thirty members: provider-request and response
+// internals, streaming message and tool-execution updates, compaction, model-select, and TUI
+// plumbing among them. Most describe how the runtime got its work done rather than what the agent
+// did. Subscribing to all of them would fill the runtime log with rows no query asks for -- the
+// same reason the Cline mapper drops unrecognized stages -- and would put Beacon in the path of
+// every streaming token update.
+//
+// `tool_call` and `tool_result` are the pair that carries tool activity: the first names the tool
+// and its arguments before it runs, the second carries the outcome. `user_bash` is a command the
+// human ran with the `!` prefix, which no tool event covers. This is Pi's own set of seven exactly
+// -- Senpi kept the shape (the same `type` discriminator, the same toolName/input/details tool
+// events, the same assistant message parts, the same input/output/cacheRead/cacheWrite/cost usage
+// object) even where it added events Pi does not have, such as `tool_execution_start` and
+// `turn_start`/`turn_end`. Those additions describe execution progress and turn bookkeeping rather
+// than a new kind of agent action tool_call/tool_result do not already cover, so they are left
+// unsubscribed rather than adding a second, thinner tool-lifecycle signal beside the one Beacon
+// already records for every Pi-family runtime.
+//
+// Deliberately absent: any approval event. Senpi's `tool_call` handler can block a call, but that
+// is an extension deciding, not an operator being asked -- it exposes no operator approval decision
+// through this API (its permission-system builtin owns that prompt and does not publish it as an
+// extension event). Synthesizing an approval from a pre-tool notification would put a decision
+// nobody made into the log, so Beacon records these as tool activity and leaves approval telemetry
+// empty, exactly as it does for Pi and Prime Agent.
+//
+// Also absent, and not an omission: `user_python`. Oh My Pi added a `$` operator prefix that runs
+// Python outside the agent loop and subscribes to its event; Senpi forked pi-mono separately and
+// has no such prefix.
+const subscribedEvents = [
+ "session_start",
+ "session_shutdown",
+ "input",
+ "tool_call",
+ "tool_result",
+ "user_bash",
+ "message_end",
+] as const
+
+function debugLog(message: string, extra?: unknown) {
+ if (!debugEnabled) return
+ try {
+ // eslint-disable-next-line no-console
+ console.error("[beacon-omo]", message, extra ?? "")
+ } catch {
+ // Debug logging must stay best-effort.
+ }
+}
+
+// safeClone turns a Senpi event into something JSON.stringify accepts.
+//
+// Its events carry live objects: an AbortSignal on the session events, AgentMessage arrays holding
+// class instances, and tool inputs that are mutable by design. JSON.stringify throws on a circular
+// reference and on a bigint, and silently flattens an Error to {}, so each is handled here rather
+// than losing the whole payload to one bad field.
+//
+// Cycles are tracked along the current path and released on the way out, so an object that legibly
+// appears twice -- the same file path referenced from two places in one edit -- is kept both times.
+// A WeakSet that never released would drop the second occurrence as if it were a cycle.
+function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unknown {
+ if (value === null) return null
+ const kind = typeof value
+ if (kind === "function" || kind === "symbol" || kind === "undefined") return undefined
+ if (kind === "bigint") return String(value)
+ if (kind !== "object") return value
+ if (depth >= maxDepth) return undefined
+
+ const object = value as object
+ if (seen.has(object)) return undefined
+ if (value instanceof Error) return { name: value.name, message: value.message }
+ if (value instanceof Date) return value.toISOString()
+
+ seen.add(object)
+ try {
+ if (Array.isArray(value)) {
+ return value.map((item) => safeClone(item, depth + 1, seen))
+ }
+ const out: Record<string, unknown> = {}
+ for (const [key, nested] of Object.entries(value as Record<string, unknown>)) {
+ const cloned = safeClone(nested, depth + 1, seen)
+ if (cloned !== undefined) out[key] = cloned
+ }
+ return out
+ } finally {
+ seen.delete(object)
+ }
+}
+
+async function sendToBeacon(payload: Record<string, unknown>): Promise<void> {
+ // Flattened before anything else sees it, so every consumer of this function is handed plain
+ // data rather than a live Senpi event with cycles and functions still attached.
+ const safe = safeClone(payload)
+
+ const testSender = (globalThis as Record<symbol, unknown>)[Symbol.for("beacon.omo.testSender")]
+ if (typeof testSender === "function") {
+ await (testSender as (value: unknown) => unknown)(safe)
+ return
+ }
+
+ let body: string
+ try {
+ body = JSON.stringify(safe)
+ } catch (err) {
+ debugLog("payload could not be serialized", err)
+ return
+ }
+ if (!body) return
+
+ try {
+ // Imported lazily so a host without node:child_process fails to send rather than failing to
+ // load: a throwing import at module scope would surface to the user as a broken extension, and
+ // Senpi reports an extension that throws at load time rather than continuing without it.
+ const { spawn } = await import("node:child_process")
+ await new Promise<void>((resolve) => {
+ let settled = false
+ const finish = () => {
+ if (settled) return
+ settled = true
+ resolve()
+ }
+ let child
+ try {
+ child = spawn(beaconArgv[0], beaconArgv.slice(1), {
+ stdio: ["pipe", "ignore", "ignore"],
+ windowsHide: true,
+ })
+ } catch (err) {
+ debugLog("hook binary could not be spawned", err)
+ finish()
+ return
+ }
+ const timer = setTimeout(() => {
+ try {
+ child.kill()
+ } catch {
+ // Already gone.
+ }
+ debugLog("hook binary timed out", { type: payload?.type })
+ finish()
+ }, sendTimeoutMs)
+ // An unreferenced timer cannot keep Senpi alive at exit waiting on Beacon telemetry.
+ if (typeof timer.unref === "function") timer.unref()
+ const done = () => {
+ clearTimeout(timer)
+ finish()
+ }
+ child.on("error", (err) => {
+ debugLog("hook binary failed", err)
+ done()
+ })
+ child.on("close", done)
+ // Without this, a hook binary that exits before reading stdin turns an EPIPE into an
+ // unhandled error event in the host process. Beacon telemetry must never do that.
+ child.stdin?.on("error", () => {})
+ try {
+ child.stdin?.end(body)
+ } catch (err) {
+ debugLog("payload could not be written", err)
+ }
+ })
+ } catch (err) {
+ debugLog("send failed", err)
+ // Beacon telemetry must never interrupt Senpi execution.
+ }
+}
+
+// identity lifts the session and workspace fields Beacon needs to the top level of the envelope.
+//
+// Senpi's real ExtensionContext hands a plain-string `cwd` and a `model` object directly rather
+// than behind an accessor the way Prime Agent's does, but the session id is still read through
+// `sessionManager.getSessionId()` -- there is no bare `sessionId` field on the context -- and it is
+// read fresh per event rather than captured at load: `/new`, a resume, a fork and `/tree` all
+// replace the session without reloading the extension, so a cached id would be silently wrong.
+//
+// Every accessor is called defensively even though the shipped types mark them non-optional. A
+// third-party extension has no contract that a future Senpi release keeps them that way, and an
+// extension that loses its session id loses the field that groups every event of a run, so a
+// throwing accessor costs that field rather than the event.
+function identity(ctx: OmoContext | undefined): Record<string, unknown> {
+ const fields: Record<string, unknown> = {}
+ if (!ctx) return fields
+ try {
+ const sessionId = ctx.sessionManager?.getSessionId?.()
+ if (sessionId) fields.sessionId = sessionId
+ } catch (err) {
+ debugLog("session id could not be read", err)
+ }
+ if (ctx.cwd) fields.cwd = ctx.cwd
+ const model = ctx.model
+ if (model) {
+ // Senpi's Model carries an id and a provider separately. Joined here so the envelope's `model`
+ // is one string, matching how every other Beacon collection path reports it and how the Prime
+ // Agent extension already joins the same two fields.
+ const name = model.id || model.name
+ if (name) fields.model = model.provider ? `${model.provider}/${name}` : name
+ }
+ // Whether the session has a user-facing surface at all: false in print mode, true in the TUI and
+ // in RPC mode. An unattended run is not a run somebody was watching, which is what a reader needs
+ // to know before drawing a conclusion from an absent objection -- the same fact Prime Agent's
+ // `primeHasUi` records, under this runtime's own name so the two are never read as one field.
+ if (typeof ctx.hasUI === "boolean") fields.omoHasUi = ctx.hasUI
+ return fields
+}
+
+type OmoExtensionAPI = {
+ on: (event: string, handler: (event: OmoEvent, ctx: OmoContext) => Promise<void> | void) => void
+}
+
+// createBeaconExtension is exported for tests; Senpi loads the default export below.
+export function createBeaconExtension() {
+ const forward = async (event: OmoEvent, ctx: OmoContext) => {
+ try {
+ // The event is spread last so a field it carries itself wins over the context's: `user_bash`
+ // carries its own cwd, and that is the one describing this action.
+ await sendToBeacon({ ...identity(ctx), ...event })
+ } catch (err) {
+ // Unreachable in practice: sendToBeacon swallows its own failures. Kept because a handler
+ // that rejects is a handler that can break the run it was observing.
+ debugLog("handler failed", err)
+ }
+ }
+
+ return {
+ register(pi: OmoExtensionAPI) {
+ for (const name of subscribedEvents) {
+ // Every handler returns undefined. Beacon observes; it never blocks a tool call, patches a
+ // tool's arguments, rewrites a prompt, transforms input, or replaces a message. Senpi reads
+ // a returned object as a request to change behavior on several of these events, so
+ // returning nothing is what keeps this extension an observer. Enforcement lives behind the
+ // policy provider seam in the hook adapter, not here.
+ pi.on(name, forward)
+ }
+ },
+ // Exposed so a test can assert the subscription list without a live Senpi instance.
+ subscribedEvents: [...subscribedEvents],
+ }
+}
+
+export default function beaconExtension(pi: OmoExtensionAPI) {
+ createBeaconExtension().register(pi)
+}
diff --git a/cli/beacon/internal/endpoint/hooks/assets/omo/embed.go b/cli/beacon/internal/endpoint/hooks/assets/omo/embed.go
new file mode 100644
index 00000000..9c2f4405
--- /dev/null
+++ b/cli/beacon/internal/endpoint/hooks/assets/omo/embed.go
@@ -0,0 +1,10 @@
+package omo
+
+import _ "embed"
+
+// Template embeds the checked copy used by Beacon's Go installer.
+// The root source of truth lives at plugins/omo-beacon/src/beacon.ts.
+// Tests fail if this copy drifts.
+//
+//go:embed beacon.ts
+var Template string
diff --git a/pkg/asymptoteobserve/harness.go b/pkg/asymptoteobserve/harness.go
index da8ccfdc..e72d7c3b 100644
--- a/pkg/asymptoteobserve/harness.go
+++ b/pkg/asymptoteobserve/harness.go
@@ -170,6 +170,29 @@ func NormalizeHarnessName(name string) string {
lower == "primeagent" || lower == "prime_cli" || lower == "prime-cli" || lower == "prime cli" ||
lower == "prime_intellect" || lower == "prime-intellect" || lower == "prime intellect":
return "prime_agent"
+ // Senpi is the standalone edition of oh-my-openagent (OMO): an in-flight fork of pi-mono that
+ // OMO brands and bundles its own extension into, distributed as the `omo` command. It is a
+ // separate product from Pi, Oh My Pi and Prime Agent, so it gets its own canonical name rather
+ // than folding into pi_cli -- recording its sessions as pi_cli would merge two runtimes'
+ // activity under one name in every query that groups by harness.name.
+ //
+ // The canonical spelling is omo_senpi rather than bare omo because oh-my-openagent ships two
+ // other editions today (a plugin riding OpenCode, and one riding Codex CLI); "omo" alone would
+ // not say which one produced a row if Beacon ever observes those too, so it is normalized to
+ // this edition's full name rather than left standing for the whole project.
+ //
+ // Deliberately narrow, and that is the whole reason for the set rather than a wider one. "senpi"
+ // and "oh-my-openagent" both name things bigger than this one edition -- upstream Senpi is a
+ // real, separately installable engine a user can run without OMO at all, and
+ // "oh-my-openagent"/"oh-my-opencode" (the pre-rename package name) name the project as a whole,
+ // under which the OpenCode and Codex CLI editions also ship. Accepting either here would claim a
+ // spelling that a future integration for one of those needs for itself. Only spellings that say
+ // "omo" specifically -- the branded binary and config directory this edition actually uses --
+ // are accepted, and equality against that closed set rather than Contains for the same reason
+ // Pi, Cline, Qwen Code and Prime Agent above use equality: "omo" is an ordinary three-letter
+ // string that could appear inside an unrelated harness attribute.
+ case lower == "omo" || lower == "omo_senpi" || lower == "omo-senpi" || lower == "omo senpi":
+ return "omo_senpi"
// fx (vercel-labs/fx) is matched by equality against a closed set for the same reason Pi is,
// only more so: "fx" is two characters and appears inside ordinary words a harness attribute
// can plausibly carry -- "sfx", "fx-runner", "effects" does not contain it but "fxagent" does
diff --git a/pkg/asymptoteobserve/harness_test.go b/pkg/asymptoteobserve/harness_test.go
index a9506c8c..16fb8b81 100644
--- a/pkg/asymptoteobserve/harness_test.go
+++ b/pkg/asymptoteobserve/harness_test.go
@@ -21,6 +21,7 @@ func TestHookPlatformsConvergeOnCanonicalNames(t *testing.T) {
"cline": "cline",
"qwen": "qwen_code",
"prime": "prime_agent",
+ "omo": "omo_senpi",
"muse": "muse_code",
"goose": "goose",
} {
@@ -41,7 +42,7 @@ func TestCanonicalNamesAreStableUnderRenormalization(t *testing.T) {
for _, canonical := range []string{
"claude_code", "codex_cli", "codex_desktop", "gemini_cli", "antigravity_cli", "vscode_copilot",
"copilot_cli", "claude_web", "chatgpt_web", "claude_cowork", "claude_agent_sdk",
- "openclaw_gateway", "pi_cli", "omp", "cline", "qwen_code", "prime_agent", "vercel_fx",
+ "openclaw_gateway", "pi_cli", "omp", "cline", "qwen_code", "prime_agent", "omo_senpi", "vercel_fx",
"muse_code", "grok_bot", "goose",
} {
t.Run(canonical, func(t *testing.T) {
@@ -337,6 +338,66 @@ func TestPrimeSubstringsAreNotTreatedAsTheHarness(t *testing.T) {
}
}
+// Senpi (the standalone edition of oh-my-openagent) reaches Beacon under more than one spelling for
+// the same reason Prime Agent does: the hook path installs with --platform omo, while the harness
+// name events are written under is the fuller omo_senpi.
+func TestOmoSenpiSpellingsConvergeOnOmoSenpi(t *testing.T) {
+ for _, in := range []string{
+ "omo", "Omo", "OMO", " omo ", "omo_senpi", "omo-senpi", "Omo Senpi", "omo senpi",
+ } {
+ t.Run(in, func(t *testing.T) {
+ if got := NormalizeHarnessName(in); got != "omo_senpi" {
+ t.Errorf("NormalizeHarnessName(%q) = %q, want %q", in, got, "omo_senpi")
+ }
+ })
+ }
+}
+
+// Senpi is a Pi distribution -- it ships Pi's extension API under a rebranded config directory --
+// which is exactly why this needs a test. The two runtimes are observed through the same
+// mechanism, so the temptation is to file them under one name; doing that would merge two products'
+// sessions in every query that groups by harness.name, and would make "which runtime is running
+// here" unanswerable from the log.
+func TestOmoSenpiIsNotAttributedToPi(t *testing.T) {
+ for _, in := range []string{"omo", "omo-senpi", "omo_senpi", "Omo Senpi"} {
+ if got := NormalizeHarnessName(in); got == "pi_cli" {
+ t.Errorf("NormalizeHarnessName(%q) = %q; Senpi must not be recorded as Pi", in, got)
+ }
+ }
+ for _, in := range []string{"pi", "pi.dev", "pi-agent"} {
+ if got := NormalizeHarnessName(in); got != "pi_cli" {
+ t.Errorf("NormalizeHarnessName(%q) = %q; adding Senpi must not move Pi", in, got)
+ }
+ }
+}
+
+// Neither upstream Senpi nor the wider oh-my-openagent project name should collapse onto this one
+// edition's harness name. Both name something bigger than the omo-branded standalone CLI: plain
+// "senpi" is a real, separately installable engine a user can run without OMO at all, and
+// "oh-my-openagent" also covers the OpenCode and Codex CLI editions Beacon does not observe through
+// this extension. Accepting either spelling here would claim a name a future integration for one of
+// those needs for itself.
+func TestBareSenpiAndOhMyOpenagentAreNotTreatedAsOmoSenpi(t *testing.T) {
+ for _, name := range []string{"senpi", "Senpi", "oh-my-openagent", "oh-my-opencode", "oh_my_openagent"} {
+ if got := NormalizeHarnessName(name); got == "omo_senpi" {
+ t.Errorf("NormalizeHarnessName(%q) = %q; only the omo-branded spelling should resolve to "+
+ "the Senpi standalone edition", name, got)
+ }
+ }
+}
+
+// The reason the omo case is an equality match rather than a Contains rule. "omo" is an ordinary
+// three-letter string that turns up in names that have nothing to do with this runtime, and a
+// substring rule would file every one of them under omo_senpi.
+func TestOmoSubstringsAreNotTreatedAsTheHarness(t *testing.T) {
+ for _, name := range []string{"ammo", "promotion", "omoplate", "homology"} {
+ if got := NormalizeHarnessName(name); got == "omo_senpi" {
+ t.Errorf("NormalizeHarnessName(%q) = %q; a name that merely contains \"omo\" must not be "+
+ "reported as the Senpi harness", name, got)
+ }
+ }
+}
+
// fx (vercel-labs/fx) reaches Beacon under the spellings a reader is likely to type and the ones
// the session collector records, and all of them must land on one canonical name. fx has no hook
// or OTLP surface, so the collector is currently the only writer -- but harness names also arrive
diff --git a/pkg/asymptoteobserve/provenance.go b/pkg/asymptoteobserve/provenance.go
index 19671257..06f9f449 100644
--- a/pkg/asymptoteobserve/provenance.go
+++ b/pkg/asymptoteobserve/provenance.go
@@ -99,7 +99,7 @@ func CollectionMethodForPlatform(platform string) string {
switch strings.ToLower(strings.TrimSpace(platform)) {
case "":
return ""
- case "opencode", "cline", "pi", "omp", "openclaw", "prime":
+ case "opencode", "cline", "pi", "omp", "openclaw", "prime", "omo":
return CollectionMethodPlugin
default:
return CollectionMethodHook
diff --git a/pkg/asymptoteobserve/provenance_test.go b/pkg/asymptoteobserve/provenance_test.go
index 7c20b30c..77539e58 100644
--- a/pkg/asymptoteobserve/provenance_test.go
+++ b/pkg/asymptoteobserve/provenance_test.go
@@ -135,6 +135,7 @@ func TestCollectionMethodForPlatform(t *testing.T) {
"pi": CollectionMethodPlugin,
"omp": CollectionMethodPlugin,
"prime": CollectionMethodPlugin,
+ "omo": CollectionMethodPlugin,
// Unset stays unset rather than defaulting to a method, so an event with no platform does
// not claim one.
"": "",
diff --git a/plugins/omo-beacon/package.json b/plugins/omo-beacon/package.json
new file mode 100644
index 00000000..85415034
--- /dev/null
+++ b/plugins/omo-beacon/package.json
@@ -0,0 +1,21 @@
+{
+ "name": "@asymptote-labs/omo-beacon",
+ "version": "0.0.0",
+ "private": true,
+ "description": "Beacon endpoint telemetry extension for Senpi (the standalone edition of oh-my-openagent)",
+ "type": "module",
+ "scripts": {
+ "check": "bun --check src/beacon.ts && cmp src/beacon.ts ../../cli/beacon/internal/endpoint/hooks/assets/omo/beacon.ts",
+ "sync": "cp src/beacon.ts ../../cli/beacon/internal/endpoint/hooks/assets/omo/beacon.ts",
+ "test": "bun test src/beacon.test.ts"
+ },
+ "exports": {
+ ".": "./src/beacon.ts"
+ },
+ "files": [
+ "src/"
+ ],
+ "peerDependencies": {
+ "@earendil-works/pi-coding-agent": "*"
+ }
+}
diff --git a/plugins/omo-beacon/src/beacon.test.ts b/plugins/omo-beacon/src/beacon.test.ts
new file mode 100644
index 00000000..b7420ba9
--- /dev/null
+++ b/plugins/omo-beacon/src/beacon.test.ts
@@ -0,0 +1,314 @@
+import { afterEach, describe, expect, test } from "bun:test"
+
+import { createBeaconExtension } from "./beacon"
+
+const senderKey = Symbol.for("beacon.omo.testSender")
+
+type Sent = Record<string, unknown>
+
+function captureSends(): Sent[] {
+ const sent: Sent[] = []
+ ;(globalThis as Record<symbol, unknown>)[senderKey] = (payload: Sent) => {
+ sent.push(payload)
+ }
+ return sent
+}
+
+// A stand-in for Senpi's ExtensionAPI that records subscriptions and lets a test fire one.
+function fakePi() {
+ const handlers = new Map<string, (event: Record<string, unknown>, ctx: unknown) => Promise<void> | void>()
+ return {
+ api: {
+ on(event: string, handler: (event: Record<string, unknown>, ctx: unknown) => Promise<void> | void) {
+ handlers.set(event, handler)
+ },
+ },
+ handlers,
+ async fire(event: Record<string, unknown> & { type: string }, ctx?: unknown) {
+ const handler = handlers.get(event.type)
+ if (!handler) throw new Error(`no handler registered for ${event.type}`)
+ await handler(event, ctx)
+ },
+ }
+}
+
+function context(overrides: Record<string, unknown> = {}) {
+ return {
+ cwd: "/repo",
+ sessionManager: { getSessionId: () => "sess-1" },
+ ...overrides,
+ }
+}
+
+afterEach(() => {
+ delete (globalThis as Record<symbol, unknown>)[senderKey]
+})
+
+describe("beacon omo (senpi) extension", () => {
+ // These strings are the contract between this extension and the omo-event mapper in the hook
+ // adapter. A typo on either side produces no telemetry rather than an error, so the list is
+ // pinned here and asserted against the mapper's own list on the Go side.
+ test("subscribes to exactly the events the mapper handles", () => {
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ expect([...pi.handlers.keys()].sort()).toEqual([
+ "input",
+ "message_end",
+ "session_shutdown",
+ "session_start",
+ "tool_call",
+ "tool_result",
+ "user_bash",
+ ])
+ })
+
+ // Senpi publishes many more events than these, most of them execution-progress, turn-bookkeeping,
+ // provider-request and TUI internals. Subscribing to one would put Beacon in the path of every
+ // streaming token update.
+ test("does not subscribe to streaming or provider internals", () => {
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ for (const noisy of [
+ "message_update",
+ "message_start",
+ "before_provider_request",
+ "before_provider_headers",
+ "after_provider_response",
+ "context",
+ "tool_execution_start",
+ "tool_execution_update",
+ "tool_execution_end",
+ "turn_start",
+ "turn_end",
+ "agent_start",
+ "agent_end",
+ "agent_settled",
+ "resources_discover",
+ "model_select",
+ "system_prompt_change",
+ "thinking_level_select",
+ "session_compact",
+ "session_abort",
+ "input_disposition",
+ ]) {
+ expect(pi.handlers.has(noisy)).toBe(false)
+ }
+ })
+
+ test("forwards the event with its type intact", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire({ type: "input", text: "do the thing", source: "interactive" }, context())
+
+ expect(sent).toHaveLength(1)
+ expect(sent[0].type).toBe("input")
+ expect(sent[0].text).toBe("do the thing")
+ })
+
+ // Senpi's context hands the session id through an accessor, not as a bare field, so the envelope
+ // has to carry it or every event loses the field that groups a run.
+ test("lifts session identity off the context onto the envelope", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire({ type: "session_start", reason: "startup" }, context())
+
+ expect(sent[0].sessionId).toBe("sess-1")
+ expect(sent[0].cwd).toBe("/repo")
+ })
+
+ // Re-read per event rather than captured at load: `/new`, a resume, a fork and `/tree` all
+ // replace the session without reloading the extension, so a cached id would be silently wrong.
+ test("re-reads the session id for every event", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ let current = "sess-first"
+ const ctx = context({ sessionManager: { getSessionId: () => current } })
+
+ await pi.fire({ type: "session_start", reason: "startup" }, ctx)
+ current = "sess-second"
+ await pi.fire({ type: "session_start", reason: "new" }, ctx)
+
+ expect(sent.map((event) => event.sessionId)).toEqual(["sess-first", "sess-second"])
+ })
+
+ test("joins provider and model id into one model string", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire(
+ { type: "input", text: "hello" },
+ context({ model: { id: "claude-opus-5", provider: "anthropic" } }),
+ )
+
+ expect(sent[0].model).toBe("anthropic/claude-opus-5")
+ })
+
+ // A throwing accessor must cost the field, not the event. An extension that drops telemetry
+ // because one getter failed is worse than one that reports an event without its session id.
+ test("survives a context whose accessors throw", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire(
+ { type: "tool_call", toolName: "bash", toolCallId: "call-1" },
+ {
+ sessionManager: {
+ getSessionId: () => {
+ throw new Error("session gone")
+ },
+ },
+ },
+ )
+
+ expect(sent).toHaveLength(1)
+ expect(sent[0].type).toBe("tool_call")
+ expect(sent[0].sessionId).toBeUndefined()
+ })
+
+ test("survives a missing context entirely", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire({ type: "session_shutdown", reason: "quit" })
+
+ expect(sent).toHaveLength(1)
+ expect(sent[0].type).toBe("session_shutdown")
+ })
+
+ // Senpi's session events carry an AbortSignal and its message events carry live AgentMessage
+ // objects, so a payload JSON.stringify would reject is the normal case, not an edge case.
+ test("serializes an event containing a cycle", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ const selfReferential: Record<string, unknown> = { name: "loop" }
+ selfReferential.self = selfReferential
+
+ await pi.fire({ type: "tool_result", toolName: "bash", details: selfReferential }, context())
+
+ expect(sent).toHaveLength(1)
+ expect(JSON.stringify(sent[0])).toContain("tool_result")
+ })
+
+ test("drops functions and stringifies bigints rather than failing the send", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire(
+ {
+ type: "tool_result",
+ toolName: "bash",
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
+ onDone: () => {},
+ bytes: BigInt(42),
+ },
+ context(),
+ )
+
+ expect(sent[0].onDone).toBeUndefined()
+ expect(sent[0].bytes).toBe("42")
+ })
+
+ // Every handler must resolve to undefined. Senpi reads a returned object as a request to change
+ // behavior on several of these events -- `{ block: true }` on tool_call, `{ action: "transform" }`
+ // on input -- so a handler that returned anything would turn this observer into an enforcer.
+ test("handlers return nothing so Senpi never reads a directive", async () => {
+ captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ for (const [, handler] of pi.handlers) {
+ const result = await handler({ type: "tool_call", toolName: "bash" }, context())
+ expect(result).toBeUndefined()
+ }
+ })
+
+ // Event fields win over the lifted identity fields on a key collision, so a value Senpi reported
+ // is never overwritten by one Beacon derived.
+ test("event fields take precedence over lifted identity", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire({ type: "user_bash", command: "ls", cwd: "/other" }, context())
+
+ expect(sent[0].cwd).toBe("/other")
+ })
+
+ test("forwards a bash tool call with its command", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire(
+ { type: "tool_call", toolName: "bash", toolCallId: "call-1", input: { command: "ls -la" } },
+ context(),
+ )
+
+ expect((sent[0].input as Record<string, unknown>).command).toBe("ls -la")
+ })
+
+ test("forwards an edit tool result with its patch", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire(
+ {
+ type: "tool_result",
+ toolName: "edit",
+ toolCallId: "call-2",
+ input: { path: "/repo/a.ts" },
+ isError: false,
+ details: { patch: "@@ -1 +1 @@\n-old\n+new" },
+ },
+ context(),
+ )
+
+ const details = sent[0].details as Record<string, unknown>
+ expect((sent[0].input as Record<string, unknown>).path).toBe("/repo/a.ts")
+ expect(details.patch).toBe("@@ -1 +1 @@\n-old\n+new")
+ })
+
+ // Senpi exposes no `hasUI` the way Prime Agent renamed it -- both mean the same thing (whether the
+ // session had a user-facing surface at all), recorded under this runtime's own key so the two are
+ // never read as one field by a query that groups by harness.
+ test("records whether the session had a user-facing surface", async () => {
+ const sent = captureSends()
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ await pi.fire({ type: "input", text: "hello" }, context({ hasUI: false }))
+ await pi.fire({ type: "input", text: "hello" }, context())
+
+ expect(sent[0].omoHasUi).toBe(false)
+ // Absent rather than defaulted: a host that did not report it should not be recorded as one
+ // that reported "no".
+ expect(sent[1].omoHasUi).toBeUndefined()
+ })
+
+ // The runtime publishes no approval event, and Beacon refuses to synthesize one from a blocking
+ // tool handler. This pins the absence from the extension's side: the Go mapper cannot invent an
+ // approval for a runtime that never sends one.
+ test("subscribes to no approval event", () => {
+ const pi = fakePi()
+ createBeaconExtension().register(pi.api)
+
+ for (const name of [...pi.handlers.keys()]) {
+ expect(name).not.toContain("approval")
+ }
+ })
+})
diff --git a/plugins/omo-beacon/src/beacon.ts b/plugins/omo-beacon/src/beacon.ts
new file mode 100644
index 00000000..ec37df67
--- /dev/null
+++ b/plugins/omo-beacon/src/beacon.ts
@@ -0,0 +1,285 @@
+// __BEACON_MANAGED_MARKER__
+// Beacon endpoint telemetry extension for Senpi (the standalone edition of oh-my-openagent).
+// Managed by beacon endpoint hooks install --harness omo.
+
+// The argv Beacon's installer writes, as an array rather than a command line.
+//
+// An argv array is passed straight to the OS with no shell in between, which sidesteps quoting
+// entirely -- the same reason the Cline plugin uses one. Senpi runs as a Bun-compiled binary or
+// under Node depending on how it was installed, and on Windows as readily as on macOS, so there is
+// no one shell whose quoting rules would hold.
+const beaconArgv: string[] = ["__BEACON_ARGV__"]
+
+const debugEnabled = process.env.BEACON_OMO_DEBUG === "1"
+
+// A send that has not finished in this long is abandoned. Senpi awaits event handlers before
+// continuing the agent loop, so this is the worst case Beacon can add to a tool call.
+const sendTimeoutMs = 2000
+
+// How deep into an event the serializer will walk before giving up.
+const maxDepth = 8
+
+// Senpi's own event objects, narrowed to the fields Beacon reads.
+//
+// Declared here rather than imported from @earendil-works/pi-coding-agent on purpose -- and Senpi
+// really does publish under that name, because it is an in-flight fork of badlogic/pi-mono
+// (code-yeongyu/senpi) that kept the upstream package name. The installed file sits in
+// ~/.omo/agent/extensions with no node_modules beside it, and Senpi loads third-party extensions
+// through Bun's own importer or jiti, neither of which resolves a type-only import. A value import
+// would fail at load; a type import would resolve for nobody. Local structural types cost the
+// compile-time link to Senpi's definitions and buy a file that loads wherever Senpi does.
+type OmoEvent = Record<string, unknown> & { type: string }
+
+interface OmoSessionManager {
+ getSessionId?: () => string
+}
+
+interface OmoContext {
+ cwd?: string
+ sessionManager?: OmoSessionManager
+ model?: { id?: string; name?: string; provider?: string } | undefined
+ hasUI?: boolean
+}
+
+// The events Beacon subscribes to, and nothing else.
+//
+// Senpi's ExtensionEvent union has more than thirty members: provider-request and response
+// internals, streaming message and tool-execution updates, compaction, model-select, and TUI
+// plumbing among them. Most describe how the runtime got its work done rather than what the agent
+// did. Subscribing to all of them would fill the runtime log with rows no query asks for -- the
+// same reason the Cline mapper drops unrecognized stages -- and would put Beacon in the path of
+// every streaming token update.
+//
+// `tool_call` and `tool_result` are the pair that carries tool activity: the first names the tool
+// and its arguments before it runs, the second carries the outcome. `user_bash` is a command the
+// human ran with the `!` prefix, which no tool event covers. This is Pi's own set of seven exactly
+// -- Senpi kept the shape (the same `type` discriminator, the same toolName/input/details tool
+// events, the same assistant message parts, the same input/output/cacheRead/cacheWrite/cost usage
+// object) even where it added events Pi does not have, such as `tool_execution_start` and
+// `turn_start`/`turn_end`. Those additions describe execution progress and turn bookkeeping rather
+// than a new kind of agent action tool_call/tool_result do not already cover, so they are left
+// unsubscribed rather than adding a second, thinner tool-lifecycle signal beside the one Beacon
+// already records for every Pi-family runtime.
+//
+// Deliberately absent: any approval event. Senpi's `tool_call` handler can block a call, but that
+// is an extension deciding, not an operator being asked -- it exposes no operator approval decision
+// through this API (its permission-system builtin owns that prompt and does not publish it as an
+// extension event). Synthesizing an approval from a pre-tool notification would put a decision
+// nobody made into the log, so Beacon records these as tool activity and leaves approval telemetry
+// empty, exactly as it does for Pi and Prime Agent.
+//
+// Also absent, and not an omission: `user_python`. Oh My Pi added a `$` operator prefix that runs
+// Python outside the agent loop and subscribes to its event; Senpi forked pi-mono separately and
+// has no such prefix.
+const subscribedEvents = [
+ "session_start",
+ "session_shutdown",
+ "input",
+ "tool_call",
+ "tool_result",
+ "user_bash",
+ "message_end",
+] as const
+
+function debugLog(message: string, extra?: unknown) {
+ if (!debugEnabled) return
+ try {
+ // eslint-disable-next-line no-console
+ console.error("[beacon-omo]", message, extra ?? "")
+ } catch {
+ // Debug logging must stay best-effort.
+ }
+}
+
+// safeClone turns a Senpi event into something JSON.stringify accepts.
+//
+// Its events carry live objects: an AbortSignal on the session events, AgentMessage arrays holding
+// class instances, and tool inputs that are mutable by design. JSON.stringify throws on a circular
+// reference and on a bigint, and silently flattens an Error to {}, so each is handled here rather
+// than losing the whole payload to one bad field.
+//
+// Cycles are tracked along the current path and released on the way out, so an object that legibly
+// appears twice -- the same file path referenced from two places in one edit -- is kept both times.
+// A WeakSet that never released would drop the second occurrence as if it were a cycle.
+function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unknown {
+ if (value === null) return null
+ const kind = typeof value
+ if (kind === "function" || kind === "symbol" || kind === "undefined") return undefined
+ if (kind === "bigint") return String(value)
+ if (kind !== "object") return value
+ if (depth >= maxDepth) return undefined
+
+ const object = value as object
+ if (seen.has(object)) return undefined
+ if (value instanceof Error) return { name: value.name, message: value.message }
+ if (value instanceof Date) return value.toISOString()
+
+ seen.add(object)
+ try {
+ if (Array.isArray(value)) {
+ return value.map((item) => safeClone(item, depth + 1, seen))
+ }
+ const out: Record<string, unknown> = {}
+ for (const [key, nested] of Object.entries(value as Record<string, unknown>)) {
+ const cloned = safeClone(nested, depth + 1, seen)
+ if (cloned !== undefined) out[key] = cloned
+ }
+ return out
+ } finally {
+ seen.delete(object)
+ }
+}
+
+async function sendToBeacon(payload: Record<string, unknown>): Promise<void> {
+ // Flattened before anything else sees it, so every consumer of this function is handed plain
+ // data rather than a live Senpi event with cycles and functions still attached.
+ const safe = safeClone(payload)
+
+ const testSender = (globalThis as Record<symbol, unknown>)[Symbol.for("beacon.omo.testSender")]
+ if (typeof testSender === "function") {
+ await (testSender as (value: unknown) => unknown)(safe)
+ return
+ }
+
+ let body: string
+ try {
+ body = JSON.stringify(safe)
+ } catch (err) {
+ debugLog("payload could not be serialized", err)
+ return
+ }
+ if (!body) return
+
+ try {
+ // Imported lazily so a host without node:child_process fails to send rather than failing to
+ // load: a throwing import at module scope would surface to the user as a broken extension, and
+ // Senpi reports an extension that throws at load time rather than continuing without it.
+ const { spawn } = await import("node:child_process")
+ await new Promise<void>((resolve) => {
+ let settled = false
+ const finish = () => {
+ if (settled) return
+ settled = true
+ resolve()
+ }
+ let child
+ try {
+ child = spawn(beaconArgv[0], beaconArgv.slice(1), {
+ stdio: ["pipe", "ignore", "ignore"],
+ windowsHide: true,
+ })
+ } catch (err) {
+ debugLog("hook binary could not be spawned", err)
+ finish()
+ return
+ }
+ const timer = setTimeout(() => {
+ try {
+ child.kill()
+ } catch {
+ // Already gone.
+ }
+ debugLog("hook binary timed out", { type: payload?.type })
+ finish()
+ }, sendTimeoutMs)
+ // An unreferenced timer cannot keep Senpi alive at exit waiting on Beacon telemetry.
+ if (typeof timer.unref === "function") timer.unref()
+ const done = () => {
+ clearTimeout(timer)
+ finish()
+ }
+ child.on("error", (err) => {
+ debugLog("hook binary failed", err)
+ done()
+ })
+ child.on("close", done)
+ // Without this, a hook binary that exits before reading stdin turns an EPIPE into an
+ // unhandled error event in the host process. Beacon telemetry must never do that.
+ child.stdin?.on("error", () => {})
+ try {
+ child.stdin?.end(body)
+ } catch (err) {
+ debugLog("payload could not be written", err)
+ }
+ })
+ } catch (err) {
+ debugLog("send failed", err)
+ // Beacon telemetry must never interrupt Senpi execution.
+ }
+}
+
+// identity lifts the session and workspace fields Beacon needs to the top level of the envelope.
+//
+// Senpi's real ExtensionContext hands a plain-string `cwd` and a `model` object directly rather
+// than behind an accessor the way Prime Agent's does, but the session id is still read through
+// `sessionManager.getSessionId()` -- there is no bare `sessionId` field on the context -- and it is
+// read fresh per event rather than captured at load: `/new`, a resume, a fork and `/tree` all
+// replace the session without reloading the extension, so a cached id would be silently wrong.
+//
+// Every accessor is called defensively even though the shipped types mark them non-optional. A
+// third-party extension has no contract that a future Senpi release keeps them that way, and an
+// extension that loses its session id loses the field that groups every event of a run, so a
+// throwing accessor costs that field rather than the event.
+function identity(ctx: OmoContext | undefined): Record<string, unknown> {
+ const fields: Record<string, unknown> = {}
+ if (!ctx) return fields
+ try {
+ const sessionId = ctx.sessionManager?.getSessionId?.()
+ if (sessionId) fields.sessionId = sessionId
+ } catch (err) {
+ debugLog("session id could not be read", err)
+ }
+ if (ctx.cwd) fields.cwd = ctx.cwd
+ const model = ctx.model
+ if (model) {
+ // Senpi's Model carries an id and a provider separately. Joined here so the envelope's `model`
+ // is one string, matching how every other Beacon collection path reports it and how the Prime
+ // Agent extension already joins the same two fields.
+ const name = model.id || model.name
+ if (name) fields.model = model.provider ? `${model.provider}/${name}` : name
+ }
+ // Whether the session has a user-facing surface at all: false in print mode, true in the TUI and
+ // in RPC mode. An unattended run is not a run somebody was watching, which is what a reader needs
+ // to know before drawing a conclusion from an absent objection -- the same fact Prime Agent's
+ // `primeHasUi` records, under this runtime's own name so the two are never read as one field.
+ if (typeof ctx.hasUI === "boolean") fields.omoHasUi = ctx.hasUI
+ return fields
+}
+
+type OmoExtensionAPI = {
+ on: (event: string, handler: (event: OmoEvent, ctx: OmoContext) => Promise<void> | void) => void
+}
+
+// createBeaconExtension is exported for tests; Senpi loads the default export below.
+export function createBeaconExtension() {
+ const forward = async (event: OmoEvent, ctx: OmoContext) => {
+ try {
+ // The event is spread last so a field it carries itself wins over the context's: `user_bash`
+ // carries its own cwd, and that is the one describing this action.
+ await sendToBeacon({ ...identity(ctx), ...event })
+ } catch (err) {
+ // Unreachable in practice: sendToBeacon swallows its own failures. Kept because a handler
+ // that rejects is a handler that can break the run it was observing.
+ debugLog("handler failed", err)
+ }
+ }
+
+ return {
+ register(pi: OmoExtensionAPI) {
+ for (const name of subscribedEvents) {
+ // Every handler returns undefined. Beacon observes; it never blocks a tool call, patches a
+ // tool's arguments, rewrites a prompt, transforms input, or replaces a message. Senpi reads
+ // a returned object as a request to change behavior on several of these events, so
+ // returning nothing is what keeps this extension an observer. Enforcement lives behind the
+ // policy provider seam in the hook adapter, not here.
+ pi.on(name, forward)
+ }
+ },
+ // Exposed so a test can assert the subscription list without a live Senpi instance.
+ subscribedEvents: [...subscribedEvents],
+ }
+}
+
+export default function beaconExtension(pi: OmoExtensionAPI) {
+ createBeaconExtension().register(pi)
+}