Files
ISEP/hooks/leo21c-write-guard.sh
Leo c2638668e3 ISEP 0.1.0:環境設定收成一個 plugin,本機與雲端共用一份
leo 2026-08-20:「同一個 plugin 你用,薄殼也用,保證兩邊同步」
              「我要你幫雲端做薄殼,永遠都有問題,你要做的就是這組設定
                你自己可以 dogfooding」

搬進來:41 支 hook(51 條註冊)/7 支 command/2 支 skill/23 支腳本。
不搬 .env、wiki、docs——那些是知識不是環境。

51 條 hook 路徑全部從 $CLAUDE_PROJECT_DIR/.claude/hooks/ 改成 ${CLAUDE_PLUGIN_ROOT}/hooks/,
零漏網。那正是薄殼一直壞掉的根:雲端 cwd 不是真身,寫死路徑就斷。

尚未驗證:Claude Code 能不能從私有 Gitea repo 裝 marketplace(要憑證)。
下一步就是在本機實際裝一次,通了才動雲端 bootstrap.sh。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 11:41:46 +08:00

81 lines
4.0 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.
#!/usr/bin/env bash
# leo21c-write-guard.sh — 不准寫 leo 的個人帳號(leo 2026-08-20 立)
#
# leo 原話:
# 「youlin = stagegeek6688 = 測試 prod 出貨機,uncle6 = 中心服務,
# 這三個都可以拿來當 default,但你要實驗當然是放在 youlin。」
# 「**leo21c 就是我這個普通用戶,不應該讓你去操控,我只用公開的更新。**」
#
# 🔴 為什麼要機器守(2026-08-20 實錯,本閘的來由):
# 總管派 subagent 驗碎形目錄索引,它用了本機 `~/.arcrun/config.yaml` 的預設
# `cypher_executor_url: …leo21c…``api_key: bfezv28v`),
# 把 8 張測試卡寫進 leo 的真庫。
# 而當時 `system-dev/wiki/agent-memory.md` §2 白紙黑字寫著
# 「底層帳號=leo21c,**任何自動化只准落在它上面**」——那是 dogfood 時代的舊分工。
# ⇒ **文件教錯 + 機器預設也錯 ⇒ 沒指定的一律流進他的帳號。**
# ⇒ 規則改對了還不夠:`~/.arcrun/config.yaml` 至今仍指著 leo21c
# (它的 KV id 與 encryption_key 是該實例專屬,換不過去),
# 所以**真正擋得住的是這道閘**,不是那張表。
#
# 判準(封動作,不封措辭 —— 同 empty-handed-stop-guard 的哲學):
# 命中 leo21c 的座標 + 這是一個寫入動作 ⇒ 擋
# 只是讀(GET/查詢/grep 到那個字串) ⇒ 放行
set -uo pipefail
payload=$(cat)
cmd=$(printf '%s' "$payload" | python3 -c "
import json,sys
try: print((json.load(sys.stdin).get('tool_input') or {}).get('command',''))
except Exception: print('')
" 2>/dev/null)
[ -z "$cmd" ] && exit 0
# 🔴 這些工具碰不到 CF 帳號 ⇒ 整個放行(2026-08-20 上線當天就誤攔兩次,本段是修正)
# ① `git commit -m "…leo21c… acr update…"` 同時命中座標與寫入動詞而被擋
# ② 連「修這道閘本身」的指令都被擋(測試案例裡自然含觸發字)
# 但 git 與文字編輯根本寫不到那台實例,**訊息裡寫到什麼都不會造成寫入**。
# leo 2026-08-17:「紅線寫得越細,命中關鍵字的機率越高 ⇒ 那些閘在懲罰謹慎。」
# ⇒ 閘要問「這個指令能不能真的寫到那台」,不是「這段文字提到什麼」。
case "$cmd" in
git\ *|jj\ *|" git "*) exit 0 ;;
esac
if printf '%s' "$cmd" | grep -qE '^[[:space:]]*(git|jj)[[:space:]]'; then
exit 0
fi
# 修這道閘自己:命中的是本檔路徑就放行(否則永遠改不動它)
if printf '%s' "$cmd" | grep -q 'leo21c-write-guard'; then
exit 0
fi
# leo21c 的三個座標(帳號 idnamespaceworker 網域)
if ! printf '%s' "$cmd" | grep -qE 'leo21c|51a01bfa2665bd7bc3fd080dc40cf3e1|bfezv28v'; then
exit 0
fi
# 寫入動作的形狀
if ! printf '%s' "$cmd" | grep -qE -- '-X *(POST|PUT|PATCH|DELETE)|--data|--data-raw|-d ["'"'"'{]|wrangler +(deploy|publish|kv|d1|secret)|acr +(update|deploy|push)|/trigger|ingest|kbdb_create|kbdb_update'; then
exit 0
fi
cat >&2 <<'MSG'
🚫 不准寫 leo 的個人帳號 leo21cleo 2026-08-20 立)
leo 原話:「**leo21c 就是我這個普通用戶,不應該讓你去操控,我只用公開的更新。**」
youlin ← 🟢 你的 stage:做實驗、跑驗證,**沒指定就用這個**
geek6688 ← 測試 prod 出貨機
uncle6 ← 中心服務(安裝器/文件站/bundle),出貨線的目的地
leo21c ← 🔴 leo 本人在用的知識庫。**讀可以,寫不行。**
改法:把目標明寫成 youlin,不要吃 `~/.arcrun/config.yaml` 的預設——
那個檔至今仍指著 leo21cKV id 與 encryption_key 是該實例專屬,換不過去)。
cypher : https://arcrun-cypher-executor.youlin-hsieh-dev.workers.dev
ns : yuga3bse
CF : 1129efd7df2e8899d537e9c8fbabb6cb
token : 頂層 .env 的 CLOUDFLARE_API_TOKEN_YOULIN_CC_USE
📌 2026-08-20 實錯:subagent 吃了那個預設,把 8 張測試卡寫進 leo 的真庫
library=demo-real-verify)。當時 wiki 還教「任何自動化只准落在 leo21c」。
MSG
exit 2