kink-discovery / scripts /install_cursor_from_parser.sh
Perplexed7675's picture
Sync from kink_cli (Docker Space)
6ff91d6 verified
Raw
History Blame Contribute Delete
3.41 kB
#!/usr/bin/env bash
# One-time sync: copy Cursor hooks and rules from the parser repo into this repo, then render hooks.json.
# Run from kink_cli root: bash scripts/install_cursor_from_parser.sh
set -euo pipefail
KINK_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PARSER_ROOT="${PARSER_ROOT:-${HOME}/PycharmProjects/parser}"
if test ! -d "${PARSER_ROOT}/.cursor/hooks"; then
echo "Missing ${PARSER_ROOT}/.cursor/hooks; set PARSER_ROOT to your parser checkout." >&2
exit 1
fi
mkdir -p "${KINK_ROOT}/.cursor/hooks/state" "${KINK_ROOT}/.cursor/rules"
cp -a "${PARSER_ROOT}/.cursor/hooks/"*.py "${PARSER_ROOT}/.cursor/hooks/"*.sh "${KINK_ROOT}/.cursor/hooks/"
cp -a "${PARSER_ROOT}/.cursor/rules/"*.mdc "${KINK_ROOT}/.cursor/rules/"
install -D -m0644 "${PARSER_ROOT}/semgrep.yml" "${KINK_ROOT}/semgrep.yml"
install -D -m0644 "${PARSER_ROOT}/scripts/codex_baseline.py" "${KINK_ROOT}/scripts/codex_baseline.py"
install -D -m0644 "${PARSER_ROOT}/scripts/codex_review.py" "${KINK_ROOT}/scripts/codex_review.py"
PYTHON_BIN="${KINK_ROOT}/.venv/bin/python"
if test ! -x "${PYTHON_BIN}"; then
PYTHON_BIN="$(command -v python3)"
fi
cat >"${KINK_ROOT}/.cursor/hooks.json" <<EOF
{
"version": 1,
"hooks": {
"sessionStart": [
{
"command": "${PYTHON_BIN} .cursor/hooks/session_clear.py",
"timeout": 5
},
{
"command": "${PYTHON_BIN} scripts/codex_baseline.py",
"timeout": 10
}
],
"preToolUse": [
{
"command": "${PYTHON_BIN} .cursor/hooks/pre_tool_guard.py",
"matcher": "Write",
"failClosed": false,
"timeout": 10
},
{
"command": "${PYTHON_BIN} .cursor/hooks/pre_tool_guard.py",
"matcher": "StrReplace",
"failClosed": false,
"timeout": 10
},
{
"command": "${PYTHON_BIN} .cursor/hooks/pre_tool_guard.py",
"matcher": "EditNotebook",
"failClosed": false,
"timeout": 10
}
],
"postToolUseFailure": [
{
"command": "${PYTHON_BIN} .cursor/hooks/failure_tracker.py",
"timeout": 5
}
],
"afterFileEdit": [
{
"command": "${PYTHON_BIN} .cursor/hooks/track_modified.py",
"timeout": 5
}
],
"beforeShellExecution": [
{
"command": "${PYTHON_BIN} .cursor/hooks/shell_guard.py",
"failClosed": true,
"timeout": 5
}
],
"beforeReadFile": [
{
"command": "bash .cursor/hooks/secrets_guard.sh",
"failClosed": false,
"timeout": 5
}
],
"preCompact": [
{
"command": "${PYTHON_BIN} .cursor/hooks/compact_guard.py",
"timeout": 5
}
],
"stop": [
{
"command": "${PYTHON_BIN} .cursor/hooks/stop_scan.py",
"loop_limit": 3,
"timeout": 120
},
{
"command": "${PYTHON_BIN} scripts/codex_review.py",
"loop_limit": 1,
"timeout": 180
}
],
"sessionEnd": [
{
"command": "${PYTHON_BIN} .cursor/hooks/session_end.py",
"timeout": 5
}
],
"afterShellExecution": [
{
"command": "${PYTHON_BIN} .cursor/hooks/worktree_setup.py",
"matcher": "git worktree add",
"timeout": 15
}
]
}
}
EOF
echo "Installed .cursor/hooks, .cursor/rules, semgrep.yml, scripts/codex_*.py, and .cursor/hooks.json (python: ${PYTHON_BIN})."