create-huenei-template 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/templates.js +14 -0
- package/dist/core/file-operations.js +15 -0
- package/dist/core/prompts.js +77 -135
- package/dist/index.js +55 -11
- package/dist/templates/README.md +7 -1
- package/dist/templates/backend/README.md +19 -9
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/dist/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/dist/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/dist/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/dist/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/dist/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/dist/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/dist/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/dist/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/dist/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/dist/templates/cursor/.cursor/commands/configurar-cursor.md +763 -0
- package/dist/templates/cursor/.cursor/skills/create-huenei-subagent/SKILL.md +223 -0
- package/dist/templates/cursor/.cursor/skills/create-huenei-subagent/examples.md +236 -0
- package/dist/templates/cursor/.cursor/skills/cursor-hooks/SKILL.md +1100 -0
- package/dist/templates/cursor/.cursor/skills/find-skills/SKILL.md +133 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/dist/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/dist/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/dist/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/dist/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/dist/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/dist/templates/frontend/react-vite/README.md +34 -34
- package/dist/templates/frontend/react-vite/package.json +82 -82
- package/dist/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/dist/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/dist/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/dist/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/dist/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/dist/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/dist/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/dist/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/dist/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/dist/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/dist/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/dist/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/dist/templates/frontend/react-vite/vite.config.ts +2 -2
- package/dist/templates/frontend/react-vite/vitest.config.ts +13 -2
- package/dist/templates/frontend/react-vite-help/.cursor/RECONSTRUCTION-PROMPT.md +738 -0
- package/package.json +1 -1
- package/templates/README.md +7 -1
- package/templates/backend/README.md +19 -9
- package/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/templates/backend/nestjs-api-mysql/dist/tsconfig.build.tsbuildinfo +1 -1
- package/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/templates/cursor/.cursor/commands/configurar-cursor.md +763 -0
- package/templates/cursor/.cursor/skills/create-huenei-subagent/SKILL.md +223 -0
- package/templates/cursor/.cursor/skills/create-huenei-subagent/examples.md +236 -0
- package/templates/cursor/.cursor/skills/cursor-hooks/SKILL.md +1100 -0
- package/templates/cursor/.cursor/skills/find-skills/SKILL.md +133 -0
- package/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/templates/frontend/react-vite/README.md +34 -34
- package/templates/frontend/react-vite/package.json +82 -82
- package/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/templates/frontend/react-vite/vite.config.ts +2 -2
- package/templates/frontend/react-vite/vitest.config.ts +13 -2
- package/templates/frontend/react-vite-help/.cursor/RECONSTRUCTION-PROMPT.md +738 -0
|
@@ -0,0 +1,1100 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cursor-hooks
|
|
3
|
+
description: Build and configure Cursor agent hooks for project automation. Use when creating .cursor/hooks/, writing hook scripts, or configuring hooks.json for afterFileEdit, beforeShellExecution, sessionStart, stop, or any other hook event.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Cursor Hooks
|
|
7
|
+
|
|
8
|
+
Hooks let you observe, control, and extend the Cursor agent loop with custom scripts. They are independent processes that communicate via stdio using JSON in both directions. They run before or after defined stages of the agent loop and can observe, block, or modify its behavior.
|
|
9
|
+
|
|
10
|
+
## When to Use
|
|
11
|
+
|
|
12
|
+
Activate this skill when:
|
|
13
|
+
|
|
14
|
+
- Setting up `.cursor/hooks.json` in a project or globally
|
|
15
|
+
- Creating hook scripts (Bash, TypeScript, Python)
|
|
16
|
+
- Implementing automated formatting after file edits
|
|
17
|
+
- Building security gates for shell commands or MCP tools
|
|
18
|
+
- Adding audit/logging for agent actions
|
|
19
|
+
- Injecting context at session start
|
|
20
|
+
- Controlling subagent execution
|
|
21
|
+
- Implementing auto-retry loops on agent stop
|
|
22
|
+
- Protecting sensitive files from being read by the agent
|
|
23
|
+
- Configuring prompt-based hooks (LLM-evaluated)
|
|
24
|
+
|
|
25
|
+
## Core Concepts
|
|
26
|
+
|
|
27
|
+
### Communication Protocol
|
|
28
|
+
|
|
29
|
+
Every hook receives a JSON payload via **stdin** and returns a JSON response via **stdout**. This is the fundamental contract:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
Cursor Agent --[JSON via stdin]--> Hook Script --[JSON via stdout]--> Cursor Agent
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Rules:
|
|
36
|
+
1. Always read stdin completely before processing (even if you don't need the input)
|
|
37
|
+
2. Write ONLY valid JSON to stdout (any other output breaks the protocol)
|
|
38
|
+
3. Use stderr for debug logs — it won't interfere with the protocol
|
|
39
|
+
4. Exit code determines behavior:
|
|
40
|
+
- `0` — Hook succeeded, use JSON output
|
|
41
|
+
- `2` — Block the action (equivalent to `permission: "deny"`)
|
|
42
|
+
- Any other code — Hook failed, action continues (fail-open by default)
|
|
43
|
+
|
|
44
|
+
### Agent Hooks vs Tab Hooks
|
|
45
|
+
|
|
46
|
+
**Agent hooks** (Cmd+K / Agent Chat) use these events:
|
|
47
|
+
- `sessionStart`, `sessionEnd`
|
|
48
|
+
- `preToolUse`, `postToolUse`, `postToolUseFailure`
|
|
49
|
+
- `subagentStart`, `subagentStop`
|
|
50
|
+
- `beforeShellExecution`, `afterShellExecution`
|
|
51
|
+
- `beforeMCPExecution`, `afterMCPExecution`
|
|
52
|
+
- `beforeReadFile`, `afterFileEdit`
|
|
53
|
+
- `beforeSubmitPrompt`
|
|
54
|
+
- `preCompact`, `stop`
|
|
55
|
+
- `afterAgentResponse`, `afterAgentThought`
|
|
56
|
+
|
|
57
|
+
**Tab hooks** (inline completions) use specialized events:
|
|
58
|
+
- `beforeTabFileRead` — Control file access for Tab completions
|
|
59
|
+
- `afterTabFileEdit` — Post-process Tab edits
|
|
60
|
+
|
|
61
|
+
These separate events allow defining different policies for autonomous Tab operations vs user-directed Agent operations.
|
|
62
|
+
|
|
63
|
+
### Execution Modes
|
|
64
|
+
|
|
65
|
+
**Command-based** (default): Execute shell scripts that receive JSON via stdin and return JSON via stdout.
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"command": ".cursor/hooks/my-hook.sh",
|
|
70
|
+
"timeout": 30
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Prompt-based**: Use an LLM to evaluate a natural-language condition. No custom scripts needed.
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"type": "prompt",
|
|
79
|
+
"prompt": "Does this command look safe to run? Only allow read-only operations.",
|
|
80
|
+
"timeout": 10
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Prompt-based hooks return `{ ok: boolean, reason?: string }`. The placeholder `$ARGUMENTS` is automatically replaced with the hook's JSON input. If absent, the input is appended automatically. Optional `model` field overrides the default LLM model.
|
|
85
|
+
|
|
86
|
+
### Fail-Open vs Fail-Closed
|
|
87
|
+
|
|
88
|
+
Most hooks are **fail-open**: if the script crashes, times out, or returns invalid JSON, the action continues.
|
|
89
|
+
|
|
90
|
+
Two hooks are **fail-closed** (action is blocked on failure):
|
|
91
|
+
- `beforeMCPExecution`
|
|
92
|
+
- `beforeReadFile`
|
|
93
|
+
|
|
94
|
+
This provides security guarantees for MCP operations and sensitive file access.
|
|
95
|
+
|
|
96
|
+
## Configuring hooks.json
|
|
97
|
+
|
|
98
|
+
### File Location and Priority
|
|
99
|
+
|
|
100
|
+
Configuration can exist at multiple levels. Higher priority overrides lower:
|
|
101
|
+
|
|
102
|
+
| Priority | Level | Location |
|
|
103
|
+
|----------|-------|----------|
|
|
104
|
+
| 1 (highest) | Enterprise | macOS: `/Library/Application Support/Cursor/hooks.json`, Linux/WSL: `/etc/cursor/hooks.json`, Windows: `C:\ProgramData\Cursor\hooks.json` |
|
|
105
|
+
| 2 | Team | Cloud-distributed via Cursor dashboard (Enterprise only) |
|
|
106
|
+
| 3 | Project | `<project-root>/.cursor/hooks.json` |
|
|
107
|
+
| 4 (lowest) | User | `~/.cursor/hooks.json` |
|
|
108
|
+
|
|
109
|
+
### Path Resolution
|
|
110
|
+
|
|
111
|
+
The working directory depends on the hook origin:
|
|
112
|
+
|
|
113
|
+
| Origin | Working directory | Example path |
|
|
114
|
+
|--------|-------------------|--------------|
|
|
115
|
+
| Project hooks | Project root | `.cursor/hooks/script.sh` |
|
|
116
|
+
| User hooks | `~/.cursor/` | `./hooks/script.sh` |
|
|
117
|
+
| Enterprise hooks | System config dir | Absolute paths recommended |
|
|
118
|
+
|
|
119
|
+
**Critical**: For project hooks, use `.cursor/hooks/script.sh` (relative to project root), NOT `./hooks/script.sh` (which would look for `<project>/hooks/script.sh`).
|
|
120
|
+
|
|
121
|
+
### Schema
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"version": 1,
|
|
126
|
+
"hooks": {
|
|
127
|
+
"<event_name>": [
|
|
128
|
+
{
|
|
129
|
+
"command": "<path-to-script>",
|
|
130
|
+
"type": "command",
|
|
131
|
+
"timeout": 30,
|
|
132
|
+
"loop_limit": 5,
|
|
133
|
+
"matcher": "<regex-pattern>"
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Per-Script Options
|
|
141
|
+
|
|
142
|
+
| Option | Type | Default | Description |
|
|
143
|
+
|--------|------|---------|-------------|
|
|
144
|
+
| `command` | string | required | Script path or shell command |
|
|
145
|
+
| `type` | `"command"` \| `"prompt"` | `"command"` | Execution type |
|
|
146
|
+
| `timeout` | number | platform default | Execution timeout in seconds |
|
|
147
|
+
| `loop_limit` | number \| null | `5` | Iteration limit for `stop`/`subagentStop` hooks. `null` = no limit |
|
|
148
|
+
| `matcher` | string | — | Regex pattern that filters when the hook fires |
|
|
149
|
+
|
|
150
|
+
### Matchers
|
|
151
|
+
|
|
152
|
+
Matchers filter when a hook executes. The field matched depends on the hook:
|
|
153
|
+
|
|
154
|
+
| Hook | Matcher applies to | Example |
|
|
155
|
+
|------|--------------------|---------|
|
|
156
|
+
| `preToolUse` (and other tool hooks) | Tool type | `"Shell\|Read\|Write"` |
|
|
157
|
+
| `subagentStart` | Subagent type | `"explore\|shell"` |
|
|
158
|
+
| `beforeShellExecution` | Full command string | `"curl\|wget\|nc"` |
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"hooks": {
|
|
163
|
+
"preToolUse": [
|
|
164
|
+
{ "command": ".cursor/hooks/validate-shell.sh", "matcher": "Shell" }
|
|
165
|
+
],
|
|
166
|
+
"beforeShellExecution": [
|
|
167
|
+
{ "command": ".cursor/hooks/approve-network.sh", "matcher": "curl|wget|nc" }
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Environment Variables
|
|
174
|
+
|
|
175
|
+
Hook scripts receive these variables at runtime:
|
|
176
|
+
|
|
177
|
+
| Variable | Description | Always present |
|
|
178
|
+
|----------|-------------|----------------|
|
|
179
|
+
| `CURSOR_PROJECT_DIR` | Workspace root directory | Yes |
|
|
180
|
+
| `CURSOR_VERSION` | Cursor version string | Yes |
|
|
181
|
+
| `CURSOR_USER_EMAIL` | Authenticated user email | If logged in |
|
|
182
|
+
| `CURSOR_CODE_REMOTE` | Remote-compatible project path | Remote workspaces |
|
|
183
|
+
| `CLAUDE_PROJECT_DIR` | Project dir alias (Claude compat) | Yes |
|
|
184
|
+
|
|
185
|
+
Session-scoped env vars from `sessionStart` hooks are passed to all subsequent hook executions within that session.
|
|
186
|
+
|
|
187
|
+
## Event Reference
|
|
188
|
+
|
|
189
|
+
### Common Input Fields
|
|
190
|
+
|
|
191
|
+
Every hook receives these base fields in addition to event-specific fields:
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{
|
|
195
|
+
"conversation_id": "string",
|
|
196
|
+
"generation_id": "string",
|
|
197
|
+
"model": "string",
|
|
198
|
+
"hook_event_name": "string",
|
|
199
|
+
"cursor_version": "string",
|
|
200
|
+
"workspace_roots": ["<path>"],
|
|
201
|
+
"user_email": "string | null",
|
|
202
|
+
"transcript_path": "string | null"
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Session Lifecycle
|
|
207
|
+
|
|
208
|
+
#### sessionStart
|
|
209
|
+
|
|
210
|
+
Fires when a new composer conversation is created.
|
|
211
|
+
|
|
212
|
+
```json
|
|
213
|
+
// Input
|
|
214
|
+
{
|
|
215
|
+
"session_id": "<unique session identifier>",
|
|
216
|
+
"is_background_agent": true | false,
|
|
217
|
+
"composer_mode": "agent" | "ask" | "edit"
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Output
|
|
221
|
+
{
|
|
222
|
+
"env": { "<key>": "<value>" },
|
|
223
|
+
"additional_context": "<context string appended to conversation>",
|
|
224
|
+
"continue": true | false,
|
|
225
|
+
"user_message": "<message shown if blocked>"
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
- `env` sets session-scoped environment variables available to all subsequent hooks
|
|
230
|
+
- `additional_context` injects text into the initial system context
|
|
231
|
+
- `continue: false` prevents session creation
|
|
232
|
+
|
|
233
|
+
#### sessionEnd
|
|
234
|
+
|
|
235
|
+
Fires when a composer conversation ends. Fire-and-forget (output is logged but not used).
|
|
236
|
+
|
|
237
|
+
```json
|
|
238
|
+
// Input
|
|
239
|
+
{
|
|
240
|
+
"session_id": "string",
|
|
241
|
+
"reason": "completed" | "aborted" | "error" | "window_close" | "user_close",
|
|
242
|
+
"duration_ms": 45000,
|
|
243
|
+
"is_background_agent": false,
|
|
244
|
+
"final_status": "string",
|
|
245
|
+
"error_message": "string (optional)"
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Tool Lifecycle (Generic)
|
|
250
|
+
|
|
251
|
+
#### preToolUse
|
|
252
|
+
|
|
253
|
+
Fires before any tool execution. Use matchers to filter by tool type (`Shell`, `Read`, `Write`, `Grep`, `Delete`, `MCP`, `Task`, etc.).
|
|
254
|
+
|
|
255
|
+
```json
|
|
256
|
+
// Input
|
|
257
|
+
{
|
|
258
|
+
"tool_name": "Shell",
|
|
259
|
+
"tool_input": { "command": "npm install", "working_directory": "/project" },
|
|
260
|
+
"tool_use_id": "abc123",
|
|
261
|
+
"cwd": "/project",
|
|
262
|
+
"agent_message": "Installing dependencies..."
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Output
|
|
266
|
+
{
|
|
267
|
+
"decision": "allow" | "deny",
|
|
268
|
+
"reason": "<shown to agent if denied>",
|
|
269
|
+
"updated_input": { "command": "npm ci" }
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
`updated_input` allows modifying the tool's input before execution.
|
|
274
|
+
|
|
275
|
+
#### postToolUse
|
|
276
|
+
|
|
277
|
+
Fires after successful tool execution. Useful for auditing.
|
|
278
|
+
|
|
279
|
+
```json
|
|
280
|
+
// Input
|
|
281
|
+
{
|
|
282
|
+
"tool_name": "Shell",
|
|
283
|
+
"tool_input": { "command": "npm test" },
|
|
284
|
+
"tool_output": "All tests passed",
|
|
285
|
+
"tool_use_id": "abc123",
|
|
286
|
+
"duration": 5432
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Output
|
|
290
|
+
{
|
|
291
|
+
"updated_mcp_tool_output": { "modified": "output" }
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
`updated_mcp_tool_output` (MCP tools only) replaces the tool output the model sees.
|
|
296
|
+
|
|
297
|
+
#### postToolUseFailure
|
|
298
|
+
|
|
299
|
+
Fires when a tool fails, times out, or is rejected.
|
|
300
|
+
|
|
301
|
+
```json
|
|
302
|
+
// Input
|
|
303
|
+
{
|
|
304
|
+
"tool_name": "Shell",
|
|
305
|
+
"tool_input": { "command": "npm test" },
|
|
306
|
+
"error_message": "Command timed out after 30s",
|
|
307
|
+
"failure_type": "timeout" | "error" | "permission_denied",
|
|
308
|
+
"duration": 5000,
|
|
309
|
+
"is_interrupt": false
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
No output fields currently supported.
|
|
314
|
+
|
|
315
|
+
### Subagent Lifecycle
|
|
316
|
+
|
|
317
|
+
#### subagentStart
|
|
318
|
+
|
|
319
|
+
Fires before starting a subagent (Task tool). Can allow or deny creation.
|
|
320
|
+
|
|
321
|
+
```json
|
|
322
|
+
// Input
|
|
323
|
+
{
|
|
324
|
+
"subagent_type": "generalPurpose" | "explore" | "shell",
|
|
325
|
+
"prompt": "Explore the authentication flow",
|
|
326
|
+
"model": "claude-sonnet-4-20250514"
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Output
|
|
330
|
+
{
|
|
331
|
+
"decision": "allow" | "deny",
|
|
332
|
+
"reason": "<reason if denied>"
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
#### subagentStop
|
|
337
|
+
|
|
338
|
+
Fires when a subagent finishes or fails.
|
|
339
|
+
|
|
340
|
+
```json
|
|
341
|
+
// Input
|
|
342
|
+
{
|
|
343
|
+
"subagent_type": "generalPurpose",
|
|
344
|
+
"status": "completed" | "error",
|
|
345
|
+
"result": "<subagent output>",
|
|
346
|
+
"duration": 45000,
|
|
347
|
+
"agent_transcript_path": "/path/to/transcript.txt"
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Output
|
|
351
|
+
{
|
|
352
|
+
"followup_message": "<auto-continue with this message>"
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
`followup_message` enables looping workflows where one subagent's completion triggers the next iteration.
|
|
357
|
+
|
|
358
|
+
### Shell Execution
|
|
359
|
+
|
|
360
|
+
#### beforeShellExecution
|
|
361
|
+
|
|
362
|
+
Fires before any shell command runs. Returns a permission decision.
|
|
363
|
+
|
|
364
|
+
```json
|
|
365
|
+
// Input
|
|
366
|
+
{
|
|
367
|
+
"command": "<full terminal command>",
|
|
368
|
+
"cwd": "<current working directory>",
|
|
369
|
+
"timeout": 30
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Output
|
|
373
|
+
{
|
|
374
|
+
"permission": "allow" | "deny" | "ask",
|
|
375
|
+
"user_message": "<message shown in client>",
|
|
376
|
+
"agent_message": "<message sent to agent>"
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
- `"allow"` — Proceed silently
|
|
381
|
+
- `"deny"` — Block execution, show `agent_message` to the model
|
|
382
|
+
- `"ask"` — Prompt the user for manual approval
|
|
383
|
+
|
|
384
|
+
#### afterShellExecution
|
|
385
|
+
|
|
386
|
+
Fires after a shell command completes. Useful for auditing.
|
|
387
|
+
|
|
388
|
+
```json
|
|
389
|
+
// Input
|
|
390
|
+
{
|
|
391
|
+
"command": "<full terminal command>",
|
|
392
|
+
"output": "<full terminal output>",
|
|
393
|
+
"duration": 1234
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
No output fields (observation-only).
|
|
398
|
+
|
|
399
|
+
### MCP Execution
|
|
400
|
+
|
|
401
|
+
#### beforeMCPExecution
|
|
402
|
+
|
|
403
|
+
Fires before an MCP tool runs. **Fail-closed**: if the hook fails, the MCP call is blocked.
|
|
404
|
+
|
|
405
|
+
```json
|
|
406
|
+
// Input
|
|
407
|
+
{
|
|
408
|
+
"tool_name": "<tool name>",
|
|
409
|
+
"tool_input": "<json params>",
|
|
410
|
+
"url": "<server url>", // OR
|
|
411
|
+
"command": "<command string>"
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Output
|
|
415
|
+
{
|
|
416
|
+
"permission": "allow" | "deny" | "ask",
|
|
417
|
+
"user_message": "<message shown in client>",
|
|
418
|
+
"agent_message": "<message sent to agent>"
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
#### afterMCPExecution
|
|
423
|
+
|
|
424
|
+
Fires after an MCP tool completes.
|
|
425
|
+
|
|
426
|
+
```json
|
|
427
|
+
// Input
|
|
428
|
+
{
|
|
429
|
+
"tool_name": "<tool name>",
|
|
430
|
+
"tool_input": "<json params>",
|
|
431
|
+
"result_json": "<tool result json>",
|
|
432
|
+
"duration": 1234
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### File Operations
|
|
437
|
+
|
|
438
|
+
#### beforeReadFile
|
|
439
|
+
|
|
440
|
+
Fires before the Agent reads a file. **Fail-closed**: if the hook fails, the read is blocked.
|
|
441
|
+
|
|
442
|
+
```json
|
|
443
|
+
// Input
|
|
444
|
+
{
|
|
445
|
+
"file_path": "<absolute path>",
|
|
446
|
+
"content": "<file contents>",
|
|
447
|
+
"attachments": [{ "type": "file" | "rule", "filePath": "<absolute path>" }]
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// Output
|
|
451
|
+
{
|
|
452
|
+
"permission": "allow" | "deny",
|
|
453
|
+
"user_message": "<message shown when denied>"
|
|
454
|
+
}
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
#### afterFileEdit
|
|
458
|
+
|
|
459
|
+
Fires after the Agent edits a file. Useful for formatters or scaffolding.
|
|
460
|
+
|
|
461
|
+
```json
|
|
462
|
+
// Input
|
|
463
|
+
{
|
|
464
|
+
"file_path": "<absolute path>",
|
|
465
|
+
"edits": [{ "old_string": "<search>", "new_string": "<replace>" }]
|
|
466
|
+
}
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
No output fields (observation-only).
|
|
470
|
+
|
|
471
|
+
### Tab-Specific Hooks
|
|
472
|
+
|
|
473
|
+
#### beforeTabFileRead
|
|
474
|
+
|
|
475
|
+
Fires before Tab (inline completions) reads a file. Only triggers for Tab, not Agent. Does not include `attachments`.
|
|
476
|
+
|
|
477
|
+
```json
|
|
478
|
+
// Input
|
|
479
|
+
{ "file_path": "<absolute path>", "content": "<file contents>" }
|
|
480
|
+
|
|
481
|
+
// Output
|
|
482
|
+
{ "permission": "allow" | "deny" }
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
#### afterTabFileEdit
|
|
486
|
+
|
|
487
|
+
Fires after Tab edits a file. Includes detailed edit info with line/column ranges.
|
|
488
|
+
|
|
489
|
+
```json
|
|
490
|
+
// Input
|
|
491
|
+
{
|
|
492
|
+
"file_path": "<absolute path>",
|
|
493
|
+
"edits": [{
|
|
494
|
+
"old_string": "<search>",
|
|
495
|
+
"new_string": "<replace>",
|
|
496
|
+
"range": { "start_line_number": 10, "start_column": 5, "end_line_number": 10, "end_column": 20 },
|
|
497
|
+
"old_line": "<line before edit>",
|
|
498
|
+
"new_line": "<line after edit>"
|
|
499
|
+
}]
|
|
500
|
+
}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### Prompt Validation
|
|
504
|
+
|
|
505
|
+
#### beforeSubmitPrompt
|
|
506
|
+
|
|
507
|
+
Fires after the user clicks send but before the backend request. Can block submission.
|
|
508
|
+
|
|
509
|
+
```json
|
|
510
|
+
// Input
|
|
511
|
+
{
|
|
512
|
+
"prompt": "<user prompt text>",
|
|
513
|
+
"attachments": [{ "type": "file" | "rule", "filePath": "<absolute path>" }]
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Output
|
|
517
|
+
{
|
|
518
|
+
"continue": true | false,
|
|
519
|
+
"user_message": "<message shown when blocked>"
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### Agent Response Observation
|
|
524
|
+
|
|
525
|
+
#### afterAgentResponse
|
|
526
|
+
|
|
527
|
+
Fires after the agent completes an assistant message.
|
|
528
|
+
|
|
529
|
+
```json
|
|
530
|
+
// Input
|
|
531
|
+
{ "text": "<final assistant text>" }
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
#### afterAgentThought
|
|
535
|
+
|
|
536
|
+
Fires after the agent completes a thinking block.
|
|
537
|
+
|
|
538
|
+
```json
|
|
539
|
+
// Input
|
|
540
|
+
{ "text": "<fully aggregated reasoning text>", "duration_ms": 5000 }
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### Flow Control
|
|
544
|
+
|
|
545
|
+
#### preCompact
|
|
546
|
+
|
|
547
|
+
Fires before context window compaction/summarization. Observation-only, cannot block compaction.
|
|
548
|
+
|
|
549
|
+
```json
|
|
550
|
+
// Input
|
|
551
|
+
{
|
|
552
|
+
"trigger": "auto" | "manual",
|
|
553
|
+
"context_usage_percent": 85,
|
|
554
|
+
"context_tokens": 120000,
|
|
555
|
+
"context_window_size": 128000,
|
|
556
|
+
"message_count": 45,
|
|
557
|
+
"messages_to_compact": 30,
|
|
558
|
+
"is_first_compaction": true | false
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// Output
|
|
562
|
+
{
|
|
563
|
+
"user_message": "<message to show when compaction occurs>"
|
|
564
|
+
}
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
#### stop
|
|
568
|
+
|
|
569
|
+
Fires when the agent loop ends. Can trigger automatic follow-up messages.
|
|
570
|
+
|
|
571
|
+
```json
|
|
572
|
+
// Input
|
|
573
|
+
{
|
|
574
|
+
"status": "completed" | "aborted" | "error",
|
|
575
|
+
"loop_count": 0
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// Output
|
|
579
|
+
{
|
|
580
|
+
"followup_message": "<text to auto-send as next user message>"
|
|
581
|
+
}
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
- `loop_count` starts at 0 and increments each time the stop hook triggers a follow-up
|
|
585
|
+
- Maximum 5 automatic follow-ups per conversation (default `loop_limit`)
|
|
586
|
+
- Set `loop_limit: null` in config for unlimited (use with caution)
|
|
587
|
+
|
|
588
|
+
## Implementation Patterns
|
|
589
|
+
|
|
590
|
+
### Universal stdin/stdout Pattern
|
|
591
|
+
|
|
592
|
+
Every hook needs to read JSON from stdin and write JSON to stdout. Here are reusable patterns for each language.
|
|
593
|
+
|
|
594
|
+
#### Bash
|
|
595
|
+
|
|
596
|
+
```bash
|
|
597
|
+
#!/bin/bash
|
|
598
|
+
input=$(cat)
|
|
599
|
+
# Parse fields with jq
|
|
600
|
+
command=$(echo "$input" | jq -r '.command // empty')
|
|
601
|
+
|
|
602
|
+
# Build and write JSON response
|
|
603
|
+
cat << EOF
|
|
604
|
+
{
|
|
605
|
+
"permission": "allow"
|
|
606
|
+
}
|
|
607
|
+
EOF
|
|
608
|
+
exit 0
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
#### TypeScript (with tsx or bun)
|
|
612
|
+
|
|
613
|
+
```typescript
|
|
614
|
+
interface HookInput {
|
|
615
|
+
file_path: string;
|
|
616
|
+
workspace_roots: string[];
|
|
617
|
+
[key: string]: unknown;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function readStdin(): Promise<string> {
|
|
621
|
+
return new Promise((resolve) => {
|
|
622
|
+
let data = "";
|
|
623
|
+
process.stdin.setEncoding("utf8");
|
|
624
|
+
process.stdin.on("data", (chunk: string) => { data += chunk; });
|
|
625
|
+
process.stdin.on("end", () => resolve(data));
|
|
626
|
+
process.stdin.on("error", () => resolve(""));
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function respond(output: Record<string, unknown>): void {
|
|
631
|
+
process.stdout.write(JSON.stringify(output) + "\n");
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
async function main(): Promise<void> {
|
|
635
|
+
try {
|
|
636
|
+
const raw = await readStdin();
|
|
637
|
+
if (!raw?.trim()) return;
|
|
638
|
+
const payload = JSON.parse(raw.replace(/^\uFEFF/, "").trim()) as HookInput;
|
|
639
|
+
|
|
640
|
+
// --- Hook logic here ---
|
|
641
|
+
|
|
642
|
+
respond({ permission: "allow" });
|
|
643
|
+
} catch (err) {
|
|
644
|
+
console.error("[hook] Error:", err instanceof Error ? err.message : String(err));
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
main();
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
Run with: `npx tsx .cursor/hooks/my-hook.ts` or `bun run .cursor/hooks/my-hook.ts`
|
|
652
|
+
|
|
653
|
+
#### Python
|
|
654
|
+
|
|
655
|
+
```python
|
|
656
|
+
#!/usr/bin/env python3
|
|
657
|
+
import json
|
|
658
|
+
import sys
|
|
659
|
+
|
|
660
|
+
def main() -> None:
|
|
661
|
+
payload = json.load(sys.stdin)
|
|
662
|
+
response = {"permission": "allow"}
|
|
663
|
+
|
|
664
|
+
# --- Hook logic here ---
|
|
665
|
+
|
|
666
|
+
print(json.dumps(response))
|
|
667
|
+
|
|
668
|
+
if __name__ == "__main__":
|
|
669
|
+
main()
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
#### Prompt-Based (No Code)
|
|
673
|
+
|
|
674
|
+
```json
|
|
675
|
+
{
|
|
676
|
+
"type": "prompt",
|
|
677
|
+
"prompt": "Is this shell command safe? Only allow read-only operations like ls, cat, grep, find. Block any command that writes, deletes, or modifies files. $ARGUMENTS",
|
|
678
|
+
"timeout": 10
|
|
679
|
+
}
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
### Choosing the Right Language
|
|
683
|
+
|
|
684
|
+
| Criteria | Bash | TypeScript | Python | Prompt-based |
|
|
685
|
+
|----------|------|------------|--------|-------------|
|
|
686
|
+
| Simple allow/deny/audit | Best | Overkill | Overkill | Good |
|
|
687
|
+
| Complex logic, type safety | No | Best | Good | No |
|
|
688
|
+
| File system manipulation | Possible | Best | Good | No |
|
|
689
|
+
| YAML/XML parsing | Poor | Good | Best | No |
|
|
690
|
+
| No code needed | No | No | No | Best |
|
|
691
|
+
| Windows compatibility | Poor | Best | Good | Best |
|
|
692
|
+
| Needs external libraries | Limited | npm/bun | pip | N/A |
|
|
693
|
+
|
|
694
|
+
## Common Use Cases
|
|
695
|
+
|
|
696
|
+
### 1. Auto-Format After Edit
|
|
697
|
+
|
|
698
|
+
Run a formatter every time the agent edits a file.
|
|
699
|
+
|
|
700
|
+
```json
|
|
701
|
+
// .cursor/hooks.json
|
|
702
|
+
{
|
|
703
|
+
"version": 1,
|
|
704
|
+
"hooks": {
|
|
705
|
+
"afterFileEdit": [
|
|
706
|
+
{ "command": ".cursor/hooks/format.sh" }
|
|
707
|
+
]
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
```bash
|
|
713
|
+
#!/bin/bash
|
|
714
|
+
# .cursor/hooks/format.sh
|
|
715
|
+
input=$(cat)
|
|
716
|
+
file_path=$(echo "$input" | jq -r '.file_path // empty')
|
|
717
|
+
|
|
718
|
+
if [[ -z "$file_path" ]]; then
|
|
719
|
+
exit 0
|
|
720
|
+
fi
|
|
721
|
+
|
|
722
|
+
case "$file_path" in
|
|
723
|
+
*.ts|*.tsx|*.js|*.jsx)
|
|
724
|
+
npx prettier --write "$file_path" 2>/dev/null
|
|
725
|
+
;;
|
|
726
|
+
*.py)
|
|
727
|
+
python3 -m black "$file_path" 2>/dev/null
|
|
728
|
+
;;
|
|
729
|
+
*.rs)
|
|
730
|
+
rustfmt "$file_path" 2>/dev/null
|
|
731
|
+
;;
|
|
732
|
+
esac
|
|
733
|
+
|
|
734
|
+
exit 0
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
### 2. Block Dangerous Shell Commands
|
|
738
|
+
|
|
739
|
+
Prevent destructive commands from executing.
|
|
740
|
+
|
|
741
|
+
```json
|
|
742
|
+
{
|
|
743
|
+
"version": 1,
|
|
744
|
+
"hooks": {
|
|
745
|
+
"beforeShellExecution": [
|
|
746
|
+
{
|
|
747
|
+
"command": ".cursor/hooks/block-dangerous.sh",
|
|
748
|
+
"matcher": "rm|drop|truncate|format|mkfs"
|
|
749
|
+
}
|
|
750
|
+
]
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
```bash
|
|
756
|
+
#!/bin/bash
|
|
757
|
+
# .cursor/hooks/block-dangerous.sh
|
|
758
|
+
input=$(cat)
|
|
759
|
+
command=$(echo "$input" | jq -r '.command // empty')
|
|
760
|
+
|
|
761
|
+
DANGEROUS_PATTERNS=(
|
|
762
|
+
"rm -rf /"
|
|
763
|
+
"rm -rf ~"
|
|
764
|
+
"DROP DATABASE"
|
|
765
|
+
"DROP TABLE"
|
|
766
|
+
"TRUNCATE"
|
|
767
|
+
"mkfs"
|
|
768
|
+
"format c:"
|
|
769
|
+
"> /dev/sda"
|
|
770
|
+
)
|
|
771
|
+
|
|
772
|
+
for pattern in "${DANGEROUS_PATTERNS[@]}"; do
|
|
773
|
+
if echo "$command" | grep -qi "$pattern"; then
|
|
774
|
+
cat << EOF
|
|
775
|
+
{
|
|
776
|
+
"permission": "deny",
|
|
777
|
+
"user_message": "Blocked potentially dangerous command: $command",
|
|
778
|
+
"agent_message": "This command was blocked by a safety hook because it matches a dangerous pattern ('$pattern'). Please use a safer alternative."
|
|
779
|
+
}
|
|
780
|
+
EOF
|
|
781
|
+
exit 0
|
|
782
|
+
fi
|
|
783
|
+
done
|
|
784
|
+
|
|
785
|
+
cat << 'EOF'
|
|
786
|
+
{ "permission": "allow" }
|
|
787
|
+
EOF
|
|
788
|
+
exit 0
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
### 3. Audit Agent Actions
|
|
792
|
+
|
|
793
|
+
Log every tool use and shell command for review.
|
|
794
|
+
|
|
795
|
+
```json
|
|
796
|
+
{
|
|
797
|
+
"version": 1,
|
|
798
|
+
"hooks": {
|
|
799
|
+
"postToolUse": [{ "command": ".cursor/hooks/audit.sh" }],
|
|
800
|
+
"afterShellExecution": [{ "command": ".cursor/hooks/audit.sh" }],
|
|
801
|
+
"afterMCPExecution": [{ "command": ".cursor/hooks/audit.sh" }]
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
```bash
|
|
807
|
+
#!/bin/bash
|
|
808
|
+
# .cursor/hooks/audit.sh
|
|
809
|
+
json_input=$(cat)
|
|
810
|
+
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
|
811
|
+
log_dir="${CURSOR_PROJECT_DIR:-.}/.cursor/hooks/logs"
|
|
812
|
+
mkdir -p "$log_dir"
|
|
813
|
+
echo "[$timestamp] $json_input" >> "$log_dir/agent-audit.log"
|
|
814
|
+
exit 0
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
### 4. Inject Context at Session Start
|
|
818
|
+
|
|
819
|
+
Add project-specific context when the agent session begins.
|
|
820
|
+
|
|
821
|
+
```json
|
|
822
|
+
{
|
|
823
|
+
"version": 1,
|
|
824
|
+
"hooks": {
|
|
825
|
+
"sessionStart": [
|
|
826
|
+
{ "command": ".cursor/hooks/session-init.sh" }
|
|
827
|
+
]
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
```bash
|
|
833
|
+
#!/bin/bash
|
|
834
|
+
# .cursor/hooks/session-init.sh
|
|
835
|
+
input=$(cat)
|
|
836
|
+
|
|
837
|
+
git_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
|
|
838
|
+
node_version=$(node --version 2>/dev/null || echo "unknown")
|
|
839
|
+
last_commit=$(git log -1 --format='%h %s' 2>/dev/null || echo "unknown")
|
|
840
|
+
|
|
841
|
+
cat << EOF
|
|
842
|
+
{
|
|
843
|
+
"env": {
|
|
844
|
+
"GIT_BRANCH": "$git_branch",
|
|
845
|
+
"NODE_VERSION": "$node_version"
|
|
846
|
+
},
|
|
847
|
+
"additional_context": "Current branch: $git_branch. Node: $node_version. Last commit: $last_commit.",
|
|
848
|
+
"continue": true
|
|
849
|
+
}
|
|
850
|
+
EOF
|
|
851
|
+
exit 0
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
### 5. Auto-Retry on Error (Stop Hook)
|
|
855
|
+
|
|
856
|
+
Automatically retry when the agent ends in error state.
|
|
857
|
+
|
|
858
|
+
```json
|
|
859
|
+
{
|
|
860
|
+
"version": 1,
|
|
861
|
+
"hooks": {
|
|
862
|
+
"stop": [
|
|
863
|
+
{ "command": ".cursor/hooks/auto-retry.sh", "loop_limit": 3 }
|
|
864
|
+
]
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
```bash
|
|
870
|
+
#!/bin/bash
|
|
871
|
+
# .cursor/hooks/auto-retry.sh
|
|
872
|
+
input=$(cat)
|
|
873
|
+
status=$(echo "$input" | jq -r '.status // empty')
|
|
874
|
+
loop_count=$(echo "$input" | jq -r '.loop_count // 0')
|
|
875
|
+
|
|
876
|
+
if [[ "$status" == "error" && "$loop_count" -lt 2 ]]; then
|
|
877
|
+
cat << 'EOF'
|
|
878
|
+
{
|
|
879
|
+
"followup_message": "The previous attempt failed. Please review the error, fix the issue, and try again."
|
|
880
|
+
}
|
|
881
|
+
EOF
|
|
882
|
+
else
|
|
883
|
+
echo '{}'
|
|
884
|
+
fi
|
|
885
|
+
exit 0
|
|
886
|
+
```
|
|
887
|
+
|
|
888
|
+
### 6. Protect Sensitive Files
|
|
889
|
+
|
|
890
|
+
Block the agent from reading files containing secrets.
|
|
891
|
+
|
|
892
|
+
```json
|
|
893
|
+
{
|
|
894
|
+
"version": 1,
|
|
895
|
+
"hooks": {
|
|
896
|
+
"beforeReadFile": [
|
|
897
|
+
{ "command": ".cursor/hooks/protect-secrets.sh" }
|
|
898
|
+
]
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
```
|
|
902
|
+
|
|
903
|
+
```bash
|
|
904
|
+
#!/bin/bash
|
|
905
|
+
# .cursor/hooks/protect-secrets.sh — fail-closed hook
|
|
906
|
+
input=$(cat)
|
|
907
|
+
file_path=$(echo "$input" | jq -r '.file_path // empty')
|
|
908
|
+
basename=$(basename "$file_path")
|
|
909
|
+
|
|
910
|
+
PROTECTED_PATTERNS=(".env" ".env.local" ".env.production" "credentials.json" "secrets.yaml" "id_rsa" "*.pem" "*.key")
|
|
911
|
+
|
|
912
|
+
for pattern in "${PROTECTED_PATTERNS[@]}"; do
|
|
913
|
+
if [[ "$basename" == $pattern ]]; then
|
|
914
|
+
cat << EOF
|
|
915
|
+
{
|
|
916
|
+
"permission": "deny",
|
|
917
|
+
"user_message": "Access to $basename blocked by security hook. This file may contain secrets."
|
|
918
|
+
}
|
|
919
|
+
EOF
|
|
920
|
+
exit 0
|
|
921
|
+
fi
|
|
922
|
+
done
|
|
923
|
+
|
|
924
|
+
cat << 'EOF'
|
|
925
|
+
{ "permission": "allow" }
|
|
926
|
+
EOF
|
|
927
|
+
exit 0
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
### 7. Control Subagent Execution
|
|
931
|
+
|
|
932
|
+
Restrict which subagent types can be launched.
|
|
933
|
+
|
|
934
|
+
```json
|
|
935
|
+
{
|
|
936
|
+
"version": 1,
|
|
937
|
+
"hooks": {
|
|
938
|
+
"subagentStart": [
|
|
939
|
+
{ "command": ".cursor/hooks/validate-subagent.sh" }
|
|
940
|
+
]
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
```bash
|
|
946
|
+
#!/bin/bash
|
|
947
|
+
# .cursor/hooks/validate-subagent.sh
|
|
948
|
+
input=$(cat)
|
|
949
|
+
subagent_type=$(echo "$input" | jq -r '.subagent_type // empty')
|
|
950
|
+
|
|
951
|
+
ALLOWED_TYPES=("explore" "generalPurpose")
|
|
952
|
+
|
|
953
|
+
for allowed in "${ALLOWED_TYPES[@]}"; do
|
|
954
|
+
if [[ "$subagent_type" == "$allowed" ]]; then
|
|
955
|
+
cat << 'EOF'
|
|
956
|
+
{ "decision": "allow" }
|
|
957
|
+
EOF
|
|
958
|
+
exit 0
|
|
959
|
+
fi
|
|
960
|
+
done
|
|
961
|
+
|
|
962
|
+
cat << EOF
|
|
963
|
+
{
|
|
964
|
+
"decision": "deny",
|
|
965
|
+
"reason": "Subagent type '$subagent_type' is not allowed by project policy. Allowed types: ${ALLOWED_TYPES[*]}"
|
|
966
|
+
}
|
|
967
|
+
EOF
|
|
968
|
+
exit 0
|
|
969
|
+
```
|
|
970
|
+
|
|
971
|
+
### 8. Auto-Scaffold Tests After Edit (TypeScript)
|
|
972
|
+
|
|
973
|
+
Detect source files without tests and generate a scaffold. This pattern is used in production (see `ensureTestsExist.ts` in the react-vite template).
|
|
974
|
+
|
|
975
|
+
```json
|
|
976
|
+
{
|
|
977
|
+
"version": 1,
|
|
978
|
+
"hooks": {
|
|
979
|
+
"afterFileEdit": [
|
|
980
|
+
{ "command": "npx tsx .cursor/hooks/ensure-tests.ts" }
|
|
981
|
+
]
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
Key implementation principles from the real-world example:
|
|
987
|
+
|
|
988
|
+
1. Parse `file_path` and `workspace_roots` from the payload
|
|
989
|
+
2. Normalize paths and compute relative path from workspace root
|
|
990
|
+
3. Filter: skip test files, config files, generated files
|
|
991
|
+
4. Detect file type (component, hook, util, route) from path conventions
|
|
992
|
+
5. Check if a corresponding test file already exists
|
|
993
|
+
6. Generate a minimal scaffold with correct imports and test structure
|
|
994
|
+
7. Write the scaffold to the test directory, creating parent dirs as needed
|
|
995
|
+
8. Log to stderr for debugging: `console.error("[hook] message")`
|
|
996
|
+
|
|
997
|
+
### 9. Block Git Commands (Redirect to GitHub CLI)
|
|
998
|
+
|
|
999
|
+
Force the use of `gh` instead of raw `git` commands.
|
|
1000
|
+
|
|
1001
|
+
```json
|
|
1002
|
+
{
|
|
1003
|
+
"version": 1,
|
|
1004
|
+
"hooks": {
|
|
1005
|
+
"beforeShellExecution": [
|
|
1006
|
+
{ "command": ".cursor/hooks/block-git.sh", "matcher": "git|gh" }
|
|
1007
|
+
]
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
```
|
|
1011
|
+
|
|
1012
|
+
```bash
|
|
1013
|
+
#!/bin/bash
|
|
1014
|
+
# .cursor/hooks/block-git.sh
|
|
1015
|
+
input=$(cat)
|
|
1016
|
+
command=$(echo "$input" | jq -r '.command // empty')
|
|
1017
|
+
|
|
1018
|
+
if [[ "$command" =~ git[[:space:]] ]] || [[ "$command" == "git" ]]; then
|
|
1019
|
+
cat << EOF
|
|
1020
|
+
{
|
|
1021
|
+
"permission": "deny",
|
|
1022
|
+
"user_message": "Git command blocked. Use the GitHub CLI (gh) instead.",
|
|
1023
|
+
"agent_message": "The command '$command' was blocked. Use the 'gh' tool instead for better GitHub integration."
|
|
1024
|
+
}
|
|
1025
|
+
EOF
|
|
1026
|
+
elif [[ "$command" =~ gh[[:space:]] ]] || [[ "$command" == "gh" ]]; then
|
|
1027
|
+
cat << EOF
|
|
1028
|
+
{
|
|
1029
|
+
"permission": "ask",
|
|
1030
|
+
"user_message": "GitHub CLI command requires permission: $command"
|
|
1031
|
+
}
|
|
1032
|
+
EOF
|
|
1033
|
+
else
|
|
1034
|
+
echo '{ "permission": "allow" }'
|
|
1035
|
+
fi
|
|
1036
|
+
exit 0
|
|
1037
|
+
```
|
|
1038
|
+
|
|
1039
|
+
## Decision Guide
|
|
1040
|
+
|
|
1041
|
+
Use this to pick the right event and language:
|
|
1042
|
+
|
|
1043
|
+
| I want to... | Event | Recommended language |
|
|
1044
|
+
|---------------|-------|---------------------|
|
|
1045
|
+
| Format files after agent edits | `afterFileEdit` | Bash |
|
|
1046
|
+
| Block dangerous shell commands | `beforeShellExecution` | Bash |
|
|
1047
|
+
| Log all agent actions | `postToolUse` + `afterShellExecution` | Bash |
|
|
1048
|
+
| Inject project context at start | `sessionStart` | Bash |
|
|
1049
|
+
| Auto-retry failed agent runs | `stop` | Bash |
|
|
1050
|
+
| Protect secret files | `beforeReadFile` | Bash |
|
|
1051
|
+
| Scaffold tests for edited files | `afterFileEdit` | TypeScript |
|
|
1052
|
+
| Validate Kubernetes manifests | `beforeShellExecution` | Python |
|
|
1053
|
+
| Enforce policies without code | Any `before*` event | Prompt-based |
|
|
1054
|
+
| Track error counts across sessions | `stop` | TypeScript |
|
|
1055
|
+
| Modify tool input before execution | `preToolUse` | TypeScript |
|
|
1056
|
+
| Control subagent creation | `subagentStart` | Bash |
|
|
1057
|
+
| Redact secrets from Tab context | `beforeTabFileRead` | Bash or TypeScript |
|
|
1058
|
+
| Post-process Tab completions | `afterTabFileEdit` | Bash |
|
|
1059
|
+
|
|
1060
|
+
## Best Practices
|
|
1061
|
+
|
|
1062
|
+
1. **Always drain stdin** — Read all input even if you don't need it, to avoid SIGPIPE errors
|
|
1063
|
+
2. **Write only valid JSON to stdout** — Any other output (debug prints, warnings) breaks the protocol
|
|
1064
|
+
3. **Use stderr for debug logging** — `console.error()` in TypeScript, `echo ... >&2` in Bash
|
|
1065
|
+
4. **Exit code 0 for success** — Even when denying; use the JSON `permission` or `decision` field instead
|
|
1066
|
+
5. **Exit code 2 to block** — Shortcut for deny without needing JSON output
|
|
1067
|
+
6. **Handle errors gracefully** — Wrap main logic in try-catch; a crashing hook should not break the agent
|
|
1068
|
+
7. **Set appropriate timeouts** — Simple hooks: 5-10s. Complex hooks with I/O: 30s. Adjust `timeout` in config
|
|
1069
|
+
8. **Use matchers to scope hooks** — Don't run a heavy hook on every event; filter to relevant tools/commands
|
|
1070
|
+
9. **Project hooks use project-relative paths** — `.cursor/hooks/script.sh`, not `./hooks/script.sh`
|
|
1071
|
+
10. **Keep hooks fast** — They run synchronously in the agent loop; slow hooks degrade the experience
|
|
1072
|
+
11. **Make hooks idempotent** — The same input should always produce the same output
|
|
1073
|
+
12. **Use `jq` for JSON parsing in Bash** — Avoid fragile string manipulation with grep/sed
|
|
1074
|
+
|
|
1075
|
+
## Anti-Patterns
|
|
1076
|
+
|
|
1077
|
+
| Anti-pattern | Problem | Fix |
|
|
1078
|
+
|-------------|---------|-----|
|
|
1079
|
+
| Writing non-JSON to stdout | Breaks the protocol, hook output is silently discarded | Use stderr for logs, stdout only for JSON |
|
|
1080
|
+
| Not reading stdin | Can cause SIGPIPE and process termination | Always `cat > /dev/null` or read fully |
|
|
1081
|
+
| No timeout configured | Hook can hang indefinitely, blocking the agent | Set `timeout` in hooks.json |
|
|
1082
|
+
| Using `process.exit(1)` on error | Triggers fail-open behavior unnecessarily | Catch errors, return valid JSON, exit 0 |
|
|
1083
|
+
| Mixing project/user paths | Script not found at runtime | Project: `.cursor/hooks/x.sh`, User: `./hooks/x.sh` |
|
|
1084
|
+
| Logging secrets in audit hooks | PII/credentials end up in log files | Redact sensitive fields before logging |
|
|
1085
|
+
| Heavy computation in every hook | Degrades agent responsiveness | Use matchers to limit scope, cache results |
|
|
1086
|
+
| Infinite retry loops in stop hooks | Agent never stops | Set `loop_limit` and check `loop_count` |
|
|
1087
|
+
| Forgetting fail-closed semantics | `beforeMCPExecution` and `beforeReadFile` block on failure | Ensure these hooks always return valid JSON |
|
|
1088
|
+
| Hardcoding absolute paths | Breaks when project moves or on different machines | Use `$CURSOR_PROJECT_DIR` or relative paths |
|
|
1089
|
+
|
|
1090
|
+
## Troubleshooting
|
|
1091
|
+
|
|
1092
|
+
**Hooks not loading**: Restart Cursor after creating/modifying `hooks.json`. Check the Hooks tab in Cursor Settings and the Hooks output channel for errors.
|
|
1093
|
+
|
|
1094
|
+
**Script not found**: Verify the path is correct for the hook origin. Project hooks resolve from the project root, not from `.cursor/`.
|
|
1095
|
+
|
|
1096
|
+
**Hook runs but has no effect**: Check that stdout contains valid JSON. Any non-JSON output is silently discarded. Redirect debug output to stderr.
|
|
1097
|
+
|
|
1098
|
+
**Permission denied on script**: On macOS/Linux, run `chmod +x .cursor/hooks/script.sh`. On Windows, use TypeScript with `npx tsx` instead of shell scripts.
|
|
1099
|
+
|
|
1100
|
+
**Hook hangs**: Add a `timeout` to the hook configuration. Check for blocking I/O operations (network calls, large file reads) and add timeouts to those as well.
|