vscode-templete/.claude/hooks/wiki-ingest-reminder.sh

44 lines
1.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# wiki-ingest-reminder.sh
# Stop hook当对话中产生了实质性研究产出时提醒用户将知识 ingest 进 wiki。
# 判断逻辑:检查 transcript 中是否包含研究/分析类关键词,且对话轮次 >= 5。
set -euo pipefail
INPUT=$(cat)
TRANSCRIPT_PATH=$(echo "$INPUT" | jq -r '.transcript_path // empty')
# 无 transcript 则静默退出
if [ -z "$TRANSCRIPT_PATH" ] || [ ! -f "$TRANSCRIPT_PATH" ]; then
echo '{"continue": true}'
exit 0
fi
# 统计对话轮次assistant 消息数)
TURN_COUNT=$(grep -c '"role":"assistant"' "$TRANSCRIPT_PATH" 2>/dev/null || echo "0")
# 轮次不足则不提醒(避免简单问答也弹提醒)
if [ "$TURN_COUNT" -lt 5 ]; then
echo '{"continue": true}'
exit 0
fi
# 检查是否包含研究/分析类产出的信号词
RESEARCH_SIGNALS="分析|研究|报告|对比|总结|结论|规律|启示|发现|梳理|整理|数据|指标|回测|归因|板块|行业|估值|财务|研报"
SIGNAL_COUNT=$(grep -cE "$RESEARCH_SIGNALS" "$TRANSCRIPT_PATH" 2>/dev/null || echo "0")
# 检查是否已经触发过 ingest避免重复提醒
ALREADY_INGESTED=$(grep -c "auto-wiki.*ingest\|ingest.*wiki\|已 ingest" "$TRANSCRIPT_PATH" 2>/dev/null || echo "0")
if [ "$SIGNAL_COUNT" -ge 10 ] && [ "$ALREADY_INGESTED" -eq 0 ]; then
jq -n '{
"continue": true,
"systemMessage": "[auto-wiki] 本次对话产生了较多研究分析内容,建议在结束前将有价值的知识 ingest 进 wiki 以便跨会话积累。可以说「把这次的研究整理进 wiki」触发。"
}'
else
echo '{"continue": true}'
fi
exit 0