From dc4fe67e156542a90f95af281f7519ffa1a4ef99 Mon Sep 17 00:00:00 2001 From: richblack Date: Tue, 21 Jul 2026 13:51:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(1.18.0):=20=E5=85=AC=E9=96=8B=20mirror=20?= =?UTF-8?q?=E8=90=BD=E5=BE=8C=E5=81=B5=E6=B8=AC=EF=BC=88=E6=89=8B=E5=8B=95?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=9A=84=E9=9D=9C=E9=BB=98=E5=A4=B1=E6=95=97?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E6=9C=89=E5=A4=96=E9=83=A8=E7=94=A8=E6=88=B6?= =?UTF-8?q?=E6=9C=83=E6=92=9E=E5=88=B0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gitea(草稿)↔ GitHub(正稿)是手動同步,改了零件沒發佈=用戶抓到舊版 且無任何錯誤訊息,只是行為不對——我們自己永遠測不到。 SessionStart hook 比對工作區 HEAD 與 .github-public 最後 release snapshot, 落後就出聲,含發佈指令;若該批改動含 .wasm 額外標紅(安裝器懶載直接抓那個)。 只提醒不阻擋(發佈需 leo 親跑 arm)。 實測 Arcrun:落後 25 個 commit 且含 wasm 變更。 Co-Authored-By: Claude Opus 4.8 (1M context) --- scripts/update.sh | 2 + template/.claude/VERSION | 2 +- template/.claude/hooks/publish-lag-check.sh | 80 +++++++++++++++++++++ template/.claude/settings.json | 9 +++ template/system-dev/VERSION | 2 +- 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100755 template/.claude/hooks/publish-lag-check.sh diff --git a/scripts/update.sh b/scripts/update.sh index c209d80..367c5f0 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -235,6 +235,8 @@ if $HAS_WIKI; then # 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" + # 1.18.0:公開 mirror 落後偵測(手動同步的靜默失敗只有外部用戶會撞到) + update_file ".claude/hooks/publish-lag-check.sh" "$TEMPLATE_URL/.claude/hooks/publish-lag-check.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" diff --git a/template/.claude/VERSION b/template/.claude/VERSION index 092afa1..84cc529 100644 --- a/template/.claude/VERSION +++ b/template/.claude/VERSION @@ -1 +1 @@ -1.17.0 +1.18.0 diff --git a/template/.claude/hooks/publish-lag-check.sh b/template/.claude/hooks/publish-lag-check.sh new file mode 100755 index 0000000..9469a82 --- /dev/null +++ b/template/.claude/hooks/publish-lag-check.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# publish-lag-check.sh — SessionStart hook:偵測「公開 mirror 落後工作區」並出聲 +# +# 病根(leo 2026-07-21 點名的真實風險): +# Gitea(草稿/工作現場)與 GitHub(正稿/成品櫥窗)是**手動同步**的 +# (靠人跑 scripts/publish-github.sh --push,且需 D20 arm)。 +# → 改了零件、重編 wasm 後若沒人記得發佈,**用戶抓到舊版且沒有任何錯誤訊息, +# 只是行為不對**——這種靜默失敗只有外部使用者會撞到,我們自己永遠測不到。 +# +# 實例:安裝器的懶載會從 +# cdn.jsdelivr.net/gh/youlinhsieh/Arcrun@main/.component-builds/<名>/component.wasm +# 抓 wasm。那個位址永遠指向 GitHub 上的**最後一次發佈**,不是我們本機的最新版。 +# +# 原理:比對「工作區 HEAD」與「.github-public 最後一個 release commit 記錄的 snapshot」。 +# publish-github.sh 的 commit 訊息格式固定為:release: snapshot <短hash> (<日期>) +# → 從中取出 hash,看它是不是工作區 HEAD 的祖先/相同。 +# +# 只提醒不阻擋(exit 0):發不發佈是人的決定(且 push GitHub 需 leo 親跑 arm), +# hook 的職責只是消滅「忘了」這個失敗模式。 +set -euo pipefail + +MIRROR_DIR=".github-public" + +# 沒裝發佈管線的 repo 直接安靜退出 +[ -d "$MIRROR_DIR/.git" ] || exit 0 +[ -f "scripts/publish-github.sh" ] || exit 0 +git rev-parse --git-dir >/dev/null 2>&1 || exit 0 + +HEAD_SHORT="$(git rev-parse --short HEAD 2>/dev/null || echo '')" +[ -z "$HEAD_SHORT" ] && exit 0 + +# 從 mirror 最後一個 commit 訊息取出它當初發佈的來源 hash +LAST_MSG="$(git -C "$MIRROR_DIR" log -1 --format=%s 2>/dev/null || echo '')" +PUBLISHED="$(printf '%s' "$LAST_MSG" | sed -n 's/.*snapshot \([0-9a-f]\{6,\}\).*/\1/p')" + +if [ -z "$PUBLISHED" ]; then + # mirror 存在但沒有可辨識的 release commit(可能還沒發過) + echo "════════════════════════════════════════════════" + echo "📦 這個 repo 有公開發佈管線,但 mirror 還沒發過任何版本" + echo "════════════════════════════════════════════════" + echo " 若已有用戶依賴公開版(例如安裝器從 jsDelivr 抓 wasm),現在是空的。" + echo " 發佈:leo 在頂層跑 scripts/github-arm.sh,再於本 repo 跑" + echo " GITHUB_REMOTE=... bash scripts/publish-github.sh --push" + echo "" + exit 0 +fi + +# 已發佈的那個 commit 就是現在的 HEAD → 同步,安靜 +if [ "$PUBLISHED" = "$HEAD_SHORT" ]; then + exit 0 +fi + +# 算出落後幾個 commit(發佈點 → HEAD)。取不到就不顯示數字。 +BEHIND="$(git rev-list --count "${PUBLISHED}..HEAD" 2>/dev/null || echo '')" + +# 落後 0 且 hash 不同 → 可能是 mirror 比工作區新(罕見,例如剛 rebase),一樣提醒 +echo "════════════════════════════════════════════════" +if [ -n "$BEHIND" ] && [ "$BEHIND" != "0" ]; then + printf '📤 公開 mirror 落後工作區 %s 個 commit(最後發佈:%s,現在:%s)\n' \ + "$BEHIND" "$PUBLISHED" "$HEAD_SHORT" +else + printf '📤 公開 mirror 與工作區不一致(最後發佈:%s,現在:%s)\n' "$PUBLISHED" "$HEAD_SHORT" +fi +echo "════════════════════════════════════════════════" +echo "⚠️ 外部使用者拿到的仍是舊版,而且**不會有任何錯誤訊息**——只是行為不對。" +echo " (安裝器的懶載直接從公開位址抓 wasm,落後=裝到舊零件。)" +echo "" +echo " 要發佈:① leo 在頂層跑 bash scripts/github-arm.sh \"<任務描述>\" 30" +echo " ② 本 repo 跑 GITHUB_REMOTE=https://github.com/<帳號>/.git \\" +echo " bash scripts/publish-github.sh --push" +echo " 不急著發也沒關係——這只是提醒,別讓它靜默漏掉。" + +# 若這次落後的內容碰到 wasm,額外警告(那是用戶會直接抓的東西) +if git diff --name-only "${PUBLISHED}..HEAD" 2>/dev/null | grep -q '\.wasm$'; then + echo "" + echo " 🔴 這批改動**包含 .wasm 變更** → 用戶抓到的零件會跟你本機不同,優先發佈。" +fi +echo "" + +exit 0 diff --git a/template/.claude/settings.json b/template/.claude/settings.json index d0b3167..7f94e81 100644 --- a/template/.claude/settings.json +++ b/template/.claude/settings.json @@ -9,6 +9,15 @@ "command": ".claude/hooks/session-start-recall.sh" } ] + }, + { + "matcher": "startup|resume|clear", + "hooks": [ + { + "type": "command", + "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/publish-lag-check.sh" + } + ] } ], "PreToolUse": [ diff --git a/template/system-dev/VERSION b/template/system-dev/VERSION index 092afa1..84cc529 100644 --- a/template/system-dev/VERSION +++ b/template/system-dev/VERSION @@ -1 +1 @@ -1.17.0 +1.18.0