mcpField
G
groove-admin-cursor-hooks

groove-admin-cursor-hooks

github.com/andreadellacorteAgent 工作流6518 次安装14 周前更新
代码仓库

关于 groove-admin-cursor-hooks

为 groove 项目安装和管理 Cursor 原生钩子的技能。钩子在模型之外确定性地响应会话、工具和停止事件,并保留现有的非 groove 配置。

主要功能

  1. 01安装六种 Cursor 生命周期钩子
  2. 02列出已注册钩子及脚本
  3. 03按名称禁用指定钩子
  4. 04合并配置并保留现有条目
  5. 05跟踪 Git 活动并暂存会话记录

适用场景

  1. 01会话开始时重新加载 groove 工作流上下文
  2. 02在指定时段提醒执行日终流程
  3. 03阻止修改 groove 管理的技能路径
  4. 04为后续审阅暂存 Git 会话记录

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/andreadellacorte/groove --skill groove-admin-cursor-hooks

安装后在 Claude Code 中输入/groove-admin-cursor-hooks确认已加载。

详细介绍

groove-admin-cursor-hooks

安装 groove 的 Cursor 原生钩子。这些钩子在模型之外运行——确定且无条件——并补充 groove 的建议性 Markdown 钩子(.groove/hooks/start.md、end.md)。

使用 --disable <hook> 移除指定钩子。使用 --list 查看当前状态。

结果

所选钩子会注册到 .cursor/hooks.json,Shell 脚本会写入 .groove/hooks/cursor/。钩子会在 Cursor 生命周期事件发生时自动触发,不涉及模型。

可用钩子

名称事件匹配项功能
context-reprimesessionStart—使用 --json 运行 prime 脚本,确保每次会话启动和压缩后都加载完整的工作流上下文
daily-end-reminderstop—如果本地时间为 16–21 点且 .groove/index.md 存在,则打印提醒,提示运行 /groove-daily-end
git-activity-bufferpostToolUseShell如果命令包含 git commit,则向 .groove/.cache/git-activity-buffer.txt 追加带时间戳的行
block-managed-pathspreToolUseWrite如果 file_path 以 .agents/skills/groove 或 skills/groove 开头,则以代码 2 退出,通过说明消息阻止写入
version-checkpostToolUse—每小时检查一次是否有新的 groove 版本;调用 groove-utilities-check
session-capturestop—如果本次会话有 Git 活动(午夜后提交、有工作区更改或有缓冲的提交),则将捕获草稿暂存到 .groove/.cache/pending-capture.md,供下次会话审查。静默执行。

步骤

--list

如果 .cursor/hooks.json 存在,则读取该文件。报告已注册的 groove 钩子,以及 .groove/hooks/cursor/ 中存在的脚本。退出。

--disable <hook>

从 .cursor/hooks.json 中移除指定钩子的条目(保留脚本)。报告已移除或未找到。退出。

默认(安装)
  1. 询问要启用哪些钩子(默认:全部六个):

    Which hooks to install? (all / comma-separated: context-reprime, daily-end-reminder, git-activity-buffer, block-managed-paths, version-check, session-capture)
    Press enter for all.
    
  2. 如果 .cursor/hooks.json 存在,则读取并解析为 JSON(默认值为 {"version": 1, "hooks": {}})。绝不丢弃现有的非 groove 条目。

  3. 如果 .groove/hooks/cursor/ 目录不存在,则创建该目录。将每个脚本设为可执行(chmod +x)。

  4. 对每个选定的钩子:编写 Shell 脚本,并将钩子条目合并到 .cursor/hooks.json。

  5. 将合并后的结果写入 .cursor/hooks.json。

  6. 报告摘要:

    ✓ context-reprime     — sessionStart hook → groove-utilities-prime.sh --json
    ✓ daily-end-reminder  — stop hook → .groove/hooks/cursor/daily-end-reminder.sh
    ✓ git-activity-buffer — postToolUse/Shell hook → .groove/hooks/cursor/git-activity-buffer.sh
    ✓ block-managed-paths — preToolUse/Write hook → .groove/hooks/cursor/block-managed-paths.sh
    ✓ version-check       — postToolUse hook → .groove/hooks/cursor/version-check.sh
    ✓ session-capture     — stop hook → .groove/hooks/cursor/session-capture.sh
    ✓ .cursor/hooks.json updated
    

Shell 脚本模板

将以下内容逐字写入 .groove/hooks/cursor/。未经展示差异并确认,绝不覆盖现有脚本。

daily-end-reminder.sh
#!/usr/bin/env bash
# groove: stop hook — remind about /groove-daily-end during work hours
hour=$(date +%H)
if [ -f "$CLAUDE_PROJECT_DIR/.groove/index.md" ] && [ "$hour" -ge 16 ] && [ "$hour" -le 21 ]; then
  echo "groove: end of work hours — consider running /groove-daily-end"
