Skip to content

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

fix(pi): record Pi-family tool results where threat rules read them

Kyle Elliott79e4031ca0cd
diff --git a/cli/beacon-hooks/cmd/endpoint_events.go b/cli/beacon-hooks/cmd/endpoint_events.go
index 7d4126ef..be7ca143 100644
--- a/cli/beacon-hooks/cmd/endpoint_events.go
+++ b/cli/beacon-hooks/cmd/endpoint_events.go
@@ -410,7 +410,10 @@ func applyIngestedToolResult(fields map[string]interface{}, action, toolName str
if len(toolResponse) == 0 {
return
}
- if !asymptoteobserve.IngestedContentAction(action) && !asymptoteobserve.IngestedContentToolName(toolName) {
+ // The target is read from the event's own tool.path, the field the engine reads it from.
+ target, _ := mutableChild(fields["tool"])["path"].(string)
+ if !asymptoteobserve.IngestedContentAction(action) && !asymptoteobserve.IngestedContentToolName(toolName) &&
+ !asymptoteobserve.IngestedContentTarget(target) {
return
}
genAI := mutableChild(fields["gen_ai"])
diff --git a/cli/beacon-hooks/cmd/omp_event_test.go b/cli/beacon-hooks/cmd/omp_event_test.go
index 61a0af5b..4161eac9 100644
--- a/cli/beacon-hooks/cmd/omp_event_test.go
+++ b/cli/beacon-hooks/cmd/omp_event_test.go
@@ -402,6 +402,173 @@ func TestOmpEventFailedToolIsRecordedAsAFailure(t *testing.T) {
}
}
+// ompTextBlocks is a tool result's content as Oh My Pi delivers it: a list of text blocks.
+func ompTextBlocks(texts ...string) []interface{} {
+ blocks := make([]interface{}, len(texts))
+ for i, text := range texts {
+ blocks[i] = map[string]interface{}{"type": "text", "text": text}
+ }
+ return blocks
+}
+
+// fieldsToolCallResult reads gen_ai.tool.call.result, the value e.gen_ai.tool.call.result_text is
+// derived from, or nil when the event carries none.
+func fieldsToolCallResult(event map[string]interface{}) interface{} {
+ genAI, _ := event["gen_ai"].(map[string]interface{})
+ tool, _ := genAI["tool"].(map[string]interface{})
+ call, _ := tool["call"].(map[string]interface{})
+ return call["result"]
+}
+
+// The payloads are Oh My Pi 18.6.3's, as a beacon-oracle run recorded them. Before this, every one
+// of these results was kept only under raw.omp, which no rule can match: the model read the file,
+// the page, the skill and the MCP reply, and nothing a detection reads held any of them.
+func TestOmpToolResultsAreRecordedWhereRulesReadThem(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ payload map[string]interface{}
+ action string
+ // marker is text the result carries; "" means the result is out of scope and not recorded.
+ marker string
+ check func(t *testing.T, event map[string]interface{})
+ }{
+ {
+ name: "file read", action: "file.read", marker: "File content marker BCN-5WWWUQ-D01",
+ payload: map[string]interface{}{
+ "toolName": "read", "input": map[string]interface{}{"path": "notes/canary.txt"},
+ "details": map[string]interface{}{"meta": map[string]interface{}{"source": map[string]interface{}{"type": "path", "value": "/home/agent/project/notes/canary.txt"}}},
+ "content": ompTextBlocks("[notes/canary.txt#5B60]\n1:File content marker BCN-5WWWUQ-D01."),
+ },
+ },
+ {
+ name: "web page through read", action: "tool.completed", marker: "Web page marker BCN-BALBZ7-D06",
+ payload: map[string]interface{}{
+ "toolName": "read", "input": map[string]interface{}{"path": "https://docs.fixture.test/guide"},
+ "details": map[string]interface{}{"url": "https://docs.fixture.test/guide", "meta": map[string]interface{}{"source": map[string]interface{}{"type": "url", "value": "https://docs.fixture.test/guide"}}},
+ "content": ompTextBlocks("URL: https://docs.fixture.test/guide\n\n---\n\n<p>Web page marker BCN-BALBZ7-D06.</p>"),
+ },
+ },
+ {
+ // A skill body is the skill author's file, read from disk: recorded as the read of that
+ // SKILL.md, the row the Skills lens and every other runtime's skill load are found by.
+ name: "skill body", action: "file.read", marker: "Skill body marker BCN-R5H6GL-C01",
+ payload: map[string]interface{}{
+ "toolName": "read", "input": map[string]interface{}{"path": "skill://oracle-probe"},
+ "details": map[string]interface{}{
+ "resolvedPath": "/home/agent/project/.omp/skills/oracle-probe/SKILL.md",
+ "meta": map[string]interface{}{"source": map[string]interface{}{"type": "internal", "value": "skill://oracle-probe"}},
+ },
+ "content": ompTextBlocks("[Skill file: /home/agent/project/.omp/skills/oracle-probe/SKILL.md]\n---\nname: oracle-probe\n---\nSkill body marker BCN-R5H6GL-C01.\n"),
+ },
+ check: func(t *testing.T, event map[string]interface{}) {
+ if got := nested(t, event, "file")["path"]; got != "/home/agent/project/.omp/skills/oracle-probe/SKILL.md" {
+ t.Fatalf("file.path = %v, want the SKILL.md the runtime read", got)
+ }
+ if got := nested(t, event, "tool")["path"]; got != "skill://oracle-probe" {
+ t.Fatalf("tool.path = %v, want the target as the model asked for it", got)
+ }
+ },
+ },
+ {
+ // Media is kept as its size and digest, the way the Claude Code hook records it: a stored
+ // copy of the bytes could never be decoded, and would spend the event's size budget.
+ name: "MCP result with media", action: "mcp.tool_invoked", marker: "Text block marker BCN-GRDUR6-D19",
+ payload: map[string]interface{}{
+ "toolName": "mcp__media_capture", "input": map[string]interface{}{"target": "screen"},
+ "details": map[string]interface{}{"serverName": "media", "mcpToolName": "capture"},
+ "content": []interface{}{
+ map[string]interface{}{"type": "text", "text": "Captured. Text block marker BCN-GRDUR6-D19."},
+ map[string]interface{}{"type": "image", "mimeType": "image/png", "data": "aW1hZ2UtYnl0ZXM="},
+ },
+ },
+ check: func(t *testing.T, event map[string]interface{}) {
+ blocks, _ := fieldsToolCallResult(event).(map[string]interface{})["content"].([]interface{})
+ image, _ := blocks[1].(map[string]interface{})
+ if _, kept := image["data"]; kept || image["bytes"] != float64(11) || image["sha256"] == "" {
+ t.Fatalf("image block = %v, want its size and digest in place of the bytes", image)
+ }
+ },
+ },
+ {
+ // What a failing server returned reached the model as well.
+ name: "failed MCP call", action: "tool.failed", marker: "MCP error marker",
+ payload: map[string]interface{}{
+ "toolName": "mcp__media_capture", "isError": true, "input": map[string]interface{}{"target": "screen"},
+ "details": map[string]interface{}{"serverName": "media", "mcpToolName": "capture"},
+ "content": ompTextBlocks("MCP error marker: capture device busy."),
+ },
+ },
+ {
+ // A shell's output has its own field; it is not recorded a second time as a result.
+ name: "shell output", action: "command.executed",
+ payload: map[string]interface{}{
+ "toolName": "bash", "input": map[string]interface{}{"command": "sh scripts/probe.sh"},
+ "details": map[string]interface{}{"wallTimeMs": 16.9},
+ "content": ompTextBlocks("Shell output marker BCN-MBS2GE-D03.\n\n\nWall time: 0.02 seconds"),
+ },
+ check: func(t *testing.T, event map[string]interface{}) {
+ command := nested(t, event, "command")
+ if command["output"] != "Shell output marker BCN-MBS2GE-D03.\n\n\nWall time: 0.02 seconds" || command["command"] != "sh scripts/probe.sh" {
+ t.Fatalf("command = %v, want the command and the output the model was given", command)
+ }
+ },
+ },
+ {
+ // A subagent's report is the runtime's own storage, not outside content.
+ name: "runtime resource", action: "tool.completed",
+ payload: map[string]interface{}{
+ "toolName": "read", "input": map[string]interface{}{"path": "agent://reviewer"},
+ "details": map[string]interface{}{
+ "resolvedPath": "/home/u/.omp/agent/sessions/s/agents/reviewer.md",
+ "meta": map[string]interface{}{"source": map[string]interface{}{"type": "internal", "value": "agent://reviewer"}},
+ },
+ "content": ompTextBlocks("Subagent report."),
+ },
+ },
+ {
+ // A write's result echoes what the agent itself produced.
+ name: "file write", action: "file.created",
+ payload: map[string]interface{}{
+ "toolName": "write", "input": map[string]interface{}{"path": "/repo/out.md", "content": "notes"},
+ "details": map[string]interface{}{"resolvedPath": "/repo/out.md"},
+ "content": ompTextBlocks("Wrote /repo/out.md."),
+ },
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ logPath := ompTestLog(t)
+ payload := cloneFields(tc.payload)
+ payload["type"], payload["toolCallId"], payload["sessionId"], payload["cwd"] = "tool_result", "call-1", "sess-1", "/home/agent/project"
+ if _, ok := payload["isError"]; !ok {
+ payload["isError"] = false
+ }
+ runHookWithInput(t, runOmpEvent, payload)
+
+ event := ompEventWithAction(t, logPath, tc.action)
+ result := fieldsToolCallResult(event)
+ if tc.marker == "" {
+ if result != nil {
+ t.Fatalf("gen_ai.tool.call.result = %v, want none for a result outside the scope", result)
+ }
+ } else {
+ if text := asymptoteobserve.ToolResultPlainText(result); !strings.Contains(text, tc.marker) {
+ t.Fatalf("gen_ai.tool.call.result = %v, want the content blocks the model read", result)
+ }
+ if content := nested(t, event, "content"); content["included"] != true {
+ t.Fatalf("content = %v, want the result's retention marker", content)
+ }
+ }
+ // raw keeps the payload verbatim whatever was promoted from it.
+ if !reflect.DeepEqual(nested(t, event, "raw", "omp")["content"], payload["content"]) {
+ t.Fatalf("raw.omp.content = %v, want the result as the runtime sent it", nested(t, event, "raw", "omp")["content"])
+ }
+ if tc.check != nil {
+ tc.check(t, event)
+ }
+ })
+ }
+}
+
func TestOmpEventEditResultRecordsTheUnifiedPatch(t *testing.T) {
logPath := ompTestLog(t)
patch := "--- a/main.go\n+++ b/main.go\n@@ -1 +1 @@\n-old\n+new\n"
diff --git a/cli/beacon-hooks/cmd/pi_event_test.go b/cli/beacon-hooks/cmd/pi_event_test.go
index 733dc5f8..10e95c72 100644
--- a/cli/beacon-hooks/cmd/pi_event_test.go
+++ b/cli/beacon-hooks/cmd/pi_event_test.go
@@ -2,6 +2,7 @@ package cmd
import (
"path/filepath"
+ "reflect"
"testing"
)
@@ -27,6 +28,33 @@ func piEventActions(t *testing.T, logPath string) []string {
return actions
}
+// The tool results are mapped by the code the whole Pi family shares, so Pi's bash output and the
+// file it read reach the same fields Oh My Pi's do, under the path as Pi was given it.
+func TestPiToolResultsAreRecordedWhereRulesReadThem(t *testing.T) {
+ logPath := piTestLog(t)
+ runHookWithInput(t, runPiEvent, map[string]interface{}{
+ "type": "tool_result", "toolName": "bash", "toolCallId": "call-1", "sessionId": "sess-1",
+ "input": map[string]interface{}{"command": "cat notes.md"}, "isError": false,
+ "content": ompTextBlocks("Pi shell output marker"),
+ })
+ runHookWithInput(t, runPiEvent, map[string]interface{}{
+ "type": "tool_result", "toolName": "read", "toolCallId": "call-2", "sessionId": "sess-1",
+ "input": map[string]interface{}{"path": "notes.md"}, "isError": false,
+ "content": ompTextBlocks("Pi file content marker"),
+ })
+
+ if got := nested(t, piEventWithAction(t, logPath, "command.executed"), "command")["output"]; got != "Pi shell output marker" {
+ t.Fatalf("command.output = %v, want the bash tool's output", got)
+ }
+ read := piEventWithAction(t, logPath, "file.read")
+ if got := nested(t, read, "file")["path"]; got != "notes.md" {
+ t.Fatalf("file.path = %v, want the path as Pi was given it", got)
+ }
+ if !reflect.DeepEqual(fieldsToolCallResult(read), map[string]interface{}{"content": ompTextBlocks("Pi file content marker")}) {
+ t.Fatalf("gen_ai.tool.call.result = %v, want the file the model read", fieldsToolCallResult(read))
+ }
+}
+
func piEventWithAction(t *testing.T, logPath, action string) map[string]interface{} {
t.Helper()
for _, event := range endpointEvents(t, logPath) {
diff --git a/cli/beacon-hooks/cmd/pi_family.go b/cli/beacon-hooks/cmd/pi_family.go
index 34e691b9..2bfd5cd2 100644
--- a/cli/beacon-hooks/cmd/pi_family.go
+++ b/cli/beacon-hooks/cmd/pi_family.go
@@ -491,12 +491,16 @@ func isURIScheme(s string) bool {
// On a runtime that resolves its tool paths, the runtime's own statement of the file is preferred,
// because it is the one path that is certainly right: it is absolute, and any selector or `~` in
// what the model wrote has already been resolved. A result whose source the runtime reports as a
-// URL or one of its own resources is not a file, whatever file backs it. A tool_call or an
+// URL or one of its own resources is not a file, whatever file backs it, except a skill, whose file
+// its author wrote (ompSkillFile). A tool_call or an
// approval, which happen before the runtime has resolved anything, resolve the target the same way
// the runtime will.
func (f piFamily) filePath(call piToolCall, input map[string]interface{}, target string) string {
if f.resolvesToolPaths {
target = ompStripPathMarker(target)
+ if path := ompSkillFile(target, call.details); path != "" {
+ return path
+ }
}
path := piFilePath(target)
if path == "" || !f.resolvesToolPaths {
@@ -512,13 +516,34 @@ func (f piFamily) filePath(call piToolCall, input map[string]interface{}, target
return ompToolPath(path, resolveCwd(input, f.platform), runtime.GOOS, ompIsWSL())
}
+// ompSkillFile returns the file a `read skill://…` result reports having read, or "".
+//
+// A skill is a file its author wrote, in the project's or the user's skill directories, and
+// `skill://<name>` is how the model reads its SKILL.md -- or, with a path after the name, a file the
+// skill bundles. That makes it the one internal resource whose backing file is not the runtime's
+// own storage, so it is recorded as the file read it is, under the path the result reports in
+// `resolvedPath`: the same row a read of that path records, and the SKILL.md read the Skills lens
+// and every other runtime's skill load are recognized by. A tool_call, an approval or a failed
+// read has no `resolvedPath`, and names no file.
+func ompSkillFile(target string, details map[string]interface{}) string {
+ scheme, _, ok := strings.Cut(target, "://")
+ if !ok || !strings.EqualFold(scheme, "skill") {
+ return ""
+ }
+ if path := getFirstStr(details, "resolvedPath"); filepath.IsAbs(path) {
+ return path
+ }
+ return ""
+}
+
// piResolvedPath returns the absolute path a tool result reports having read or written, and
// whether the result describes a file at all.
//
// Oh My Pi reports the path in three places, one per tool: a read names its source in
// `meta.source`, a write names the file in `resolvedPath`, and an edit of one file names it in
// `path`. A read whose source is a URL or an `internal` resource is not a file read, even when a
-// file in the runtime's own storage backs it and `resolvedPath` names that file.
+// file in the runtime's own storage backs it and `resolvedPath` names that file. A skill, whose
+// file is not the runtime's, is resolved before this; see ompSkillFile.
func piResolvedPath(details map[string]interface{}) (string, bool) {
var path string
switch source := firstMap(firstMap(details, "meta"), "source"); getFirstStr(source, "type") {
@@ -896,8 +921,18 @@ func (f piFamily) toolResultEvents(input map[string]interface{}, fields map[stri
f.applyPythonResult(fields, name, input)
kernelWrites := f.pythonDiffEvents(name, input, fields)
+ // The result is what the tool returned to the model: a list of content blocks, which the
+ // runtime also keeps verbatim under `raw`. Recorded the way every capture path records one, and
+ // only where the shared scope puts it -- outside content and a shell's output -- because a
+ // write or an edit echoes what the agent itself produced.
+ blocks, _ := input["content"].([]interface{})
+ response := contentBlockResponse(blocks)
+ applyShellOutput(fields, name, blocks)
+
if isErr, ok := input["isError"].(bool); ok && isErr {
fields["error"] = map[string]interface{}{"type": "tool_error"}
+ // What a failing MCP server or web page returned still reached the model.
+ applyIngestedToolResult(fields, "tool.failed", name, response)
return append(f.one("tool.failed", "tool", "high", "tool failed", fields), kernelWrites...)
}
@@ -924,9 +959,28 @@ func (f piFamily) toolResultEvents(input map[string]interface{}, fields map[stri
action, category = "tool.completed", "tool"
}
}
+ applyIngestedToolResult(fields, action, name, response)
return append(f.one(action, category, "info", piToolMessageSuffix(action), fields), kernelWrites...)
}
+// applyShellOutput records what the agent's `bash` tool printed as command.output, the field the
+// risky-command and exfiltration rules match on. The runtime reports no exit code, so none is
+// recorded, and the output is the text the model was given, the runtime's own trailing notes (Oh My
+// Pi's `Wall time`) included. The retention marker stays the command's: it is the more specific
+// claim, the same precedence applyPythonResult uses.
+func applyShellOutput(fields map[string]interface{}, toolName string, blocks []interface{}) {
+ if !strings.EqualFold(toolName, "bash") {
+ return
+ }
+ output := asymptoteobserve.ToolResultPlainText(blocks)
+ if output == "" {
+ return
+ }
+ command := mutableChild(fields["command"])
+ command["output"] = output
+ fields["command"] = command
+}
+
// applyPythonMarker notes that a command block holds Python rather than a shell command line.
//
// Applied to the caller's fields rather than inside toolFields, which returns a fresh map that
diff --git a/cli/beacon-hooks/cmd/post_tool.go b/cli/beacon-hooks/cmd/post_tool.go
index b0ccd3c1..5655b2f5 100644
--- a/cli/beacon-hooks/cmd/post_tool.go
+++ b/cli/beacon-hooks/cmd/post_tool.go
@@ -397,15 +397,10 @@ func resolveToolResponse(input map[string]interface{}) map[string]interface{} {
}
}
}
- // Claude Code sends an MCP tool's result as a bare list of content blocks. It is kept under
- // "content", where an MCP CallToolResult holds its blocks, so the result reads the same
- // whichever path recorded it. A list from any other runtime is read the same way: until this,
- // every list response was dropped. An empty list is a result with no content.
+ // Claude Code sends an MCP tool's result as a bare list of content blocks. A list from any
+ // other runtime is read the same way: until this, every list response was dropped.
if content, ok := input["tool_response"].([]interface{}); ok {
- if len(content) == 0 {
- return nil
- }
- return map[string]interface{}{"content": asymptoteobserve.SummarizeEncodedContent(content)}
+ return contentBlockResponse(content)
}
// If tool_response is a plain string, wrap it for downstream compatibility
if respStr, ok := input["tool_response"].(string); ok && respStr != "" {
@@ -414,6 +409,17 @@ func resolveToolResponse(input map[string]interface{}) map[string]interface{} {
return nil
}
+// contentBlockResponse is a tool result that arrived as a list of content blocks, in the shape every
+// capture path records one: under "content", where an MCP CallToolResult holds its blocks, so a
+// result reads the same whichever path or runtime recorded it, with each block's encoded bytes
+// replaced by their size and digest. An empty list is a result with no content.
+func contentBlockResponse(blocks []interface{}) map[string]interface{} {
+ if len(blocks) == 0 {
+ return nil
+ }
+ return map[string]interface{}{"content": asymptoteobserve.SummarizeEncodedContent(blocks)}
+}
+
func emitPostToolObserved(logger *logging.Logger, input map[string]interface{}) {
if platformFlag == "cursor" && emitCursorPostHookObserved(logger, input) {
return
diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdx
index f77eae49..b9e5db1e 100644
--- a/docs/changelog/cli.mdx
+++ b/docs/changelog/cli.mdx
@@ -13,6 +13,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.
- **Model-visible skill listings** · Claude transcript sync and the Oh My Pi extension capture only the skill index the model was shown, as a `session.context` event rather than an operator prompt. `gen_ai.system_instructions` holds one OpenTelemetry GenAI `text` part per skill, so each skill's description is limited on its own and none is cut off by the ones before it. A new `system_context` block says the event is a skill index and names each skill with the `skill_name_hash` the configuration inventory uses; it is metadata, so metadata-only forwarding keeps it while removing the text. Invoked skill bodies and unrelated system instructions remain outside this signal.
- **New rule field `e.gen_ai.system_instructions_text`** · Threat rules can match the text of `gen_ai.system_instructions`, whether Beacon recorded it or an OTLP producer reported it. Like `e.gen_ai.tool.call.result_text`, it is derived by the engine from text parts only, redacted, capped at 4 KB per part, and empty when content was not retained. `e.system_context.kind` and `e.system_context.skills` select a skill index without matching its text.
+- **Pi-family tool results reach the rules** · Oh My Pi, Pi, Prime Agent and Senpi kept every tool result only under `raw`, which no rule can match. A file or skill the agent read, a web page fetched through Oh My Pi's `read`, and an MCP reply are now in `gen_ai.tool.call.result`, matched by `e.gen_ai.tool.call.result_text`, and `bash` output is in `command.output`. The scope is the one every runtime shares, which now also includes any result whose `tool.path` is an http or https URL. An Oh My Pi `skill://` read is recorded as a `file.read` of the `SKILL.md` it read, and media in an MCP reply is kept as its size and SHA-256.
- **System instructions are always a list of parts** · The collector now writes an OTLP `gen_ai.system_instructions` that arrives as a plain string or a single part as a parts list, so the field has one shape on every event and a typed index such as the Elastic pack's maps it consistently.
---
diff --git a/docs/runtimes/oh-my-pi.mdx b/docs/runtimes/oh-my-pi.mdx
index 6866d230..3c6cfd69 100644
--- a/docs/runtimes/oh-my-pi.mdx
+++ b/docs/runtimes/oh-my-pi.mdx
@@ -100,9 +100,9 @@ Unlike Pi, a project-level install needs no trust prompt: Oh My Pi loads `.omp`
| Extension install, status, uninstall, and repair | Supported |
| Session lifecycle | Supported. `session.started` and `session.ended` |
| Prompts | Supported. `prompt.submitted`. In the terminal and over RPC it comes from Oh My Pi's `input` event and records whether the input was typed, delivered over RPC, or injected by another extension. Print (`omp -p`) and ACP sessions never emit `input`, so there it comes from the user message Oh My Pi delivers to the model, marked `raw.omp_prompt_origin: message_end`; see Known gaps for how that text differs |
-| Tool use | Supported. `tool.invoked` before execution, then `tool.completed` or `tool.failed`, joined by `gen_ai.tool.call.id` |
+| Tool use | Supported. `tool.invoked` before execution, then `tool.completed` or `tool.failed`, joined by `gen_ai.tool.call.id`. The result of a tool that brought outside content into the session (a file read, a web page, a skill, an MCP reply) is kept in `gen_ai.tool.call.result`, which rules match as `e.gen_ai.tool.call.result_text`; see [tool results](#tool-results) |
| **Approval decisions** | **Supported.** `approval.requested`, `approval.allowed`, and `approval.denied` from real operator prompts, carrying the command or file being decided on, the approval mode the session was running under, and the tool call id of the execution they decided. This is the capability Oh My Pi has that upstream Pi does not |
-| Commands | Supported. `command.executed` for the agent's `bash` tool, for commands you run with the `!` prefix, and for code you run with the `$` Python prefix — the last two marked as operator-initiated |
+| Commands | Supported. `command.executed` for the agent's `bash` tool, with its output in `command.output`, for commands you run with the `!` prefix, and for code you run with the `$` Python prefix — the last two marked as operator-initiated |
| File activity | Supported. `file.read`, `file.created`, and `file.modified` under the absolute path Oh My Pi resolved, with the edit's diff. An edit that changes several files records one `file.modified` per file. Only filesystem targets count: see [file paths](#file-paths) and [tool devices and URIs](#tool-devices-and-uris) |
| MCP activity | Supported. `tool.invoked` then `mcp.tool_invoked`, whether the model called the tool directly or through its `xd://` device. `mcp.server` and `mcp.tool` are the server's configured name and the tool's own name, read from the result Oh My Pi reports. A `read mcp://<uri>` is recorded as an MCP `resources/read` with `mcp.resource.uri` |
| Agent reasoning | Supported. `agent.reasoning` from an assistant message's thinking parts, in the OTel GenAI reasoning-part shape |
@@ -130,7 +130,11 @@ Oh My Pi's default edit format can change several files in one call. Such an edi
### Tool devices and URIs
-Oh My Pi's `read` and `write` tools take URIs as well as paths. `https://` fetches a web page, and the runtime's own schemes (`artifact://`, `agent://`, `skill://`, `local://`, `proc://`, `omp://`, `xd://`, and others) address its resources: a spilled tool output, a subagent's report, a skill, a background job, its own docs, a tool device. None of these is file activity. Beacon records them as `tool.invoked` and `tool.completed` with the URI in `tool.path` and no `file` block, the same way every other runtime records a web fetch or a resource read. A `file://` URI is recorded as the path it names. `read mcp://<uri>` reads an MCP resource and is recorded as an MCP call, with no server named: Oh My Pi does not report which server served it. A resource URI whose scheme Oh My Pi does not handle itself is also sent to MCP, but Beacon cannot tell those from the runtime's own schemes, and records them as plain tool events.
+Oh My Pi's `read` and `write` tools take URIs as well as paths. `https://` fetches a web page, and the runtime's own schemes (`artifact://`, `agent://`, `skill://`, `local://`, `proc://`, `omp://`, `xd://`, and others) address its resources: a spilled tool output, a subagent's report, a skill, a background job, its own docs, a tool device. Beacon records them as `tool.invoked` and `tool.completed` with the URI in `tool.path` and no `file` block, the same way every other runtime records a web fetch or a resource read. A `file://` URI is recorded as the path it names. A `skill://` read is the exception among the runtime's schemes, because a skill is a file its author wrote rather than the runtime's own storage: its result is recorded as a `file.read` of the `SKILL.md` (or the bundled file) Oh My Pi reports having read, with the URI still in `tool.path`. `read mcp://<uri>` reads an MCP resource and is recorded as an MCP call, with no server named: Oh My Pi does not report which server served it. A resource URI whose scheme Oh My Pi does not handle itself is also sent to MCP, but Beacon cannot tell those from the runtime's own schemes, and records them as plain tool events.
+
+### Tool results
+
+A tool's result is what Oh My Pi returned to the model, and the whole payload is kept in `raw.omp`. The results that brought content from outside the session into it are also recorded where threat rules match them, in `gen_ai.tool.call.result`, read by rules as `e.gen_ai.tool.call.result_text`: a file or a skill the agent read, a web page fetched through `read`, and an MCP tool's reply, a failed call's included. These are where indirect prompt injection arrives. The scope is the one every capture path shares, so a rule written against another runtime's file reads or MCP replies matches Oh My Pi's. The `bash` tool's output is recorded as `command.output`, including the `Wall time` line Oh My Pi appends. A write's or an edit's result, a subagent's report, and the runtime's other resources are not recorded again, because they echo what the agent itself produced. Images and audio in an MCP reply are kept as their size and SHA-256, not their bytes.
Writing JSON to `xd://<tool>` is how the model calls a tool that Oh My Pi exposes as a device. That includes every MCP tool. Beacon records the device as the tool that ran, under the device's name, so an MCP call through a device produces the same `tool.invoked` and `mcp.tool_invoked` pair as one called directly. Oh My Pi reports most device calls twice: once as the `write`, and once from inside the dispatch as the device's own call, under the same tool call id. Beacon keeps one of them. Reading `xd://<tool>`, or writing `?` to it, fetches the device's documentation and is recorded as the `read` or `write` it is.
diff --git a/docs/runtimes/pi.mdx b/docs/runtimes/pi.mdx
index 536950e0..ebfa43ea 100644
--- a/docs/runtimes/pi.mdx
+++ b/docs/runtimes/pi.mdx
@@ -92,8 +92,8 @@ Install writes one file and refuses to touch a `beacon.ts` it did not write, so
| Session lifecycle | Supported. `session.started` and `session.ended`, carrying why the session started or stopped |
| Prompts | Supported. `prompt.submitted`, with whether the input was typed, delivered over RPC, or injected by another extension |
| Tool use | Supported. `tool.invoked` before execution, then `tool.completed` or `tool.failed` |
-| Commands | Supported. `command.executed` for the agent's `bash` tool and for commands you run with Pi's `!` prefix, which are marked as operator-initiated |
-| File activity | Supported. `file.read`, `file.created`, and `file.modified`, with the unified patch on an edit |
+| Commands | Supported. `command.executed` for the agent's `bash` tool, with its output in `command.output`, and for commands you run with Pi's `!` prefix, which are marked as operator-initiated |
+| File activity | Supported. `file.read`, `file.created`, and `file.modified`, with the unified patch on an edit. A read's result is kept in `gen_ai.tool.call.result`, which rules match as `e.gen_ai.tool.call.result_text` |
| Agent reasoning | Supported. `agent.reasoning` from an assistant message's thinking parts, in the OTel GenAI reasoning-part shape |
| Token usage and cost | Supported. `token.usage` normalized into `gen_ai.usage`, including cache and reasoning tokens and runtime-reported cost |
| Approval decisions | Not available. Pi exposes no operator approval decision to observe. See [Known gaps](#known-gaps) |
diff --git a/docs/runtimes/prime-agent.mdx b/docs/runtimes/prime-agent.mdx
index 99c8f43d..88e0bdc0 100644
--- a/docs/runtimes/prime-agent.mdx
+++ b/docs/runtimes/prime-agent.mdx
@@ -110,7 +110,7 @@ Install writes one file and refuses to touch a `beacon.ts` it did not write, so
| Session lifecycle | Supported. `session.started` and `session.ended`, carrying why the session started or stopped — a fork and a resume both produce a session with history behind it |
| Prompts | Supported. `prompt.submitted`, with whether the input was typed, delivered over RPC, or injected by another extension |
| Tool use | Supported. `tool.invoked` before execution, then `tool.completed` or `tool.failed` |
-| Commands | Supported. `command.executed` for each `ipython` cell, for the optional `bash` tool, and for commands you run with the `!` prefix, which are marked as operator-initiated. A cell's result carries its captured output, the runtime's own duration, and its status |
+| Commands | Supported. `command.executed` for each `ipython` cell, for the optional `bash` tool, and for commands you run with the `!` prefix, which are marked as operator-initiated. A cell's result carries its captured output, the runtime's own duration, and its status, and a `bash` call's output is in `command.output` |
| File activity | Supported. `file.modified` per file a kernel cell rewrote, with the unified patch; plus `file.modified` for the optional `edit` tool, carrying the unified diff it reports |
| Agent reasoning | Supported. `agent.reasoning` from an assistant message's thinking parts, in the OTel GenAI reasoning-part shape |
| Token usage and cost | Supported. `token.usage` normalized into `gen_ai.usage`, including cache and reasoning tokens and runtime-reported cost |
diff --git a/docs/runtimes/senpi.mdx b/docs/runtimes/senpi.mdx
index 8189fbf3..d17237e7 100644
--- a/docs/runtimes/senpi.mdx
+++ b/docs/runtimes/senpi.mdx
@@ -101,8 +101,8 @@ Install writes one file and refuses to touch a `beacon.ts` it did not write, so
| Session lifecycle | Supported. `session.started` and `session.ended`, carrying why the session started or stopped — a fork and a resume both produce a session with history behind it |
| Prompts | Supported. `prompt.submitted`, with whether the input was typed, delivered over RPC, or injected by another extension |
| Tool use | Supported. `tool.invoked` before execution, then `tool.completed` or `tool.failed` |
-| Commands | Supported. `command.executed` for the `bash` tool and for commands you run with the `!` prefix, which are marked as operator-initiated |
-| File activity | Supported. `file.read`, `file.created`, and `file.modified` for the `read`, `write`, and `edit` tools, the last carrying the unified patch |
+| Commands | Supported. `command.executed` for the `bash` tool, with its output in `command.output`, and for commands you run with the `!` prefix, which are marked as operator-initiated |
+| File activity | Supported. `file.read`, `file.created`, and `file.modified` for the `read`, `write`, and `edit` tools, the last carrying the unified patch. A read's result is kept in `gen_ai.tool.call.result`, which rules match as `e.gen_ai.tool.call.result_text` |
| Agent reasoning | Supported. `agent.reasoning` from an assistant message's thinking parts, in the OTel GenAI reasoning-part shape |
| Token usage and cost | Supported. `token.usage` normalized into `gen_ai.usage`, including cache and reasoning tokens and runtime-reported cost |
| Approval decisions | Not available. Senpi exposes no operator approval decision through its extension API. See [Known gaps](#known-gaps) |
diff --git a/pkg/asymptoteobserve/threatrules/fields.go b/pkg/asymptoteobserve/threatrules/fields.go
index f04049e6..3a429a32 100644
--- a/pkg/asymptoteobserve/threatrules/fields.go
+++ b/pkg/asymptoteobserve/threatrules/fields.go
@@ -138,8 +138,9 @@ func RenderFieldsMarkdown() string {
// rendered. TestEveryDerivedFieldIsDocumented requires one per field.
var derivedFieldDocs = map[string]string{
ToolResultTextPath: "`gen_ai.tool.call.result` as text, only on read-type tool\n" +
- " results (`file.read`, `mcp.tool_invoked`, MCP-named tools, web fetch/search tools) whose\n" +
- " content was retained. String leaves of an object or list result are joined one per line;\n" +
+ " results (`file.read`, `mcp.tool_invoked`, MCP-named tools, web fetch/search tools, a\n" +
+ " `tool.path` that is an http(s) URL) whose content was retained. String leaves of an\n" +
+ " object or list result are joined one per line;\n" +
" content blocks in a list contribute their text without metadata or encoded bytes.\n" +
fmt.Sprintf(" Capped at %d bytes and secret-redacted like other retained text; empty otherwise.", ToolResultTextLimit),
SystemInstructionsTextPath: "`gen_ai.system_instructions` as text: the `content` of each\n" +
diff --git a/pkg/asymptoteobserve/threatrules/toolresult.go b/pkg/asymptoteobserve/threatrules/toolresult.go
index 7033b774..16fa0830 100644
--- a/pkg/asymptoteobserve/threatrules/toolresult.go
+++ b/pkg/asymptoteobserve/threatrules/toolresult.go
@@ -20,7 +20,8 @@ const ToolResultTextLimit = asymptoteobserve.DefaultStringLimit
//
// - The event carries gen_ai.tool.call.result.
// - The event is a read-type tool result: file.read, mcp.tool_invoked, a tool named as an
-// MCP tool (mcp__server__tool, MCP:tool), or a web fetch/search tool. These are the
+// MCP tool (mcp__server__tool, MCP:tool), a web fetch/search tool, or a tool whose
+// tool.path is an http or https URL. These are the
// results whose content came from somewhere other than the agent itself, which is where
// indirect prompt injection arrives. A shell command's output already has its own field
// (command.output), and a write or edit echoes what the agent produced.
@@ -96,6 +97,9 @@ func toolResultIsIngestedContent(event asymptoteobserve.Event) bool {
if event.MCP != nil && (event.MCP.Server != "" || event.MCP.Tool != "") {
return true
}
+ if event.Tool != nil && asymptoteobserve.IngestedContentTarget(event.Tool.Path) {
+ return true
+ }
for _, name := range toolNames(event) {
if asymptoteobserve.IngestedContentToolName(name) {
return true
diff --git a/pkg/asymptoteobserve/threatrules/toolresult_test.go b/pkg/asymptoteobserve/threatrules/toolresult_test.go
index a7409e04..5300a164 100644
--- a/pkg/asymptoteobserve/threatrules/toolresult_test.go
+++ b/pkg/asymptoteobserve/threatrules/toolresult_test.go
@@ -123,6 +123,26 @@ func TestToolResultTextEmptyWhenContentNotRetained(t *testing.T) {
})
}
+// Oh My Pi's `read` fetches a URL as well as a file, and is recorded as a `read` with the URL as its
+// target. Only the target places the page in scope: the action is tool.completed and the name is
+// the file tool's.
+func TestToolResultTextReadsAResultFromAWebTarget(t *testing.T) {
+ for path, want := range map[string]bool{
+ "https://docs.example/guide": true, "HTTP://docs.example/guide": true,
+ "/repo/NOTES.md": false, "file:///repo/NOTES.md": false, "skill://guide": false, "https://": false,
+ } {
+ t.Run(path, func(t *testing.T) {
+ event := toolResultEvent("tool.completed", "read", map[string]interface{}{"content": []interface{}{
+ map[string]interface{}{"type": "text", "text": injectedNotes},
+ }})
+ event.Tool.Path = path
+ if got := mustMatch(t, `e.gen_ai.tool.call.result_text.matches("SYSTEM OVERRIDE")`, event); got != want {
+ t.Fatalf("matched = %v, want %v; derived text = %q", got, want, ToolResultText(event))
+ }
+ })
+ }
+}
+
func TestToolResultTextNotPopulatedForOtherActions(t *testing.T) {
cases := map[string]asymptoteobserve.Event{
"command.executed": toolResultEvent("command.executed", "Bash", injectedNotes),
diff --git a/pkg/asymptoteobserve/toolresult.go b/pkg/asymptoteobserve/toolresult.go
index 2a58dec2..a265be1c 100644
--- a/pkg/asymptoteobserve/toolresult.go
+++ b/pkg/asymptoteobserve/toolresult.go
@@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"maps"
+ "net/url"
"slices"
"strings"
)
@@ -14,10 +15,10 @@ import (
// from outside the agent -- a file it read, an MCP server's reply -- and so is where indirect
// prompt injection arrives.
//
-// This and IngestedContentToolName are the one definition of that scope. The threat-rules engine
-// reads them to decide which events expose gen_ai.tool.call.result_text, and the hook adapter
-// reads them to decide which tool results it records, so a capture path cannot drop a result the
-// engine would have matched on, or record one the engine ignores.
+// This, IngestedContentToolName and IngestedContentTarget are the one definition of that scope.
+// The threat-rules engine reads them to decide which events expose gen_ai.tool.call.result_text,
+// and the hook adapter reads them to decide which tool results it records, so a capture path
+// cannot drop a result the engine would have matched on, or record one the engine ignores.
func IngestedContentAction(action string) bool {
switch action {
case "file.read", "mcp.tool_invoked":
@@ -45,6 +46,20 @@ func IngestedContentToolName(name string) bool {
return false
}
+// IngestedContentTarget reports whether a tool's target, its tool.path, is a web address: an
+// http or https URL with a host. Whatever the tool is called, its result came from that server.
+//
+// It exists for the runtimes whose general-purpose tools also fetch: Oh My Pi's `read` takes a URL
+// as well as a path and returns the page, recorded as a `read` with the URL as its target, which
+// neither the action nor the tool's name places in scope.
+func IngestedContentTarget(target string) bool {
+ parsed, err := url.Parse(strings.TrimSpace(target))
+ if err != nil || parsed.Host == "" {
+ return false
+ }
+ return strings.EqualFold(parsed.Scheme, "http") || strings.EqualFold(parsed.Scheme, "https")
+}
+
// ToolResultPlainText renders a tool result as text: a string as is; for an object or list (a
// hook's tool_response, an MCP content-block list), every string it contains, with maps in sorted
// key order, one per line. Numbers, booleans and nulls are sizes, counts and flags rather than
diff --git a/pkg/asymptoteobserve/toolresult_test.go b/pkg/asymptoteobserve/toolresult_test.go
index ea72a3fa..14d6bf09 100644
--- a/pkg/asymptoteobserve/toolresult_test.go
+++ b/pkg/asymptoteobserve/toolresult_test.go
@@ -27,6 +27,15 @@ func TestIngestedContentScope(t *testing.T) {
t.Errorf("IngestedContentToolName(%q) = %v, want %v", name, got, want)
}
}
+ for target, want := range map[string]bool{
+ "https://docs.example/guide": true, "HTTP://docs.example/guide": true, " https://x.test ": true,
+ "https://": false, "/repo/NOTES.md": false, "notes.md": false, "file:///repo/NOTES.md": false,
+ "skill://review": false, "mcp://notes/1": false, "ftp://files.example/a": false, "": false,
+ } {
+ if got := IngestedContentTarget(target); got != want {
+ t.Errorf("IngestedContentTarget(%q) = %v, want %v", target, got, want)
+ }
+ }
}
func TestToolResultPlainText(t *testing.T) {
diff --git a/spec/threat-rules/FIELDS.md b/spec/threat-rules/FIELDS.md
index 28c65282..5848053f 100644
--- a/spec/threat-rules/FIELDS.md
+++ b/spec/threat-rules/FIELDS.md
@@ -177,7 +177,8 @@ never written to or read from the log, so a fixture sets the source field, not t
runtime-provided instructions such as a skill index, never operator prompt text.
Each part is capped at 4096 bytes and secret-redacted like other retained text; empty otherwise.
- `e.gen_ai.tool.call.result_text`: `gen_ai.tool.call.result` as text, only on read-type tool
- results (`file.read`, `mcp.tool_invoked`, MCP-named tools, web fetch/search tools) whose
- content was retained. String leaves of an object or list result are joined one per line;
+ results (`file.read`, `mcp.tool_invoked`, MCP-named tools, web fetch/search tools, a
+ `tool.path` that is an http(s) URL) whose content was retained. String leaves of an
+ object or list result are joined one per line;
content blocks in a list contribute their text without metadata or encoded bytes.
Capped at 4096 bytes and secret-redacted like other retained text; empty otherwise.
diff --git a/spec/threat-rules/SPEC.md b/spec/threat-rules/SPEC.md
index bf55601f..3f32051d 100644
--- a/spec/threat-rules/SPEC.md
+++ b/spec/threat-rules/SPEC.md
@@ -150,7 +150,8 @@ the steps in both orders still fires once. A single event never satisfies two st
the same way. Objects outside a list are never treated as content blocks. It is
the empty string unless the event is a read-type tool result — `event.action` is
`file.read` or `mcp.tool_invoked`, `mcp.server`/`mcp.tool` is set, or the tool is named
- as an MCP tool (`mcp__…`, `MCP:…`) or a web fetch/search tool — and its `content`
+ as an MCP tool (`mcp__…`, `MCP:…`) or a web fetch/search tool, or `tool.path` is an
+ `http` or `https` URL with a host — and its `content`
marker, if present, is `included` with a `retention` other than `metadata`. The
reference derivation is `threatrules.ToolResultText`.
- `e.gen_ai.system_instructions_text` is derived under the same rules (computed, never