You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9c6acd6
Browse filesBrowse the repository at this point in the historyBrowse files
fix(hook-to-otlp): scrub only the user-name component of home paths
The previous round let a home-path user name run across spaces up to the
next slash, so opted-in Shell command text such as
"cd /Users/alice && ls src/foo" lost "&& ls src". The generic scrub now
replaces only the one directory component after /Users/, /home/ or
C:\Users\: it stops at whitespace, quotes and punctuation no account name
uses, and does not end with a dot.
Names with spaces are handled through this machine's own home directory:
the basename of os.path.expanduser("~") is matched literally after any
home prefix (raw, JSON-escaped or forward-slash Windows form), with a
boundary check so /Users/al does not match inside /Users/alice. This also
fixes "/Users/Jo Ann." and "/Users/Jo Ann," leaking "Ann". Another
account's spaced name keeps the part after the first space; README and
the shared page document that.
Docs: the shared page no longer says every app page uses the guarded
command (hook-based apps do; native-OTel apps have no hook command), and
both pages note that fish reads the subshell parentheses as command
substitution.
Tests: command-text regression cases, own spaced home (POSIX and
Windows forms, end of string, punctuation, al/alice), and the documented
limitation for other accounts.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copy file name to clipboardExpand all lines: src/pages/docs/integrations/coding-agents/cursor.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ The project `.cursor/hooks.json` it writes registers the emitter on the observat
65
65
}
66
66
```
67
67
68
-
Each command is guarded with `2>/dev/null || true` so a missing emitter or `python3` can never return exit code 2, which Cursor treats as "block this action". Cursor runs each command with `$SHELL -c` (falling back to `/bin/sh`), so your login shell must be a POSIX shell such as zsh or bash. The parentheses are required: the IDE agent pipes the hook payload to stdin, but Cursor's headless agent host appends it to the command as a heredoc (`<command> <<'CURSOR_HOOK_EOF'`), and without the subshell that heredoc would reach `true` instead of `python3`. `-B` keeps `__pycache__` out of your repository. Project hooks run from the project root, so the paths start with `.cursor/`. User hooks run from `~/.cursor/` and use `./hooks/fi-hook-to-otlp/emit.py` instead (the installer handles this). Project hooks only run in a [trusted workspace](https://cursor.com/docs/hooks).
68
+
Each command is guarded with `2>/dev/null || true` so a missing emitter or `python3` can never return exit code 2, which Cursor treats as "block this action". Cursor runs each command with `$SHELL -c` (falling back to `/bin/sh`), so your login shell must be a POSIX shell such as zsh or bash (fish reads the parentheses as command substitution). The parentheses are required: the IDE agent pipes the hook payload to stdin, but Cursor's headless agent host appends it to the command as a heredoc (`<command> <<'CURSOR_HOOK_EOF'`), and without the subshell that heredoc would reach `true` instead of `python3`. `-B` keeps `__pycache__` out of your repository. Project hooks run from the project root, so the paths start with `.cursor/`. User hooks run from `~/.cursor/` and use `./hooks/fi-hook-to-otlp/emit.py` instead (the installer handles this). Project hooks only run in a [trusted workspace](https://cursor.com/docs/hooks).
69
69
70
70
<Note>
71
71
The emitter is deliberately not registered on permission hooks (`preToolUse`, `beforeShellExecution`, `beforeMCPExecution`, `beforeReadFile`, `subagentStart`). Tool timing comes from the `duration` Cursor reports in `postToolUse`, so tracing never takes part in approving or blocking an action. On `beforeSubmitPrompt` it always answers `{"continue": true}`. If you register it on a permission hook by mistake, it prints nothing: Cursor treats that as a failed hook and lets the action through, so it never approves or blocks anything.
Copy file name to clipboardExpand all lines: src/pages/docs/integrations/coding-agents/hook-to-otlp.mdx
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,8 @@ By default the emitter exports structure and metadata only: ids, names, model, d
59
59
| Paths inside prompts, tool input, and tool output (for example a Read tool's `file_path`) |**not exported**| exported as part of that content, with the user name in home-directory paths replaced by `<user>` (`/Users/<user>/project/README.md`) |
60
60
| User email |**never exported**|**never exported**|
61
61
62
+
The user name is the one directory after `/Users/`, `/home/`, or `C:\Users\` (and the name in `~name/`); the text after it, such as the rest of a shell command, is kept as it was. A name with spaces is replaced in full when it is this machine's own home directory. For another account's name with spaces (for example in a log copied from another machine), only the part before the first space is replaced.
63
+
62
64
The emitter never reads files named in a payload (for example a transcript path) and never reads the app's local database or logs. It only sees the JSON the app passes to the hook.
63
65
64
66
<Warning>
@@ -84,7 +86,7 @@ Set these in the environment that starts the agent, or in `~/.config/fi-hook-to-
84
86
85
87
## Registering the hook
86
88
87
-
Every app page uses the same guarded command, so a missing emitter or a missing `python3` can never block the agent (many apps treat exit code 2 from a hook as "block this action"):
89
+
Apps that export OpenTelemetry natively do not use this emitter and have no hook command; their pages set up the app's own telemetry export. Every app that is traced through hooks registers this same guarded command, so a missing emitter or a missing `python3` can never block the agent (many apps treat exit code 2 from a hook as "block this action"):
@@ -96,7 +98,7 @@ Every app page uses the same guarded command, so a missing emitter or a missing
96
98
-`-B` stops Python from writing `__pycache__` into your project.
97
99
- The event name is passed explicitly, so the emitter works even if the app leaves it out of the payload.
98
100
99
-
This form needs a POSIX shell (`sh`, `bash`, `zsh`). On macOS and Linux, Cursor runs each hook command with `$SHELL -c` (falling back to `/bin/sh`). The commands and installers on these pages are not tested on native Windows; there, use WSL or write the equivalent for the shell your app runs hooks with, and keep it exiting 0 with no output on failure.
101
+
This form needs a POSIX shell (`sh`, `bash`, `zsh`); fish, for example, reads the parentheses as command substitution. On macOS and Linux, Cursor runs each hook command with `$SHELL -c` (falling back to `/bin/sh`). The commands and installers on these pages are not tested on native Windows; there, use WSL or write the equivalent for the shell your app runs hooks with, and keep it exiting 0 with no output on failure.
0 commit comments