fi
git-activity-buffer.sh
#!/usr/bin/env bash
# groove: postToolUse/Shell hook — buffer git commits for memory log
input=$(cat)
command=$(echo "$input" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('tool_input',{}).get('command',''))" 2>/dev/null)
if echo "$command" | grep -q "git commit"; then
  msg=$(echo "$command" | grep -oP '(?<=-m ")[^"]+' | head -1)
  mkdir -p "$CLAUDE_PROJECT_DIR/.groove/.cache"
  echo "$(date '+%Y-%m-%d %H:%M') | ${msg:-<no message>}" >> "$CLAUDE_PROJECT_DIR/.groove/.cache/git-activity-buffer.txt"
fi
block-managed-paths.sh
#!/usr/bin/env bash
# groove: preToolUse/Write hook — block edits to managed groove paths
input=$(cat)
path=$(echo "$input" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('tool_input',{}).get('file_path',''))" 2>/dev/null)
if echo "$path" | grep -qE '^(\.agents/skills/groove|skills/groove)'; then
  echo "groove: blocked — '$path' is managed by groove update. Edit under skills/ and rsync to .agents/skills/." >&2
  exit 2
fi
version-check.sh
#!/usr/bin/env bash
# groove: postToolUse hook — check for new groove version (once per hour)
CACHE="$CLAUDE_PROJECT_DIR/.groove/.cache/last-version-check-ts"
mkdir -p "$CLAUDE_PROJECT_DIR/.groove/.cache"
now=$(date +%s)
if [ -f "$CACHE" ]; then
  last=$(cat "$CACHE")
  diff=$((now - last))
  [ "$diff" -lt 3600 ] && exit 0
fi
echo "$now" > "$CACHE"
bash "$CLAUDE_PROJECT_DIR/.agents/skills/groove-utilities-check/scripts/check.sh" 2>/dev/null || true
session-capture.sh
#!/usr/bin/env bash
# groove: stop hook — stage a session capture draft from git activity for next-session review
ROOT="${CLAUDE_PROJECT_DIR:-$PWD}"
[ -f "$ROOT/.groove/index.md" ] || exit 0
command -v git >/dev/null 2>&1 || exit 0
git -C "$ROOT" rev-parse --git-dir >/dev/null 2>&1 || exit 0

CACHE="$ROOT/.groove/.cache"
PENDING="$CACHE/pending-capture.md"
BUFFER="$CACHE/git-activity-buffer.txt"

commits=$(git -C "$ROOT" log --since=midnight --oneline 2>/dev/null)
changes=$(git -C "$ROOT" diff --stat HEAD 2>/dev/null)
buffered=""
[ -s "$BUFFER" ] && buffered=$(cat "$BUFFER")

# No activity → clear any stale draft and stay silent.
if [ -z "$commits" ] && [ -z "$changes" ] && [ -z "$buffered" ]; then
  rm -f "$PENDING"
  exit 0
fi

mkdir -p "$CACHE"
{
  echo "# Pending capture — $(date '+%Y-%m-%d %H:%M')"
  echo
  echo "## Commits since midnight"
  echo "${commits:-(none)}"
  echo
  echo "## Working changes"
  echo "${changes:-(none)}"
  if [ -n "$buffered" ]; then
    echo
    echo "## Buffered commit messages"
    echo "$buffered"
  fi
} > "$PENDING"

.cursor/hooks.json 模板

将以下内容合并到 hooks 键中。保留所有其他键。

{
  "version": 1,
  "hooks": {
    "sessionStart": [
      {
        "command": "bash $CLAUDE_PROJECT_DIR/.agents/skills/groove-utilities-prime/scripts/groove-utilities-prime.sh --json"
      }
    ],
    "stop": [
      {
        "command": "bash $CLAUDE_PROJECT_DIR/.groove/hooks/cursor/daily-end-reminder.sh"
      },
      {
        "command": "bash $CLAUDE_PROJECT_DIR/.groove/hooks/cursor/session-capture.sh"
      }
    ],
    "postToolUse": [
      {
        "matcher": "Shell",
        "command": "bash $CLAUDE_PROJECT_DIR/.groove/hooks/cursor/git-activity-buffer.sh"
      },
      {
        "command": "bash $CLAUDE_PROJECT_DIR/.groove/hooks/cursor/version-check.sh"
      }
    ],
    "preToolUse": [
      {
        "matcher": "Write",
        "command": "bash $CLAUDE_PROJECT_DIR/.groove/hooks/cursor/block-managed-paths.sh"
      }
    ]
  }
}

合并时:如果已有 hooks 键,则将 groove 条目追加到相关事件数组中。不要创建重复项——追加前检查是否已存在 groove 命令条目。

限制

  • 绝不覆盖 .cursor/hooks.json 中的非 groove 条目
  • 未经差异对比和确认,绝不覆盖现有脚本
  • 脚本使用 python3 解析 JSON 标准输入;如果没有 python3,则跳过该钩子并发出警告
  • block-managed-paths 使用退出代码 2(Cursor 阻止工具使用的约定)
  • 安装后:提醒用户钩子将在下次重启 Cursor 会话后生效
  • .groove/hooks/cursor/ 遵循 .groove/index.md 中的 git.hooks Git 策略
  • 如果 .cursor/ 目录不存在,则创建该目录

评论

支持 Markdown