Repository navigation
fix(cursor): manage hooks declaratively, fix GUI PATH timeout #1839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9279a6e
fix(cursor): manage hooks declaratively, fix GUI PATH timeout
shunkakinoki 8b95380
refactor(hooks): consolidate rtk-rewrite and security to shared/
shunkakinoki b416c74
fix(hooks): address review feedback
shunkakinoki f973a29
fix(hooks): sync /usr/sbin into shared PATH bootstraps
shunkakinoki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,49 @@ | ||
| { | ||
| "version": 1, | ||
| "hooks": { | ||
| "beforeShellExecution": [ | ||
| { | ||
| "command": "$HOME/.cursor/hooks/security.sh", | ||
| "timeout": 5 | ||
| }, | ||
| { | ||
| "command": "$HOME/.cursor/hooks/with-env.sh $HOME/dotfiles/config/shared/hooks/block-git-push.sh", | ||
| "timeout": 5 | ||
| }, | ||
| { | ||
| "command": "$HOME/.cursor/hooks/with-env.sh $HOME/dotfiles/config/shared/hooks/block-gh-settings.sh", | ||
| "timeout": 5 | ||
| }, | ||
| { | ||
| "command": "$HOME/.cursor/hooks/notify.sh", | ||
| "timeout": 3 | ||
| }, | ||
| { | ||
| "command": "$HOME/.cursor/hooks/pushover.sh", | ||
| "timeout": 6 | ||
| } | ||
| ], | ||
| "afterFileEdit": [ | ||
| { | ||
| "command": "git-ai checkpoint cursor --hook-input stdin" | ||
| "command": "$HOME/.cargo/bin/git-ai checkpoint cursor --hook-input stdin", | ||
| "timeout": 15 | ||
| } | ||
| ], | ||
| "beforeSubmitPrompt": [ | ||
| { | ||
| "command": "git-ai checkpoint cursor --hook-input stdin" | ||
| "command": "$HOME/.cargo/bin/git-ai checkpoint cursor --hook-input stdin", | ||
| "timeout": 15 | ||
| } | ||
| ], | ||
| "stop": [ | ||
| { | ||
| "command": "$HOME/.cursor/hooks/notify.sh", | ||
| "timeout": 3 | ||
| }, | ||
| { | ||
| "command": "$HOME/.cursor/hooks/pushover.sh", | ||
| "timeout": 6 | ||
| } | ||
| ] | ||
| }, | ||
| "version": 1 | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Cursor local notification hook | ||
| # Sends native OS notifications via the shared notify-local script. | ||
| # Skips local popups when Pushover is configured (pushover.sh handles those). | ||
|
|
||
| export PATH="$HOME/.cargo/bin:/etc/profiles/per-user/shunkakinoki/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:${PATH:-}" | ||
|
|
||
| command -v jq >/dev/null 2>&1 || exit 0 | ||
|
|
||
| if [[ -z ${PUSHOVER_API_TOKEN:-} ]] || [[ -z ${PUSHOVER_USER_KEY:-} ]]; then | ||
| if [[ -f "$HOME/dotfiles/.env" ]]; then | ||
| set -a | ||
| # shellcheck source=/dev/null | ||
| source "$HOME/dotfiles/.env" 2>/dev/null | ||
| set +a | ||
| fi | ||
| fi | ||
|
|
||
| if [[ -n ${PUSHOVER_API_TOKEN:-} ]] && [[ -n ${PUSHOVER_USER_KEY:-} ]]; then | ||
| exit 0 | ||
| fi | ||
|
shunkakinoki marked this conversation as resolved.
Resolved
|
||
|
|
||
| input=$(cat) | ||
|
|
||
| notify() { | ||
| local message="$1" | ||
| local sound="${2:-Sonar}" | ||
| local notifier | ||
|
|
||
| [[ -z $message ]] && return | ||
|
|
||
| notifier="$(command -v notify-local 2>/dev/null || true)" | ||
| if [[ -z $notifier ]] && [[ -x "$HOME/.local/scripts/notify-local" ]]; then | ||
| notifier="$HOME/.local/scripts/notify-local" | ||
| fi | ||
|
|
||
| [[ -n $notifier ]] && "$notifier" "Cursor" "$message" "$sound" | ||
| } | ||
|
|
||
| event=$(echo "$input" | jq -r '.hook_event_name // empty' 2>/dev/null) | ||
|
|
||
| case "$event" in | ||
| stop) | ||
| status=$(echo "$input" | jq -r '.status // "completed"' 2>/dev/null) | ||
| case "$status" in | ||
| completed) notify "Work completed" ;; | ||
| aborted) notify "Work aborted" "Basso" ;; | ||
| error) notify "Work errored" "Basso" ;; | ||
| esac | ||
| ;; | ||
| beforeShellExecution) | ||
| command=$(echo "$input" | jq -r '.command // empty' 2>/dev/null) | ||
| if echo "$command" | grep -qiE 'rm -rf|drop database|truncate|DELETE FROM|format'; then | ||
| risky_msg=$(echo "$command" | head -c 100) | ||
| notify "Risky: ${risky_msg}" "Basso" | ||
| fi | ||
| ;; | ||
| esac | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Cursor Pushover notification hook | ||
| # Sends notifications to phone/watch via the shared pushover-notify script. | ||
|
|
||
| export PATH="$HOME/.cargo/bin:/etc/profiles/per-user/shunkakinoki/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:${PATH:-}" | ||
|
|
||
| command -v jq >/dev/null 2>&1 || exit 0 | ||
|
|
||
| input=$(cat) | ||
|
|
||
| pushover="$(command -v pushover-notify 2>/dev/null || true)" | ||
| if [[ -z $pushover ]] && [[ -x "$HOME/.local/scripts/pushover-notify" ]]; then | ||
| pushover="$HOME/.local/scripts/pushover-notify" | ||
| fi | ||
| [[ -z $pushover ]] && exit 0 | ||
|
|
||
| HOSTNAME=$(scutil --get ComputerName 2>/dev/null || hostname -s 2>/dev/null || echo "unknown") | ||
|
shunkakinoki marked this conversation as resolved.
Resolved
|
||
| CWD=$(echo "$input" | jq -r '.cwd // (.workspace_roots[0] // empty)' 2>/dev/null | sed "s|$HOME|~|") | ||
|
|
||
| event=$(echo "$input" | jq -r '.hook_event_name // empty' 2>/dev/null) | ||
|
|
||
| case "$event" in | ||
| stop) | ||
| status=$(echo "$input" | jq -r '.status // "completed"' 2>/dev/null) | ||
| case "$status" in | ||
| completed) "$pushover" "Cursor" "[$HOSTNAME] Work completed${CWD:+ in $CWD}" 0 ;; | ||
| aborted) "$pushover" "Cursor" "[$HOSTNAME] Work aborted${CWD:+ in $CWD}" 0 ;; | ||
| error) "$pushover" "Cursor" "[$HOSTNAME] Work errored${CWD:+ in $CWD}" 1 ;; | ||
| esac | ||
| ;; | ||
| beforeShellExecution) | ||
| command=$(echo "$input" | jq -r '.command // empty' 2>/dev/null) | ||
| if echo "$command" | grep -qiE 'rm -rf|drop database|truncate|DELETE FROM|format'; then | ||
| risky_msg=$(echo "$command" | head -c 100) | ||
| "$pushover" "Cursor" "[$HOSTNAME] Risky: ${risky_msg}" 1 | ||
| fi | ||
| ;; | ||
| esac | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Cursor Security Hook (beforeShellExecution) | ||
| # Blocks dangerous Bash commands by checking against deny patterns. | ||
| # Mirrors codex/copilot security.sh; Cursor sends `command` at top level. | ||
| # Returns exit code 2 to block, exit code 0 to allow. | ||
|
|
||
| export PATH="$HOME/.cargo/bin:/etc/profiles/per-user/shunkakinoki/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:${PATH:-}" | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| command -v jq >/dev/null 2>&1 || exit 0 | ||
|
|
||
| input=$(cat) | ||
|
|
||
| command=$(echo "$input" | jq -r ' | ||
| .command | ||
| // .tool.input.command | ||
| // .tool_input.command | ||
| // empty | ||
| ' 2>/dev/null) | ||
| [[ -z $command ]] && exit 0 | ||
|
|
||
| deny_patterns=( | ||
| "chmod -R 777" | ||
| "dd if=" | ||
| "docker system prune -a" | ||
| "docker system prune -f" | ||
| "git push --force origin main" | ||
| "git push --force origin master" | ||
| "git push --force-with-lease origin main" | ||
| "git push --force-with-lease origin master" | ||
| "git push -f origin main" | ||
| "git push -f origin master" | ||
| "mkfs" | ||
| "rm -rf /*" | ||
| "rm -rf ~/*" | ||
| "sudo" | ||
| ) | ||
|
|
||
| IFS=$'\n' read -r -d '' -a segments < <(echo "$command" | sed -E 's/[;&|]+/\n/g' && printf '\0') || true | ||
|
|
||
| for segment in "${segments[@]}"; do | ||
| segment=$(echo "$segment" | xargs 2>/dev/null) || continue | ||
| [[ -z $segment ]] && continue | ||
|
|
||
| for pattern in "${deny_patterns[@]}"; do | ||
| if [[ $segment == $pattern* ]]; then | ||
| jq -n --arg msg "Command '$segment' matches deny pattern '$pattern'" \ | ||
| '{permission: "deny", user_message: $msg, agent_message: $msg}' | ||
| exit 2 | ||
|
shunkakinoki marked this conversation as resolved.
Resolved
|
||
| fi | ||
| done | ||
| done | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/usr/bin/env bash | ||
| # Cursor on macOS launches GUI apps with a minimal PATH that excludes | ||
| # ~/.cargo/bin, ~/.nix-profile/bin, /opt/homebrew/bin, etc. | ||
| # This wrapper exports a full PATH then execs the given command. | ||
| # Usage (in hooks.json): | ||
| # {"command": "$HOME/.cursor/hooks/with-env.sh /path/to/hook.sh"} | ||
| export PATH="$HOME/.cargo/bin:/etc/profiles/per-user/shunkakinoki/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:${PATH:-}" | ||
| exec "$@" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.