The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
feat(cursor): record cloud agents' reasoning, replies and turn ends
shukieshah48cd2c5ef5f3
diff --git a/.cursor/hooks.json b/.cursor/hooks.jsonindex 3520ec5f..cd641182 100644--- a/.cursor/hooks.json+++ b/.cursor/hooks.json@@ -1,6 +1,16 @@{"version": 1,"hooks": {+ "afterAgentResponse": [+ {+ "command": "BEACON_ENDPOINT_MODE=1 BEACON_ORIGIN=cloud BEACON_RUN_PROVIDER=cursor_cloud BEACON_RUN_EPHEMERAL=true BEACON_ENDPOINT_LOG='/tmp/beacon/runtime.jsonl' '/tmp/beacon/bin/beacon-hooks' --platform cursor agent-response"+ }+ ],+ "afterAgentThought": [+ {+ "command": "BEACON_ENDPOINT_MODE=1 BEACON_ORIGIN=cloud BEACON_RUN_PROVIDER=cursor_cloud BEACON_RUN_EPHEMERAL=true BEACON_ENDPOINT_LOG='/tmp/beacon/runtime.jsonl' '/tmp/beacon/bin/beacon-hooks' --platform cursor agent-thought"+ }+ ],"afterFileEdit": [{"command": "BEACON_ENDPOINT_MODE=1 BEACON_ORIGIN=cloud BEACON_RUN_PROVIDER=cursor_cloud BEACON_RUN_EPHEMERAL=true BEACON_ENDPOINT_LOG='/tmp/beacon/runtime.jsonl' '/tmp/beacon/bin/beacon-hooks' --platform cursor post-tool"@@ -42,6 +52,11 @@"command": "BEACON_ENDPOINT_MODE=1 BEACON_ORIGIN=cloud BEACON_RUN_PROVIDER=cursor_cloud BEACON_RUN_EPHEMERAL=true BEACON_ENDPOINT_LOG='/tmp/beacon/runtime.jsonl' '/tmp/beacon/bin/beacon-hooks' --platform cursor cursor-event"}],+ "stop": [+ {+ "command": "BEACON_ENDPOINT_MODE=1 BEACON_ORIGIN=cloud BEACON_RUN_PROVIDER=cursor_cloud BEACON_RUN_EPHEMERAL=true BEACON_ENDPOINT_LOG='/tmp/beacon/runtime.jsonl' '/tmp/beacon/bin/beacon-hooks' --platform cursor stop"+ }+ ],"subagentStart": [{"command": "BEACON_ENDPOINT_MODE=1 BEACON_ORIGIN=cloud BEACON_RUN_PROVIDER=cursor_cloud BEACON_RUN_EPHEMERAL=true BEACON_ENDPOINT_LOG='/tmp/beacon/runtime.jsonl' '/tmp/beacon/bin/beacon-hooks' --platform cursor subagent-start"diff --git a/CLAUDE.md b/CLAUDE.mdindex 1fb92ca9..49d77cd9 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -47,7 +47,7 @@ Do not recreate or depend on removed `asymptote` mirror trees. Keep new work focSupported runtime surfaces today:- Claude Code and Codex CLI use local OpenTelemetry settings, and `beacon endpoint install` writes their user-level hooks alongside those settings (`otlpTargetCarriesHook` in `cli/beacon/cmd/endpoint_targets.go`), because Claude's OTLP export has no session lifecycle, file activity, or subagent events and Codex's SessionStart hook supplies the OS-user context its spans lack. Both runtimes' Stop hooks record the turn's final reply from `last_assistant_message` as `agent.message` (Codex through the dedicated `codex-assistant-response` command, since its OTLP export carries no response text and it gets no generic hooks). `beacon endpoint codex sync` is the offline poll backfill from `~/.codex/sessions`; it never reads `~/.codex/auth.json` and cannot approve, deny, or delay tool calls.-- Cursor hook telemetry for sessions, prompt submission, tool use, command execution, MCP-like tool activity, approval decisions, file edits, and agent reasoning (`afterAgentThought` thinking text recorded as `agent.reasoning` events in the OTel GenAI `gen_ai.output.messages` reasoning-part shape) where hook payloads expose those fields. The Cursor IDE also runs the hooks in the user-level `~/.claude/settings.json`, with Cursor payloads; when Beacon's own `~/.cursor/hooks.json` runs the same hook subcommand and that entry's matcher selects the call's tool, that Claude Code run writes nothing and asks no policy provider (`cursorRecordsThisHook` in `cli/beacon-hooks/cmd/cursor_compat.go`), so each event is recorded once. The two pre-tool matchers differ (Claude's names Read, Grep and Glob; Cursor's names Shell and MCP), so a call only Claude's matcher selects, a subcommand Beacon's Cursor hooks don't run, or a machine without them at the user level still gets the Claude Code run's record and policy check. While the desktop app shows a cloud agent it also runs the user-level hooks for that agent's `afterAgentThought`, `subagentStart` and `subagentStop` (nothing else; measured on Cursor 3.29 and 3.30); a Cursor payload whose conversation id starts with `bc-` (the cloud agent) or `task-call-` (its subagent) and that has no `workspace_roots` writes nothing outside a cloud sandbox (`cursorRelaysCloudAgent` in `cli/beacon-hooks/cmd/cursor_compat.go`), so a cloud agent never reads as a partial local session; the cloud agent's own project hooks from `beacon cloud cursor print-hooks` record it.+- Cursor hook telemetry for sessions, prompt submission, tool use, command execution, MCP-like tool activity, approval decisions, file edits, and agent reasoning (`afterAgentThought` thinking text recorded as `agent.reasoning` events in the OTel GenAI `gen_ai.output.messages` reasoning-part shape) where hook payloads expose those fields. The Cursor IDE also runs the hooks in the user-level `~/.claude/settings.json`, with Cursor payloads; when Beacon's own `~/.cursor/hooks.json` runs the same hook subcommand and that entry's matcher selects the call's tool, that Claude Code run writes nothing and asks no policy provider (`cursorRecordsThisHook` in `cli/beacon-hooks/cmd/cursor_compat.go`), so each event is recorded once. The two pre-tool matchers differ (Claude's names Read, Grep and Glob; Cursor's names Shell and MCP), so a call only Claude's matcher selects, a subcommand Beacon's Cursor hooks don't run, or a machine without them at the user level still gets the Claude Code run's record and policy check. While the desktop app shows a cloud agent it also runs the user-level hooks for that agent's `afterAgentThought`, `subagentStart` and `subagentStop` (nothing else; measured on Cursor 3.29 and 3.30); a Cursor payload whose conversation id starts with `bc-` (the cloud agent) or `task-call-` (its subagent) and that has no `workspace_roots` writes nothing outside a cloud sandbox (`cursorRelaysCloudAgent` in `cli/beacon-hooks/cmd/cursor_compat.go`), so a cloud agent never reads as a partial local session; the cloud agent's own project hooks from `beacon cloud cursor print-hooks` record it, including reasoning, replies and turn end.- Cline uses a Beacon-managed plugin (`~/.cline/plugins/beacon.ts`) for live capture plus `beacon endpoint cline sync` for local history backfill. Cline's own OTel export/hosted prompt storage are not used, and approvals are not exposed or synthesized.- Pi-family runtimes use Beacon-managed extensions and the shared `cli/beacon-hooks/cmd/pi_family.go` mapper while keeping separate harness names and install roots: Pi (`pi_cli`), Oh My Pi (`omp`), Prime Agent (`prime_agent`), and Senpi/OMO (`omo_senpi`). Pi, Prime, and Senpi do not expose operator approval decisions, so Beacon does not synthesize them. Oh My Pi exposes real approval events and the extension carries the remembered tool input onto those approvals.- Prime Agent is the Pi-family exception with a single persistent `ipython` tool: kernel cells are recorded as `command.executed`, carry Python status/output metadata, and have no invented exit code. MCP is not separately attributed because Prime exposes integrations inside the kernel. `beacon endpoint prime sync` is the local poll backfill from `~/.prime/agent/sessions` and session artifacts.diff --git a/cli/beacon/cmd/cloud_test.go b/cli/beacon/cmd/cloud_test.goindex 8a68a347..72f1b1bb 100644--- a/cli/beacon/cmd/cloud_test.go+++ b/cli/beacon/cmd/cloud_test.go@@ -30,6 +30,11 @@ func TestRenderCursorCloudHooks(t *testing.T) {`"subagentStart"`,`"subagentStop"`,`"preCompact"`,+ `"afterAgentThought"`,+ `agent-thought`,+ `"afterAgentResponse"`,+ `agent-response`,+ `"stop"`,`BEACON_ORIGIN=cloud`,`BEACON_RUN_PROVIDER=cursor_cloud`,`'/tmp/beacon/bin/beacon-hooks' --platform cursor`,@@ -38,7 +43,7 @@ func TestRenderCursorCloudHooks(t *testing.T) {t.Fatalf("rendered hooks missing %q:\n%s", want, got)}}- for _, unsupported := range []string{`"preToolUse"`, `"sessionStart"`, `"sessionEnd"`, `"stop"`} {+ for _, unsupported := range []string{`"preToolUse"`, `"sessionStart"`, `"sessionEnd"`} {if strings.Contains(got, unsupported) {t.Fatalf("rendered cursor cloud hooks should not contain %q:\n%s", unsupported, got)}@@ -60,6 +65,9 @@ func TestRenderCursorCloudSafeHooks(t *testing.T) {`"postToolUse"`,`"subagentStart"`,`"preCompact"`,+ `"afterAgentThought"`,+ `"afterAgentResponse"`,+ `"stop"`,} {if !strings.Contains(got, want) {t.Fatalf("rendered safe hooks missing %q:\n%s", want, got)diff --git a/cli/beacon/internal/endpoint/hooks/cursor.go b/cli/beacon/internal/endpoint/hooks/cursor.goindex 72280601..0e0cc08f 100644--- a/cli/beacon/internal/endpoint/hooks/cursor.go+++ b/cli/beacon/internal/endpoint/hooks/cursor.go@@ -202,6 +202,13 @@ func CursorCloudHookRefs(opts CursorCloudOptions) map[string][]HookRef {"preCompact": {{Command: prefix + " cursor-event"},},+ // The agent's reasoning, its replies and the end of each turn. The Cursor desktop app also+ // runs the user-level afterAgentThought hook for a cloud agent it shows, which the endpoint+ // leaves unrecorded (cursorRelaysCloudAgent in beacon-hooks), so these are where a cloud+ // agent's reasoning is recorded. stop also uploads the log once the turn is over.+ "afterAgentThought": {{Command: prefix + " agent-thought"}},+ "afterAgentResponse": {{Command: prefix + " agent-response"}},+ "stop": {{Command: prefix + " stop"}},}if !opts.SafeHooks {refs["beforeShellExecution"] = []HookRef{{Command: prefix + " pre-tool"}}diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdxindex 4f0a124c..e485a10e 100644--- a/docs/changelog/cli.mdx+++ b/docs/changelog/cli.mdx@@ -14,6 +14,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.Changes on `main` since v1.3.60. They ship in the next release.- **Cursor cloud agents no longer leave partial sessions on the endpoint** · While the Cursor desktop app shows a cloud agent, it runs the user-level hooks on your machine for that agent's reasoning and subagent events, but not for its prompts, tool calls, replies or turn ends, which run in Cursor's VM. Beacon recorded those calls as `agent.reasoning` and `subagent.stopped` events from the machine, so a cloud agent looked like a local Cursor session with only reasoning in it, and a subagent's reasoning formed a session of its own. A Cursor hook payload that names a cloud agent (`bc-…`) or one of its subagents (`task-call-…`) and no workspace now writes nothing outside a cloud sandbox. A cloud agent on a self-hosted worker, which runs in a checkout, is still recorded, and so is everything the [Cursor Cloud Agents](/runtimes/cursor-cloud-agents) project hooks capture in the VM.+- **Cursor cloud agents record reasoning, replies and turn ends** · `beacon cloud cursor print-hooks` now also wires `afterAgentThought`, `afterAgentResponse` and `stop`, which Cursor runs in cloud agents, so a cloud agent's trace carries its reasoning (`agent.reasoning`), its replies (`agent.message`) and the end of each turn (`tool.completed` with `turn.status`), and `stop` uploads the log when the turn is over. Regenerate and commit `.cursor/hooks.json` to pick them up.- **Antigravity CLI records every prompt** · Antigravity has no prompt hook, so Beacon recovered only a session's first prompt, from its transcript on the first tool call: later prompts, and turns that ran no tool, were never recorded. The managed hook block now also runs `beacon-hooks` on `PreInvocation`, which Antigravity calls before every model call with the turn's prompt as `lastUserInput`, and Beacon records it on the first call of each turn (`invocationNum` 0), resumed conversations included. Package repair adds the handler to installed user-level hooks; for project-level or manual installs, rerun `beacon endpoint hooks install --harness antigravity` at the same level.- **Antigravity CLI session sync** · `beacon endpoint antigravity sync|status` (alias `antigravity-cli`) reads the conversations Antigravity keeps under `~/.gemini/antigravity-cli/brain` and records them as `harness.collection_method=poll` events: prompts, agent messages, reasoning, tool calls, commands with exit code and output, file reads and edits, and per-response token usage, with the working directory from `conversation_summaries.db`. The install-time backfill and the scheduled session sync include it, so conversations from before the hooks worked are recorded. For a conversation the hooks already recorded, sync adds only agent messages, reasoning, and token usage from the point the hooks started, plus any prompt the hooks did not record, matched by content hash, such as the later prompts of a conversation recorded by v1.3.60 hooks. `beacon token-usage --coverage` now expects Antigravity usage from the sync instead of reporting it as not instrumented.- **Antigravity CLI file edits are recorded as edits** · Antigravity edits files with `replace_file_content` and `multi_replace_file_content`, whose names the hook adapter's edit rule did not match, so a live edit was recorded as a plain `tool.invoked`; and its write and replace tools name their file `TargetFile`, which the adapter did not read, so even `write_to_file` carried no path. All three are now `file.modified` with the file's path. The hook adapter and `beacon endpoint antigravity sync` classify Antigravity tools from one table, so a call reads the same on either path.diff --git a/docs/cli/cloud-cursor-print-hooks.mdx b/docs/cli/cloud-cursor-print-hooks.mdxindex 42e03f87..94503a30 100644--- a/docs/cli/cloud-cursor-print-hooks.mdx+++ b/docs/cli/cloud-cursor-print-hooks.mdx@@ -23,8 +23,9 @@ Cursor Cloud only runs command-based project hooks after the cloud VM starts.The generated hook set uses supported Cursor Cloud hooks such as`beforeSubmitPrompt`, `beforeReadFile`, `beforeShellExecution`, `afterShellExecution`,`afterFileEdit`, `postToolUse`, `postToolUseFailure`, `subagentStart`,-`subagentStop`, and `preCompact`. It currently omits broad `preToolUse`,-`sessionStart`, `sessionEnd`, and `stop`. See+`subagentStop`, `preCompact`, `afterAgentThought`, `afterAgentResponse`, and+`stop`. It currently omits broad `preToolUse`, `sessionStart`, and+`sessionEnd`. `stop` also uploads the log at the end of each turn. See[Cursor's Cloud Agent hook support matrix](https://cursor.com/docs/hooks#cloud-agent-support)for the current platform support list.diff --git a/docs/runtimes/cursor-cloud-agents.mdx b/docs/runtimes/cursor-cloud-agents.mdxindex 762814c4..45fcf064 100644--- a/docs/runtimes/cursor-cloud-agents.mdx+++ b/docs/runtimes/cursor-cloud-agents.mdx@@ -77,8 +77,8 @@ you read older endpoint data.## Prerequisites-- Beacon CLI `v1.0.3` or later for direct S3 upload. Cursor Cloud prompt capture- requires the branch containing this change until a release includes it.+- A current Beacon CLI release. Releases after `v1.3.60` also record the+ agent's reasoning, its replies, and the end of each turn.- For GCS: `gcloud` installed and authenticated to a project where you cancreate buckets, service accounts, IAM bindings, and service account keys.- For S3: AWS CLI installed and authenticated to an account where you can@@ -280,9 +280,7 @@ Generate the setup script for your Beacon release:beacon cloud cursor print-setup --version vX.Y.Z```-Replace `vX.Y.Z` with a release tag that contains Cursor Cloud prompt capture.-Until that release exists, use the source-build path below; `v1.0.3` supports-direct S3 upload but predates the prompt hook.+Replace `vX.Y.Z` with the latest Beacon release tag.Paste the generated script into the Cursor cloud environment setup step. Thescript:@@ -312,8 +310,9 @@ Read the README, run pwd && ls, create a tiny temporary markdown note under```Beacon captures observed prompt submissions, tool use, shell execution, file-reads and edits, subagent lifecycle events, and compaction events where Cursor-exposes hook payloads.+reads and edits, subagent lifecycle events, compaction events, the agent's+reasoning and replies, and the end of each turn where Cursor exposes hook+payloads.Then submit a prompt-only follow-up with a unique marker:diff --git a/docs/runtimes/cursor.mdx b/docs/runtimes/cursor.mdxindex 352ae2c1..90897083 100644--- a/docs/runtimes/cursor.mdx+++ b/docs/runtimes/cursor.mdx@@ -69,9 +69,9 @@ beacon endpoint hooks install --harness cursor --level project| Turn identity | Supported. Cursor's `generation_id`, which changes with every user message, is promoted to `prompt.id` on hook events || Command, tool, and file telemetry | Supported for tool, shell command, MCP-like, approval, and file edit payloads where Cursor exposes them; Cursor Cloud support is limited to Cursor's [cloud-supported command hooks](https://cursor.com/docs/hooks#cloud-agent-support). || Pre-tool answer | `preToolUse`, `beforeShellExecution` and `beforeReadFile` answer `{"permission":"allow"}`, because Cursor's hooks reference does not make `permission` optional and blocks an action whose hook response does not match the schema. Cursor enforces only a hook's `deny`: an `allow` does not override your allowlist or approval mode, so a command Cursor would ask about still asks. A deny from a `BEACON_POLICY_PROVIDER` policy provider returns `{"permission":"deny"}` |-| Agent responses | Supported for local Cursor through `afterAgentResponse` hooks. Each finished assistant message is recorded as an `agent.message` event with the reply text in `gen_ai.output.messages` (a `text` part) and a `content` marker, in the same turn (`prompt.id`) as the prompt that produced it. Cursor Cloud does not install this hook. `beacon endpoint cursor sync` also recovers committed assistant text |-| Turn end | Supported for local Cursor through the `stop` hook, recorded as `tool.completed` ("Agent response completed") like every runtime's turn end. Cursor's `status` for the turn (`completed`, `aborted` or `error`) is kept verbatim as `turn.status`, so in the runtime log a stopped or failed turn can be told apart from a finished one, and a threat rule can match `e.turn.status`. The session view and shared traces do not show it yet |-| Agent reasoning telemetry | Supported for local Cursor through `afterAgentThought` hooks. Each completed thinking block is recorded as an `agent.reasoning` event carrying the reasoning text in the OpenTelemetry GenAI output-messages shape (`gen_ai.output.messages` with a `reasoning` part), plus a `content` marker with the original text's hash and byte count. Reasoning is only available for models/modes where Cursor exposes visible thinking text. |+| Agent responses | Supported for local and cloud Cursor through `afterAgentResponse` hooks. Each finished assistant message is recorded as an `agent.message` event with the reply text in `gen_ai.output.messages` (a `text` part) and a `content` marker, in the same turn (`prompt.id`) as the prompt that produced it. Cursor Cloud records them through the committed project hooks. `beacon endpoint cursor sync` also recovers committed assistant text |+| Turn end | Supported for local and cloud Cursor through the `stop` hook, recorded as `tool.completed` ("Agent response completed") like every runtime's turn end. Cursor's `status` for the turn (`completed`, `aborted` or `error`) is kept verbatim as `turn.status`, so in the runtime log a stopped or failed turn can be told apart from a finished one, and a threat rule can match `e.turn.status`. The session view and shared traces do not show it yet |+| Agent reasoning telemetry | Supported for local and cloud Cursor through `afterAgentThought` hooks. Each completed thinking block is recorded as an `agent.reasoning` event carrying the reasoning text in the OpenTelemetry GenAI output-messages shape (`gen_ai.output.messages` with a `reasoning` part), plus a `content` marker with the original text's hash and byte count. Reasoning is only available for models/modes where Cursor exposes visible thinking text. || Repository and branch context | Events include the workspace path as `repository`, and `branch` is resolved from the workspace's local git checkout (`.git/HEAD`) when Cursor does not supply one; disable local git resolution with `BEACON_DISABLE_GIT_METADATA=1`. || Token usage and cost | No Cursor hook payload or local record carries a token count or a cost. Team admins can collect per-request token usage and Cursor's charges from the Cursor Admin API with [`beacon endpoint cursor usage sync`](/cli/endpoint-cursor#token-usage-from-the-cursor-admin-api), which writes one `token.usage` event per request || Context occupancy | Supported through `preCompact`, which reports `context_tokens` and `context_window_size`. Recorded as `gen_ai.context` (`used_tokens`, `limit_tokens`) and used by the token-usage utilization view. This is a level, not spend: it is never summed into a total, and Cursor still reports as `not_instrumented` in `beacon token-usage --coverage` because it has not said what a turn cost. The sibling `context_usage_percent` is derivable from the pair and stays in the retained payload. |