Compare commits

..

1 Commits

Author SHA1 Message Date
Leo 0bafdf141f WIP(未實測,不要併):待驗單 dedup —— 改 hash 宣稱內容本身
問題:檔名 hash 用 (transcript_path + session_id + agent_id)
⇒ 每個新 agent 拿到新檔名、但抽出的宣稱是同一批
⇒ 2026-08-20 同兩條宣稱產了 6 張單,總管每回合重做一次已驗完的事。

改法:hash 宣稱內容本身 + 跳過 verified-claims/ 裡已存在的同 hash。

🔴 未實測:造不出會觸發抽取邏輯的測資,dedup 是否生效沒驗到。
   失敗形式是『該產單時不產單』=驗證機制靜默停擺(fail-open)
   ⇒ 沒驗過不准併。明天先解決測資問題。

Refs inkstone/InkStoneCo#48
2026-08-20 22:34:10 +08:00
5 changed files with 23 additions and 77 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "isep",
"description": "InkStone Environment Plugin —— leo 的 Claude Code 環境唯一真相源:43 支機械閘(53 條註冊,白話盤點見 docs/hooks-inventory.md)、7 支 slash command、2 支 skill、27 支腳本,外加治理規範與標籤真相源。本機與雲端裝同一份,沒有子集。",
"version": "0.3.0",
"version": "0.0.0",
"keywords": [
"inkstone",
"guardrails",
+6 -40
View File
@@ -27,46 +27,12 @@ if [ -z "${GITEA_TOKEN_CLAUDE_CODE:-}" ]; then
exit 1
fi
# ── git 認證:三個機制都設,因為它們失效的方式不同 ────────────────
# ① URL 重寫(global ② 憑證存檔(global ③ 系統層(HOME 無關,best effort
# 2026-08-20 雲端實測:session 裡 git 是「匿名」的 ⇒ setup 設的東西沒生效到 session。
# 原因未定(沒跑到/HOME 不同/快照沒帶),所以三條都設,並在下面自我驗證。
git config --global url."https://claude-code:${GITEA_TOKEN_CLAUDE_CODE}@git.uncle6.me/".insteadOf \
# 官方文件建議的私有 marketplace 認證寫法:只重寫這個 host 的 URL,不動其他 git 操作。
git config --global url."https://x-access-token:${GITEA_TOKEN_CLAUDE_CODE}@git.uncle6.me/".insteadOf \
"https://git.uncle6.me/"
git config --global credential.helper store
printf 'https://claude-code:%s@git.uncle6.me\n' "$GITEA_TOKEN_CLAUDE_CODE" > "$HOME/.git-credentials"
chmod 600 "$HOME/.git-credentials"
git config --system url."https://claude-code:${GITEA_TOKEN_CLAUDE_CODE}@git.uncle6.me/".insteadOf \
"https://git.uncle6.me/" 2>/dev/null || echo "system 層設不了,只靠 global——非致命)"
# ── 🔴 自我驗證一:認證真的通了嗎 ──────────────────────────
# 這一步是 2026-08-20 事故的直接產物:舊版設完就結束,token 沒生效也不出聲,
# 於是雲端 session 開起來才發現 marketplace 拉不下來,而 setup log 一片綠。
echo "── 驗證 git 認證 ──"
if GIT_TERMINAL_PROMPT=0 git ls-remote https://git.uncle6.me/inkstone/ISEP.git >/dev/null 2>&1; then
echo "✅ git 認證通:拉得到 inkstone/ISEP"
else
echo "❌ git 認證不通——marketplace 一定裝不起來,後面不用往下做了。" >&2
echo " 檢查:GITEA_TOKEN_CLAUDE_CODE 的值對不對、那把 token 有沒有被撤銷。" >&2
exit 1
fi
# 用乾淨網址(不帶 token)加 marketplace,實際認證交給上面那條 URL 重寫。
claude plugin marketplace add https://git.uncle6.me/inkstone/ISEP.git --scope user
claude plugin install isep@inkstone --scope user
# ── 安裝(user scope 只是備援)─────────────────────────────
# 🔴 官方文件(cloud-environments 的 what-carries-over 表)明文:
# 「Plugins enabled only in your user settings」→ **不會**帶到雲端 session。
# 真正生效的是薄殼 repo 的 .claude/settings.json 裡的 enabledPlugins extraKnownMarketplaces。
# 這兩行留著當本地備援,不是主要路徑——不要以為裝完就等於雲端有了。
claude plugin marketplace add https://git.uncle6.me/inkstone/ISEP.git --scope user 2>/dev/null || true
claude plugin install isep@inkstone --scope user 2>/dev/null || true
# ── 🔴 自我驗證二:marketplace 真的拉下來了嗎 ────────────────
echo "── 驗證 marketplace ──"
if claude plugin marketplace list 2>/dev/null | grep -q "inkstone"; then
echo "✅ marketplace inkstone 已就位"
else
echo "❌ marketplace 沒就位——session 啟動時 enabledPlugins 會是一張跳票的支票。" >&2
exit 1
fi
echo "✅ setup 完成。session 啟動後請用「有鑑別力的探針」驗閘,"
echo " 不要用 git tag(它在三支閘的白名單裡,閘死了也會過)。"
echo "✅ ISEP 已裝成 user-scope plugin,之後每個 session 啟動時直接生效。"
-4
View File
@@ -178,10 +178,6 @@
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/skill-deploy-drift-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/isep-presence-beacon.sh"
}
]
}
-30
View File
@@ -1,30 +0,0 @@
#!/usr/bin/env bash
# isep-presence-beacon.sh — SessionStart:報出「ISEP 真的載入了,幾版、幾支閘」
#
# 這不是閘,是**信標**。存在的理由是 2026-08-20 的雲端事故:
# 雲端 session 的閘全滅,而三個驗證步驟全部回綠——因為它們沒有鑑別力
# (`git tag` 在三支閘的白名單裡;`Skills(9)/Hooks(5)` 剛好是薄殼自己的 .claude/ 產生的數字)。
#
# 🔴 鑑別力就是這支的全部意義:
# 這行出現 ⇒ plugin 一定載入了(因為它自己就住在 plugin 裡)
# 這行不見 ⇒ plugin 沒載入,那個 session 是零閘狀態
# ——沒有第三種情況,也沒有「剛好也會過」的巧合。
set -uo pipefail
ROOT="${CLAUDE_PLUGIN_ROOT:-}"
[ -n "$ROOT" ] || exit 0
VER="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' \
"$ROOT/.claude-plugin/plugin.json" 2>/dev/null | head -1)"
VER="${VER:-未知}"
GATES="$(ls "$ROOT"/hooks/*.sh 2>/dev/null | wc -l | tr -d ' ')"
MSG="🟢 ISEP v${VER} 已載入(${GATES} 支閘在 ${ROOT}"
printf '%s\n' "{
\"systemMessage\": \"${MSG}\",
\"hookSpecificOutput\": {
\"hookEventName\": \"SessionStart\",
\"additionalContext\": \"${MSG}。這行是 ISEP plugin 自己發的——看得到它就表示閘真的生效了。若某個 session 從頭到尾沒有這行,那個 session 是零閘狀態,先修 plugin 再做事,不要用『跑得動』當證據。\"
}
}"
+16 -2
View File
@@ -118,10 +118,24 @@ if not ok_hits and not ng_hits:
print("SKIP:no-claims"); raise SystemExit
sid = (d.get("session_id") or "nosid")[:8]
aid = (d.get("agent_id") or d.get("subagent_id") or "")[:10]
stamp = hashlib.sha1((tp + sid + aid).encode()).hexdigest()[:8]
# 2026-08-20 修:檔名原本 hash (transcript_path + session_id + agent_id)
# => 每個新 agent 拿到新檔名,但抽出的宣稱是同一批(取 transcript 最後一個
# <result>,那個可能是舊的——檔頭 08-18 註解已記過同源問題)。
# 實害:同兩條宣稱一天內產了 6 張不同 hash 的單,總管每回合重做一次已驗完的事。
# => InkStoneCo#48:「永遠在誤響的警報,等於訓練人忽略這個警報」。
# 改成 hash 宣稱內容本身,且已驗歸檔的直接跳過。
claims_sig = "\n".join(sorted(ok_hits + ng_hits))
stamp = hashlib.sha1(claims_sig.encode()).hexdigest()[:8]
path = os.path.join(os.environ["DIR"], "claims-%s-%s.md" % (sid, stamp))
_vdir = os.path.join(os.path.dirname(os.environ["DIR"]), "verified-claims")
if os.path.isdir(_vdir):
for _f in os.listdir(_vdir):
if stamp in _f:
print("SKIP:already-verified:%s" % stamp)
raise SystemExit
def block(title, items, howto, cap):
if not items:
return ""