From e5ca9e70abe948349a4545f95c27e44cf9fbd339 Mon Sep 17 00:00:00 2001 From: gouki Date: Wed, 14 Oct 2026 12:50:22 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20post-edit=20hook?= =?UTF-8?q?=20=E8=87=AA=E5=8A=A8=E9=AA=8C=E8=AF=81=20Python=20=E5=92=8C=20?= =?UTF-8?q?JavaScript=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 .qoder/hooks/post-edit-check.sh 脚本 - 编辑 *.py 文件后自动运行 pytest tests/ -x -q - 编辑 static/js/*.js 文件后自动运行 node --check - 配置 PostToolUse hook 监听 Write|Edit 事件 - 更新 .gitignore 跟踪 hooks 目录和 settings.json --- .gitignore | 6 +++++- .qoder/hooks/post-edit-check.sh | 24 ++++++++++++++++++++++++ .qoder/settings.json | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 .qoder/hooks/post-edit-check.sh create mode 100644 .qoder/settings.json diff --git a/.gitignore b/.gitignore index 69e7bd9..3515d17 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,13 @@ data/ .env.local .DS_Store .pytest_cache/ +node_modules/ +package-lock.json -# IDE 指令层:仅跟踪手写资产 .qoder/rules 与 .qoder/agents +# IDE 指令层:仅跟踪手写资产 .qoder/rules、.qoder/agents 与 .qoder/hooks # 其余 .qoder 产物(repowiki / better-harness 报告)可由 IDE 重生成,不入库 .qoder/* !.qoder/rules/ !.qoder/agents/ +!.qoder/hooks/ +!.qoder/settings.json diff --git a/.qoder/hooks/post-edit-check.sh b/.qoder/hooks/post-edit-check.sh new file mode 100755 index 0000000..423d718 --- /dev/null +++ b/.qoder/hooks/post-edit-check.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Post-edit hook: 自动验证编辑后的文件 +# - Python 文件 → 运行 pytest +# - JavaScript 文件 → 运行 node --check + +input=$(cat) +file_path=$(echo "$input" | jq -r '.tool_input.file_path') + +# 提取相对于项目根的路径 +rel_path="${file_path#$QODER_PROJECT_DIR/}" + +case "$rel_path" in + *.py) + echo "🔍 检测到 Python 文件变更: $rel_path" >&2 + cd "$QODER_PROJECT_DIR" || exit 0 + .venv/bin/python -m pytest tests/ -x -q + ;; + static/js/*.js) + echo "🔍 检测到 JavaScript 文件变更: $rel_path" >&2 + node --check "$file_path" + ;; +esac + +exit 0 diff --git a/.qoder/settings.json b/.qoder/settings.json new file mode 100644 index 0000000..0bf14ee --- /dev/null +++ b/.qoder/settings.json @@ -0,0 +1,16 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Write|Edit", + "hooks": [ + { + "type": "command", + "command": ".qoder/hooks/post-edit-check.sh", + "timeout": 120 + } + ] + } + ] + } +}