From 97bbb3f3061d075ca16b76b93822197c96188e3b Mon Sep 17 00:00:00 2001 From: "Shin@HOME" Date: Mon, 13 Apr 2026 23:43:57 +0800 Subject: [PATCH] =?UTF-8?q?changelog=E8=AE=B0=E5=BD=95=E5=9C=A8debug=20mod?= =?UTF-8?q?e=E4=B8=AD=E4=B8=8D=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cursor/changelog/.changelog-ack | 0 .cursor/hooks.json | 9 ++---- .cursor/hooks/check-changelog.ps1 | 48 +++++++++++++++++++++---------- 3 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 .cursor/changelog/.changelog-ack diff --git a/.cursor/changelog/.changelog-ack b/.cursor/changelog/.changelog-ack new file mode 100644 index 0000000..e69de29 diff --git a/.cursor/hooks.json b/.cursor/hooks.json index b6e04e5..f3c7ae3 100644 --- a/.cursor/hooks.json +++ b/.cursor/hooks.json @@ -8,15 +8,10 @@ } ], "stop": [ - { - "type": "prompt", - "prompt": "You are a changelog compliance checker. Return ONLY valid JSON, nothing else.\n\nSTEP 1 — EXEMPTION CHECK (if ANY condition is true, return {} immediately):\n- The conversation is in Debug mode, debug-mode, or any debugging/troubleshooting context\n- The agent's recent actions were ONLY: reading files, running shell commands, adding log/debug statements, or modifying .cursor/ files\n- The agent did NOT use Write or StrReplace tools on files outside .cursor/ directory\n- The agent was acknowledging a previous hook reminder\n- There is a CURSOR_SKIP_CHANGELOG environment variable set\n\nIf ANY exemption matches → return: {}\n\nSTEP 2 — Only if NO exemption matched:\nCheck if the agent used Write or StrReplace on source files (*.py, *.tsx, *.ts, *.css, *.json outside .cursor/) AND did NOT also write to all three: .cursor/changelog/changelog-full.md, changelog-recent.md, changelog-headlines.md.\n\nIf changelog writes were missed → return: {\"followup_message\":\"Changelog not synced. Run dev-changelog Skill operation A to write all three changelog layers.\"}\n\nOtherwise → return: {}\n\nHere is the hook input: $ARGUMENTS", - "timeout": 15, - "loop_limit": 1 - }, { "command": "powershell -ExecutionPolicy Bypass -File .cursor/hooks/check-changelog.ps1", - "timeout": 10 + "timeout": 10, + "loop_limit": 1 } ] } diff --git a/.cursor/hooks/check-changelog.ps1 b/.cursor/hooks/check-changelog.ps1 index 1fbcf7c..fbda0f1 100644 --- a/.cursor/hooks/check-changelog.ps1 +++ b/.cursor/hooks/check-changelog.ps1 @@ -1,46 +1,64 @@ -# Changelog sync guard: compare source file mtime vs changelog mtime. -# If source files are newer than changelog, inject a followup_message -# reminding the agent to write changelog entries. +# Changelog sync guard — 统一 stop hook(合并了原 prompt hook 和 command hook) +# +# 用确定性逻辑检查: +# 1. 源文件是否比 changelog 更新(mtime 比较) +# 2. stdin 中的 agent 上下文是否显示有源文件编辑操作 # # 静默条件(不触发提醒): -# 1. 环境变量 CURSOR_SKIP_CHANGELOG 被设置(由 sessionStart hook 在非 agent 模式设置) -# 2. Debug 模式 — 项目根目录存在 debug-*.log 文件,说明正在调试 +# 1. 环境变量 CURSOR_SKIP_CHANGELOG 被设置(sessionStart 在非 agent 模式设置) +# 2. stdin JSON 中 composer_mode 不是 "agent"(如 debug/ask/edit 模式) # 3. changelog 文件不存在 # 4. .changelog-ack 标记文件存在且足够新(本会话已确认过 changelog 状态) +# 5. 没有源文件比 changelog 更新 $input = [Console]::In.ReadToEnd() -# 检测 sessionStart 设置的跳过标志(覆盖一开始就是 debug/ask 模式的场景) +# === 豁免检查 1:环境变量跳过标志 === if ($env:CURSOR_SKIP_CHANGELOG) { Write-Output '{}' exit 0 } +# === 豁免检查 2:从 stdin 解析 composer_mode === +try { + $data = $input | ConvertFrom-Json + $mode = $data.composer_mode + if ($mode -and $mode -ne "agent") { + Write-Output '{}' + exit 0 + } +} catch { + # JSON 解析失败,继续后续检查 +} + +# === 豁免检查 3:从 stdin 文本匹配 debug 上下文关键词 === +# stop hook 的 $ARGUMENTS 可能包含对话/工具上下文,检测 debug 相关信号 +if ($input -match '"mode"\s*:\s*"debug"' -or + $input -match 'debug[\s_-]?mode' -or + $input -match 'Debug Mode') { + Write-Output '{}' + exit 0 +} + $changelog = ".cursor\changelog\changelog-headlines.md" $srcDir = "art-agent" +# === 豁免检查 4:changelog 文件不存在 === if (-not (Test-Path $changelog)) { Write-Output '{}' exit 0 } -# 检测 debug 模式:项目中存在活跃的 debug 日志文件 -$debugLogs = Get-ChildItem -Path "." -Filter "debug-*.log" -Recurse -Depth 3 -ErrorAction SilentlyContinue | - Where-Object { $_.FullName -notlike "*node_modules*" -and $_.FullName -notlike "*venv*" } -if ($debugLogs) { - Write-Output '{}' - exit 0 -} - $clMtime = (Get-Item $changelog).LastWriteTime -# 检测 ack 标记文件:Agent 已确认 changelog 状态(写入或跳过),本会话不再提醒 +# === 豁免检查 5:ack 标记文件足够新 === $ackFile = ".cursor\changelog\.changelog-ack" if ((Test-Path $ackFile) -and (Get-Item $ackFile).LastWriteTime -ge $clMtime) { Write-Output '{}' exit 0 } +# === 核心检查:是否有源文件比 changelog 更新 === $extensions = @("*.py", "*.tsx", "*.ts", "*.css") $excludeDirs = @("node_modules", ".next", "__pycache__", "venv")