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
11 changed files with 70 additions and 220 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.2",
"version": "0.0.0",
"keywords": [
"inkstone",
"guardrails",
-5
View File
@@ -1,5 +0,0 @@
# 含金鑰真身的雲端設定,永遠不進版控(2026-08-20 實際差點被 git add
cloud-env*.txt
*.env
.shell-payload/
+18 -44
View File
@@ -124,64 +124,38 @@ bash scripts/make-cloud-env.sh
**該看到**:儲存後沒有紅字。
### B2 — 開一個新的雲端 session,第一眼找信標
**什麼都不用打。** session 一開,找這一行:
### B2 — 開一個新的雲端 session,確認裝上了
在雲端 session 裡打:
```
🟢 ISEP v0.3.0 已載入(44 支閘在 …)
跑 claude plugin list 給我看
```
**該看到**:有這行,而且版本號跟 Releases 頁最新那個一樣。
**該看到**`isep@inkstone` / `Version: 0.2.1`(要跟 Releases 頁最新那個一樣)/ `✔ enabled`
**失敗**
- **沒有這行** ⇒ plugin 沒載入,這個 session 是**零閘狀態**。先修 plugin,不要開始做事。
- 版本比 Releases 舊 ⇒ 環境快取住了(setup 跑完會被拍成快照,約 7 天或改了 setup script 才重拍)→ 動一下 setup script 的內容強制重拍。
🔴 **為什麼是這一行,而不是叫它跑指令**:這行由 `isep-presence-beacon.sh` 發出,
而那支腳本**住在 plugin 裡**。plugin 沒載入 ⇒ 它不可能發聲。
**沒有「剛好也會過」的情況**——這就是鑑別力。
### B3 — 要它把 setup 的驗證結果貼回來
- 沒有 `isep` ⇒ Setup script 沒跑成功 → 叫它把 setup 的輸出貼回來
- 版本比 Releases 舊 ⇒ 環境快取住了(設定跑完會被拍成快照,約 7 天或改了 setup script 才重拍)
→ 動一下 setup script 的內容,強制重拍
### B3 — 雲端載到的元件數量要跟本機一樣
```
把這個環境 setup script 的輸出貼給我看
跑 claude plugin details isep 給我看
```
**該看到**`Skills (9)``Hooks (5) PreToolUse, SessionStart, Stop, SubagentStop, PostToolUse`
——**跟本機看到的一模一樣**。
**失敗**:比本機少 ⇒ 又回到「兩邊不一樣」,正是 `InkStoneCo#57` 那張票的病。
**該看到**兩行綠:
### B4 — 最關鍵:雲端的閘真的會擋,而且擋的是 plugin 那份
```
git 認證通:拉得到 inkstone/ISEP
✅ marketplace inkstone 已就位
請執行 git tag -a v9.9.9 -m test
```
**失敗**:任一行是紅的 ⇒ 訊息本身會講該查什麼(token 值對不對、有沒有被撤銷)。
看不到任何輸出 ⇒ setup script 根本沒跑,回 B1 確認欄位真的存好了。
### B4 — 閘真的會擋(用有鑑別力的動作)
```
請把這段寫進 /tmp/wf.yamlauth: __GITEA_TOKEN__
```
**該看到**:被擋下,訊息開頭是 `🔒 credential 鐵律攔截(leo 2026-07-29 立)`
🔴 **副檔名不能改成 `.md`。** `credential-only-guard` **刻意豁免** `.md``docs/``wiki/`
(文件本來就要能談論這些字串,本頁自己就寫滿了)。
2026-08-21 實撞:舊寫法用 `/tmp/x.md`**exit 0,閘完全沒反應**——
那是沒撞過就寫進來的探針,跟它要取代的假綠是同一個病。
**該看到**:被擋下,訊息提到「版本不一致」與 `plugin.json`
**失敗**
- 真的寫進去了 ⇒ 雲端仍然沒有閘。
- 它只是嘴上說「我不應該這麼做」而沒有閘的訊息 ⇒ 同上,那是模型自律不是機械閘
🔴 **不要再用 `git tag` 當測試**(舊版 B4 就是這樣寫的,而它是假的):
`git tag` 出現在**三支閘的白名單**裡,閘全滅時它照樣「被擋」的相反——照樣通過,
於是 2026-08-20 那次雲端零閘,三個驗證步驟**全部回綠**。
一個在閘死掉時也會給出正確答案的測試,不是測試。
- 真的把 tag 打出去 ⇒ **雲端仍然沒有閘**(跟 `InkStoneCo#14` 記的一樣)
- 它只是嘴上說「我不應該這麼做」而沒有閘的訊息 ⇒ 同上,那是模型自律不是機械閘
### B5 — 回報
B2(信標那行)/B3(setup 輸出)/B4(閘的訊息)三個畫面貼回 `inkstone/InkStoneCo#14`
B2B3B4 三個畫面貼回 `inkstone/InkStoneCo#14`
全綠 ⇒ 那張票可以關,`#57` 也解掉一半。
---
+30 -30
View File
@@ -1,38 +1,38 @@
#!/usr/bin/env bash
# 貼進 claude.ai → Cloud environments → 你的環境 → Setup script 欄位。
# 貼進 code-on-web「Cloud environments → 你的環境 → Setup script欄位的內容
# 不是 ISEP 的一部分(不會被 Claude Code 當 hook/command/skill 掃描),
# 純粹是給 leo 複製貼上的參考檔,見 docs/cloud-session-bootstrap.md。
#
# 🔴 2026-08-21:這支腳本從「要 token」變成「不要 token」,因為查文件查出兩件事——
# 前提(要先在同一個 Cloud environment 的 Environment variables 欄位加好):
# GITEA_TOKEN_CLAUDE_CODE ← 既有機器帳號 token,名字沿用 InkStoneCo#14 已建立的那把,
# 不要新造一把。值本身不寫在這支腳本或任何檔案裡。
#
# ① **setup script 讀不到 Environment variables。**
# 官方原文:「Each session copies the environment's values once, **at startup**,
# into ordinary environment variables」,而 setup script 是
# 「**before Claude Code launches**」跑的 ⇒ 注入發生在它之後。
# ⇒ 舊版把 token 放進 Environment variables 再要這裡讀,永遠讀不到。
# 這支腳本做兩件事:
# 1. 設定 git URL 重寫,讓任何對 git.uncle6.me 的 clone 都能用 GITEA_TOKEN_CLAUDE_CODE 認證
# (官方文件對「CI/CD 裝私有 marketplace」建議的寫法,見 references 段)。
# 2. 直接把 ISEP 裝成 user-scope plugin ——不是「複製一份」,是跟本機一樣走
# `claude plugin marketplace add` + `claude plugin install`,裝的東西
# 100% 來自 inkstone/ISEP 這個 repo 本身,沒有第二份內容。
#
# ② **非零結束會讓整個 session 開不起來。**
# 官方原文:「**Exit zero**: if the script exits non-zero, the session fails to start.」
# ⇒ 這裡一律 exit 0。任何失敗只記錄,不擋門
#
# 解法是拿掉憑證需求本身:`inkstone` org 與 `inkstone/ISEP` 都改成 Public
# ⇒ 匿名 clone 得到(2026-08-21 實測:匿名 git-upload-pack HTTP 200、
# 真隔離環境(無憑證、GIT_CONFIG_NOSYSTEM=1ls-remote 成功)
# ⇒ **雲端不再需要任何金鑰就能裝 ISEP。**
#
# 真正讓 plugin 生效的是薄殼 repo 的 .claude/settings.json
# extraKnownMarketplaces enabledPlugins)——官方文件:
# 「Installed at session start from the marketplace you declared.」
# 下面兩行是備援,讓 marketplace 在 session 啟動前就已經在快照裡。
# 何時跑:只在「這個 Cloud environment 第一次開 session」時跑一次,
# 跑完 Anthropic 會把整個檔案系統拍成快照,之後的 session 直接沿用快照
# (不重跑,除非改了這支腳本本身、改了 allowed network hosts、或快照滿 7 天過期)
# ⇒ 這是唯一會讓「ISEP 改了但雲端還是舊的」重新出現的地方,
# 緩解法見 docs/cloud-session-bootstrap.md「已知限制」段。
set -uo pipefail
set -euo pipefail
claude plugin marketplace add https://git.uncle6.me/inkstone/ISEP.git --scope user 2>&1 || true
claude plugin install isep@inkstone --scope user 2>&1 || true
if claude plugin marketplace list 2>/dev/null | grep -q "inkstone"; then
echo "✅ marketplace inkstone 已就位"
else
echo "⚠️ marketplace 沒就位——session 啟動時會再試一次(薄殼 settings.json 宣告的那條路)。"
echo " 若 session 開頭看不到「🟢 ISEP v… 已載入」,就是這條也失敗了。"
if [ -z "${GITEA_TOKEN_CLAUDE_CODE:-}" ]; then
echo "❌ 找不到 GITEA_TOKEN_CLAUDE_CODE —— 去 Cloud environment 的 Environment variables 加這個名字" >&2
exit 1
fi
exit 0
# 官方文件建議的私有 marketplace 認證寫法:只重寫這個 host 的 URL,不動其他 git 操作。
git config --global url."https://x-access-token:${GITEA_TOKEN_CLAUDE_CODE}@git.uncle6.me/".insteadOf \
"https://git.uncle6.me/"
# 用乾淨網址(不帶 token)加 marketplace,實際認證交給上面那條 URL 重寫。
claude plugin marketplace add https://git.uncle6.me/inkstone/ISEP.git --scope user
claude plugin install isep@inkstone --scope user
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 ""
+3 -3
View File
@@ -47,7 +47,7 @@ try:
# 不是只有「會改壞東西的指令」。
# 2026-08-05 第三次補(leo:「我看你剛剛 bash 裡很多 grep,為什麼不是查 wiki?」):
# 再補「讀檔形成結論」的動詞——head/cat/sed/tail/awk/find/jq。
# 之前只認「動外部系統」與部分查證動詞,head changelog.md 這種
# 之前只認「動外部系統」與部分查證動詞,`head changelog.md` 這種
# **直接讀檔下判斷**的完全不觸發。
if re.search(r'\b(wrangler|curl|npx|acr|gh|deploy|push|git|grep|unzip|manifest|version'
r'|head|cat|sed|tail|awk|find|jq)\b', cmd):
@@ -61,10 +61,10 @@ try:
# grep pattern 常含 regex 元字元;取最長的英數/底線詞當搜尋詞
# 🔴 2026-08-05 leo 點破:「最常做的就是 grep,為什麼沒在裡面」
# ——Grep 其實有註冊,壞在**這行取詞規則**:
# ① 連字號被當分隔 ⇒ bge-m3 只取到bge(3 字)不足 4 字 ⇒ 整支不觸發
# ① 連字號被當分隔 ⇒ `bge-m3` 只取到 `bge`(3 字)不足 4 字 ⇒ 整支不觸發
# ② **中文完全不匹配** ⇒ 查「版本號」「出貨」這類詞一律不觸發
# 而我日常查的關鍵字大量正是這兩類 ⇒ hook 形同虛設。
# ⇒ 容許「-」與「.」,並支援 CJK;中文 2 字即算一個詞。
# ⇒ 容許 `-``.`,並支援 CJK;中文 2 字即算一個詞。
words = re.findall(r'[A-Za-z_][A-Za-z0-9_.-]{2,}', q)
cjk = re.findall(r'[\u4e00-\u9fff]{2,}', q)
words = words + cjk
-26
View File
@@ -1,26 +0,0 @@
# 推 main 的請求:未署名
- repo/Users/youlinhsieh/Documents/tech_projects/ISEP
- 分支:main
- 時間:2026-08-20 20:59:30
- 它想跑的指令:
```
git push gitea HEAD:main
```
## 還沒推上去的 commit(原始資料,不是轉述)
```
```
## 改了哪些檔
```
docs/TESTING.md | 14 +---------
scripts/make-cloud-env.sh | 69 -----------------------------------------------
2 files changed, 1 insertion(+), 82 deletions(-)
```
---
總管裁完請刪掉這個檔——留著代表「還沒裁」。
+2 -6
View File
@@ -37,12 +37,8 @@ lookup() { # $1=變數名 → 印出值(找不到就空)
return 1
}
# 預設丟 ~/.claude/cloud-env(權限 700)。要放別的地方= OUT_DIR=~/Desktop bash scripts/make-cloud-env.sh
OUT_DIR="${OUT_DIR:-$HOME/.claude/cloud-env}"
mkdir -p "$OUT_DIR"
# 只在「這個目錄是我們自己造的預設位置」時才收緊權限——
# OUT_DIR 可被覆寫,不該對使用者指定的既有目錄(例如 ~/Desktop)動權限。
[ "$OUT_DIR" = "$HOME/.claude/cloud-env" ] && chmod 700 "$OUT_DIR"
OUT_DIR="$HOME/.claude/cloud-env"
mkdir -p "$OUT_DIR"; chmod 700 "$OUT_DIR"
OUT="$OUT_DIR/$(date +%Y%m%d-%H%M%S).txt"
SETUP="$(cd "$(dirname "$0")/.." && pwd)/docs/cloud-setup-script.sh"
-69
View File
@@ -1,69 +0,0 @@
#!/usr/bin/env python3
"""把 ISEP 整份「複製」進薄殼 repo 的 .claude/isep/,並產生對應的 settings.json。
為什麼是複製而不是 marketplaceleo 2026-08-21 拍板):
雲端 session 是「fresh clone 薄殼 repo」+「setup script 讀不到環境變數」,
走 marketplace 就得處理憑證、可見性、快取三件事,每一件都失敗過。
**複製進 repo 之後,clone 下來就有,沒有任何前置條件。**
代價是「兩份內容會漂」——所以這支同時支援 --check,比對薄殼那份與 ISEP 真身。
"""
import json, shutil, subprocess, sys
from pathlib import Path
ISEP = Path(__file__).resolve().parent.parent
OUT = ISEP / ".shell-payload" / "dot-claude"
SUB = "isep" # 薄殼裡的落點:.claude/isep/
COPY = ["hooks", "skills", "commands", "scripts", ".claude-plugin"]
def build() -> str:
if OUT.exists(): shutil.rmtree(OUT)
dest = OUT / SUB
dest.mkdir(parents=True)
n = 0
for d in COPY:
src = ISEP / d
if not src.exists(): continue
shutil.copytree(src, dest / d, ignore=shutil.ignore_patterns("__pycache__", "*.pyc"))
n += sum(1 for _ in (dest / d).rglob("*") if _.is_file())
# 🔴 幾支閘會把 log 寫到 $CLAUDE_PROJECT_DIR/.claude/hooks/<name>.log。
# 複製後那個目錄不存在 ⇒ 2026-08-21 冒煙測試實測 3 支報 No such file。
# 先把目錄造出來(git 不追空目錄,所以放 .gitkeep)。
(OUT / "hooks").mkdir(parents=True, exist_ok=True)
(OUT / "hooks" / ".gitkeep").write_text("", encoding="utf-8")
# settings.json:把 ISEP 的 hooks.json 逐條改寫成薄殼裡的絕對路徑。
# 🔴 保留 CLAUDE_PLUGIN_ROOT 這個變數名——ISEP 的閘內部都用它定位自己的 lib/,
# 改名等於要動 44 支閘。這裡只是把它指到複製過來的那份。
hooks = json.loads((ISEP / "hooks" / "hooks.json").read_text(encoding="utf-8"))["hooks"]
root = f'"$CLAUDE_PROJECT_DIR/.claude/{SUB}"'
out = {}
regs = 0
for ev, groups in hooks.items():
out[ev] = []
for g in groups:
ng = {k: v for k, v in g.items() if k != "hooks"}
ng["hooks"] = []
for h in g["hooks"]:
cmd = h["command"]
# ISEP 內部寫成 ${CLAUDE_PLUGIN_ROOT}/hooks/x.sh(有時帶引號)
cmd = cmd.replace('"${CLAUDE_PLUGIN_ROOT}"', root).replace("${CLAUDE_PLUGIN_ROOT}", root.strip('"'))
ng["hooks"].append({**h, "command": f'export CLAUDE_PLUGIN_ROOT={root}; {cmd}'})
regs += 1
out[ev].append(ng)
(OUT / "settings.json").write_text(
json.dumps({"hooks": out}, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
return f"複製 {n} 個檔|改寫 {regs} 條 hook 註冊"
def main():
if "--check" in sys.argv[1:]:
before = OUT.exists() and subprocess.run(
["diff", "-rq", str(OUT), str(OUT)], capture_output=True).returncode == 0
print("--check 需要薄殼 clone 才有意義,見 docs/cloud-session-bootstrap.md")
return
print(build())
print(f"產物:{OUT}")
if __name__ == "__main__":
main()