hooks.json 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. {
  2. "_comment": "通用示例配置(占位符模板 hooks.json)。command 用 {{PYTHON_BIN}} 与 {{HOOKS_DIR}} 占位符,由运行时环境变量替换(方式 A),或经 hooks/install_hooks.py 预处理生成 hooks.installed.json(方式 B)。本模板不写死任何机器路径,换机/换项目只改环境变量或重跑安装器即可。matcher 已并集 write_to_file|replace_in_file|Write|Edit,跨工具(CodeBuddy CN / Trae / Cursor 等)通用。",
  3. "hooks": {
  4. "PreToolUse": [
  5. {
  6. "matcher": "write_to_file|replace_in_file|Write|Edit",
  7. "hooks": [
  8. {
  9. "type": "command",
  10. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/backup_on_write.py\"",
  11. "timeout": 10
  12. }
  13. ]
  14. },
  15. {
  16. "matcher": "write_to_file|replace_in_file|Write|Edit",
  17. "hooks": [
  18. {
  19. "type": "command",
  20. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/guard_dirs.py\"",
  21. "timeout": 10
  22. }
  23. ]
  24. },
  25. {
  26. "matcher": "write_to_file|replace_in_file|Write|Edit",
  27. "hooks": [
  28. {
  29. "type": "command",
  30. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/plan_guard.py\"",
  31. "timeout": 10
  32. }
  33. ]
  34. }
  35. ],
  36. "PostToolUse": [
  37. {
  38. "matcher": "write_to_file|replace_in_file|Write|Edit",
  39. "hooks": [
  40. {
  41. "type": "command",
  42. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/lint_on_write.py\"",
  43. "timeout": 30
  44. }
  45. ]
  46. },
  47. {
  48. "matcher": "write_to_file|replace_in_file|Write|Edit",
  49. "hooks": [
  50. {
  51. "type": "command",
  52. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/php8_compat.py\"",
  53. "timeout": 20
  54. }
  55. ]
  56. },
  57. {
  58. "matcher": "write_to_file|replace_in_file|Write|Edit",
  59. "hooks": [
  60. {
  61. "type": "command",
  62. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/security_scan.py\"",
  63. "timeout": 20
  64. }
  65. ]
  66. },
  67. {
  68. "matcher": "write_to_file|replace_in_file|Write|Edit",
  69. "hooks": [
  70. {
  71. "type": "command",
  72. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/secret_scan.py\"",
  73. "timeout": 20
  74. }
  75. ]
  76. },
  77. {
  78. "matcher": "write_to_file|replace_in_file|Write|Edit",
  79. "hooks": [
  80. {
  81. "type": "command",
  82. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/utf8_check.py\"",
  83. "timeout": 10
  84. }
  85. ]
  86. },
  87. {
  88. "matcher": "write_to_file|replace_in_file|Write|Edit",
  89. "hooks": [
  90. {
  91. "type": "command",
  92. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/debug_residue.py\"",
  93. "timeout": 10
  94. }
  95. ]
  96. },
  97. {
  98. "matcher": "write_to_file|replace_in_file|Write|Edit",
  99. "hooks": [
  100. {
  101. "type": "command",
  102. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/select_star.py\"",
  103. "timeout": 10
  104. }
  105. ]
  106. },
  107. {
  108. "matcher": "write_to_file|replace_in_file|Write|Edit",
  109. "hooks": [
  110. {
  111. "type": "command",
  112. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/dep_scan.py\"",
  113. "timeout": 10
  114. }
  115. ]
  116. },
  117. {
  118. "matcher": "write_to_file|replace_in_file|Write|Edit",
  119. "hooks": [
  120. {
  121. "type": "command",
  122. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/sql_injection_check.py\"",
  123. "timeout": 15
  124. }
  125. ]
  126. },
  127. {
  128. "matcher": "write_to_file|replace_in_file|Write|Edit",
  129. "hooks": [
  130. {
  131. "type": "command",
  132. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/cms_risk_check.py\"",
  133. "timeout": 15
  134. }
  135. ]
  136. },
  137. {
  138. "matcher": "write_to_file|replace_in_file|Write|Edit|Bash|execute_command|run_command|run_in_terminal|terminal",
  139. "hooks": [
  140. {
  141. "type": "command",
  142. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/capture_learning.py\"",
  143. "timeout": 15
  144. }
  145. ]
  146. }
  147. ],
  148. "PreCompact": [
  149. {
  150. "matcher": "*",
  151. "hooks": [
  152. {
  153. "type": "command",
  154. "command": "{{PYTHON_BIN}} \"{{HOOKS_DIR}}/handoff_snapshot.py\"",
  155. "timeout": 20
  156. }
  157. ]
  158. }
  159. ]
  160. }
  161. }