Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0024d697f9 |
@@ -16,8 +16,3 @@ __pycache__/
|
||||
# (寫成 `目錄/*` 而不是 `目錄/`:後者連目錄本身都排除,下一行的例外就永遠生效不了)
|
||||
pending-main-push/*
|
||||
!pending-main-push/README.md
|
||||
|
||||
# 閘的動作紀錄(gate-log-wrap.sh 寫的,inkstone/InkStoneCo#48)。
|
||||
# 這是**執行期狀態**不是原始碼:dogfood 這個 repo 時會在自己的 system-dev/ 底下生出來。
|
||||
# 進版控=把「這台機器上發生過的閘動作」帶給每個 clone 的人,語意就錯了。
|
||||
system-dev/gate-log/
|
||||
|
||||
+18
-23
@@ -823,32 +823,27 @@ claude -p '請執行 git tag -a v9.9.9 -m test'
|
||||
> 為什麼挑 `release-tag-guard` 當考題:它**只存在於 ISEP**,舊的 `.claude/` 那份沒有。
|
||||
> 用它才分得出「載到的是 plugin」還是「載到的是舊的」。
|
||||
|
||||
### A18 — 記錄層:包在外面不改閘的行為,三種 verdict 都留得下:22 條
|
||||
```
|
||||
bash hooks/tests/gate-log.test.sh
|
||||
```
|
||||
**該看到**:`通過 22 條,失敗 0 條`。全程離線(帳本走 `ISEP_GATE_LOG` 指到 mktemp)。
|
||||
**它在守什麼**(`inkstone/InkStoneCo#48`):`hooks/lib/gate-log-wrap.sh` 把每一支閘的
|
||||
「擋/放行/被逃生口繞過」各留一筆,讓「規則有沒有在運作」變成查得出來的事實。
|
||||
**失敗**:
|
||||
- A 群任何一條紅 ⇒ **包在外面改變了閘的行為**(離開碼/stdout/stderr/stdin 沒原樣穿過)
|
||||
——這是最高紅線:寧可漏記一筆,不可擋錯一次。
|
||||
- C 群任何一條紅 ⇒ 逃生口沒被記成 `bypass`(票上驗收 #4 的反面驗證失效)。
|
||||
- E 群紅 ⇒ 金鑰真身漏進帳本(D36)。
|
||||
---
|
||||
|
||||
### A19 — 三題查得出來、答得對:8 條
|
||||
### A27 — 未出貨警察:改了 code 沒出貨要擋,只改 wiki/已出貨/先不出都不擋:13 條
|
||||
```
|
||||
bash scripts/test-gate-report.sh
|
||||
bash scripts/test-unreleased-police.sh
|
||||
```
|
||||
**該看到**:`通過 8 條,失敗 0 條`。用寫死的 fixture 帳本驗
|
||||
`scripts/gate-report` 的三題**數字對不對**,不是「有沒有印字」(`mistakes.md` #158:
|
||||
出路要真的走得通)。
|
||||
**該跑一次基線**(拿今天當基線,票上驗收 #3):
|
||||
```
|
||||
python3 scripts/gate-report all # 讀真實帳本,印基線數字+三題
|
||||
python3 scripts/gate-report ledger-path # 帳本在哪
|
||||
```
|
||||
**失敗**:Q1 排序或數字錯/Q2 把最近有擋過的閘誤點名/Q3 把只撞 1 次的算進來。
|
||||
**該看到**:`13/13 通過`。全程在 `mktemp -d` 底下造假 repo 與假 transcript,
|
||||
不碰任何真 repo、不打網路、跑完自己清。
|
||||
|
||||
**它在守什麼**(`inkstone/ISEP#68`,leo 2026-08-27):「每個 repo 只要有改動就要出貨⋯⋯
|
||||
這個 session 有改但要結束沒出貨就抓」。「改過」認的是**這個 session 期間新長出來的 commit**
|
||||
(committer-date 晚於 transcript 第一列的時間戳),「出貨」認的是**有沒有 release tag 收進 HEAD**
|
||||
(`git tag --contains HEAD`)——兩者同一個單位(commit),才數得出「最後 commit 與最新 release 差幾筆」。
|
||||
|
||||
**失敗**:
|
||||
- A 群「該擋」任一放行 ⇒ 假綠:改了 code 卻沒出貨溜過去了
|
||||
- B 群「不該擋」任一被擋 ⇒ **誤攔**(比漏擋嚴重)——特別看「只改 wiki/docs」「已出貨」
|
||||
「有 exempt marker」「release-holds.md 有它」四條,任何一條紅代表閘在懲罰謹慎
|
||||
- C 群紅 ⇒ 訊息教的出路(寫 `.claude/release-holds.md` 一行)**跑不動**,
|
||||
被擋的人只會去找繞過去的方法(`mistakes.md` ISEP#112 的課)
|
||||
- D 群紅 ⇒ 偵測根本不會亮,「全綠」其實是偵測壞了,不是真的乾淨
|
||||
|
||||
---
|
||||
|
||||
|
||||
+9
-25
@@ -1,4 +1,4 @@
|
||||
# 61 支閘,白話盤點表
|
||||
# 62 支閘,白話盤點表
|
||||
|
||||
> 回應 `inkstone/InkStoneCo#40`:「如果加入了,我應該可以白話文看到 hooks 的內容?」
|
||||
> 這份表就是那個「白話文」——不用點開任何 `.sh` 檔,一行看懂一支閘在管什麼。
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
## 一句話結論
|
||||
|
||||
`hooks/` 底下有 **61 個 `.sh` 檔**,`hooks.json` 實際掛上 **84 條註冊**(同一支閘常被多種情境同時掛上);
|
||||
`hooks/` 底下有 **62 個 `.sh` 檔**,`hooks.json` 實際掛上 **85 條註冊**(同一支閘常被多種情境同時掛上);
|
||||
其中 **3 支檔案存在但沒被掛上**(2 支是待人填的空範本、1 支是刻意留著沒開的止血帶,見下面「未生效」表)。
|
||||
下面按「你會在什麼時候撞到它」分組,一支一行。
|
||||
|
||||
> 🔴 **這兩個數字上一版是錯的(2026-08-26 實際數過才發現)**:本頁原本寫「43 個檔、53 條註冊」,
|
||||
> 而當時真實是 **45 個檔、55 條註冊**——中間有兩支閘進來時沒有回頭改這裡。
|
||||
> 現在的寫法是實際數出來的:
|
||||
> `ls hooks/*.sh | wc -l` = 61;`grep -c '"command":' hooks/hooks.json` = 84。
|
||||
> `ls hooks/*.sh | wc -l` = 62;`grep -c '"command":' hooks/hooks.json` = 85。
|
||||
> ⚠️ **冒號不能省**:`grep -c '"command"'`(沒冒號)會連 `"type": "command"` 一起數到,回 **120**。
|
||||
> 本頁 2026-08-27 之前寫的是沒冒號那版——**照著它跑會拿到一個跟本頁不符的數字**。
|
||||
> **一份會偷偷過期的盤點表,跟沒有盤點表差不多**——見本頁最後「怎麼跟實況對帳」那段。
|
||||
@@ -98,6 +98,11 @@
|
||||
> 另外描述欄的「38 支腳本」是把 `kbdb-live-exam/`/`lib/`/`patches/` 三個**目錄**也數進去了;
|
||||
> 用本頁寫死的那道指令(只數檔案)實數是 **39**。
|
||||
|
||||
> 📌 **`inkstone/ISEP#68`(2026-09-03)進來一支**:`unreleased-police.sh`(F 組,Stop)。
|
||||
> 61→**62** 支、84→**85** 條,兩個數字都是**在自己的樹上當場數出來的**(指令同上),
|
||||
> 不是拿上一版加一。它只掛 `Stop` 一個事件(+1 支、+1 條)——刻意不掛 `SubagentStop`:
|
||||
> subagent 交回分支、release 由總管出,在 subagent 收工逼它出貨純屬誤攔。
|
||||
|
||||
---
|
||||
|
||||
## 怎麼讀這張表
|
||||
@@ -226,6 +231,7 @@
|
||||
| `delivery-police.sh` | AI 宣稱「這件事做完了」,卻看不到任何實測證據(畫面截圖、指令輸出、HTTP 狀態碼…)就擋下。 | 🛑 擋 |
|
||||
| `wiki-first-police.sh` | AI 做完事卻沒有把結論寫回 wiki 就想收工,就擋下——下次(或別的 AI)查 wiki 會查不到這次做過什麼。 | 🛑 擋 |
|
||||
| `unpushed-police.sh` | AI 改好的東西還留在本機、沒有真的推送出去給別人用,卻想收工,就擋下——「改對了但沒送到」跟沒改是一樣的。 | 🛑 擋 |
|
||||
| `unreleased-police.sh` | 這個 session 改過的 repo,收工那一刻還沒**出貨**(沒有一個 release tag 收進 HEAD),就擋一次,並點名是哪個 repo、最後 commit 與最新 release 差幾筆。「改過」認的是**這個 session 期間新長出來的 commit**(不是工作區髒、不是 push),跟「出貨」用同一個單位(commit)才數得出差多少。**只在收工問一次,不是每次 commit 都吼**(leo 明說可以累積)。三種不擋:①只改了 wiki/docs(知識就地被讀,不需出版本)②repo 根目錄放了 `.isep-release-exempt`(產物/模板 repo 自己帶理由排除,不是中央手列清單)③在 `.claude/release-holds.md` 寫一行「這次先不出,因為 X」(放行且留痕,出貨後刪掉那行)。只掛 `Stop` 不掛 `SubagentStop`——subagent 交回分支、release 由總管出,在 subagent 收工逼它出貨純屬誤攔。 | 🛑 擋(至多攔一次) |
|
||||
|
||||
> 🔴 **`claim-verify-police.sh` 已於 `inkstone/ISEP#60` 移除**(連同下面原本的 G 組 `subagent-claim-worksheet.sh`)。
|
||||
> 這一對是自造的「待驗單」機制(一張沒有狀態、沒有持有人的 markdown),違反 D58:
|
||||
@@ -256,28 +262,6 @@
|
||||
|
||||
---
|
||||
|
||||
## 記錄層:每一支閘現在都會留下「這一次判成什麼」(`inkstone/InkStoneCo#48`)
|
||||
|
||||
在此之前,36 支閘裡只有 2 支會記錄自己擋了什麼,六種逃生口
|
||||
(`NOT_MY_BRANCH_OK=1`/`no-ticket-needed`/`wiki-secret-ok`/`credential-ok`/
|
||||
`solo-ok`/`kbdb-down`)用了**完全不留痕** ⇒ 一條閘擋對 100 次跟擋錯 100 次,
|
||||
在資料上長得一模一樣 ⇒ 規則只會累積、不會被淘汰。
|
||||
|
||||
現在 `hooks/lib/gate-log-wrap.sh` **包在每一支閘外面**(`hooks.json` 裡每一條
|
||||
gate 的 command 都從 `…/hooks/<gate>.sh` 變成
|
||||
`…/hooks/lib/gate-log-wrap.sh …/hooks/<gate>.sh`),把每一次閘動作留一筆:
|
||||
**哪支閘、什麼時候、對什麼工具、判成什麼(擋/放行/被逃生口繞過)、(若繞過)用了哪個逃生口**。
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 它是閘嗎 | **不是**。它從不 `exit 2`,只把真正那支閘的離開碼原樣傳出去 ⇒ 記錄壞掉最多漏記一筆,不可能誤攔。**所以它不算進 61/84 那兩個數字**(它住在 `hooks/lib/`,不是 `hooks/*.sh`;也沒有新增 `hooks.json` 註冊,只是把既有 command 包起來)。 |
|
||||
| 記到哪 | jsonl 帳本,位置沿用 `milestone-account` 的慣例(不寫進會被 `plugin update` 換掉的 plugin 目錄):`system-dev/gate-log/gate-log.jsonl`。查它:`python3 scripts/gate-report ledger-path`。 |
|
||||
| 怎麼看 | `python3 scripts/gate-report all` —— 基線數字 + 三題:①哪支閘擋最多、其中多少被繞過(誤擋嫌疑)②哪條規則最近 N 天一次都沒擋過(可能沒用了)③同一 session 反覆撞同一支閘幾次(規則沒被理解或閘寫錯)。 |
|
||||
| 金鑰安全 | **只記中繼資料,完全不寫入指令原文/payload** ⇒ 金鑰在結構上就進不了帳本(D36)。 |
|
||||
| 測試 | `hooks/tests/gate-log.test.sh`(22 條)+ `scripts/test-gate-report.sh`(8 條)。 |
|
||||
|
||||
---
|
||||
|
||||
## 目前沒生效的 3 支(存在但沒掛進 `hooks.json`)
|
||||
|
||||
| 檔名 | 為什麼沒掛 |
|
||||
|
||||
+90
-82
@@ -7,71 +7,71 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/github-contact-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/github-contact-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/stage-before-prod-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/stage-before-prod-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/main-and-prod-push-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/main-and-prod-push-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/prod-write-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/prod-write-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/not-my-branch-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/not-my-branch-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/leo21c-write-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/leo21c-write-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/release-tag-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/release-tag-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/ticket-api-bypass-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/ticket-api-bypass-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/comment-carries-task-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/comment-carries-task-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/milestone-due-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/milestone-due-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/milestone-account-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/milestone-account-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/reply-identity-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/reply-identity-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/diagnosis-evidence-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/diagnosis-evidence-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/line-needs-own-worktree.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/line-needs-own-worktree.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -80,7 +80,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/prod-write-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/prod-write-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -89,43 +89,43 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/guard-cross-project.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/guard-cross-project.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-secret-scan.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-secret-scan.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/component-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/component-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/credential-only-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/credential-only-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/arcrun-intent-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/arcrun-intent-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/subagent-first-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/subagent-first-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/mistake-needs-ticket-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/mistake-needs-ticket-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/pending-changes-retired.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/pending-changes-retired.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -134,7 +134,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-search.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-search.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -143,43 +143,43 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/subagent-wiki-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/subagent-wiki-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/micromanage-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/micromanage-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/irreversible-dispatch-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/irreversible-dispatch-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/no-ticket-no-dispatch.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/no-ticket-no-dispatch.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/roster-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/roster-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/mainline-focus-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/mainline-focus-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/parallel-lines-cap-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/parallel-lines-cap-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -188,7 +188,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/arcrun-intent-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/arcrun-intent-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -197,7 +197,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/history-first-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/history-first-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -206,35 +206,35 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/micromanage-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/micromanage-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/irreversible-dispatch-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/irreversible-dispatch-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/no-ticket-no-dispatch.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/no-ticket-no-dispatch.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/roster-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/roster-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/mainline-focus-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/mainline-focus-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/parallel-lines-cap-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/parallel-lines-cap-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -243,7 +243,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -252,7 +252,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/ask-user-question-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/ask-user-question-guard.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -263,15 +263,15 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/session-start-recall.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/session-start-recall.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/skill-deploy-drift-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/skill-deploy-drift-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/isep-presence-beacon.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/isep-presence-beacon.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
@@ -283,11 +283,11 @@
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/overdue-nag-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/overdue-nag-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -297,7 +297,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh \"${CLAUDE_PLUGIN_ROOT}\"/hooks/empty-handed-stop-guard.sh"
|
||||
"command": "\"${CLAUDE_PLUGIN_ROOT}\"/hooks/empty-handed-stop-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -305,19 +305,19 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/worklist-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/worklist-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/factory-idle-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/factory-idle-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/mainline-idle-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/mainline-idle-guard.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/pr-verdict-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/pr-verdict-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -325,7 +325,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/browser-verify-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/browser-verify-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -333,19 +333,19 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-police.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-police.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-judge.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-judge.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/delivery-police.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/delivery-police.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-police.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-police.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -353,7 +353,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/unpushed-police.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/unpushed-police.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -361,7 +361,15 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/countdown-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/countdown-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/unreleased-police.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -371,7 +379,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/worklist-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/worklist-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -379,19 +387,19 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-police.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-police.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-judge.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-judge.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/delivery-police.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/delivery-police.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-police.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-police.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -399,7 +407,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/unpushed-police.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/unpushed-police.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -410,7 +418,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-asked-stamp.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-asked-stamp.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -419,7 +427,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-evidence-stamp.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-evidence-stamp.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -428,19 +436,19 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/subagent-first-stamp.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/subagent-first-stamp.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/investigate-first-stamp.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/investigate-first-stamp.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/issue-status-autoflip.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/issue-status-autoflip.sh"
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/baton-handback-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/baton-handback-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -449,7 +457,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/investigate-first-stamp.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/investigate-first-stamp.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -459,7 +467,7 @@
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/countdown-guard.sh"
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/countdown-guard.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
#!/bin/sh
|
||||
# gate-log-wrap.sh — 透明記錄層:包在每一支閘外面,把「這支閘這一次判成什麼」留一筆。
|
||||
# (inkstone/InkStoneCo#48:36 支閘對著虛空開火,沒有任何資料
|
||||
# 說得出任一支擋對幾次、擋錯幾次、被逃生口繞過幾次。)
|
||||
#
|
||||
# ── 它解什麼 ────────────────────────────────────────────────────────────────
|
||||
# 在此之前只有 2 支閘會記錄自己擋了什麼,六種逃生口(NOT_MY_BRANCH_OK=1/
|
||||
# no-ticket-needed/wiki-secret-ok/credential-ok/solo-ok/kbdb-down)用了**完全不留痕**。
|
||||
# ⇒ 一條閘擋對 100 次跟擋錯 100 次,在資料上長得一模一樣 ⇒ 規則只會累積不會被淘汰。
|
||||
# 這一層讓「規則有沒有在運作」變成查得出來的事實:每一次閘動作(擋/放行/繞過)留一筆。
|
||||
#
|
||||
# ── 為什麼是「包在外面」而不是改 61 支閘的內部 ──────────────────────────────
|
||||
# ① 一份機制,一處測——不是散進 61 個檔各留一手(那正是「疊床架屋」)。
|
||||
# ② 閘的離開碼是唯一權威:包在外面就能對每一支統一抓到「擋(2)/放行(0)」,
|
||||
# 完全不必動任何一支閘的邏輯。
|
||||
# hooks.json 把每一支閘的 command 從
|
||||
# ${CLAUDE_PLUGIN_ROOT}/hooks/<gate>.sh
|
||||
# 改成
|
||||
# ${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/<gate>.sh
|
||||
# 閘路徑當第一個參數傳進來;`bash "$GATE"` 是子行程,所以閘內部的 $0/BASH_SOURCE[0]
|
||||
# 仍是閘自己的路徑,`source .../lib/...` 那套定位照常成立。
|
||||
#
|
||||
# ── 紅線(InkStoneCo#48,逐條落在這支上)────────────────────────────────────
|
||||
# 🔴 寧可漏記一筆,不可擋錯一次:這支**永遠只把真正那支閘的離開碼原樣傳出去**,
|
||||
# 它自己的邏輯裡沒有任何一條 `exit 2`。記錄整段包在一個永遠成功的子殼裡
|
||||
# (`( … ) 2>/dev/null || true`),記錄壞掉最多漏記一筆,不可能造成誤攔。
|
||||
# 🔴 不得讓閘變慢或變脆:記錄全程純 POSIX shell,不另外起 python;閘本來就要跑,
|
||||
# 這裡只多一次輕量 shell fork。
|
||||
# 🔴 D36 金鑰不落地:**只記中繼資料(閘名/事件/工具名/判成什麼/session/逃生口代號)**,
|
||||
# **完全不寫入 payload 或指令原文** ⇒ 金鑰在結構上就進不了紀錄,不必事後遮罩。
|
||||
# 🔴 零輪詢(D20):紀錄長在既有的閘動作上,不新增任何排程/cron/輪詢/事件 fan-out。
|
||||
# 🔴 不新增第二套落地方式:沿用 milestone-account 的 jsonl 帳本慣例
|
||||
# (不寫進會被 `plugin update` 整個換掉的 plugin 目錄;env 可覆寫路徑供測試)。
|
||||
#
|
||||
# 記錄檔位置(沿用 scripts/milestone-account 的 _resolve_dir 順序):
|
||||
# ISEP_GATE_LOG(env,測試/停用用) → $CLAUDE_PROJECT_DIR/system-dev/gate-log/ →
|
||||
# plugin 根的 system-dev/gate-log/ → ~/.claude/isep-gate-log/
|
||||
# 檔名 gate-log.jsonl。用 `scripts/gate-report` 讀它回答三題。
|
||||
|
||||
GATE="$1"
|
||||
[ -n "$GATE" ] || exit 0 # 沒給閘路徑:什麼都不做,放行(絕不擋、絕不報錯)
|
||||
shift 2>/dev/null || true
|
||||
|
||||
# 讀一次 stdin(閘要吃的 payload)
|
||||
INPUT=$(cat 2>/dev/null || true)
|
||||
|
||||
# ── 先跑真正那支閘 ──────────────────────────────────────────────────────────
|
||||
# stdin 原樣餵進去;stdout/stderr 原樣流出去(閘的紅字說明、注入的 context 都不動)。
|
||||
# pipeline 最後一段是閘 ⇒ $? 就是閘的離開碼。
|
||||
printf '%s' "$INPUT" | "$GATE" "$@"
|
||||
rc=$?
|
||||
|
||||
# ── 記錄:全程 best-effort,包在永遠成功的子殼裡,絕不影響 rc、絕不外洩任何字 ──
|
||||
(
|
||||
GATE_NAME=${GATE##*/}; GATE_NAME=${GATE_NAME%.sh}
|
||||
|
||||
# 只從 payload 抽固定幾個「天生安全」的欄位;全部再過一層白名單字元清洗,
|
||||
# 保證組出來的 JSON 一定合法、且不可能夾帶金鑰或引號破壞結構。
|
||||
_field() { # _field <json-key> —— 印出第一個同名字串欄位的值(清洗後)
|
||||
printf '%s' "$INPUT" \
|
||||
| sed -n "s/.*\"$1\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" \
|
||||
| head -n1 \
|
||||
| tr -cd 'A-Za-z0-9_.:@/#+-' \
|
||||
| cut -c1-100
|
||||
}
|
||||
EVENT=$(_field hook_event_name)
|
||||
TOOL=$(_field tool_name)
|
||||
SID=$(_field session_id)
|
||||
|
||||
# 判成什麼
|
||||
if [ "$rc" = "2" ]; then VERDICT=block
|
||||
elif [ "$rc" = "0" ]; then VERDICT=pass
|
||||
else VERDICT=error; fi
|
||||
|
||||
# 逃生口偵測(owner-scoped:只有**擁有**那個逃生口的閘才檢查它自己那一個,
|
||||
# 避免「指令裡剛好出現 credential-ok」被誤記到別支閘頭上)。
|
||||
BYPASS=
|
||||
case "$GATE_NAME" in
|
||||
not-my-branch-guard) [ "${NOT_MY_BRANCH_OK:-}" = "1" ] && BYPASS=NOT_MY_BRANCH_OK ;;
|
||||
subagent-first-guard) [ -n "$SID" ] && [ -f "/tmp/.solo-ok-$SID" ] && BYPASS=solo-ok ;;
|
||||
history-first-guard) [ -f "${KBDB_STAMP_DIR:-/tmp}/.kbdb-down" ] && BYPASS=kbdb-down ;;
|
||||
credential-only-guard) case "$INPUT" in *credential-ok*) BYPASS=credential-ok ;; esac ;;
|
||||
wiki-secret-scan) case "$INPUT" in *wiki-secret-ok*) BYPASS=wiki-secret-ok ;; esac ;;
|
||||
mistake-needs-ticket-guard) case "$INPUT" in *no-ticket-needed*) BYPASS=no-ticket-needed ;; esac ;;
|
||||
esac
|
||||
# 逃生口只有在「閘放行了」時才算真的被繞過;閘照樣擋下 ⇒ 逃生口沒生效,維持 block。
|
||||
if [ -n "$BYPASS" ] && [ "$VERDICT" = "pass" ]; then VERDICT=bypass; fi
|
||||
|
||||
# 是不是子 session(給「同一支 agent 反覆撞同一支閘」那一題用)
|
||||
if [ "${CLAUDE_CODE_CHILD_SESSION:-}" = "1" ]; then CHILD=1; else CHILD=0; fi
|
||||
|
||||
# 記錄檔位置(沿用 milestone-account 慣例;不寫進 plugin 目錄)
|
||||
LEDGER=${ISEP_GATE_LOG:-}
|
||||
if [ -z "$LEDGER" ]; then
|
||||
_root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." 2>/dev/null && pwd) || _root=
|
||||
_dir=
|
||||
for _b in "${CLAUDE_PROJECT_DIR:-}" "$_root"; do
|
||||
[ -n "$_b" ] && [ -d "$_b/system-dev" ] && { _dir="$_b/system-dev/gate-log"; break; }
|
||||
done
|
||||
[ -n "$_dir" ] || _dir="$HOME/.claude/isep-gate-log"
|
||||
LEDGER="$_dir/gate-log.jsonl"
|
||||
fi
|
||||
[ "$LEDGER" = /dev/null ] && exit 0 # 明示停用
|
||||
|
||||
TS=$(date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || printf '')
|
||||
GATE_NAME=$(printf '%s' "$GATE_NAME" | tr -cd 'A-Za-z0-9_.-' | cut -c1-80)
|
||||
|
||||
LINE=$(printf '{"ts":"%s","gate":"%s","event":"%s","tool":"%s","verdict":"%s","bypass":"%s","sid":"%s","child":%s}' \
|
||||
"$TS" "$GATE_NAME" "$EVENT" "$TOOL" "$VERDICT" "$BYPASS" "$SID" "$CHILD")
|
||||
|
||||
mkdir -p -- "$(dirname -- "$LEDGER")" 2>/dev/null || true
|
||||
# 單一 printf 的短行 append(<4KB)在 O_APPEND 下是原子的 ⇒ 併發的多支閘不會互相截斷。
|
||||
printf '%s\n' "$LINE" >> "$LEDGER" 2>/dev/null || true
|
||||
) >/dev/null 2>&1 || true
|
||||
|
||||
exit $rc
|
||||
@@ -1,144 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# gate-log-wrap.sh 的迴歸測試(inkstone/InkStoneCo#48)
|
||||
#
|
||||
# A 群「透明」——包在外面絕不改變閘的行為:離開碼、stdout、stderr、stdin 全部原樣穿過。
|
||||
# 🔴 這是最高紅線:寧可漏記一筆,不可擋錯一次。
|
||||
# B 群「留痕」——擋(2)/放行(0)/被逃生口繞過,各留一筆,欄位答得出票上要的五件事。
|
||||
# C 群「反面驗證」——故意用一次逃生口,那一筆一定要以 verdict=bypass 出現(票上驗收 #4)。
|
||||
# D 群「不變脆」——記錄失敗(帳本目錄不可寫)絕不影響閘的離開碼。
|
||||
# E 群「不外洩」——payload 帶金鑰時,帳本裡不得出現金鑰真身(D36)。
|
||||
#
|
||||
# 全程離線:帳本走 ISEP_GATE_LOG 指到 mktemp 的檔,不打網路、不碰真實帳本。
|
||||
set -u
|
||||
WRAP="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" && pwd)/gate-log-wrap.sh}"
|
||||
TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT
|
||||
LED="$TMP/gate-log.jsonl"; : > "$LED"
|
||||
PASS=0; FAIL=0; N=0
|
||||
|
||||
ok() { N=$((N+1)); printf ' ✅ %s\n' "$1"; PASS=$((PASS+1)); }
|
||||
bad() { N=$((N+1)); printf ' ❌ %s\n' "$1"; FAIL=$((FAIL+1)); shift; for l in "$@"; do printf ' %s\n' "$l"; done; }
|
||||
|
||||
# ── 造幾支假閘:行為可控,用來驗「包在外面有沒有原樣穿過」──────────────────
|
||||
mkgate() { # mkgate <name> <exit> <stdout> <stderr>
|
||||
local f="$TMP/$1.sh"
|
||||
{
|
||||
echo '#!/bin/sh'
|
||||
echo 'IN=$(cat)' # 讀 stdin
|
||||
printf 'printf "%%s" "%s"\n' "$3" # 印到 stdout
|
||||
printf 'printf "%%s" "%s" >&2\n' "$4" # 印到 stderr
|
||||
printf 'printf "STDIN=[%%s]" "$IN" >&2\n' # 把收到的 stdin 回吐到 stderr 供比對
|
||||
printf 'exit %s\n' "$2"
|
||||
} > "$f"
|
||||
chmod +x "$f"; printf '%s' "$f"
|
||||
}
|
||||
|
||||
run() { # run <gate-file> <payload> ; 設定 OUT/ERR/RC/last log line
|
||||
local gate="$1" payload="$2"
|
||||
ERRF="$TMP/err"; OUTF="$TMP/out"
|
||||
printf '%s' "$payload" | ISEP_GATE_LOG="$LED" "$WRAP" "$gate" >"$OUTF" 2>"$ERRF"
|
||||
RC=$?; OUT=$(cat "$OUTF"); ERR=$(cat "$ERRF")
|
||||
LOGLINE=$(tail -n1 "$LED" 2>/dev/null)
|
||||
}
|
||||
|
||||
jget() { printf '%s' "$1" | python3 -c "import json,sys;print(json.load(sys.stdin).get('$2',''))" 2>/dev/null; }
|
||||
|
||||
echo "── A 群:透明——閘的行為原樣穿過(寧可漏記,不可擋錯)───────"
|
||||
|
||||
G=$(mkgate blockgate 2 "" "擋你了")
|
||||
run "$G" '{"hook_event_name":"PreToolUse","tool_name":"Bash","session_id":"s1"}'
|
||||
[ "$RC" = 2 ] && ok "① 閘 exit 2 → 包完仍 exit 2(不會把擋變成放行,也不會把放行變成擋)" \
|
||||
|| bad "① 期望 rc=2 得 $RC"
|
||||
|
||||
G=$(mkgate passgate 0 "" "")
|
||||
run "$G" '{"hook_event_name":"PreToolUse","tool_name":"Bash","session_id":"s1"}'
|
||||
[ "$RC" = 0 ] && ok "② 閘 exit 0 → 包完仍 exit 0" || bad "② 期望 rc=0 得 $RC"
|
||||
|
||||
G=$(mkgate outgate 0 "注入的context" "")
|
||||
run "$G" '{"hook_event_name":"UserPromptSubmit","session_id":"s1"}'
|
||||
[ "$OUT" = "注入的context" ] && ok "③ 閘的 stdout 原樣穿過(SessionStart/UserPromptSubmit 靠它注入)" \
|
||||
|| bad "③ stdout 沒穿過" "得:[$OUT]"
|
||||
|
||||
G=$(mkgate errgate 2 "" "紅字說明")
|
||||
run "$G" '{"hook_event_name":"PreToolUse","tool_name":"Bash","session_id":"s1"}'
|
||||
case "$ERR" in *"紅字說明"*) ok "④ 閘的 stderr 原樣穿過(被擋的人看得到為什麼)" ;; *) bad "④ stderr 沒穿過" "得:[$ERR]" ;; esac
|
||||
|
||||
G=$(mkgate echogate 0 "" "")
|
||||
run "$G" '{"tool_name":"Bash","session_id":"s1","tool_input":{"command":"樣本指令XYZ"}}'
|
||||
case "$ERR" in *"樣本指令XYZ"*) ok "⑤ stdin 原樣餵給閘(閘拿到的 payload 一字不差)" ;; *) bad "⑤ stdin 沒穿過" "得:[$ERR]" ;; esac
|
||||
|
||||
# 沒給閘路徑:不擋、不報錯
|
||||
printf '%s' '{}' | ISEP_GATE_LOG="$LED" "$WRAP" >/dev/null 2>&1
|
||||
[ $? = 0 ] && ok "⑥ 沒給閘路徑 → exit 0(自己絕不擋、絕不報錯)" || bad "⑥ 空參數應 exit 0"
|
||||
|
||||
echo "── B 群:留痕——三種 verdict 各留一筆,欄位齊全 ──────────────"
|
||||
|
||||
G=$(mkgate github-contact-guard 2 "" "x")
|
||||
run "$G" '{"hook_event_name":"PreToolUse","tool_name":"Bash","session_id":"sess-AAA"}'
|
||||
[ "$(jget "$LOGLINE" verdict)" = block ] && ok "⑦ 擋下 → verdict=block" || bad "⑦ verdict 不是 block" "$LOGLINE"
|
||||
[ "$(jget "$LOGLINE" gate)" = github-contact-guard ] && ok "⑧ 記得下是哪支閘" || bad "⑧ gate 欄錯" "$LOGLINE"
|
||||
[ "$(jget "$LOGLINE" tool)" = Bash ] && ok "⑨ 記得下對什麼工具動作" || bad "⑨ tool 欄錯" "$LOGLINE"
|
||||
[ "$(jget "$LOGLINE" sid)" = sess-AAA ] && ok "⑩ 記得下哪個 session(Q3 要用)" || bad "⑩ sid 欄錯" "$LOGLINE"
|
||||
[ -n "$(jget "$LOGLINE" ts)" ] && ok "⑪ 記得下什麼時候" || bad "⑪ ts 欄空" "$LOGLINE"
|
||||
|
||||
G=$(mkgate someguard 0 "" "")
|
||||
run "$G" '{"tool_name":"Edit","session_id":"s2"}'
|
||||
[ "$(jget "$LOGLINE" verdict)" = pass ] && ok "⑫ 放行 → verdict=pass(活著但沒擋,Q2 靠它)" || bad "⑫ 放行沒記成 pass" "$LOGLINE"
|
||||
|
||||
echo "── C 群:反面驗證——故意用逃生口,一定要記成 bypass(驗收#4)─"
|
||||
|
||||
# credential-only-guard 的逃生口 = 內容裡有 credential-ok,且閘放行(0)
|
||||
G=$(mkgate credential-only-guard 0 "" "")
|
||||
run "$G" '{"tool_name":"Write","session_id":"s3","tool_input":{"new_string":"token=x # credential-ok"}}'
|
||||
[ "$(jget "$LOGLINE" verdict)" = bypass ] && ok "⑬ credential-ok 放行 → verdict=bypass" || bad "⑬ 逃生口沒記成 bypass" "$LOGLINE"
|
||||
[ "$(jget "$LOGLINE" bypass)" = credential-ok ] && ok "⑭ 記得下用了哪個逃生口(理由)" || bad "⑭ bypass 理由欄錯" "$LOGLINE"
|
||||
|
||||
# NOT_MY_BRANCH_OK=1 env(owner = not-my-branch-guard),閘放行
|
||||
G=$(mkgate not-my-branch-guard 0 "" "")
|
||||
printf '%s' '{"tool_name":"Bash","session_id":"s3"}' | NOT_MY_BRANCH_OK=1 ISEP_GATE_LOG="$LED" "$WRAP" "$G" >/dev/null 2>&1
|
||||
L=$(tail -n1 "$LED")
|
||||
[ "$(jget "$L" bypass)" = NOT_MY_BRANCH_OK ] && ok "⑮ 環境變數逃生口 NOT_MY_BRANCH_OK 也記得下" || bad "⑮ env 逃生口沒記" "$L"
|
||||
|
||||
# solo-ok = 檔案 /tmp/.solo-ok-<sid>(owner = subagent-first-guard)
|
||||
SID="solo-test-$$"; touch "/tmp/.solo-ok-$SID"
|
||||
G=$(mkgate subagent-first-guard 0 "" "")
|
||||
run "$G" "{\"tool_name\":\"Agent\",\"session_id\":\"$SID\"}"
|
||||
[ "$(jget "$LOGLINE" bypass)" = solo-ok ] && ok "⑯ 檔案式逃生口 solo-ok 也記得下" || bad "⑯ solo-ok 沒記" "$LOGLINE"
|
||||
rm -f "/tmp/.solo-ok-$SID"
|
||||
|
||||
# 逃生口只有在「放行」時才算 bypass:同一個 token 但閘照樣擋(2) → 維持 block
|
||||
G=$(mkgate credential-only-guard 2 "" "x")
|
||||
run "$G" '{"tool_name":"Write","session_id":"s3","tool_input":{"new_string":"# credential-ok"}}'
|
||||
[ "$(jget "$LOGLINE" verdict)" = block ] && ok "⑰ token 在場但閘照樣擋 → 維持 block(逃生口沒生效不算繞過)" || bad "⑰ 錯記成 bypass" "$LOGLINE"
|
||||
|
||||
# owner-scoped:別支閘的指令裡剛好有 credential-ok,不該被記成它繞過
|
||||
G=$(mkgate github-contact-guard 0 "" "")
|
||||
run "$G" '{"tool_name":"Bash","session_id":"s3","tool_input":{"command":"echo credential-ok"}}'
|
||||
[ "$(jget "$LOGLINE" verdict)" = pass ] && ok "⑱ 非擁有者的閘看到別人的 token 字樣 → 仍是 pass(不誤記)" || bad "⑱ 誤記成 bypass" "$LOGLINE"
|
||||
|
||||
echo "── D 群:不變脆——記錄失敗不影響閘的離開碼 ──────────────────"
|
||||
|
||||
G=$(mkgate blockgate2 2 "" "x")
|
||||
printf '%s' '{"tool_name":"Bash","session_id":"s4"}' \
|
||||
| ISEP_GATE_LOG="/this/dir/does/not/exist/nope.jsonl" "$WRAP" "$G" >/dev/null 2>&1
|
||||
[ $? = 2 ] && ok "⑲ 帳本目錄不可寫 → 閘照樣 exit 2(記錄壞掉不擋錯)" || bad "⑲ 記錄失敗改變了 rc"
|
||||
|
||||
G=$(mkgate passgate2 0 "" "")
|
||||
printf '%s' '{"tool_name":"Bash","session_id":"s4"}' \
|
||||
| ISEP_GATE_LOG="/dev/null" "$WRAP" "$G" >/dev/null 2>&1
|
||||
[ $? = 0 ] && ok "⑳ 明示停用(/dev/null)→ 閘照樣放行、不留痕" || bad "⑳ /dev/null 改變了 rc"
|
||||
|
||||
echo "── E 群:不外洩——payload 帶金鑰,帳本裡不得出現金鑰真身(D36)─"
|
||||
|
||||
SECRET="ghp_ABCDEF1234567890abcdef1234567890XYZ"
|
||||
G=$(mkgate github-contact-guard 2 "" "x")
|
||||
run "$G" "{\"tool_name\":\"Bash\",\"session_id\":\"s5\",\"tool_input\":{\"command\":\"curl -H 'Authorization: Bearer $SECRET' x\"}}"
|
||||
if grep -qF "$SECRET" "$LED"; then bad "㉑ 金鑰真身出現在帳本裡(D36 破口)" "$LOGLINE"; else ok "㉑ 帳本只有中繼資料,金鑰真身進不去(D36)"; fi
|
||||
|
||||
# 每一行都是合法 JSON
|
||||
BADJSON=0
|
||||
while IFS= read -r l; do [ -z "$l" ] && continue; printf '%s' "$l" | python3 -c 'import json,sys;json.load(sys.stdin)' 2>/dev/null || BADJSON=$((BADJSON+1)); done < "$LED"
|
||||
[ "$BADJSON" = 0 ] && ok "㉒ 帳本每一行都是合法 JSON" || bad "㉒ 有 $BADJSON 行不是合法 JSON"
|
||||
|
||||
echo ""
|
||||
echo "通過 $PASS 條,失敗 $FAIL 條(共 $N)"
|
||||
[ "$FAIL" = 0 ]
|
||||
Executable
+241
@@ -0,0 +1,241 @@
|
||||
#!/usr/bin/env bash
|
||||
# unreleased-police.sh — 未出貨警察(Stop hook) inkstone/ISEP#68
|
||||
#
|
||||
# 🔴 本機 LC_ALL 未固定時,把變數(repo 名/數字)串進含全形標點的字串會吃掉字元
|
||||
# (unpushed-police.sh 檔頭第 4 行記過同一課)。固定 locale,別讓報告被環境吃掉。
|
||||
export LC_ALL=C
|
||||
#
|
||||
# ── leo 2026-08-27 的規格(原話就是判準,inkstone/ISEP#68)────────────────
|
||||
# 「每個 repo 只要有改動就要出貨」
|
||||
# 「這個警察很簡單,這個 session 有改但要結束沒出貨就抓,
|
||||
# 你可以久一點再出貨累積幾個 PR,但最後一定要出貨」
|
||||
# 「版本出去之前都只是內部測試」
|
||||
#
|
||||
# 掛點 Stop(session 要結束的那一刻)—— 不是每次 commit,只在收工問一次
|
||||
# 條件 這個 session 改過的 repo
|
||||
# 檢查 有沒有出貨(新的 release)
|
||||
# 寬容 可以累積幾個 PR 再一起出(「先不出」要留痕)
|
||||
# 底線 session 結束前一定要出
|
||||
#
|
||||
# ── 為什麼是 Stop、不是 SubagentStop(誤攔第一防線)────────────────────
|
||||
# leo 規則三點七:subagent 交 deliverable(分支上的 commit),**總管**把它們
|
||||
# 收斂成一個 release。subagent 交回分支、天生不出 release ⇒ 在 SubagentStop
|
||||
# 要它出貨=逼它做一件它不該做的事=純誤攔。所以本閘只掛 Stop。
|
||||
#
|
||||
# ── 四個判準,每一個都寫得出理由(票要求我自己判,不照抄總管)──────────
|
||||
#
|
||||
# ① 「改過」= 這個 session 期間 HEAD 前進了新的 commit(不是「工作區髒」、不是「push」)。
|
||||
# · 出貨(release/tag)的單位是 commit;leo 的「累積幾個 PR」也是累積 commit。
|
||||
# 「改過」要和「出貨」用同一個單位對齊,才數得出「差多少」。
|
||||
# · 「工作區髒」還沒落地,且已被 unpushed-police 管——用它會重疊、又會逼暫存檔出貨(誤攔)。
|
||||
# · 「push」是 D20 開閘的動作、又是 release 的上游,用它當「改過」太晚。
|
||||
# session 起點 = transcript 第一列的時間戳(同 countdown.py 的基準:一段對話=一個 release)。
|
||||
#
|
||||
# ② 「該不該出貨」= 這個 session 的 commit 有沒有動到**知識以外**的檔案。
|
||||
# principles.md:環境(hooks/commands/skills/scripts/plugin)要升版才到得了人手上;
|
||||
# 知識(wiki/docs/_archive)改了就地被讀到,不需要出版本。
|
||||
# ⇒ 只改 wiki/docs 的 commit **不算要出貨的改動**(票驗收 4「只改了 wiki 不該擋」)。
|
||||
# 判準是「有沒有任何一個改到的檔在知識目錄之外」,不是維護一張「哪些算 code」的清單。
|
||||
# 方向:把 docs 誤判成「不用出貨」是漏擋(安全方向);把 wiki 判成「要出貨」是誤攔(要避免)。
|
||||
#
|
||||
# ③ 「哪些 repo 不適用」= repo 根目錄有 `.isep-release-exempt` 這個檔(裡面寫一行理由)。
|
||||
# · 判準是「檔在不在」,不是一張會過期的中央手列清單,也不是名字黑名單。
|
||||
# · **預設納管**:新 repo 進來自動被管(沒人需要記得加),只有產物 repo/模板 repo
|
||||
# 這種真的不出版的才放一個 marker——而且它自己帶著「為什麼不適用」的理由。
|
||||
# (票明說 arcrun-rag-bundles-staging 是產物、system-dev-template 是模板;它們各放一個 marker 即可。)
|
||||
#
|
||||
# ④ 「這次先不出」= $CLAUDE_PROJECT_DIR/.claude/release-holds.md 裡有一行提到這個 repo(+理由)。
|
||||
# · 形狀跟 unpushed-police 的 branch-holds.md 一樣:**要求某個東西在場**(leo 認可的兩種閘形狀之一),
|
||||
# 不是去 transcript 裡撈「先不出因為」這種字(文字層封路已被證偽:8 次誤攔 0 次命中)。
|
||||
# · 「明說先不出」寫進一個檔=同時滿足「放行」與「留痕」(票驗收 5)。
|
||||
# · 出貨了就把那一行刪掉——訊息會這樣講。
|
||||
#
|
||||
# ── 「出貨」怎麼認 ──────────────────────────────────────────────────────
|
||||
# shipped ⟺ `git tag --contains HEAD` 非空(HEAD 這顆已經被某個 release tag 收進去)。
|
||||
# Gitea 的 release 就是 tag;tag 打在哪顆 commit 上是本機答得準的事實,不必打網路。
|
||||
# 沒被收進去 ⇒ 用 `git describe` 找出「最新 release」、數出 HEAD 領先它幾筆——
|
||||
# 那就是「最後 commit 與最新 release 差多少」(票驗收 1 要訊息點得出來)。
|
||||
#
|
||||
# ── fail-open:Stop 閘擋下內部錯誤會鎖死 session,誤攔是本 repo 第一級缺陷 ──
|
||||
# 拿不到 transcript 起點/不是 git repo/git 問不出來 ⇒ 一律放行。
|
||||
#
|
||||
# 迴歸測試:scripts/test-unreleased-police.sh(含「不該擋」與「出路走得通」兩組)
|
||||
|
||||
input="$(cat 2>/dev/null || echo '{}')"
|
||||
|
||||
# ── 防無限迴圈:已被別的 Stop 閘擋出來這一輪 ⇒ 不再擋 ──
|
||||
stop_active="$(printf '%s' "$input" | python3 -c '
|
||||
import sys, json
|
||||
try: print(json.load(sys.stdin).get("stop_hook_active", False))
|
||||
except Exception: print(False)
|
||||
' 2>/dev/null)"
|
||||
[ "$stop_active" = "True" ] && exit 0
|
||||
|
||||
# ── 一次取出 transcript 路徑與 session 起點(epoch)──
|
||||
# 起點的算法跟 hooks/lib/countdown.py transcript_start 同源:transcript 第一列的時間戳。
|
||||
LIBDIR="$(dirname "$0")/lib"
|
||||
read -r START_EPOCH TRANSCRIPT <<EOF2
|
||||
$(printf '%s' "$input" | LIBDIR="$LIBDIR" python3 -c '
|
||||
import sys, json, os
|
||||
sys.path.insert(0, os.environ.get("LIBDIR", ""))
|
||||
start = ""
|
||||
tp = ""
|
||||
try:
|
||||
d = json.load(sys.stdin)
|
||||
tp = d.get("transcript_path") or ""
|
||||
except Exception:
|
||||
d = {}
|
||||
try:
|
||||
from countdown import transcript_start
|
||||
dt = transcript_start(tp)
|
||||
if dt: start = str(int(dt.timestamp()))
|
||||
except Exception:
|
||||
# lib 不在時就地補:讀第一列時間戳
|
||||
try:
|
||||
from datetime import datetime, timezone
|
||||
with open(tp) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line: continue
|
||||
try: row = json.loads(line)
|
||||
except Exception: continue
|
||||
raw = row.get("timestamp")
|
||||
if isinstance(raw, str) and raw.strip():
|
||||
s = raw.strip().replace("Z", "+00:00")
|
||||
try:
|
||||
dt = datetime.fromisoformat(s)
|
||||
if not dt.tzinfo: dt = dt.replace(tzinfo=timezone.utc)
|
||||
start = str(int(dt.timestamp())); break
|
||||
except Exception: pass
|
||||
except Exception: pass
|
||||
print(start or "-", tp or "-")
|
||||
' 2>/dev/null)
|
||||
EOF2
|
||||
|
||||
# 拿不到起點 ⇒ 無從界定「這個 session 改了什麼」⇒ 放行(誤攔比漏擋嚴重)
|
||||
case "$START_EPOCH" in ''|'-'|*[!0-9]*) exit 0 ;; esac
|
||||
|
||||
TOP="${CLAUDE_PROJECT_DIR:-$(cd "$(dirname "$0")/../.." && pwd)}"
|
||||
|
||||
# 掃描對象:頂層 + 已知子 repo(存在才掃),與 unpushed-police 同一份排法。
|
||||
REPOS=""
|
||||
for _body in "$TOP" "$TOP/InkStoneCo"; do
|
||||
[ -d "$_body/.git" ] || [ -f "$_body/.git" ] || continue
|
||||
REPOS="$REPOS $_body $_body/matrix/arcrun $_body/products/arcrun-rag $_body/polaris/mira"
|
||||
done
|
||||
[ -n "$REPOS" ] || REPOS="$TOP"
|
||||
|
||||
HOLDS="$TOP/.claude/release-holds.md"
|
||||
|
||||
problems=""
|
||||
held_note=""
|
||||
exempt_note=""
|
||||
|
||||
for r in $REPOS; do
|
||||
[ -d "$r/.git" ] || [ -f "$r/.git" ] || continue
|
||||
name="${r#$TOP/}"; [ "$name" = "$r" ] && name="$(basename "$r")"
|
||||
[ "$r" = "$TOP" ] && name="(頂層) $(basename "$r")"
|
||||
base="$(basename "$r")"
|
||||
|
||||
# ── ① 這個 session 有沒有新 commit(reachable from HEAD, committer-date >= 起點)──
|
||||
files="$(git -C "$r" log HEAD --since="@$START_EPOCH" --name-only --format= 2>/dev/null \
|
||||
| grep -v '^$' | sort -u)"
|
||||
[ -z "$files" ] && continue # 這個 session 沒動這個 repo → 放行(票驗收 3/4「只讀不寫」)
|
||||
|
||||
# ── ② 有沒有動到「知識以外」的檔(要出貨的改動)──
|
||||
# 知識目錄:路徑含 /wiki/、/docs/、/_archive/,或以它們開頭。
|
||||
nonknow="$(printf '%s\n' "$files" | grep -vE '(^|/)(wiki|docs|_archive)(/|$)' | head -1)"
|
||||
[ -z "$nonknow" ] && continue # 只改了知識(wiki/docs)→ 不需出貨(票驗收 4)
|
||||
|
||||
# ── ③ 這個 repo 是不是 marker 排除(產物/模板)──
|
||||
if [ -f "$r/.isep-release-exempt" ]; then
|
||||
_why="$(head -1 "$r/.isep-release-exempt" 2>/dev/null)"
|
||||
exempt_note="$exempt_note
|
||||
- $name(.isep-release-exempt:${_why:-未寫理由})"
|
||||
continue
|
||||
fi
|
||||
|
||||
# ── 已經出貨了嗎?HEAD 被某個 tag 收進去 ⇒ 出過貨,放行(票驗收 2)──
|
||||
if [ -n "$(git -C "$r" tag --contains HEAD 2>/dev/null | head -1)" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# ── 到這裡:這個 session 動過、要出貨、卻還沒出貨 ──
|
||||
# 「最後 commit 與最新 release 差多少」
|
||||
base_tag="$(git -C "$r" describe --tags --abbrev=0 HEAD 2>/dev/null || true)"
|
||||
if [ -n "$base_tag" ]; then
|
||||
n="$(git -C "$r" rev-list --count "$base_tag"..HEAD 2>/dev/null || echo '?')"
|
||||
detail="最新 release $base_tag ,HEAD 領先它 $n 筆(其中有環境/code 改動未出貨)"
|
||||
else
|
||||
n="$(git -C "$r" rev-list --count HEAD 2>/dev/null || echo '?')"
|
||||
detail="從未出過版(一個 release tag 都沒有),HEAD 共 $n 筆 commit 未出貨"
|
||||
fi
|
||||
short_top="$(printf '%s\n' "$files" | grep -vE '(^|/)(wiki|docs|_archive)(/|$)' | head -3 \
|
||||
| sed 's/^/ · /')"
|
||||
|
||||
# ── ④ 這次先不出(release-holds.md 有提到這個 repo)⇒ 放行 + 留痕 ──
|
||||
if [ -f "$HOLDS" ] && grep -qF "$base" "$HOLDS" 2>/dev/null; then
|
||||
_line="$(grep -F "$base" "$HOLDS" 2>/dev/null | head -1)"
|
||||
held_note="$held_note
|
||||
- $name(先不出,理由在 .claude/release-holds.md):$_line"
|
||||
continue
|
||||
fi
|
||||
|
||||
problems="$problems
|
||||
📦 $name :$detail
|
||||
這個 session 動到、需要出貨的檔(節錄):
|
||||
$short_top"
|
||||
done
|
||||
|
||||
# 沒有任何「改了卻沒出貨」的 repo ⇒ 放行
|
||||
if [ -z "$problems" ]; then
|
||||
# 有 hold/exempt 但沒有真問題時安靜放行——不無事生非(票紅線)
|
||||
exit 0
|
||||
fi
|
||||
|
||||
REPLACE_HOLDS="$HOLDS"
|
||||
|
||||
printf '%s\n' "🚢 未出貨警察:這個 session 改過的 repo,收工前還沒出貨。" >&2
|
||||
# 靜態訊息用 quoted heredoc(mistakes.md:unquoted heredoc 會把反引號當命令執行);
|
||||
# 動態內容用 printf '%s' 分開印,變數與全形標點之間都留空白(避免 locale 吃字元)。
|
||||
cat >&2 <<'EOF'
|
||||
|
||||
【leo 2026-08-27(原話就是判準)】
|
||||
「每個 repo 只要有改動就要出貨」「版本出去之前都只是內部測試」
|
||||
「你可以久一點再出貨累積幾個 PR,但最後一定要出貨」
|
||||
【判準】改對了、commit 了 ≠ 送到人手上。release 出去之前都只是內部測試。
|
||||
EOF
|
||||
|
||||
printf '%s\n' "$problems" >&2
|
||||
|
||||
if [ -n "$held_note" ]; then
|
||||
printf '%s\n' "" >&2
|
||||
printf '%s\n' "⏸️ 這次先不出(已留痕,不擋):$held_note" >&2
|
||||
fi
|
||||
if [ -n "$exempt_note" ]; then
|
||||
printf '%s\n' "" >&2
|
||||
printf '%s\n' "⊘ 排除(.isep-release-exempt):$exempt_note" >&2
|
||||
fi
|
||||
|
||||
cat >&2 <<'EOF'
|
||||
|
||||
━━ 收工前擇一,都走得通 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
1. 該出貨就出貨:升版(改了會被載入的東西=plugin/worker/bundle 就升版)
|
||||
+ 打 release tag。ISEP 自己:bash scripts/check-version-consistency.sh 先對齊,
|
||||
版本三處一致後由總管打 tag。
|
||||
2. 這次先不出(累積、或交回分支由總管出):在下面這個檔寫一行理由——
|
||||
寫完再收工就放行,而且留了痕,總管看得到有東西在路上:
|
||||
EOF
|
||||
|
||||
printf '%s\n' " $REPLACE_HOLDS" >&2
|
||||
printf '%s\n' " 一行格式: <repo 名>: <為什麼這次先不出>" >&2
|
||||
printf '%s\n' " (repo 名就是上面每個 📦 後面那個名字的最後一段,例如 ISEP/mira)" >&2
|
||||
|
||||
cat >&2 <<'EOF'
|
||||
3. 是產物 repo/模板 repo(本來就不出版):在該 repo 根目錄放一個
|
||||
.isep-release-exempt,第一行寫理由。之後這支閘就不再管它。
|
||||
|
||||
🔴 本閘只在收工那一刻問一次,不是每次 commit 都吼(leo 明說可以累積)。
|
||||
出貨之後記得把 release-holds.md 裡對應那一行刪掉,否則下次它會以為你還在累積。
|
||||
EOF
|
||||
exit 2
|
||||
@@ -1,206 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""gate-report — 把 gate-log.jsonl 變成「規則有沒有在運作」的答案(inkstone/InkStoneCo#48)。
|
||||
|
||||
這支不是文件、不是感覺,是**查資料**。紀錄由 hooks/lib/gate-log-wrap.sh 在每一次
|
||||
閘動作當下留下(擋/放行/被逃生口繞過各一種 verdict)。本工具回答票上那三題:
|
||||
|
||||
q1 哪支閘擋最多?其中有多少最後被繞過? (=誤擋嫌疑最高的)
|
||||
q2 哪條規則最近 N 天一次都沒擋過? (=可能已經沒有存在意義)
|
||||
q3 同一個 session/agent 反覆撞同一支閘幾次? (=規則沒被理解,或閘寫錯)
|
||||
|
||||
用法:
|
||||
scripts/gate-report [--log PATH] [--days N] [all|q1|q2|q3|summary|ledger-path]
|
||||
|
||||
--log 紀錄檔路徑(預設沿用 gate-log-wrap.sh 的解析順序)
|
||||
--days N q2 的視窗,最近 N 天(預設 7)
|
||||
(不給子命令 = all:先印基線數字,再依序印三題)
|
||||
|
||||
離線、唯讀:只讀那個 jsonl,不打任何網路,不寫任何東西。
|
||||
"""
|
||||
import argparse
|
||||
import collections
|
||||
import datetime as dt
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
ROOT = os.path.dirname(HERE) # scripts/ 的上一層 = plugin 根
|
||||
|
||||
|
||||
def resolve_log():
|
||||
"""跟 gate-log-wrap.sh 同一套順序找紀錄檔。"""
|
||||
v = os.environ.get("ISEP_GATE_LOG")
|
||||
if v:
|
||||
return v
|
||||
for base in (os.environ.get("CLAUDE_PROJECT_DIR") or "", ROOT):
|
||||
if base and os.path.isdir(os.path.join(base, "system-dev")):
|
||||
return os.path.join(base, "system-dev", "gate-log", "gate-log.jsonl")
|
||||
return os.path.join(os.path.expanduser("~"), ".claude", "isep-gate-log", "gate-log.jsonl")
|
||||
|
||||
|
||||
def registered_gates():
|
||||
"""從 hooks.json 讀出「目前真的被記錄層包著的閘」清單——q2 要拿它跟紀錄比對,
|
||||
才分得出『掛著但從沒擋過』與『根本沒掛』。
|
||||
|
||||
判準是「這條 command 有沒有被 gate-log-wrap.sh 包住」:包住的才是我們在計數的閘,
|
||||
scripts/ 底下的 refresher(不是閘、刻意沒包)就不會被誤算進來。
|
||||
讀不到 hooks.json 就回空集合(q2 會退回只用紀錄裡看過的閘,不會因此爆掉)。"""
|
||||
path = os.path.join(ROOT, "hooks", "hooks.json")
|
||||
names = set()
|
||||
try:
|
||||
d = json.load(open(path))
|
||||
for ev in d.get("hooks", {}).values():
|
||||
for group in ev:
|
||||
for h in group.get("hooks", []):
|
||||
cmd = h.get("command", "")
|
||||
if "gate-log-wrap" not in cmd:
|
||||
continue # 沒被記錄層包住 = 不是我們在計數的閘
|
||||
last = cmd.split()[-1] if cmd.split() else "" # 閘路徑一律是最後一段
|
||||
base = last.rsplit("/", 1)[-1]
|
||||
if base.endswith(".sh"):
|
||||
names.add(base[:-3])
|
||||
except Exception:
|
||||
pass
|
||||
return names
|
||||
|
||||
|
||||
def load(path):
|
||||
rows = []
|
||||
try:
|
||||
with open(path) as f:
|
||||
for ln in f:
|
||||
ln = ln.strip()
|
||||
if not ln:
|
||||
continue
|
||||
try:
|
||||
rows.append(json.loads(ln))
|
||||
except Exception:
|
||||
continue # 壞行跳過,不讓一行毀掉整份報告
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return rows
|
||||
|
||||
|
||||
def parse_ts(s):
|
||||
try:
|
||||
return dt.datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=dt.timezone.utc)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def summary(rows):
|
||||
v = collections.Counter(r.get("verdict") for r in rows)
|
||||
gates = {r.get("gate") for r in rows if r.get("gate")}
|
||||
print("── 基線數字(拿今天當基線)───────────────────────────")
|
||||
print(" 紀錄總筆數 : %d" % len(rows))
|
||||
print(" 出現過的閘 : %d 支" % len(gates))
|
||||
print(" 擋下 (block) : %d" % v.get("block", 0))
|
||||
print(" 被繞過 (bypass) : %d" % v.get("bypass", 0))
|
||||
print(" 放行 (pass) : %d" % v.get("pass", 0))
|
||||
print(" 其他/錯 (error) : %d" % v.get("error", 0))
|
||||
if not rows:
|
||||
print(" (帳本還是空的——這一層剛裝上,還沒有任何閘動作被記錄。)")
|
||||
|
||||
|
||||
def q1(rows):
|
||||
print("── Q1 哪支閘擋最多?其中多少被繞過?(誤擋嫌疑排序)──────")
|
||||
block = collections.Counter()
|
||||
byp = collections.Counter()
|
||||
for r in rows:
|
||||
g = r.get("gate")
|
||||
if not g:
|
||||
continue
|
||||
if r.get("verdict") == "block":
|
||||
block[g] += 1
|
||||
elif r.get("verdict") == "bypass":
|
||||
byp[g] += 1
|
||||
gates = set(block) | set(byp)
|
||||
if not gates:
|
||||
print(" (還沒有任何 block/bypass 紀錄。)")
|
||||
return
|
||||
# 「擋」= block + bypass(兩者都是「這支閘本來要擋」的動作);被繞過率高 = 誤擋嫌疑高
|
||||
print(" %-30s %6s %7s %7s %s" % ("閘", "擋下", "被繞過", "本要擋", "繞過率"))
|
||||
for g in sorted(gates, key=lambda x: -(block[x] + byp[x])):
|
||||
would = block[g] + byp[g]
|
||||
rate = (byp[g] / would * 100) if would else 0.0
|
||||
print(" %-30s %6d %7d %7d %5.1f%%" % (g, block[g], byp[g], would, rate))
|
||||
|
||||
|
||||
def q2(rows, days, reg):
|
||||
print("── Q2 最近 %d 天一次都沒擋過的規則(可能已無存在意義)──" % days)
|
||||
now = dt.datetime.now(dt.timezone.utc)
|
||||
cutoff = now - dt.timedelta(days=days)
|
||||
blocked_recent = set()
|
||||
seen = set()
|
||||
for r in rows:
|
||||
g = r.get("gate")
|
||||
if not g:
|
||||
continue
|
||||
seen.add(g)
|
||||
ts = parse_ts(r.get("ts", ""))
|
||||
if r.get("verdict") in ("block", "bypass") and ts and ts >= cutoff:
|
||||
blocked_recent.add(g)
|
||||
universe = (reg | seen) if reg else seen
|
||||
idle = sorted(g for g in universe if g not in blocked_recent)
|
||||
if not universe:
|
||||
print(" (沒有可比對的閘清單。)")
|
||||
return
|
||||
for g in idle:
|
||||
tag = "(掛著,但這視窗內沒有任何紀錄)" if g not in seen else "(有動作,但都是放行,沒擋過)"
|
||||
print(" · %-30s %s" % (g, tag))
|
||||
if not idle:
|
||||
print(" (這視窗內每一支掛著的閘都至少擋過一次。)")
|
||||
|
||||
|
||||
def q3(rows):
|
||||
print("── Q3 同一個 session/agent 反覆撞同一支閘(≥2 次)─────")
|
||||
hit = collections.Counter()
|
||||
child = {}
|
||||
for r in rows:
|
||||
if r.get("verdict") not in ("block", "bypass"):
|
||||
continue
|
||||
g, sid = r.get("gate"), r.get("sid") or "(no-sid)"
|
||||
if not g:
|
||||
continue
|
||||
hit[(sid, g)] += 1
|
||||
child[(sid, g)] = r.get("child", 0)
|
||||
repeat = [(k, n) for k, n in hit.items() if n >= 2]
|
||||
if not repeat:
|
||||
print(" (還沒有『同一 session 撞同一支閘 2 次以上』的紀錄。)")
|
||||
return
|
||||
print(" %6s %-4s %-30s %s" % ("撞幾次", "子?", "閘", "session"))
|
||||
for (sid, g), n in sorted(repeat, key=lambda x: -x[1]):
|
||||
print(" %6d %-4s %-30s %s" % (n, "子" if child[(sid, g)] else "主", g, sid))
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(add_help=True)
|
||||
ap.add_argument("cmd", nargs="?", default="all",
|
||||
choices=["all", "q1", "q2", "q3", "summary", "ledger-path"])
|
||||
ap.add_argument("--log", default=None)
|
||||
ap.add_argument("--days", type=int, default=7)
|
||||
a = ap.parse_args()
|
||||
|
||||
path = a.log or resolve_log()
|
||||
if a.cmd == "ledger-path":
|
||||
print(path)
|
||||
return
|
||||
|
||||
rows = load(path)
|
||||
reg = registered_gates()
|
||||
if a.cmd in ("all", "summary"):
|
||||
summary(rows)
|
||||
if a.cmd == "summary":
|
||||
return
|
||||
print()
|
||||
if a.cmd in ("all", "q1"):
|
||||
q1(rows); print() if a.cmd == "all" else None
|
||||
if a.cmd in ("all", "q2"):
|
||||
q2(rows, a.days, reg); print() if a.cmd == "all" else None
|
||||
if a.cmd in ("all", "q3"):
|
||||
q3(rows)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,66 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# scripts/gate-report 的迴歸測試(inkstone/InkStoneCo#48 驗收 #2)
|
||||
#
|
||||
# 用一份寫死的 fixture 帳本,驗這三題「查得出來、答得對」,不是憑印象:
|
||||
# Q1 哪支閘擋最多?其中多少被繞過?
|
||||
# Q2 哪條規則最近 N 天一次都沒擋過?
|
||||
# Q3 同一個 session 反覆撞同一支閘幾次?
|
||||
# 🔴 出路要真的走得通(mistakes.md #158):這裡不驗「有沒有印字」,
|
||||
# 驗「印出來的數字對不對」。
|
||||
set -u
|
||||
REPORT="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/gate-report}"
|
||||
TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT
|
||||
LED="$TMP/gate-log.jsonl"
|
||||
PASS=0; FAIL=0; N=0
|
||||
ok() { N=$((N+1)); printf ' ✅ %s\n' "$1"; PASS=$((PASS+1)); }
|
||||
bad() { N=$((N+1)); printf ' ❌ %s\n' "$1"; FAIL=$((FAIL+1)); shift; for l in "$@"; do printf ' %s\n' "$l"; done; }
|
||||
|
||||
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
OLD=$(python3 -c "import datetime as d;print((d.datetime.now(d.timezone.utc)-d.timedelta(days=30)).strftime('%Y-%m-%dT%H:%M:%SZ'))")
|
||||
row() { printf '{"ts":"%s","gate":"%s","event":"PreToolUse","tool":"Bash","verdict":"%s","bypass":"%s","sid":"%s","child":%s}\n' \
|
||||
"$1" "$2" "$3" "$4" "$5" "${6:-0}" >> "$LED"; }
|
||||
|
||||
# gateA:擋 3 次、繞過 2 次(誤擋嫌疑最高);session sA 撞它 3 次
|
||||
row "$NOW" gateA block "" sA 0
|
||||
row "$NOW" gateA block "" sA 0
|
||||
row "$NOW" gateA block "" sA 0 # sA 撞 gateA 共 3 次(Q3)
|
||||
row "$NOW" gateA bypass NOT_MY_BRANCH_OK sB 1
|
||||
row "$NOW" gateA bypass NOT_MY_BRANCH_OK sB 1
|
||||
# gateB:擋 1 次
|
||||
row "$NOW" gateB block "" sC 0
|
||||
# gateC:最近只有放行,從沒擋過(Q2 該點名)
|
||||
row "$NOW" gateC pass "" sC 0
|
||||
row "$NOW" gateC pass "" sD 0
|
||||
# gateD:只有 30 天前擋過,最近 7 天沒擋(Q2 該點名)
|
||||
row "$OLD" gateD block "" sE 0
|
||||
|
||||
echo "── Q1:擋最多的是 gateA,且看得出被繞過 2 次 ────────────────"
|
||||
Q1=$(ISEP_GATE_LOG="$LED" "$REPORT" q1 2>&1)
|
||||
FIRST=$(printf '%s' "$Q1" | grep -E '^\s+gate[A-Z]' | head -n1)
|
||||
case "$FIRST" in *gateA*) ok "① 誤擋嫌疑排序第一名是 gateA" ;; *) bad "① 排序第一名不是 gateA" "$Q1" ;; esac
|
||||
# gateA 那行:擋下 3、被繞過 2、本要擋 5
|
||||
if printf '%s' "$Q1" | grep -E 'gateA' | grep -qE '\b3\b.*\b2\b.*\b5\b'; then
|
||||
ok "② gateA 的數字對:擋下3 / 被繞過2 / 本要擋5"
|
||||
else bad "② gateA 數字不對" "$(printf '%s' "$Q1" | grep gateA)"; fi
|
||||
|
||||
echo "── Q2:最近 7 天沒擋過的是 gateC(只放行)與 gateD(30天前才擋)─"
|
||||
Q2=$(ISEP_GATE_LOG="$LED" "$REPORT" q2 --days 7 2>&1)
|
||||
printf '%s' "$Q2" | grep -q 'gateC' && ok "③ gateC(活著但只放行)被點名" || bad "③ 沒點名 gateC" "$Q2"
|
||||
printf '%s' "$Q2" | grep -q 'gateD' && ok "④ gateD(最近7天沒擋)被點名" || bad "④ 沒點名 gateD" "$Q2"
|
||||
printf '%s' "$Q2" | grep -qE '^\s+·\s+gateA' && bad "⑤ 誤點名 gateA(它最近有擋)" "$Q2" || ok "⑤ 有擋過的 gateA 不被點名"
|
||||
|
||||
echo "── Q3:sA 反覆撞 gateA 3 次 ─────────────────────────────────"
|
||||
Q3=$(ISEP_GATE_LOG="$LED" "$REPORT" q3 2>&1)
|
||||
if printf '%s' "$Q3" | grep -E 'gateA' | grep -q 'sA'; then
|
||||
if printf '%s' "$Q3" | grep -E 'sA' | grep -qE '\b3\b'; then ok "⑥ sA 撞 gateA 記成 3 次"; else bad "⑥ 次數不是 3" "$Q3"; fi
|
||||
else bad "⑥ 沒抓到 sA×gateA" "$Q3"; fi
|
||||
# sC 撞 gateB 只 1 次,不該出現在 Q3
|
||||
printf '%s' "$Q3" | grep -E 'gateB' | grep -q 'sC' && bad "⑦ 撞1次的 sC×gateB 不該出現" "$Q3" || ok "⑦ 只撞1次的不入 Q3"
|
||||
|
||||
echo "── 基線:空帳本也要能跑(不爆炸)───────────────────────────"
|
||||
EMPTY="$TMP/empty.jsonl"; : > "$EMPTY"
|
||||
if ISEP_GATE_LOG="$EMPTY" "$REPORT" all >/dev/null 2>&1; then ok "⑧ 空帳本跑 all 不報錯"; else bad "⑧ 空帳本跑 all 爆了"; fi
|
||||
|
||||
echo ""
|
||||
echo "通過 $PASS 條,失敗 $FAIL 條(共 $N)"
|
||||
[ "$FAIL" = 0 ]
|
||||
Executable
+102
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env bash
|
||||
# unreleased-police.sh 的迴歸測試(inkstone/ISEP#68,docs/TESTING.md A27)
|
||||
#
|
||||
# 兩個方向都要有證據(本 repo 心法:誤攔比漏擋嚴重):
|
||||
# A 群「該擋」 —— session 改了 code 卻沒出貨(含「從未出過版」與「領先最新 release N 筆」)
|
||||
# B 群「不該擋」 —— 只讀不寫/只改 wiki/已出貨(tag 收進 HEAD)/排除 marker/這次先不出/stop_hook_active
|
||||
# C 群「出路走得通」—— 照擋下訊息教的「寫 release-holds.md 一行」做,再送一次就放行(ISEP#112 的課)
|
||||
# D 群「鑑別力」 —— 拿掉 marker 同一個 repo 就會擋(證明放行是 marker 造成的,不是偵測壞了)
|
||||
#
|
||||
# 🔴 全程在乾淨的 TMP 底下造假 repo/假 transcript,跑完自己清;不碰任何真 repo、不打網路。
|
||||
set -u
|
||||
HOOK="${1:-$(cd "$(dirname "$0")/.." && pwd)/hooks/unreleased-police.sh}"
|
||||
TMP=$(mktemp -d)
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
# session 起點固定成 2026-01-01T00:00:00Z(transcript 第一列的時間戳)。
|
||||
# 「這個 session 的 commit」=committer-date 晚於這一刻。
|
||||
T0="2026-01-01T00:00:00Z"
|
||||
TR="$TMP/transcript.jsonl"
|
||||
printf '{"timestamp":"%s","type":"user","message":{"content":[{"type":"text","text":"開工"}]}}\n' "$T0" > "$TR"
|
||||
AFTER="2026-06-01T00:00:00Z" # 晚於起點 = 這個 session 改的
|
||||
BEFORE="2025-06-01T00:00:00Z" # 早於起點 = 不是這個 session 改的
|
||||
|
||||
PASS=0; FAIL=0; N=0
|
||||
|
||||
mkrepo() { git init -q "$1"; git -C "$1" config user.email t@t; git -C "$1" config user.name t; }
|
||||
# commit <repo> <date> <相對路徑> <訊息>
|
||||
commit() {
|
||||
mkdir -p "$(dirname "$1/$3")"; echo x >> "$1/$3"; git -C "$1" add -A
|
||||
GIT_AUTHOR_DATE="$2" GIT_COMMITTER_DATE="$2" git -C "$1" commit -qm "$4"
|
||||
}
|
||||
|
||||
# fire <說明> <期望exit> <repo目錄> [extra-json] [--grep <字串>]
|
||||
fire() {
|
||||
desc="$1"; want="$2"; repo="$3"; extra="${4:-}"; needle="${6:-}"
|
||||
N=$((N+1))
|
||||
payload=$(printf '{"session_id":"s%s","transcript_path":"%s"%s}' "$N" "$TR" "$extra")
|
||||
out=$(printf '%s' "$payload" | CLAUDE_PROJECT_DIR="$repo" bash "$HOOK" 2>&1); rc=$?
|
||||
ok=1
|
||||
[ "$rc" = "$want" ] || ok=0
|
||||
if [ -n "$needle" ] && ! printf '%s' "$out" | grep -qF "$needle"; then ok=0; fi
|
||||
if [ "$ok" = 1 ]; then
|
||||
printf ' ✅ %s\n' "$desc"; PASS=$((PASS+1))
|
||||
else
|
||||
printf ' ❌ %s —— 期望 exit=%s,實得 exit=%s' "$desc" "$want" "$rc"
|
||||
[ -n "$needle" ] && printf '(找 "%s")' "$needle"
|
||||
printf '\n'
|
||||
printf '%s\n' "$out" | sed -n '1,10p' | sed 's/^/ /'
|
||||
FAIL=$((FAIL+1))
|
||||
fi
|
||||
}
|
||||
|
||||
echo "── A 群:該擋(改了 code 卻沒出貨)──"
|
||||
mkrepo "$TMP/a1"; commit "$TMP/a1" "$AFTER" hooks/foo.sh "加一支 hook"
|
||||
fire "改了 hook、從未出過版 → 擋,且點名 repo+筆數" 2 "$TMP/a1" "" --grep "從未出過版"
|
||||
|
||||
mkrepo "$TMP/a2"; commit "$TMP/a2" "$BEFORE" hooks/a.sh a; git -C "$TMP/a2" tag v1
|
||||
commit "$TMP/a2" "$AFTER" hooks/b.sh b
|
||||
fire "有舊 release、新 commit 未收進 → 擋,訊息說『領先它 N 筆』" 2 "$TMP/a2" "" --grep "領先它 1 筆"
|
||||
|
||||
mkrepo "$TMP/a3"; commit "$TMP/a3" "$AFTER" scripts/x.sh x; commit "$TMP/a3" "$AFTER" system-dev/wiki/n.md n
|
||||
fire "同一 session 改了 code+wiki → 擋(只要有一個非知識檔)" 2 "$TMP/a3" "" --grep "未出貨"
|
||||
|
||||
echo "── B 群:不該擋 ──"
|
||||
mkrepo "$TMP/b1"; commit "$TMP/b1" "$BEFORE" hooks/foo.sh old
|
||||
fire "這個 session 什麼都沒 commit(只讀不寫)→ 放行" 0 "$TMP/b1"
|
||||
|
||||
mkrepo "$TMP/b2"; commit "$TMP/b2" "$AFTER" system-dev/wiki/note.md "只改 wiki"
|
||||
fire "這個 session 只改了 wiki → 放行" 0 "$TMP/b2"
|
||||
|
||||
mkrepo "$TMP/b2b"; commit "$TMP/b2b" "$AFTER" docs/hooks-inventory.md "只改 docs"
|
||||
fire "這個 session 只改了 docs → 放行" 0 "$TMP/b2b"
|
||||
|
||||
mkrepo "$TMP/b3"; commit "$TMP/b3" "$AFTER" hooks/foo.sh code; git -C "$TMP/b3" tag v9
|
||||
fire "改了 code 而且已出貨(tag 收進 HEAD)→ 放行" 0 "$TMP/b3"
|
||||
|
||||
mkrepo "$TMP/b4"; commit "$TMP/b4" "$AFTER" hooks/foo.sh code
|
||||
printf '產物 repo,管線產出,不出版\n' > "$TMP/b4/.isep-release-exempt"
|
||||
fire "改了 code 但有 .isep-release-exempt marker → 放行" 0 "$TMP/b4"
|
||||
|
||||
mkrepo "$TMP/b5"; commit "$TMP/b5" "$AFTER" hooks/foo.sh code
|
||||
mkdir -p "$TMP/b5/.claude"; printf 'b5: 交回分支,release 由總管出\n' > "$TMP/b5/.claude/release-holds.md"
|
||||
fire "改了 code 沒出貨、但 release-holds.md 有這個 repo(先不出)→ 放行且留痕" 0 "$TMP/b5"
|
||||
|
||||
mkrepo "$TMP/b6"; commit "$TMP/b6" "$AFTER" hooks/foo.sh code
|
||||
fire "已被別的 Stop 閘擋過這一輪(stop_hook_active)→ 放行" 0 "$TMP/b6" ',"stop_hook_active":true'
|
||||
|
||||
echo "── C 群:擋下訊息教的出路,照做真的走得通 ──"
|
||||
mkrepo "$TMP/c1"; commit "$TMP/c1" "$AFTER" hooks/foo.sh code
|
||||
fire "先擋一次" 2 "$TMP/c1" "" --grep "release-holds.md"
|
||||
# 照訊息說的:在 .claude/release-holds.md 寫「<repo 名>: <理由>」
|
||||
mkdir -p "$TMP/c1/.claude"; printf 'c1: 這次累積,下個 session 一起出\n' > "$TMP/c1/.claude/release-holds.md"
|
||||
fire "照訊息寫了 release-holds.md 那一行,再送 → 放行" 0 "$TMP/c1"
|
||||
|
||||
echo "── D 群:鑑別力(放行是 marker/hold 造成的,不是偵測壞了)──"
|
||||
# b4 若拿掉 marker,同一個 repo 就會擋 → 證明偵測本身是會亮的
|
||||
rm -f "$TMP/b4/.isep-release-exempt"
|
||||
fire "把 b4 的 marker 拿掉 → 同一個 repo 就擋(偵測真的會亮)" 2 "$TMP/b4"
|
||||
|
||||
echo
|
||||
echo "$PASS/$N 通過"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
Reference in New Issue
Block a user