feat(1.16.0): 讓 wiki 真的被讀到——查詢即搜尋 wiki+subagent 自動注入

病根(leo 2026-07-20 點破,真實事故):總管三次擋回 leo「某機制早已棄用」的
正確判斷,查證後 leo 全對。根因不是知識不足,是讀取流程:
① wiki 只讀開頭就開工(關鍵記載在第 56 行,答案一直在那裡)
② 派 subagent 只叫它讀 code、沒叫讀 wiki → 從稿子推論必然得出過時結論
③ 把 wiki 的「當時狀態」當永久事實(沒核對解除條件)

leo:「我需要的不是你記住,而是機制面的解法」
「如果你不是讀而是搜尋 wiki,就不會只讀 50 行就下定論,像 cmd+F 那樣高亮。」

新增:
- wiki-first-search.sh(PreToolUse: Grep|Glob|Read)
  查 code/文件的當下,用同一組關鍵字 grep wiki,只推命中行。
  開場 push 全文解決不了「只讀開頭」——時機才是關鍵。提醒不阻擋。
- subagent-wiki-guard.sh(PreToolUse: Task)
  查證/實作類任務 → 注入「先查 wiki」指示。
  第一版為「上游沒交代就擋」,經 leo 指正改注入式:
  「它只要聽到查,就應該主動查 wiki」——依賴上游記得寫=同一個病。

update.sh 除同步兩支 hook 外,自動註冊進 settings.json(不只提醒)——
靠人看提醒手動補,等於把同一個病搬到安裝環節。
template/ 新裝樣板同步(新 repo 裝完即生效)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-21 01:30:46 +08:00
parent 7b83465acf
commit ed3a97c6a2
6 changed files with 235 additions and 2 deletions
+31
View File
@@ -228,6 +228,9 @@ if $HAS_WIKI; then
update_file "system-dev/wiki/INDEX.md" "$TEMPLATE_URL/system-dev/wiki/INDEX.md"
update_file ".claude/hooks/session-start-recall.sh" "$TEMPLATE_URL/.claude/hooks/session-start-recall.sh"
update_file ".claude/hooks/wiki-secret-scan.sh" "$TEMPLATE_URL/.claude/hooks/wiki-secret-scan.sh"
# 1.16.0:讓 wiki 真的被讀到的兩支(開場 push 全文解決不了「只讀開頭」,見 CHANGELOG)
update_file ".claude/hooks/wiki-first-search.sh" "$TEMPLATE_URL/.claude/hooks/wiki-first-search.sh"
update_file ".claude/hooks/subagent-wiki-guard.sh" "$TEMPLATE_URL/.claude/hooks/subagent-wiki-guard.sh"
update_file ".claude/commands/wiki-init.md" "$TEMPLATE_URL/.claude/commands/wiki-init.md"
update_file ".claude/commands/wiki-capture.md" "$TEMPLATE_URL/.claude/commands/wiki-capture.md"
update_file ".claude/commands/wiki-update.md" "$TEMPLATE_URL/.claude/commands/wiki-update.md"
@@ -337,6 +340,34 @@ if [ -f ".claude/settings.json" ]; then
$HAS_WIKI && ! grep -q "session-start-recall.sh" .claude/settings.json && MISSING+=("SessionStart: session-start-recall.sh")
$HAS_WIKI && ! grep -q "wiki-secret-scan.sh" .claude/settings.json && MISSING+=("PreToolUse(Write|Edit): wiki-secret-scan.sh")
$HAS_SDD && ! grep -q "sdd-guard.sh" .claude/settings.json && MISSING+=("PreToolUse(Write|Edit): sdd-guard.sh")
# ── 1.16.0:兩支 wiki 讀取 hook 自動註冊(不只提醒)──
# 理由:這兩支的整個存在意義就是「不依賴任何人記得」。
# 若靠人看提醒去手動補 settings.json,等於把同一個病搬到安裝環節。
if $HAS_WIKI && command -v python3 >/dev/null 2>&1; then
python3 - <<'PYEOF' 2>/dev/null || true
import json, os
p = ".claude/settings.json"
try:
with open(p) as f: d = json.load(f)
except Exception:
raise SystemExit(0) # 壞掉的 settings 不碰,交給下方提醒
pre = d.setdefault("hooks", {}).setdefault("PreToolUse", [])
blob = json.dumps(pre)
added = []
if "wiki-first-search" not in blob:
pre.append({"matcher": "Grep|Glob|Read", "hooks": [
{"type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/wiki-first-search.sh"}]})
added.append("wiki-first-search")
if "subagent-wiki-guard" not in blob:
pre.append({"matcher": "Task", "hooks": [
{"type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/subagent-wiki-guard.sh"}]})
added.append("subagent-wiki-guard")
if added:
with open(p, "w") as f: json.dump(d, f, ensure_ascii=False, indent=2)
print(" ✅ 已自動註冊 wiki 讀取 hook" + "、".join(added))
PYEOF
fi
if [ ${#MISSING[@]} -gt 0 ]; then
echo ""
t "📌 settings.json 是你的設定(沒動),但偵測到缺以下 hook,請手動補上:" \