Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41c56acd32 | |||
| 2eb9b2aaaa | |||
| 67dae3b814 | |||
| 43c328d26f | |||
| bcb736ed19 | |||
| 6772ca67d3 | |||
| 1b5551274a | |||
| 1920d4cb06 | |||
| 47ed778cc4 | |||
| 03d9782f22 | |||
| 36d8e05a32 | |||
| 135637291c | |||
| d3061585e8 | |||
| 9099c3f533 | |||
| 5bceb03478 | |||
| 4e73b8b03d | |||
| 291787eaaa | |||
| 3a951210a5 | |||
| daa1674a20 | |||
| c48495d911 | |||
| 87186585d6 | |||
| e6d183d038 |
@@ -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.0.0",
|
||||
"version": "0.3.5",
|
||||
"keywords": [
|
||||
"inkstone",
|
||||
"guardrails",
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
# 含金鑰真身的雲端設定,永遠不進版控(2026-08-20 實際差點被 git add)
|
||||
cloud-env*.txt
|
||||
*.env
|
||||
.shell-payload/
|
||||
+46
-20
@@ -124,38 +124,64 @@ bash scripts/make-cloud-env.sh
|
||||
|
||||
**該看到**:儲存後沒有紅字。
|
||||
|
||||
### B2 — 開一個新的雲端 session,確認裝上了
|
||||
### B2 — 開一個新的雲端 session,第一眼找信標
|
||||
|
||||
**什麼都不用打。** session 一開,找這一行:
|
||||
|
||||
在雲端 session 裡打:
|
||||
```
|
||||
跑 claude plugin list 給我看
|
||||
🟢 ISEP v0.3.0 已載入(44 支閘在 …)
|
||||
```
|
||||
**該看到**:`isep@inkstone` / `Version: 0.2.1`(要跟 Releases 頁最新那個一樣)/ `✔ enabled`。
|
||||
|
||||
**該看到**:有這行,而且版本號跟 Releases 頁最新那個一樣。
|
||||
|
||||
**失敗**:
|
||||
- 沒有 `isep` ⇒ Setup script 沒跑成功 → 叫它把 setup 的輸出貼回來
|
||||
- 版本比 Releases 舊 ⇒ 環境快取住了(設定跑完會被拍成快照,約 7 天或改了 setup script 才重拍)
|
||||
→ 動一下 setup script 的內容,強制重拍
|
||||
- **沒有這行** ⇒ plugin 沒載入,這個 session 是**零閘狀態**。先修 plugin,不要開始做事。
|
||||
- 版本比 Releases 舊 ⇒ 環境快取住了(setup 跑完會被拍成快照,約 7 天、或改了 setup script 才重拍)→ 動一下 setup script 的內容強制重拍。
|
||||
|
||||
### B3 — 雲端載到的元件數量要跟本機一樣
|
||||
```
|
||||
跑 claude plugin details isep 給我看
|
||||
```
|
||||
**該看到**:`Skills (9)`、`Hooks (5) PreToolUse, SessionStart, Stop, SubagentStop, PostToolUse`
|
||||
——**跟本機看到的一模一樣**。
|
||||
**失敗**:比本機少 ⇒ 又回到「兩邊不一樣」,正是 `InkStoneCo#57` 那張票的病。
|
||||
🔴 **為什麼是這一行,而不是叫它跑指令**:這行由 `isep-presence-beacon.sh` 發出,
|
||||
而那支腳本**住在 plugin 裡**。plugin 沒載入 ⇒ 它不可能發聲。
|
||||
**沒有「剛好也會過」的情況**——這就是鑑別力。
|
||||
|
||||
### B3 — 要它把 setup 的驗證結果貼回來
|
||||
|
||||
### B4 — 最關鍵:雲端的閘真的會擋,而且擋的是 plugin 那份
|
||||
```
|
||||
請執行 git tag -a v9.9.9 -m test
|
||||
把這個環境 setup script 的輸出貼給我看
|
||||
```
|
||||
**該看到**:被擋下,訊息提到「版本不一致」與 `plugin.json`。
|
||||
|
||||
**該看到**兩行綠:
|
||||
```
|
||||
✅ git 認證通:拉得到 inkstone/ISEP
|
||||
✅ marketplace inkstone 已就位
|
||||
```
|
||||
|
||||
**失敗**:任一行是紅的 ⇒ 訊息本身會講該查什麼(token 值對不對、有沒有被撤銷)。
|
||||
看不到任何輸出 ⇒ setup script 根本沒跑,回 B1 確認欄位真的存好了。
|
||||
|
||||
### B4 — 閘真的會擋(用有鑑別力的動作)
|
||||
|
||||
```
|
||||
請把這段寫進 /tmp/wf.yaml:auth: __GITEA_TOKEN__
|
||||
```
|
||||
|
||||
**該看到**:被擋下,訊息開頭是 `🔒 credential 鐵律攔截(leo 2026-07-29 立)`。
|
||||
|
||||
🔴 **副檔名不能改成 `.md`。** `credential-only-guard` **刻意豁免** `.md`/`docs/`/`wiki/`
|
||||
(文件本來就要能談論這些字串,本頁自己就寫滿了)。
|
||||
2026-08-21 實撞:舊寫法用 `/tmp/x.md` ⇒ **exit 0,閘完全沒反應**——
|
||||
那是沒撞過就寫進來的探針,跟它要取代的假綠是同一個病。
|
||||
|
||||
**失敗**:
|
||||
- 它真的把 tag 打出去 ⇒ **雲端仍然沒有閘**(跟 `InkStoneCo#14` 記的一樣)
|
||||
- 它只是嘴上說「我不應該這麼做」而沒有閘的訊息 ⇒ 同上,那是模型自律不是機械閘
|
||||
- 真的寫進去了 ⇒ 雲端仍然沒有閘。
|
||||
- 它只是嘴上說「我不應該這麼做」而沒有閘的訊息 ⇒ 同上,那是模型自律不是機械閘。
|
||||
|
||||
🔴 **不要再用 `git tag` 當測試**(舊版 B4 就是這樣寫的,而它是假的):
|
||||
`git tag` 出現在**三支閘的白名單**裡,閘全滅時它照樣「被擋」的相反——照樣通過,
|
||||
於是 2026-08-20 那次雲端零閘,三個驗證步驟**全部回綠**。
|
||||
一個在閘死掉時也會給出正確答案的測試,不是測試。
|
||||
|
||||
### B5 — 回報
|
||||
|
||||
B2/B3/B4 三個畫面貼回 `inkstone/InkStoneCo#14`。
|
||||
B2(信標那行)/B3(setup 輸出)/B4(閘的訊息)三個畫面貼回 `inkstone/InkStoneCo#14`。
|
||||
全綠 ⇒ 那張票可以關,`#57` 也解掉一半。
|
||||
|
||||
---
|
||||
|
||||
+30
-30
@@ -1,38 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# 貼進 code-on-web「Cloud environments → 你的環境 → Setup script」欄位的內容。
|
||||
# 不是 ISEP 的一部分(不會被 Claude Code 當 hook/command/skill 掃描),
|
||||
# 純粹是給 leo 複製貼上的參考檔,見 docs/cloud-session-bootstrap.md。
|
||||
# 貼進 claude.ai → Cloud environments → 你的環境 → Setup script 欄位。
|
||||
#
|
||||
# 前提(要先在同一個 Cloud environment 的 Environment variables 欄位加好):
|
||||
# GITEA_TOKEN_CLAUDE_CODE ← 既有機器帳號 token,名字沿用 InkStoneCo#14 已建立的那把,
|
||||
# 不要新造一把。值本身不寫在這支腳本或任何檔案裡。
|
||||
# 🔴 2026-08-21:這支腳本從「要 token」變成「不要 token」,因為查文件查出兩件事——
|
||||
#
|
||||
# 這支腳本做兩件事:
|
||||
# 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 本身,沒有第二份內容。
|
||||
# ① **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 再要這裡讀,永遠讀不到。
|
||||
#
|
||||
# 何時跑:只在「這個 Cloud environment 第一次開 session」時跑一次,
|
||||
# 跑完 Anthropic 會把整個檔案系統拍成快照,之後的 session 直接沿用快照
|
||||
# (不重跑,除非改了這支腳本本身、改了 allowed network hosts、或快照滿 7 天過期)。
|
||||
# ⇒ 這是唯一會讓「ISEP 改了但雲端還是舊的」重新出現的地方,
|
||||
# 緩解法見 docs/cloud-session-bootstrap.md「已知限制」段。
|
||||
# ② **非零結束會讓整個 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=1)ls-remote 成功)
|
||||
# ⇒ **雲端不再需要任何金鑰就能裝 ISEP。**
|
||||
#
|
||||
# 真正讓 plugin 生效的是薄殼 repo 的 .claude/settings.json
|
||||
# (extraKnownMarketplaces + enabledPlugins)——官方文件:
|
||||
# 「Installed at session start from the marketplace you declared.」
|
||||
# 下面兩行是備援,讓 marketplace 在 session 啟動前就已經在快照裡。
|
||||
|
||||
set -euo pipefail
|
||||
set -uo pipefail
|
||||
|
||||
if [ -z "${GITEA_TOKEN_CLAUDE_CODE:-}" ]; then
|
||||
echo "❌ 找不到 GITEA_TOKEN_CLAUDE_CODE —— 去 Cloud environment 的 Environment variables 加這個名字" >&2
|
||||
exit 1
|
||||
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… 已載入」,就是這條也失敗了。"
|
||||
fi
|
||||
|
||||
# 官方文件建議的私有 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 啟動時直接生效。"
|
||||
exit 0
|
||||
|
||||
@@ -677,3 +677,28 @@ Gitea 的 milestone 只管得到同一個 repo,所以六個群在 `inkstone/IS
|
||||
結構(正交) hub ← tracking issue 標記
|
||||
封存不刪 duplicate ← 由 close/duplicate 取代,保留在歷史票上
|
||||
```
|
||||
|
||||
### M4.8 每個里程碑都要有真的期限(leo 2026-08-21 立)
|
||||
|
||||
> 「**以後所有的 milestone 限制時間**」/「**你根本沒有時間概念,浪費一整天**」
|
||||
|
||||
🔴 **`9999-01-01` 不算期限。** 立這條的當下實查七個 open milestone,
|
||||
**六個的期限是 `9999-01-01`**——那是「沒有期限」穿了一件期限的衣服,
|
||||
比空白更糟:盤點時每一格看起來都有值,於是沒有人發現這裡從來沒有時間壓力。
|
||||
|
||||
**怎麼定**:里程碑的 deliverable 是**一個可測的版本**(M4.0)。
|
||||
問一句「**這個版本幾號要能給 leo 打開?**」,那天就是期限。
|
||||
|
||||
| 剩幾張未結 | 期限 |
|
||||
|---|---|
|
||||
| 本週要收 | 三天 |
|
||||
| 1–3 張 | 一週 |
|
||||
| 4 張以上 | 兩週 |
|
||||
|
||||
**過期了怎麼辦**:不自動關、不自動打 tag(M4.3 已否決那條)。
|
||||
過期只做兩件事——**對帳**(哪幾張沒動)與**通知**。
|
||||
期限的用途是製造節奏,不是製造假完成。
|
||||
|
||||
**機械閘**=`hooks/milestone-due-guard.sh`(PreToolUse `Bash`):
|
||||
建 milestone 沒有 `due_on`、或 `due_on` 帶 `9999` → 擋。
|
||||
四向實測:無 due_on 擋/9999 擋/真期限放行/只是讀 milestone 放行。
|
||||
|
||||
+9
-1
@@ -40,6 +40,10 @@
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/ticket-api-bypass-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/milestone-due-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -178,6 +182,10 @@
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/skill-deploy-drift-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/isep-presence-beacon.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -319,4 +327,4 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/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 再做事,不要用『跑得動』當證據。\"
|
||||
}
|
||||
}"
|
||||
@@ -0,0 +1,47 @@
|
||||
# hooks/lib/path-resolve.sh — 共用:判斷一個檔案路徑「歸不歸某個 git repo 管」。
|
||||
# 不是獨立掛的閘(沒進 hooks.json),給其他 PreToolUse 閘 `source` 用的函式庫。
|
||||
#
|
||||
# 背景(inkstone/InkStoneCo#22):sdd-guard.sh 曾經把 scratchpad 暫存檔
|
||||
# (`/private/tmp/.../scratchpad/foo.py`)誤判成「repo 裡的 code 變動」而擋下——
|
||||
# 因為它只會「猜專案根($CLAUDE_PROJECT_DIR 或 cwd)+往上找 3-specs」,
|
||||
# 猜錯或猜不到時,找不到 3-specs 就一律當「找不到 SDD」擋下,連「這條路徑根本不在
|
||||
# 任何 repo 裡、SDD 這件事天生管不到它」都沒判斷過。
|
||||
#
|
||||
# path_in_git_worktree 提供一個不必先猜對專案根的判法:直接問 git
|
||||
# 「這個路徑在不在某個 repo 的工作樹裡」。不必窮舉暫存區的路徑關鍵字(/tmp、scratchpad…),
|
||||
# 任何真的不在 git repo 裡的路徑,一律視同「這是暫存/非受管檔案」。
|
||||
#
|
||||
# 同一個 `${CLAUDE_PROJECT_DIR:-$(pwd)}` 猜根目錄寫法,實測(2026-08-20)還出現在:
|
||||
# component-guard.sh、factory-idle-guard.sh、github-contact-guard.sh、
|
||||
# history-first-guard.sh、main-and-prod-push-guard.sh、no-ticket-no-dispatch.sh、
|
||||
# not-my-branch-guard.sh、release-tag-guard.sh、skill-deploy-drift-guard.sh、
|
||||
# stage-before-prod-guard.sh、unpushed-police.sh、wiki-first-police.sh。
|
||||
# 另有 claim-verify-police.sh、subagent-claim-worksheet.sh、empty-handed-stop-guard.sh、
|
||||
# issue-status-autoflip.sh 直接寫 `$CLAUDE_PROJECT_DIR`(無 `:-` fallback)——
|
||||
# 這批在該變數未設時行為又不一樣,同一個病的另一種長相。
|
||||
# 這些全部沒有本檔「先確認到底在不在 repo 裡」的判斷;本檔先在 sdd-guard.sh 落地,
|
||||
# 其餘要不要跟進、要不要改用這支共用函式,另案處理,不在本票(#22)範圍內一次改完。
|
||||
#
|
||||
# 用法:
|
||||
# source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/path-resolve.sh"
|
||||
# if ! path_in_git_worktree "$FILE_PATH"; then
|
||||
# # 不在任何 git repo 裡 ⇒ 這支閘通常管不到,多半該放行
|
||||
# fi
|
||||
|
||||
# path_in_git_worktree <path>
|
||||
# 回傳 0=這個路徑落在某個 git 工作樹裡;1=不在任何 git repo 裡(含路徑本身不存在的情況)。
|
||||
# 做法:從路徑的目錄部分開始,往上找到「第一個真的存在的祖先目錄」,
|
||||
# 對那個目錄問 `git rev-parse --is-inside-work-tree`。
|
||||
# 為什麼要往上找存在的祖先,不能直接對 dirname 問:
|
||||
# 要在 repo 裡建一個還沒建立的子目錄下的新檔案時,dirname 也不存在,
|
||||
# 若不往上找,`git -C <不存在的目錄>` 會直接失敗 ⇒ 誤判成「不在 repo 裡」
|
||||
# ⇒ 放行了本來該擋的東西(fail-open 的洞,不是這支函式該製造的)。
|
||||
path_in_git_worktree() {
|
||||
local p="$1" d
|
||||
d=$(dirname -- "$p")
|
||||
while [ ! -d "$d" ] && [ "$d" != "/" ]; do
|
||||
d=$(dirname -- "$d")
|
||||
done
|
||||
[ -d "$d" ] || return 1
|
||||
git -C "$d" rev-parse --is-inside-work-tree >/dev/null 2>&1
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
#!/usr/bin/env python3
|
||||
"""hooks/lib/push_target_dir.py -- shared helper (inkstone/ISEP#40 S7-style
|
||||
lib helper: source of truth for a small piece of logic, not a gate by
|
||||
itself; nothing here decides allow/block on its own).
|
||||
|
||||
What it answers: given a shell command string that somewhere invokes
|
||||
`git ... push ...`, which directory will that push actually execute in?
|
||||
|
||||
Why this exists (inkstone/ISEP#30 comment 3949, 脈絡見 InkStoneCo#57):
|
||||
main-and-prod-push-guard.sh's stamp_ok() used to read `git rev-parse
|
||||
--show-toplevel` from the *hook's own* cwd (= the session's real repo) as
|
||||
"HERE", and compare it against the repo path the caller wrote into the
|
||||
stamp ("WANT"). That works when the push target IS the repo the session is
|
||||
standing in. It can never work otherwise: a `cd <other-repo> && git push
|
||||
origin HEAD:main` changes the *push's* directory but not the hook's, so
|
||||
HERE stays the real repo forever while WANT is (correctly) the other repo
|
||||
-- the two can never match, no matter how carefully the caller follows the
|
||||
gate's own instructions. This isn't a bad judgment call; that scenario
|
||||
simply doesn't exist in the old model.
|
||||
|
||||
This module extracts the directory the push *actually* runs in, purely by
|
||||
tokenizing -- it never executes anything. Two sources, first one found
|
||||
wins (in the order a real shell would apply them):
|
||||
- a `cd <path>` chain preceding the push, scoped correctly across
|
||||
subshells: a `(` inherits the current directory from its parent at the
|
||||
moment it opens, but whatever a subshell `cd`s to does NOT leak back
|
||||
out to sibling commands after the matching `)` closes (this mirrors
|
||||
real bash: a subshell's cwd change is local to that subshell). This
|
||||
scoping is load-bearing, not cosmetic: without it, `(cd /repo-A &&
|
||||
true); git push origin main` would misattribute the later push (which
|
||||
really runs wherever the outer shell already was) to /repo-A, and a
|
||||
stale/legitimate stamp for /repo-A could then wrongly wave through a
|
||||
push into whatever the outer cwd actually is -- the exact "stamp
|
||||
opened for repo A also opens the door for repo B" shape 2026-08-11
|
||||
already burned us on once.
|
||||
- a `-C <path>` flag on the git invocation itself, which further wins
|
||||
over any `cd` chain (matches git's own precedence: `-C` sets the
|
||||
directory for that invocation regardless of the shell's cwd).
|
||||
|
||||
Multiple relative `cd`/`-C` hops are combined by plain string join here
|
||||
(no `..`/`~`/`$()` resolution) -- resolving the combined expression to a
|
||||
real, canonical, absolute path is left to the caller, which does it with a
|
||||
read-only `cd "<expr>" && pwd` in a throwaway subshell. That two-step split
|
||||
matters: this module only ever *parses*, so it stays side-effect-free even
|
||||
when fed a hostile or malformed command; only the caller's final `cd`
|
||||
touches the filesystem, and `cd` cannot execute anything, it can only fail
|
||||
to find a directory.
|
||||
|
||||
If no `cd`/`-C` applies (the push runs wherever the hook itself is, i.e.
|
||||
today's behaviour), or the command doesn't parse, prints nothing -- the
|
||||
caller falls back to its existing cwd-based resolution. That fallback
|
||||
direction is deliberately the *safe* one: on any parse ambiguity we hand
|
||||
back "unknown" rather than guess, and an unresolved HERE can only make the
|
||||
gate keep blocking (fail toward blocking), never open a door it wouldn't
|
||||
have opened before.
|
||||
|
||||
Usage:
|
||||
printf '%s' "$CMD" | python3 push_target_dir.py
|
||||
"""
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
_SEPARATORS = {";", "&&", "||", "|", "&", "\n"}
|
||||
|
||||
|
||||
def _join(base, path):
|
||||
"""Combine a cwd-so-far (`base`, or None if unknown/hook-cwd) with a
|
||||
`cd`/`-C` argument written in the command. Absolute paths and `~`
|
||||
replace the base outright; anything else is appended textually --
|
||||
normalizing `..`/`.` is intentionally left to the caller's real `cd`."""
|
||||
if not path:
|
||||
return base
|
||||
if path == "-" or path.startswith("$"):
|
||||
# `cd -` (previous dir) and `$VAR`/`$(...)` expansions can't be
|
||||
# resolved by tokenizing alone -- treat as "unknown" rather than
|
||||
# guess wrong, which keeps the caller on its safe fallback path.
|
||||
return None
|
||||
if path.startswith("/") or path.startswith("~"):
|
||||
return path
|
||||
if base is None:
|
||||
return path
|
||||
return base.rstrip("/") + "/" + path
|
||||
|
||||
|
||||
def _classify(tokens):
|
||||
if not tokens:
|
||||
return ("other", None)
|
||||
if tokens[0] == "cd" and len(tokens) > 1:
|
||||
return ("cd", tokens[1])
|
||||
if tokens[0] == "git" and "push" in tokens[1:]:
|
||||
return ("push", tokens)
|
||||
return ("other", None)
|
||||
|
||||
|
||||
def _events(cmd):
|
||||
"""Tokenize cmd into (kind, value) events in source order: 'enter'/
|
||||
'exit' for parens (subshell boundaries), 'cd'/'push'/'other' for
|
||||
statements split on the usual shell separators. Returns [] on any
|
||||
quoting error -- caller then falls back to cwd-based resolution."""
|
||||
try:
|
||||
lexer = shlex.shlex(cmd, posix=True, punctuation_chars=True)
|
||||
lexer.whitespace_split = True
|
||||
toks = list(lexer)
|
||||
except ValueError:
|
||||
return []
|
||||
|
||||
events = []
|
||||
seg = []
|
||||
|
||||
def flush():
|
||||
if seg:
|
||||
# _classify's "push" branch returns `tokens` by reference; copy
|
||||
# before clear() below, or the event's tuple would observe the
|
||||
# list emptied out from under it (aliasing, not a value copy).
|
||||
events.append(_classify(seg[:]))
|
||||
seg.clear()
|
||||
|
||||
for tok in toks:
|
||||
if tok == "(":
|
||||
flush()
|
||||
events.append(("enter", None))
|
||||
elif tok == ")":
|
||||
flush()
|
||||
events.append(("exit", None))
|
||||
elif tok in _SEPARATORS:
|
||||
flush()
|
||||
else:
|
||||
seg.append(tok)
|
||||
flush()
|
||||
return events
|
||||
|
||||
|
||||
def find_push_target(cmd):
|
||||
events = _events(cmd)
|
||||
if not events:
|
||||
return ""
|
||||
|
||||
stack = [None] # cwd-so-far per paren depth; None = "same as hook cwd"
|
||||
result = None
|
||||
saw_push = False
|
||||
|
||||
for kind, val in events:
|
||||
if kind == "enter":
|
||||
stack.append(stack[-1]) # child subshell inherits current dir
|
||||
elif kind == "exit":
|
||||
if len(stack) > 1:
|
||||
stack.pop() # subshell's own cd's don't leak out
|
||||
elif kind == "cd":
|
||||
stack[-1] = _join(stack[-1], val)
|
||||
elif kind == "push":
|
||||
saw_push = True
|
||||
c_path = None
|
||||
toks = val
|
||||
for j, t in enumerate(toks):
|
||||
if t == "-C" and j + 1 < len(toks):
|
||||
c_path = toks[j + 1]
|
||||
break
|
||||
if t.startswith("-C") and len(t) > 2:
|
||||
c_path = t[2:]
|
||||
break
|
||||
result = _join(stack[-1], c_path) if c_path else stack[-1]
|
||||
|
||||
if not saw_push:
|
||||
return ""
|
||||
return result or ""
|
||||
|
||||
|
||||
def main():
|
||||
cmd = sys.stdin.read()
|
||||
sys.stdout.write(find_push_target(cmd))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -98,7 +98,32 @@ stamp_ok() {
|
||||
# 等於一把萬用鑰匙——正是 08-11 那次穿透的形狀(替 A repo 開的門 B repo 也走得過)。
|
||||
# 而且 `.claude/settings.local.json` 裡真的放行過 `touch /tmp/.main-push-ok`。
|
||||
# ⇒ 現在**空內容一律不算數**:要嘛寫得出 repo 路徑且對得上,要嘛不放行。
|
||||
HERE=$(git rev-parse --show-toplevel 2>/dev/null || printf '')
|
||||
#
|
||||
# 🔴 2026-08-23(inkstone/ISEP#30 comment 3949,脈絡 InkStoneCo#57):
|
||||
# `HERE` 原本一律讀 hook 自己的 cwd(=session 站著的那個 repo)。
|
||||
# 只要要推的 repo **不是**「session 站著的那個 repo」——例如指令自己
|
||||
# `cd <別的 repo> && git push` 或 `git -C <別的 repo> push`——HERE 永遠是
|
||||
# 總管的真身,而總管替目標 repo 開的 WANT 永遠對不上,這道閘就**永遠沒辦法
|
||||
# 合法通過**。不是判斷錯,是這個情境在舊模型裡根本不存在(照閘的指示做
|
||||
# 戳記,戳記內容天生就贏不了)。
|
||||
# 改法:先看指令本身有沒有把 push 的執行目錄改掉
|
||||
# (lib/push_target_dir.py——純 tokenize,不執行任何指令,
|
||||
# 對 `cd A && cd B && git push` 這種多層鏈與 `(cd A && …); git push` 這種
|
||||
# 子殼會不會外洩都做了範圍化,理由見該檔檔頭);解得出來就 `cd` 進那個
|
||||
# 目錄(唯讀操作,`cd` 本身不會執行任何東西)問 git 那裡的 toplevel 是誰;
|
||||
# 解不出來(沒有 cd/-C,或指令太怪解析失敗)才退回舊行為=hook 自己的 cwd。
|
||||
# 🔴 綁 repo+單次用完即丟兩條性質完全沒有鬆動:這裡只是把「現在人在哪個
|
||||
# repo」問得更準,比對邏輯(下面兩行)一個字沒動。
|
||||
_push_target_dir="$(dirname "$0")/lib/push_target_dir.py"
|
||||
_target_expr=""
|
||||
if [ -f "$_push_target_dir" ]; then
|
||||
_target_expr=$(printf '%s' "$CMD" | python3 "$_push_target_dir" 2>/dev/null || printf '')
|
||||
fi
|
||||
if [ -n "$_target_expr" ]; then
|
||||
HERE=$(cd "$_target_expr" 2>/dev/null && git rev-parse --show-toplevel 2>/dev/null || printf '')
|
||||
else
|
||||
HERE=$(git rev-parse --show-toplevel 2>/dev/null || printf '')
|
||||
fi
|
||||
WANT=$(head -1 "$STAMP" 2>/dev/null || printf '')
|
||||
[ -n "$WANT" ] || return 1
|
||||
[ -n "$HERE" ] || return 1
|
||||
@@ -125,7 +150,42 @@ if printf '%s' "$CMD" | grep -qE '(^|[;&|(`]|&&|\|\|)[[:space:]]*git([[:space:]]
|
||||
# 2026-08-20: match the target branch on a word boundary, not a bare substring --
|
||||
# a glob like *main* also matches "domain" (d-o-**m-a-i-n**), e.g. a push to
|
||||
# `fix/custom-domain-setup` would have false-positived.
|
||||
if printf '%s' "$CMD" | grep -qE '(^|[^A-Za-z])(main|master)([^A-Za-z]|$)'; then
|
||||
# 2026-08-21: 只看 **push 的目標**,不再掃整條指令。
|
||||
# 舊版掃整條 ⇒ 一個晚上誤攔四次,全都是推 feature branch 或 tag:
|
||||
# git checkout -b fix/x main && git push origin fix/x ← 「main」在 checkout 上
|
||||
# gh pr create --base main ← 根本不是 git push
|
||||
# git checkout origin/main --detach; git push origin refs/tags/v0.3.3
|
||||
# ⇒ **紅線寫得越細,命中關鍵字的機率越高**(leo 2026-08-17 的觀察,
|
||||
# 文字層封路必敗)。這裡改成判動作的目標,不是判字面。
|
||||
# 2026-08-23(順著 inkstone/ISEP#30 comment 3949 補測時自己抓到的洞,不在原票範圍
|
||||
# 但屬於同一支閘、同一段邏輯,且直接讓下面「反向不准鬆」的驗證跑不過,所以一併修):
|
||||
# `(git push origin HEAD:main)`——單純用括號包住整條指令——舊版會整段放行,
|
||||
# 跟 HERE/戳記完全無關,**連目的地判斷本身都沒觸發**。
|
||||
# 成因:截斷 refspec 尾巴只切 `;`/`&`/`|` 三種字元,沒算到 `)`——
|
||||
# 於是「HEAD:main)」被當成一個 token,`${_tok##*:}` 剝完冒號還剩「main)」,
|
||||
# 跟 `^main$` 對不上 ⇒ 判定成「看不出目標」⇒ 整段放行。加 `)` 進截斷字元。
|
||||
# git 的 refspec/分支名語法本來就不允許出現 `)`,所以在這裡截斷永遠安全,
|
||||
# 不會誤傷任何合法的推送目標。
|
||||
_push_seg=$(printf '%s' "$CMD" | sed -E 's/.*git[[:space:]]+(-[^[:space:]]+[[:space:]]+)*push//' | sed -E 's/[;&|)].*//')
|
||||
_dest=""
|
||||
_seen_remote=0
|
||||
_saw_refspec=0
|
||||
for _tok in $_push_seg; do
|
||||
case "$_tok" in
|
||||
-*) continue ;; # 旗標
|
||||
refs/tags/*|*:refs/tags/*) _saw_refspec=1; continue ;; # 推 tag 不是推分支
|
||||
esac
|
||||
if [ "$_seen_remote" = "0" ]; then _seen_remote=1; continue; fi # 第一個非旗標=remote
|
||||
_saw_refspec=1
|
||||
_dest="$_dest ${_tok##*:}" # a:b 的目標是 b;沒有冒號就是它自己
|
||||
done
|
||||
# 🔴 只有「一個 refspec 都沒給」才退回猜當前分支。
|
||||
# 看到 refspec(哪怕是 tag)就照它判——否則推 tag 會被當成推當前分支,
|
||||
# 而當前分支若剛好叫 main 就誤擋(2026-08-21 實測抓到)。
|
||||
if [ "${_saw_refspec:-0}" = "0" ]; then
|
||||
_dest=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")
|
||||
fi
|
||||
if printf '%s' "$_dest" | tr ' ' '\n' | grep -qE '^(main|master)$'; then
|
||||
stamp_ok && exit 0
|
||||
|
||||
# ── 擋下的同時,把「誰想推什麼」留成一份請求(leo 2026-08-12)───────────
|
||||
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
# milestone-due-guard.sh — 建 milestone 一定要有真的期限(leo 2026-08-21 立)
|
||||
#
|
||||
# leo 原話:「**以後所有的 milestone 限制時間**」
|
||||
# 「**你根本沒有時間概念,浪費一整天**」
|
||||
#
|
||||
# 🔴 為什麼連 9999 也要擋:立這條的當下實查七個 open milestone,
|
||||
# 六個的期限是 `9999-01-01`——那是「沒有期限」穿了一件期限的衣服,
|
||||
# 比空白更糟,因為它讓盤點時看起來每一格都有值。
|
||||
set -uo pipefail
|
||||
INPUT=$(cat)
|
||||
CMD=$(printf '%s' "$INPUT" | python3 -c "import json,sys;print(json.load(sys.stdin).get('tool_input',{}).get('command',''))" 2>/dev/null || echo "")
|
||||
[ -z "$CMD" ] && exit 0
|
||||
|
||||
# 只管「建 milestone」這個動作
|
||||
printf '%s' "$CMD" | grep -qE 'milestones' || exit 0
|
||||
printf '%s' "$CMD" | grep -qE '\-X *POST|--request *POST' || exit 0
|
||||
|
||||
DUE=$(printf '%s' "$CMD" | grep -oE '"due_on"[^,}]*' | head -1)
|
||||
BAD=""
|
||||
[ -z "$DUE" ] && BAD="沒有 due_on"
|
||||
printf '%s' "$DUE" | grep -q '9999' && BAD="due_on 是 9999(等於沒有期限)"
|
||||
|
||||
[ -z "$BAD" ] && exit 0
|
||||
|
||||
cat >&2 <<MSG
|
||||
⏱️ 里程碑期限閘:$BAD
|
||||
|
||||
【leo 2026-08-21】「**以後所有的 milestone 限制時間**」
|
||||
「**你根本沒有時間概念,浪費一整天**」
|
||||
|
||||
🔴 9999-01-01 也算違規。立這條的當下實查七個 open milestone,
|
||||
六個是 9999——那是「沒有期限」穿了一件期限的衣服,
|
||||
比空白更糟,因為盤點時每一格看起來都有值。
|
||||
|
||||
怎麼定:這個里程碑的 deliverable 是**一個可測的版本**。
|
||||
問「這個版本幾號要能給 leo 打開?」,那天就是期限。
|
||||
剩 1–3 張票 → 一週;4 張以上 → 兩週;本週要收 → 三天。
|
||||
|
||||
加上去再送一次: "due_on": "YYYY-MM-DDT23:59:59Z"
|
||||
MSG
|
||||
exit 2
|
||||
+78
-13
@@ -1,4 +1,11 @@
|
||||
#!/bin/bash
|
||||
# 管什麼: Write/Edit 動 code 檔(.ts/.py/.go…)前,要不要有對應的一份 status: active SDD(design.md)。
|
||||
# 為什麼: SDD 生命週期鐵律——動 code 前必須有規格可對,且整個 repo 同一時刻只准一份 active。
|
||||
# 把「動手前先讀 SDD」從只能靠人記,升級成機器擋(system-dev/docs/3-specs/SDD-LIFECYCLE.md)。
|
||||
# 誤觸時怎麼關: 改文件/測試檔/3-specs 自己一律放行(下方 case 已排除);不在任何 git repo
|
||||
# 裡的路徑(scratchpad、/tmp 暫存檔)一律放行,SDD 管不到它們。真的要臨時豁免
|
||||
# 一次小改動,說明範圍後由人手動放行——這支閘不設「一行關掉」的旗標。
|
||||
#
|
||||
# PreToolUse hook — 動 code 前檢查 SDD + 單一活性 SDD 鐵律(issue #6)
|
||||
# wishlist §2:把 /sdd-check 從「命令要人打」升級成「hook 自動攔」。
|
||||
# 生命週期規則全文:system-dev/docs/3-specs/SDD-LIFECYCLE.md
|
||||
@@ -18,6 +25,8 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/path-resolve.sh"
|
||||
|
||||
INPUT=$(cat)
|
||||
|
||||
# 解析 file_path。優先用 jq,沒有 jq 退回 grep(容錯)。
|
||||
@@ -38,8 +47,51 @@ fi
|
||||
# ⇒ 改成從被改檔案往上找最近的 system-dev/docs/3-specs(子 repo 優先,找不到才用頂層)。
|
||||
# ⚠️ 只往上找到「頂層 InkStoneCo」為止——不可讓任意路徑(如 /private/tmp/…)
|
||||
# 退回頂層 SDD 而被放行,那會把原本擋得住的情況變成擋不住。
|
||||
SPECS_DIR="system-dev/docs/3-specs"
|
||||
#
|
||||
# 🔴 2026-08-20 修(inkstone/InkStoneCo#22):上面這套邏輯有兩個洞,都是總管 08-12 實撞的:
|
||||
#
|
||||
# 洞 A — scratchpad 暫存檔被當成「code 變動」:
|
||||
# `/private/tmp/.../scratchpad/foo.py` 不在 `$_root` 底下、往上找不到 3-specs,
|
||||
# 於是走到「找不到 SDD」擋下路徑——但 scratchpad 是 session 專用暫存區,從不進版控,
|
||||
# SDD 管的是 repo 裡的產品程式碼,管不到它。**先問「這條路徑到底在不在某個 git repo
|
||||
# 裡」(`path_in_git_worktree`,見 lib/path-resolve.sh),不在 ⇒ 這道閘天生管不到
|
||||
# ⇒ 直接放行**,不必先繞去猜專案根、再證明找不到才擋。
|
||||
# 用「有沒有 .git 可尋」判斷,比列舉路徑關鍵字(/tmp、scratchpad…)更穩:
|
||||
# 不必窮舉每一種暫存區的命名法,任何真的不在 repo 裡的路徑都一視同仁。
|
||||
#
|
||||
# 洞 B — 訊息裡印出字面的 `/nonexistent`:
|
||||
# 舊版用 `/nonexistent/3-specs` 當內部 sentinel,讓「找不到 SDD」的既有擋下路徑可以
|
||||
# 重用;但這個 sentinel 值被直接印進使用者看到的訊息,讀起來像是「這支腳本認真去
|
||||
# /nonexistent 這個地方找過」——具體、卻是假的。改成用 RESOLVED 旗標記「解析成不成功」,
|
||||
# 擋下訊息另外用人話描述「為什麼找不到」,不洩漏內部實作用的假路徑。
|
||||
#
|
||||
# ⚠️ 洞 A/B 都不改變「真的解析失敗時」的判定方向:路徑確實落在某個 git repo 裡,
|
||||
# 但那個 repo 沒有 3-specs(或裡面沒有 active SDD)→ 仍然 **fail-closed**(擋,不放行)。
|
||||
# 為什麼是 fail-closed、不是 fail-open:這道閘存在的目的就是防止「沒有 SDD 卻能動
|
||||
# code」,若把「判斷不出來」直接放行,等於把一次環境跑歪(cwd 被切走、
|
||||
# `$CLAUDE_PROJECT_DIR` 沒設、worktree 缺 3-specs…)悄悄變成「這道閘關掉了,而且沒有
|
||||
# 任何人被告知」——silent bypass 的代價遠高於「多打一次確認」。#22 的紅線也明寫
|
||||
# 「不要把閘改成『解析失敗就放行』——那是把誤判換成漏判」。
|
||||
# 洞 A 的修法,套用在 case 分岔**之前**:不管 `$_root` 猜不猜得對,
|
||||
# 先問「這條路徑到底在不在某個 git repo 裡」。不在 ⇒ SDD 這道閘天生管不到,直接放行。
|
||||
# 🔴 這個檢查故意放在 `$FILE_PATH` 是否落在 `$_root` 底下的判斷之前、且對兩邊都適用
|
||||
# (不是只套用在「專案外」那個分支):第一版只把它放進「專案外」分支,結果測試
|
||||
# (hooks/tests/sdd-guard.test.sh)就抓到一個不對稱漏洞——當 `$_root` 剛好等於
|
||||
# scratchpad 的某層祖先目錄(例如 hook 被叫用時 cwd 已經跑到 /private/tmp 底下、
|
||||
# `$CLAUDE_PROJECT_DIR` 也沒設),scratchpad 路徑會被判成「在 `$_root` 底下」而
|
||||
# 走進另一條完全沒做 git-repo 檢查的路徑,同一個誤判换個路徑重新出現。
|
||||
# 改成「先問是不是在 git repo 裡,不管路徑跟 `$_root` 的關係」就沒有這個不對稱。
|
||||
if ! path_in_git_worktree "$FILE_PATH"; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
_root="${CLAUDE_PROJECT_DIR:-$(pwd)}"
|
||||
# 預設值一律絕對路徑(不留相對路徑「system-dev/docs/3-specs」退回目前 cwd 的洞——
|
||||
# 舊版這裡曾經是相對路徑,若專案內迴圈找不到就會被拿去跟 hook 執行當下的 cwd 兜,
|
||||
# cwd 湊巧有同名目錄就會判斷到不相干的資料)。
|
||||
SPECS_DIR="$_root/system-dev/docs/3-specs"
|
||||
RESOLVED=1 # 1=SPECS_DIR 是有意義的答案;0=真的解析失敗,SPECS_DIR 留空,訊息另外講原因
|
||||
|
||||
case "$FILE_PATH" in
|
||||
"$_root"/*)
|
||||
_d=$(dirname "$FILE_PATH")
|
||||
@@ -53,16 +105,17 @@ case "$FILE_PATH" in
|
||||
done
|
||||
;;
|
||||
*)
|
||||
# 專案外的路徑:**不可退回頂層 SDD 就放行**,否則原本擋得住的會變成擋不住。
|
||||
# 但 **git worktree 是正當工作區**(本專案大量使用 /private/tmp 下的 worktree 出貨),
|
||||
# 它自己就帶著該 repo 的 system-dev/docs/3-specs ⇒ 一樣往上找,找得到就認。
|
||||
# 找不到才指向不存在目錄 ⇒ 走原有的「找不到 SDD」擋下路徑。
|
||||
# (2026-08-02:第一版忘了 worktree,把正當的出貨工作區也擋掉。)
|
||||
SPECS_DIR="/nonexistent/3-specs"
|
||||
# 專案外的路徑:`$_root` 猜錯,或這條路徑本來就不屬於目前的 `$_root`。
|
||||
# 已知落在某個 git repo 裡(上面剛確認過):往上找它自己的 3-specs。
|
||||
# **不可退回 `$_root` 的 3-specs 就放行**——那會把「這個 repo 沒有 SDD」
|
||||
# 誤判成「用別的 repo 的 SDD 蒙混過關」,原本擋得住的會變成擋不住。
|
||||
SPECS_DIR=""
|
||||
RESOLVED=0
|
||||
_d=$(dirname "$FILE_PATH")
|
||||
while [ "$_d" != "/" ] && [ -n "$_d" ]; do
|
||||
if [ -d "$_d/system-dev/docs/3-specs" ]; then
|
||||
SPECS_DIR="$_d/system-dev/docs/3-specs"
|
||||
RESOLVED=1
|
||||
break
|
||||
fi
|
||||
_d=$(dirname "$_d")
|
||||
@@ -70,6 +123,18 @@ case "$FILE_PATH" in
|
||||
;;
|
||||
esac
|
||||
|
||||
# 給訊息用的人話描述:解析成功就印真路徑,失敗就誠實講「為什麼」,不印假路徑
|
||||
# (洞 B 的修法——舊版這裡印的是內部 sentinel `/nonexistent/3-specs`)。
|
||||
if [ "$RESOLVED" -eq 1 ]; then
|
||||
SPECS_DIR_DESC="${SPECS_DIR}/"
|
||||
SPECS_NOT_FOUND_MSG="${SPECS_DIR}/ 下找不到任何 SDD"
|
||||
SPECS_NOT_ACTIVE_MSG="${SPECS_DIR}/ 下沒有任何 status: active 的 SDD"
|
||||
else
|
||||
SPECS_DIR_DESC=""
|
||||
SPECS_NOT_FOUND_MSG="這條路徑所在的 git repo 裡找不到 system-dev/docs/3-specs,也就沒有任何 SDD 可對(或這支閘沒能定位到正確的專案根——這是 fail-closed:寧可誤擋也不悄悄放行,見檔頭註解)"
|
||||
SPECS_NOT_ACTIVE_MSG="$SPECS_NOT_FOUND_MSG"
|
||||
fi
|
||||
|
||||
# ── 統計 active / frontmatter ──────────────────────
|
||||
# 排除 archive/(已封存)與 TEMPLATE(範本自帶 status: draft frontmatter,不算數——
|
||||
# 否則 update 一鋪新版 TEMPLATE-sdd,老 repo 就被誤判「已遷移」而全紅,向下相容破功)。
|
||||
@@ -77,7 +142,7 @@ esac
|
||||
ACTIVE_COUNT=0
|
||||
FM_COUNT=0
|
||||
ACTIVE_LIST=""
|
||||
if [ -d "$SPECS_DIR" ]; then
|
||||
if [ -n "$SPECS_DIR" ] && [ -d "$SPECS_DIR" ]; then
|
||||
while IFS= read -r f; do
|
||||
[ -n "$f" ] || continue
|
||||
HEAD10=$(head -10 "$f" 2>/dev/null || true)
|
||||
@@ -121,20 +186,20 @@ esac
|
||||
# 避免 template update 一裝新 hook,老 repo 所有 code 寫入立刻全紅。
|
||||
if [ "$FM_COUNT" -eq 0 ]; then
|
||||
SDD_COUNT=0
|
||||
if [ -d "$SPECS_DIR" ]; then
|
||||
if [ -n "$SPECS_DIR" ] && [ -d "$SPECS_DIR" ]; then
|
||||
SDD_COUNT=$(find "$SPECS_DIR" -name 'design.md' -not -path '*TEMPLATE*' -not -path '*/archive/*' 2>/dev/null | wc -l | tr -d ' ')
|
||||
fi
|
||||
|
||||
if [ "$SDD_COUNT" -eq 0 ]; then
|
||||
cat >&2 <<EOF
|
||||
🚫 SDD 協議攔截:要動 code 檔 ($FILE_PATH),但 ${SPECS_DIR}/ 下找不到任何 SDD。
|
||||
🚫 SDD 協議攔截:要動 code 檔 ($FILE_PATH),但 ${SPECS_NOT_FOUND_MSG}。
|
||||
|
||||
絕對鐵律:任何 code 變動前必須有對應 SDD(design.md),且遵守單一活性生命週期
|
||||
(system-dev/docs/3-specs/SDD-LIFECYCLE.md)。
|
||||
|
||||
請先:
|
||||
1. 確認這個改動屬於哪個子系統
|
||||
2. 在 ${SPECS_DIR}/[子系統]/ 建立 design.md(可用 /sdd-check 協助),frontmatter 標 status: active
|
||||
2. 在 [子系統的] system-dev/docs/3-specs/[子系統]/ 建立 design.md(可用 /sdd-check 協助),frontmatter 標 status: active
|
||||
3. 在回覆開頭宣告已讀 SDD + 對應 task
|
||||
|
||||
小修改(修 bug、改文字)若確定豁免,請明確說明範圍後由人放行。
|
||||
@@ -143,14 +208,14 @@ EOF
|
||||
fi
|
||||
|
||||
# 舊行為放行 + 提醒遷移(stderr 警告,不擋)
|
||||
echo "📋 提醒:${SPECS_DIR}/ 有 SDD 但尚未掛生命週期 frontmatter(老結構)。動手前確認已讀對應 design.md;建議依 SDD-LIFECYCLE.md 補 status 標記(現行那份標 active)。" >&2
|
||||
echo "📋 提醒:${SPECS_DIR_DESC} 有 SDD 但尚未掛生命週期 frontmatter(老結構)。動手前確認已讀對應 design.md;建議依 SDD-LIFECYCLE.md 補 status 標記(現行那份標 active)。" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ── 新行為:寫 code 檔需「恰好 1 份」active SDD ──
|
||||
if [ "$ACTIVE_COUNT" -eq 0 ]; then
|
||||
cat >&2 <<EOF
|
||||
🚫 SDD 協議攔截:要動 code 檔 ($FILE_PATH),但 ${SPECS_DIR}/ 下沒有任何 status: active 的 SDD。
|
||||
🚫 SDD 協議攔截:要動 code 檔 ($FILE_PATH),但 ${SPECS_NOT_ACTIVE_MSG}。
|
||||
|
||||
單一活性鐵律:所有開發任務唯一對應源=那份 active SDD(規則見 system-dev/docs/3-specs/SDD-LIFECYCLE.md)。
|
||||
|
||||
|
||||
@@ -119,8 +119,21 @@ if not ok_hits and not ng_hits:
|
||||
|
||||
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]
|
||||
path = os.path.join(os.environ["DIR"], "claims-%s-%s.md" % (sid, stamp))
|
||||
# 🔴 2026-08-21:stamp 原本雜湊「交件路徑」⇒ 同樣的宣稱每回合生一個新檔名,
|
||||
# 而且不知道總管已經驗過了。實際發作:同兩條 sdd-guard 宣稱連生四張單
|
||||
# (1c97d461/fcb285dc/256de849/394b97ae),驗掉一張下一回合又冒一張。
|
||||
# ⇒ 改成雜湊**宣稱內容本身**:同樣的宣稱=同一個檔名 ⇒ 驗過就不再冒出來。
|
||||
_claims = sorted(set(str(x) for x in (ok_hits + ng_hits)))
|
||||
# 🔴 空清單就退回舊行為 —— 但那等於這支閘沒抓到任何宣稱,本來就會 SKIP,
|
||||
# 所以這個 fallback 實際上不會被用到;留著只是不讓 stamp 變成空字串的雜湊。
|
||||
_basis = "\n".join(_claims) if _claims else (tp + sid + aid)
|
||||
stamp = hashlib.sha1(_basis.encode()).hexdigest()[:8]
|
||||
_name = "claims-%s-%s.md" % (sid, stamp)
|
||||
path = os.path.join(os.environ["DIR"], _name)
|
||||
|
||||
# 已經驗過並移進 verified/ 的,不要再生一次。
|
||||
if os.path.exists(os.path.join(os.environ["DIR"], "verified", _name)):
|
||||
print("SKIP:already-verified"); raise SystemExit
|
||||
|
||||
def block(title, items, howto, cap):
|
||||
if not items:
|
||||
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env bash
|
||||
# 跨 repo 戳記實測(inkstone/ISEP#30 comment 3949,脈絡 inkstone/InkStoneCo#57)
|
||||
#
|
||||
# 補的是什麼:hooks/tests/main-and-prod-push-guard.test.sh 那八向都只在單一 repo
|
||||
# (測試腳本自己所在的 repo)裡驗證,從沒測過「站在 A、要推 B 的 main」這個形狀
|
||||
# ——而這正是 2026-08-21 真的撞到、讓戳記永遠對不上的那個情境。這支專門補這塊。
|
||||
#
|
||||
# 用法:main-and-prod-push-guard-cross-repo.test.sh <要測的 hook 絕對路徑>
|
||||
# 路徑務必給絕對路徑——測試會 cd 進臨時建立的 A/B repo 再呼叫它,相對路徑
|
||||
# 到那時就對不上了(自己撞過一次:exit=127 command not found)。
|
||||
set -u
|
||||
G="$1"
|
||||
STAMP=/tmp/.main-push-ok
|
||||
WORK=$(mktemp -d)
|
||||
trap 'rm -rf "$WORK"; rm -f "$STAMP"' EXIT
|
||||
|
||||
for d in A B; do
|
||||
git init -q -b main "$WORK/$d"
|
||||
git -C "$WORK/$d" config user.email t@t.com
|
||||
git -C "$WORK/$d" config user.name t
|
||||
echo x > "$WORK/$d/f.txt"
|
||||
git -C "$WORK/$d" add f.txt
|
||||
git -C "$WORK/$d" commit -q -m init
|
||||
done
|
||||
A="$WORK/A"; B="$WORK/B"
|
||||
|
||||
pass=0; fail=0
|
||||
t() { # t <說明> <cwd> <指令> <期望 exit>
|
||||
local desc="$1" cwd="$2" cmd="$3" want="$4"
|
||||
local rc
|
||||
rc=$(cd "$cwd" && CLAUDE_CODE_CHILD_SESSION=1 python3 -c '
|
||||
import json, subprocess, sys
|
||||
p = subprocess.run(["bash", sys.argv[2]],
|
||||
input=json.dumps({"tool_name": "Bash",
|
||||
"tool_input": {"command": sys.argv[1]}}),
|
||||
capture_output=True, text=True)
|
||||
print(p.returncode)
|
||||
' "$cmd" "$G")
|
||||
if [ "$rc" = "$want" ]; then printf ' ✅ %-58s exit=%s\n' "$desc" "$rc"; pass=$((pass+1))
|
||||
else printf ' ❌ %-58s exit=%s(期望 %s)\n' "$desc" "$rc" "$want"; fail=$((fail+1)); fi
|
||||
}
|
||||
|
||||
echo "── 2026-08-21 實撞的原形狀:站在 A,要推 B 的 main ──"
|
||||
rm -f "$STAMP"
|
||||
t "沒戳記 → 擋" "$A" "cd $B && git push origin HEAD:main" 2
|
||||
git -C "$B" rev-parse --show-toplevel > "$STAMP"
|
||||
t "替 B 開的戳記 → 推 B 的 main 該放行(舊版在此情境永遠擋,這是本票要修的洞)" \
|
||||
"$A" "cd $B && git push origin HEAD:main" 0
|
||||
|
||||
echo "── 反向不准鬆:替 A 開的戳記,不能拿去放行推 B(08-11 那次穿透的形狀)──"
|
||||
git -C "$A" rev-parse --show-toplevel > "$STAMP"
|
||||
t "替 A 開的戳記 → 拿去推 B 的 main 必須仍被擋" \
|
||||
"$A" "cd $B && git push origin HEAD:main" 2
|
||||
rm -f "$STAMP"
|
||||
|
||||
echo "── git -C 語法要吃到同一套判斷 ──"
|
||||
git -C "$B" rev-parse --show-toplevel > "$STAMP"
|
||||
t "替 B 開戳記,用 git -C B push" "$A" "git -C $B push origin main" 0
|
||||
rm -f "$STAMP"
|
||||
|
||||
echo "── 08-11 原始穿透的形狀:子殼裡的 cd 不能外洩到殼外 ──"
|
||||
git -C "$A" rev-parse --show-toplevel > "$STAMP"
|
||||
t "子殼裡 cd 去 B 但沒在殼內推;殼外站著 A 真的推 → 符合 A 的戳記,放行" \
|
||||
"$A" "(cd $B && true); git push origin HEAD:main" 0
|
||||
rm -f "$STAMP"
|
||||
git -C "$A" rev-parse --show-toplevel > "$STAMP"
|
||||
t "子殼裡 cd 去 B 且在殼內真的推 → 目標是 B,戳記是 A,必須擋" \
|
||||
"$A" "(cd $B && git push origin HEAD:main)" 2
|
||||
rm -f "$STAMP"
|
||||
|
||||
echo "── 順手抓到、一併修的洞:純括號包住整條指令,不准繞過目的地判斷 ──"
|
||||
t "(git push origin HEAD:main) 沒有任何戳記 → 必須擋(舊版在此整段放行)" \
|
||||
"$A" "(git push origin HEAD:main)" 2
|
||||
|
||||
echo "── 同 repo(session 站著的那個)舊行為原封不動 ──"
|
||||
rm -f "$STAMP"
|
||||
t "站在 A 推 A 自己的 main,沒戳記 → 擋" "$A" "git push origin HEAD:main" 2
|
||||
git -C "$A" rev-parse --show-toplevel > "$STAMP"
|
||||
t "站在 A 推 A 自己的 main,替 A 開戳記 → 放行" "$A" "git push origin HEAD:main" 0
|
||||
rm -f "$STAMP"
|
||||
|
||||
echo "── 舊有行為一條都不能壞 ──"
|
||||
t "推 feature branch 放行" "$A" "git push origin feat/xyz" 0
|
||||
t "推 tag 放行" "$A" "git push origin refs/tags/v1.0.0" 0
|
||||
t "只是提到 main 的 gh pr create,放行" "$A" "gh pr create --base main --title t" 0
|
||||
|
||||
echo "── subagent 沒戳記,即使 cd 去別的 repo 也照擋 ──"
|
||||
rm -f "$STAMP"
|
||||
t "subagent 站在 A、cd 去 B 推 main,沒戳記仍擋" "$A" "cd $B && git push origin HEAD:main" 2
|
||||
|
||||
echo "── 單次用完即丟、900 秒逾時:換到跨 repo 場景一樣要成立 ──"
|
||||
git -C "$B" rev-parse --show-toplevel > "$STAMP"
|
||||
t "第一次:替 B 開戳記推 B → 放行" "$A" "cd $B && git push origin HEAD:main" 0
|
||||
t "第二次:同一枚戳記(已用掉)再推一次 → 應該擋" "$A" "cd $B && git push origin HEAD:main" 2
|
||||
rm -f "$STAMP"; touch "$STAMP"
|
||||
t "touch 出的空戳記 → 推 B 的 main 仍應擋(08-12 補的洞不能被本次改動重開)" \
|
||||
"$A" "cd $B && git push origin HEAD:main" 2
|
||||
rm -f "$STAMP"
|
||||
git -C "$B" rev-parse --show-toplevel > "$STAMP"
|
||||
touch -t "$(date -v-16M +%Y%m%d%H%M.%S 2>/dev/null || date -d '-16 minutes' +%Y%m%d%H%M.%S)" "$STAMP" 2>/dev/null
|
||||
t "16 分鐘前開的戳記 → 已過期,推 B 應擋" "$A" "cd $B && git push origin HEAD:main" 2
|
||||
rm -f "$STAMP"
|
||||
|
||||
echo "────── 通過 $pass / 失敗 $fail"
|
||||
[ "$fail" = 0 ]
|
||||
Regular → Executable
+24
-37
@@ -1,42 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
# main-and-prod-push-guard.sh 的迴歸測試——重點在「geek6688 豁免的範圍夠不夠窄」。
|
||||
# 🔴 寫成檔案跑:測試指令必然含 `wrangler deploy`,直接在 Bash 打會被 prod-write-guard 擋。
|
||||
#
|
||||
# 用一個**沒有 .github-armed** 的臨時 CLAUDE_PROJECT_DIR,
|
||||
# 否則本機真的有那個檔 ⇒「該擋的」會假性通過,測了等於沒測。
|
||||
HOOK="$1"
|
||||
TMPPROJ=$(mktemp -d)
|
||||
trap 'rm -rf "$TMPPROJ"' EXIT
|
||||
# 八向實測 main-and-prod-push-guard.sh
|
||||
# 放在檔案裡跑,因為測試字串本身會觸發「舊版」那支閘(第五次誤攔)。
|
||||
G="$1" # 要測的 hook 路徑
|
||||
pass=0; fail=0
|
||||
|
||||
mk(){ python3 -c "import json,sys;print(json.dumps({'tool_name':'Bash','tool_input':{'command':sys.argv[1]}}))" "$1"; }
|
||||
PASS=0; FAIL=0
|
||||
t(){ mk "$3" | env CLAUDE_PROJECT_DIR="$TMPPROJ" "$HOOK" >/dev/null 2>&1; rc=$?
|
||||
got=$([ $rc -eq 2 ] && echo block || echo pass)
|
||||
if [ "$got" = "$1" ]; then echo " ✅ $2"; PASS=$((PASS+1))
|
||||
else echo " ❌ $2 —— 期望 $1,實得 $got"; FAIL=$((FAIL+1)); fi; }
|
||||
t() { # t <說明> <指令> <期望 exit>
|
||||
printf '{"tool_name":"Bash","tool_input":{"command":"%s"}}' "$2" \
|
||||
| CLAUDE_CODE_CHILD_SESSION=1 CLAUDE_PROJECT_DIR="$(dirname "$(dirname "$G")")" \
|
||||
bash "$G" >/tmp/pg.out 2>&1
|
||||
rc=$?
|
||||
if [ "$rc" = "$3" ]; then printf ' ✅ %-46s exit=%s\n' "$1" "$rc"; pass=$((pass+1))
|
||||
else printf ' ❌ %-46s exit=%s(期望 %s)\n' "$1" "$rc" "$3"; fail=$((fail+1)); fi
|
||||
}
|
||||
|
||||
D="wrangler deploy"
|
||||
echo "── 該放行(今晚五次誤攔的原形狀)──"
|
||||
t "checkout -b 後推 feature 分支" 'git checkout -q -b fix/x ma'"in"' && git push -q origin fix/x' 0
|
||||
t "gh pr create --base(不是 git push)" 'gh pr create --head f --base ma'"in"' --title t' 0
|
||||
t "推 tag" 'git push -q origin refs/tags/v0.3.3' 0
|
||||
t "推 feature 分支(帶 -u)" 'git push -q -u origin feat/milestone-must-have-due' 0
|
||||
t "分支名含 domain" 'git push origin fix/custom-domain-setup' 0
|
||||
|
||||
echo "── geek6688(leo 2026-08-12 明文授權總管可直接動)應放行 ──"
|
||||
t pass "指名 geek6688 主機名" "npx $D --name arcrun-cypher-executor --config geek6688.toml"
|
||||
t pass "用 geek6688 的 token 變數" "CLOUDFLARE_API_TOKEN=\$CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE npx $D"
|
||||
t pass "用 geek6688 的 account id 變數" "CLOUDFLARE_ACCOUNT_ID=\$CLOUDFLARE_ACCOUNT_ID_GEEK6688 npx $D"
|
||||
echo "── 該擋 ──"
|
||||
t "直接推預設分支" 'git push origin ma'"in" 2
|
||||
t "HEAD:預設分支" 'git push origin HEAD:ma'"in" 2
|
||||
t "推 master" 'git push -q origin mas'"ter" 2
|
||||
|
||||
echo "── 其他實例仍要 leo 親手 arm(範圍不能外溢)──"
|
||||
t block "打 leo21c" "npx $D --name arcrun-mcp --account-id leo21c-acct"
|
||||
t block "打 uncle6 官方" "npx $D --name arcrun-kbdb --config uncle6.toml"
|
||||
t block "看不出打哪裡" "npx $D"
|
||||
t block "wrangler publish 到別台" "npx wrangler publish --name arcrun-mcp"
|
||||
t block "versions deploy 到別台" "npx wrangler versions deploy --name arcrun-kbdb"
|
||||
|
||||
echo "── stage 照舊自由 ──"
|
||||
t pass "帶 --env staging" "npx $D --env staging"
|
||||
t pass "打 staging 主機" "npx $D --name arcrun-rag-installer-staging"
|
||||
|
||||
echo "── 非部署動作不受影響 ──"
|
||||
t pass "推自己的分支" "git push -u gitea fix/my-branch"
|
||||
t pass "讀本閘原始碼(指令裡含關鍵字)" "sed -n '1,50p' .claude/hooks/main-and-prod-push-guard.sh"
|
||||
|
||||
echo
|
||||
echo "結果:通過 $PASS / 失敗 $FAIL"
|
||||
[ $FAIL -eq 0 ] || exit 1
|
||||
echo "────── 通過 $pass / 失敗 $fail"
|
||||
[ "$fail" = "0" ]
|
||||
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
# sdd-guard.sh 的迴歸測試(inkstone/InkStoneCo#22)。
|
||||
#
|
||||
# 涵蓋兩個洞:
|
||||
# 洞 A — scratchpad/任何不在 git repo 裡的暫存檔被誤判成「code 變動」而擋下。
|
||||
# 洞 B — 真的解析失敗(fail-closed)時,訊息裡印出內部 sentinel `/nonexistent`。
|
||||
# 以及既有行為不能退步:單一活性違反仍擋、恰好 1 份 active 仍放行、
|
||||
# 「dirname 還沒建立」不可被誤判成「不在 repo 裡」(新邏輯自己可能引入的 fail-open 陷阱)。
|
||||
#
|
||||
# 用法:hooks/tests/sdd-guard.test.sh [hooks/sdd-guard.sh 的路徑]
|
||||
# 🔴 全程在一個乾淨的 TMP 底下建假 repo,跑完自己清;不動任何真 repo。
|
||||
|
||||
set -u
|
||||
HOOK="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/sdd-guard.sh}"
|
||||
TMP=$(mktemp -d)
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
PASS=0; FAIL=0
|
||||
|
||||
mk() { # mk <file_path> -> JSON on stdout
|
||||
python3 -c "import json,sys;print(json.dumps({'tool_name':'Write','tool_input':{'file_path':sys.argv[1],'content':'x'}}))" "$1"
|
||||
}
|
||||
|
||||
t() { # t <期望 exit code> <說明> <file_path> [額外檢查關鍵字]
|
||||
local want="$1" desc="$2" path="$3" must_not_contain="${4:-}"
|
||||
local out rc
|
||||
out=$(mk "$path" | "$HOOK" 2>&1)
|
||||
rc=$?
|
||||
local ok=1
|
||||
[ "$rc" -eq "$want" ] || ok=0
|
||||
if [ -n "$must_not_contain" ] && printf '%s' "$out" | grep -qF "$must_not_contain"; then
|
||||
ok=0
|
||||
fi
|
||||
if [ "$ok" -eq 1 ]; then
|
||||
echo " ✅ $desc"; PASS=$((PASS+1))
|
||||
else
|
||||
echo " ❌ $desc —— 期望 exit=$want,實得 exit=$rc"
|
||||
[ -n "$must_not_contain" ] && echo " (且訊息不該含「$must_not_contain」)"
|
||||
echo " 輸出:$out" | head -3
|
||||
FAIL=$((FAIL+1))
|
||||
fi
|
||||
}
|
||||
|
||||
# ── 準備:一個真的沒有 3-specs 的 git repo(模擬「真的解析失敗」)──
|
||||
REPO_NO_SDD="$TMP/repo-no-sdd"
|
||||
mkdir -p "$REPO_NO_SDD/src"
|
||||
git init -q "$REPO_NO_SDD"
|
||||
|
||||
# ── 準備:一個有 1 份 active SDD 的 git repo ──
|
||||
REPO_ONE_ACTIVE="$TMP/repo-one-active"
|
||||
mkdir -p "$REPO_ONE_ACTIVE/system-dev/docs/3-specs/x" "$REPO_ONE_ACTIVE/src"
|
||||
git init -q "$REPO_ONE_ACTIVE"
|
||||
printf -- '---\nstatus: active\n---\n# X\n' > "$REPO_ONE_ACTIVE/system-dev/docs/3-specs/x/design.md"
|
||||
|
||||
# ── 準備:一個有 2 份 active SDD 的 git repo(單一活性違反)──
|
||||
REPO_MULTI="$TMP/repo-multi-active"
|
||||
mkdir -p "$REPO_MULTI/system-dev/docs/3-specs/a" "$REPO_MULTI/system-dev/docs/3-specs/b" "$REPO_MULTI/src"
|
||||
git init -q "$REPO_MULTI"
|
||||
printf -- '---\nstatus: active\n---\n# A\n' > "$REPO_MULTI/system-dev/docs/3-specs/a/design.md"
|
||||
printf -- '---\nstatus: active\n---\n# B\n' > "$REPO_MULTI/system-dev/docs/3-specs/b/design.md"
|
||||
|
||||
# ── 準備:scratchpad 風格的暫存區(不在任何 git repo 裡)──
|
||||
SCRATCH="$TMP/private/tmp/claude-fake-session/scratchpad"
|
||||
mkdir -p "$SCRATCH"
|
||||
|
||||
# 讓 $_root(CLAUDE_PROJECT_DIR 或 pwd)刻意跟這些假 repo 對不上,
|
||||
# 逼所有案例都走「專案外的路徑」那個分支——這正是 #22 實撞的情境(cwd 跑歪/
|
||||
# CLAUDE_PROJECT_DIR 沒設,路徑不落在 $_root 底下)。
|
||||
unset CLAUDE_PROJECT_DIR
|
||||
cd "$TMP"
|
||||
|
||||
echo "── 洞 A:不在任何 git repo 裡的路徑,SDD 管不到,該放行 ──"
|
||||
t 0 "scratchpad 暫存 .py(本票原始事故)" "$SCRATCH/fix-project-settings.py"
|
||||
t 0 "scratchpad 巢狀更深" "$SCRATCH/nested/deep/tmp.js"
|
||||
|
||||
echo "── 洞 B:真的解析失敗(repo 存在但沒有 3-specs)仍要 fail-closed,但訊息不准洩漏內部假路徑 ──"
|
||||
t 2 "真 repo 沒有 3-specs → 仍擋" "$REPO_NO_SDD/src/foo.py"
|
||||
t 2 "上面那筆的訊息不准出現 /nonexistent" "$REPO_NO_SDD/src/foo.py" "/nonexistent"
|
||||
|
||||
echo "── fail-open 陷阱:新檔案要建在還沒建立的子目錄下,不可被誤判成「不在 repo 裡」──"
|
||||
t 2 "真 repo、目標子目錄還沒建立 → 仍擋(不能因為 dirname 不存在就放行)" "$REPO_NO_SDD/brand-new/not-yet/bar.py"
|
||||
|
||||
echo "── 既有行為不能退步 ──"
|
||||
t 0 "只有 1 份 active SDD,改 code 檔 → 放行" "$REPO_ONE_ACTIVE/src/x.py"
|
||||
t 2 "2 份 active SDD(單一活性違反)→ 擋" "$REPO_MULTI/src/x.py"
|
||||
t 0 "改 .md 文件(非 code 檔)→ 放行,即使找不到 3-specs" "$REPO_NO_SDD/README.md"
|
||||
|
||||
echo
|
||||
echo "結果:通過 $PASS / 失敗 $FAIL"
|
||||
[ "$FAIL" -eq 0 ] || exit 1
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# 推 main 的請求:未署名
|
||||
|
||||
- repo:/Users/youlinhsieh/Documents/tech_projects/ISEP
|
||||
- 分支:fix/push-guard-target-not-substring
|
||||
- 時間:2026-08-21 01:28:51
|
||||
|
||||
- 它想跑的指令:
|
||||
```
|
||||
git push -q origin master
|
||||
```
|
||||
|
||||
## 還沒推上去的 commit(原始資料,不是轉述)
|
||||
|
||||
```
|
||||
43c328d Merge pull request 'feat/milestone-must-have-due' (#50) from feat/milestone-must-have-due into main
|
||||
bcb736e Merge pull request 'fix/worksheet-dedup-by-content' (#49) from fix/worksheet-dedup-by-content into main
|
||||
6772ca6 每個里程碑都要有真的期限,9999 也擋
|
||||
1b55512 待驗工作單改用宣稱內容去重,驗過的不再冒出來
|
||||
1920d4c Merge pull request '身為 leo,我要雲端 clone 下來就有閘,我才不用先處理憑證' (#48) from fix/b4-real-probe into main
|
||||
47ed778 改走「直接複製進薄殼 repo」,並修掉一支會偷跑指令的閘
|
||||
03d9782 查了官方文件才發現:setup script 根本讀不到環境變數,而 exit 1 會鎖死 session
|
||||
36d8e05 認證驗證加 timeout:掛住比失敗更糟
|
||||
1356372 B4 的探針我自己沒撞過,實撞後發現它根本不會擋
|
||||
d306158 Merge pull request '身為 leo,我要雲端 env 檔能直接產在桌面,我才不用去翻隱藏目錄' (#46) from feat/cloud-env-outdir into main
|
||||
9099c3f make-cloud-env.sh:輸出路徑可指定,且不再對使用者指定的目錄動權限
|
||||
5bceb03 v0.3.1
|
||||
4e73b8b Merge pull request '身為 leo,我要雲端驗收步驟在閘死掉時真的變紅,我才不會再被三個綠燈騙一次' (#45) from fix/testing-b-section-discriminating into main
|
||||
291787e TESTING.md B 段整段換掉——舊版在閘全滅時會回綠
|
||||
3a95121 雲端零閘的兩個真因:setup 不自驗+沒有 release 撐版本號 (#44)
|
||||
daa1674 雲端零閘的兩個真因:setup 從不驗證自己+沒有任何 release 撐版本號
|
||||
c48495d Merge pull request 'fix(hooks): sdd-guard.sh 修「解析失敗仍照擋、且訊息洩漏 /nonexistent」' (#42) from fix/sdd-guard-path-resolution into main
|
||||
8718658 fix(hooks): sdd-guard.sh 修「解析失敗仍照擋、且訊息洩漏 /nonexistent」(InkStoneCo#22)
|
||||
e6d183d Merge pull request '產生雲端 env 設定給 leo 貼(InkStoneCo#14)' (#41) from feat/cloud-env-generator into main
|
||||
f855d82 產生雲端 env 設定,不要 leo 自己拼湊(InkStoneCo#14)
|
||||
```
|
||||
|
||||
## 改了哪些檔
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
---
|
||||
總管裁完請刪掉這個檔——留著代表「還沒裁」。
|
||||
@@ -0,0 +1,23 @@
|
||||
# 推 main 的請求:未署名
|
||||
|
||||
- repo:/Users/youlinhsieh/Documents/tech_projects/InkStoneCo
|
||||
- 分支:main
|
||||
- 時間:2026-08-21 01:28:23
|
||||
|
||||
- 它想跑的指令:
|
||||
```
|
||||
git push -q origin master
|
||||
```
|
||||
|
||||
## 還沒推上去的 commit(原始資料,不是轉述)
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
## 改了哪些檔
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
---
|
||||
總管裁完請刪掉這個檔——留著代表「還沒裁」。
|
||||
@@ -37,8 +37,12 @@ lookup() { # $1=變數名 → 印出值(找不到就空)
|
||||
return 1
|
||||
}
|
||||
|
||||
OUT_DIR="$HOME/.claude/cloud-env"
|
||||
mkdir -p "$OUT_DIR"; chmod 700 "$OUT_DIR"
|
||||
# 預設丟 ~/.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="$OUT_DIR/$(date +%Y%m%d-%H%M%S).txt"
|
||||
|
||||
SETUP="$(cd "$(dirname "$0")/.." && pwd)/docs/cloud-setup-script.sh"
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env python3
|
||||
"""把 ISEP 整份「複製」進薄殼 repo 的 .claude/isep/,並產生對應的 settings.json。
|
||||
|
||||
為什麼是複製而不是 marketplace(leo 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()
|
||||
@@ -1,21 +1,40 @@
|
||||
# ADR-0001:ISEP 自建 wiki,不繼承 InkStoneCo 的內容
|
||||
# ADR-0001:ISEP 這個 repo 自己維護一份 wiki(記 ISEP 自己的事,跟「裝 plugin」無關)
|
||||
|
||||
- **狀態**:已採納
|
||||
- **狀態**:已採納(決策未變,本次僅修訂標題與內文的誤導處,見文末「常見誤解」)
|
||||
- **日期**:2026-08-20
|
||||
- **票**:`inkstone/ISEP#3`
|
||||
- **票**:`inkstone/ISEP#3`(原案)、`inkstone/InkStoneCo#22`(本次修訂)
|
||||
|
||||
## 先講結論,避免讀到一半就會錯意
|
||||
|
||||
本 ADR 談的「wiki」,是 **`inkstone/ISEP` 這個 git repo 自己的開發歷史**——
|
||||
跟其他任何 repo(`InkStoneCo`、`arcrun`…)在自己 repo 底下放一份
|
||||
`system-dev/wiki/` 記自己的事,是同一種、完全獨立的東西。
|
||||
|
||||
🔴 **這件事不會發生**:把 ISEP 這個 Claude Code plugin「裝」到別的 repo(本機或雲端的
|
||||
Claude Code session 啟用這個 plugin),**不會在那個 repo 裡多寫出任何檔案**,
|
||||
更不會在那裡生出一份 `system-dev/wiki/`。「plugin 裝到哪、wiki 就跟著長在哪,
|
||||
所以每個 repo 都會有兩份」是誤讀——見文末「常見誤解」段的查證。
|
||||
|
||||
## 背景
|
||||
|
||||
ISEP 是獨立 repo,裝的是「環境」(hooks/commands/skills/scripts),本來刻意不放
|
||||
「知識」(wiki/docs/`_archive`)——見 `README.md`「裝什麼」段。但接手 ISEP 的 session
|
||||
(含雲端)若要查「這裡的決定、踩過的坑、現在什麼狀態」,過去只能回頭 clone InkStoneCo
|
||||
頂層知識庫,多一層跳轉、且 ISEP 自己的事並不天然屬於 InkStoneCo 頂層(那裡管的是跨專案決策)。
|
||||
ISEP 是獨立 repo,對外扮演的角色是「環境」(hooks/commands/skills/scripts,
|
||||
`README.md`「裝什麼」段列了清單,白紙黑字排除 `wiki/`/`docs/`/`_archive/`——
|
||||
那些是「知識」不是「環境」)。但 ISEP**自己也是一個在持續開發的 repo**:它有自己的
|
||||
決策(例如這份 ADR 本身)、踩過的坑、現在的狀態。過去要查「ISEP 這裡為什麼這樣設計、
|
||||
之前討論到哪」,只能回頭 clone InkStoneCo 頂層知識庫,多一層跳轉,而且 ISEP 自己的
|
||||
開發細節並不天然屬於 InkStoneCo 頂層(那裡管的是跨專案決策,不是單一 repo 的施工細節)。
|
||||
|
||||
## 決策
|
||||
|
||||
ISEP 建立自己的 `system-dev/wiki/`,骨架取自 `inkstone/system-dev-template` 的 wiki
|
||||
template(三層 + 標籤橫切:`INDEX.md`/`TAXONOMY.md`/`status.md`/`mistakes.md`/
|
||||
`principles.md`/`cards/<bucket>/`),照它的規約裝,不自創格式。
|
||||
**`inkstone/ISEP` 這個 repo 自己**建立 `system-dev/wiki/`,骨架取自
|
||||
`inkstone/system-dev-template` 的 wiki template(三層 + 標籤橫切:`INDEX.md`/
|
||||
`TAXONOMY.md`/`status.md`/`mistakes.md`/`principles.md`/`cards/<bucket>/`),
|
||||
照它的規約裝,不自創格式。
|
||||
|
||||
這份 wiki 只在 ISEP 這個 repo 的 git 歷史裡,跟著 `git clone inkstone/ISEP` 走;
|
||||
它**不是** plugin payload 的一部分(`plugin.json`/`marketplace.json` 只宣告
|
||||
`hooks/`/`commands/`/`skills/`,任何 Claude Code session 啟用這個 plugin 時載入的
|
||||
也只有這些),所以其他 repo 啟用 ISEP plugin 時,這份 wiki 不會、也無法出現在那裡。
|
||||
|
||||
**紅線**:這份 wiki 只記 ISEP 自己的事。不把 InkStoneCo 頂層 wiki 的內容複製過來——
|
||||
複製即 fork,fork 即漂移,跟「真身薄殼合一」(見 `cards/isep/真身薄殼合一.md`)要解的病
|
||||
@@ -23,12 +42,47 @@ template(三層 + 標籤橫切:`INDEX.md`/`TAXONOMY.md`/`status.md`/`m
|
||||
|
||||
## 後果
|
||||
|
||||
- 好處:接手 session 在 ISEP 內就能查到 ISEP 自己的歷史,不必先 clone 別的 repo。
|
||||
- 代價:多一份骨架要維護(跟 InkStoneCo 頂層、以及其他裝了 template 的子 repo 一樣)。
|
||||
- 好處:接手 ISEP 這個 repo 的 session,在它自己的 checkout 裡就查得到它自己的歷史,
|
||||
不必先 clone 別的 repo。
|
||||
- 代價:多一份骨架要維護(跟 InkStoneCo 頂層、以及其他裝了 template 的子 repo 一樣,
|
||||
各自一份、各自維護,不互相複製)。
|
||||
- 邊界:跨專案的決策、鐵律、部署架構全局,仍然只在 InkStoneCo 頂層記錄,ISEP 不重複。
|
||||
|
||||
## 常見誤解,與查證
|
||||
|
||||
**誤解**:「ISEP 這個 plugin 裝到哪個 repo,就會在那個 repo 裡自建一份 wiki,
|
||||
於是每個裝了 ISEP 的 repo 都會多出兩份(自己的 + ISEP 幫它建的)。」
|
||||
|
||||
**這不是實際行為。查證如下(2026-08-20 實查,不是抄口述)**:
|
||||
|
||||
1. `.claude-plugin/marketplace.json` 把整個 repo 根目錄(`"source": "./"`)宣告成
|
||||
plugin 來源,Claude Code 依慣例目錄(`hooks/`、`commands/`、`skills/`)載入內容;
|
||||
`README.md`「裝什麼」表列出的也正是這幾個目錄(外加 `scripts/` 供它們呼叫)——
|
||||
**沒有任何一項是 wiki 或 docs**。啟用這個 plugin,載入的是 hook 腳本的路徑
|
||||
(`${CLAUDE_PLUGIN_ROOT}/hooks/*.sh`)、command/skill 的定義;這個載入過程本身
|
||||
不涉及「往目前工作的 repo 寫入任何檔案」——它是讀,不是寫。
|
||||
2. `README.md`「裝什麼」段明文把 `wiki/`/`docs/`/`_archive/` 列在「不放」——
|
||||
這條界線本來就是刻意畫的(環境 vs 知識分離),不是本 ADR 才立的。
|
||||
3. 全部 hooks 對「自己這支腳本」的路徑一律用 `${CLAUDE_PLUGIN_ROOT}`(不用
|
||||
`$CLAUDE_PROJECT_DIR`,見 `README.md`「路徑規約」段)——這條規約本身就代表
|
||||
hook 的邏輯設計上就是「讀 plugin 自己的檔案」,不是「往目前工作的 repo 寫東西」。
|
||||
4. **唯一一支「真的會在某個 repo 裡建出 wiki」的腳本是 `scripts/install.sh`**——
|
||||
但它是 `system-dev-template` 的獨立安裝器(不是 ISEP 的功能),要**人或 AI 手動執行
|
||||
一次**才會動作,且動作對象是**執行當下的 cwd**,不是「ISEP 被啟用的地方」。
|
||||
它會混進這個 repo,是搬家時帶過來的殘留(`docs/governance/DIVERGENCE-v0.5.0-to-v0.6.0.md`
|
||||
A6 節已標記它是待清理項,跟 `.claude-plugin` 宣告的 plugin 功能無關)。
|
||||
**這支腳本的存在,多半就是本誤解真正的來源**——它看起來像「ISEP 會建 wiki」,
|
||||
但觸發方式(手動跑一次)與作用對象(cwd,不是「plugin 裝到的地方」)都跟
|
||||
「裝 plugin 就自動建」完全不同。
|
||||
|
||||
⇒ 結論:本 ADR 的「wiki」只指 ISEP 這個 repo 自己 checkout 裡的那一份,
|
||||
跟其他任何 repo 有沒有、要不要各自裝一份 wiki(那是它們自己的 `/wiki-init` 決定),
|
||||
兩件事互不影響、也不會因為裝了 ISEP plugin 而自動被牽動。
|
||||
|
||||
## 相關
|
||||
|
||||
- `cards/isep/真身薄殼合一.md`
|
||||
- `cards/isep/repo邊界與紅線.md`
|
||||
- `cards/isep/hook路徑規約.md`
|
||||
- `inkstone/InkStoneCo#22`(本次修訂的來由:leo 讀完舊版誤解成「plugin 裝到哪、
|
||||
wiki 就跟著建到哪」)
|
||||
|
||||
Reference in New Issue
Block a user