Cursor · HooksPerfiles
Perfil Python seguro
Ruff al editar, pytest al terminar y protección de secretos.
por Prompt Studio
hooksafterFileEditbeforeReadFilebeforeShellExecutionstop
Licencia: MITVer original
Contenido
Dónde va: .cursor/hooks.json
{
"version": 1,
"hooks": {
"afterFileEdit": [
{
"command": "bash -c 'f=$(jq -r .file_path); echo \"$f\" | grep -Eq -e \"[.]py\" && ruff format \"$f\" && ruff check --fix \"$f\" >/dev/null 2>&1; exit 0'"
}
],
"stop": [
{
"command": "bash -c 'jq -e \".status == \\\"completed\\\"\" >/dev/null || { echo \"{}\"; exit 0; }; if pytest -q >/tmp/cursor-hook-check.log 2>&1; then echo \"{}\"; else echo \"{\\\"followup_message\\\":\\\"Fallan tests de pytest. Revisa /tmp/cursor-hook-check.log y corrígelo.\\\"}\"; fi'"
}
],
"beforeReadFile": [
{
"command": "bash -c 'jq -r .file_path | grep -Eq -e \"(^|/)[.]env([.]|$)\" && echo \"{\\\"permission\\\":\\\"deny\\\",\\\"userMessage\\\":\\\"Archivo protegido: el agente no puede leer archivos .env\\\",\\\"agentMessage\\\":\\\"Archivo protegido: el agente no puede leer archivos .env\\\"}\" || echo \"{\\\"permission\\\":\\\"allow\\\"}\"'"
}
],
"beforeShellExecution": [
{
"command": "bash -c 'jq -r .command | grep -Eiq -e \"pip3? install[^;&|]*--break-system-packages\" && echo \"{\\\"permission\\\":\\\"deny\\\",\\\"userMessage\\\":\\\"Bloqueado por hooks.json: no se permite instalar con pip en el sistema\\\",\\\"agentMessage\\\":\\\"Bloqueado por hooks.json: no se permite instalar con pip en el sistema\\\"}\" || echo \"{\\\"permission\\\":\\\"allow\\\"}\"'"
}
]
}
}
Más en Hooks
Bloquear comandos peligrosos
Detiene rm -rf, git push --force y similares antes de ejecutarse.
Proteger .env
Impide que el agente lea archivos con secretos.
Formatear al editar
Ejecuta Prettier en cada archivo que edita el agente.
Lint al terminar
Corre el linter cuando el agente termina su turno.
Aviso al terminar
Notificación de escritorio cuando el agente acaba (macOS).
Registro de comandos
Guarda cada comando del agente en .cursor/audit.log.