gate-log: 透明記錄層——每一支閘的擋/放行/繞過都留得下(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 的 82 條
gate command 全部前綴這支 wrapper;2 條 scripts/ refresher 不是閘、不包)。
它從不 exit 2,只把真正那支閘的離開碼原樣傳出去 ⇒ 記錄壞掉最多漏記一筆,
不可能誤攔(票紅線:寧可漏記,不可擋錯)。每次留一筆中繼資料:
哪支閘/何時/對什麼工具/判成什麼/(若繞過)用了哪個逃生口。

- 只記中繼資料,完全不寫入指令原文或 payload ⇒ 金鑰在結構上進不了帳本(D36)
- 純 POSIX shell 記錄,不另起 python ⇒ 不讓閘變慢變脆
- 紀錄長在既有閘動作上,零輪詢/零 cron(D20)
- 帳本沿用 milestone-account 慣例(不寫進會被 plugin update 換掉的目錄)

報告:scripts/gate-report all 回答票上三題(誤擋嫌疑排序/最近沒擋過的規則/
同一 session 反覆撞同一支閘)。基線與反面驗證見票留言。

測試:hooks/tests/gate-log.test.sh 22 條(透明/留痕/反面驗證/不變脆/不外洩)
+ scripts/test-gate-report.sh 8 條(三題數字對不對)。
hooks 檔數 61、hooks.json 註冊 84 均不變(wrapper 住 hooks/lib,非 gate .sh)。

版本:待總管定版(改了會被載入的東西需升版才傳得到,但 tag 由總管打)。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TNfNypeDaCVEZQW1Wqwfxq
This commit is contained in:
Claude
2026-09-06 21:01:42 +00:00
parent 605f1fe5a6
commit dda4852938
8 changed files with 668 additions and 82 deletions
+82 -82
View File
@@ -7,71 +7,71 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/github-contact-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/github-contact-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/stage-before-prod-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/stage-before-prod-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/main-and-prod-push-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/main-and-prod-push-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/prod-write-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/prod-write-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/not-my-branch-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/not-my-branch-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/leo21c-write-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/leo21c-write-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/release-tag-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/release-tag-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/ticket-api-bypass-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/ticket-api-bypass-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/comment-carries-task-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/comment-carries-task-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/milestone-due-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/milestone-due-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/milestone-account-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/milestone-account-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/reply-identity-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/reply-identity-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/diagnosis-evidence-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/diagnosis-evidence-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/line-needs-own-worktree.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/line-needs-own-worktree.sh"
}
]
},
@@ -80,7 +80,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/prod-write-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/prod-write-guard.sh"
}
]
},
@@ -89,43 +89,43 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/guard-cross-project.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/guard-cross-project.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-secret-scan.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-secret-scan.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/component-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/component-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/credential-only-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/credential-only-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/arcrun-intent-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/arcrun-intent-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/subagent-first-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/subagent-first-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/mistake-needs-ticket-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/mistake-needs-ticket-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/pending-changes-retired.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/pending-changes-retired.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
}
]
},
@@ -134,7 +134,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-search.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-search.sh"
}
]
},
@@ -143,43 +143,43 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/subagent-wiki-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/subagent-wiki-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-api-wall-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/micromanage-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/micromanage-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/irreversible-dispatch-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/irreversible-dispatch-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/no-ticket-no-dispatch.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/no-ticket-no-dispatch.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/roster-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/roster-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/mainline-focus-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/mainline-focus-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/parallel-lines-cap-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/parallel-lines-cap-guard.sh"
}
]
},
@@ -188,7 +188,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/arcrun-intent-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/arcrun-intent-guard.sh"
}
]
},
@@ -197,7 +197,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/history-first-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/history-first-guard.sh"
}
]
},
@@ -206,35 +206,35 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/micromanage-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/micromanage-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/irreversible-dispatch-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/irreversible-dispatch-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/no-ticket-no-dispatch.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/no-ticket-no-dispatch.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/roster-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/roster-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/mainline-focus-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/mainline-focus-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/search-is-not-proof-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/parallel-lines-cap-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/parallel-lines-cap-guard.sh"
}
]
},
@@ -243,7 +243,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/dispatch-format-guard.sh"
}
]
},
@@ -252,7 +252,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/ask-user-question-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/ask-user-question-guard.sh"
}
]
}
@@ -263,15 +263,15 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/session-start-recall.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/session-start-recall.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/skill-deploy-drift-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/skill-deploy-drift-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/isep-presence-beacon.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/isep-presence-beacon.sh"
},
{
"type": "command",
@@ -283,11 +283,11 @@
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/overdue-nag-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/overdue-nag-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
}
]
}
@@ -297,7 +297,7 @@
"hooks": [
{
"type": "command",
"command": "\"${CLAUDE_PLUGIN_ROOT}\"/hooks/empty-handed-stop-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh \"${CLAUDE_PLUGIN_ROOT}\"/hooks/empty-handed-stop-guard.sh"
}
]
},
@@ -305,19 +305,19 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/worklist-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/worklist-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/factory-idle-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/factory-idle-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/mainline-idle-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/mainline-idle-guard.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/pr-verdict-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/pr-verdict-guard.sh"
}
]
},
@@ -325,7 +325,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/browser-verify-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/browser-verify-guard.sh"
}
]
},
@@ -333,19 +333,19 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-police.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-police.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-judge.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-judge.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/delivery-police.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/delivery-police.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-police.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-police.sh"
}
]
},
@@ -353,7 +353,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/unpushed-police.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/unpushed-police.sh"
}
]
},
@@ -361,7 +361,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/countdown-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/countdown-guard.sh"
}
]
}
@@ -371,7 +371,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/worklist-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/worklist-guard.sh"
}
]
},
@@ -379,19 +379,19 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-police.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-police.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-judge.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/self-drive-judge.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/delivery-police.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/delivery-police.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-police.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/wiki-first-police.sh"
}
]
},
@@ -399,7 +399,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/unpushed-police.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/unpushed-police.sh"
}
]
}
@@ -410,7 +410,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-asked-stamp.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-asked-stamp.sh"
}
]
},
@@ -419,7 +419,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-evidence-stamp.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/kbdb-evidence-stamp.sh"
}
]
},
@@ -428,19 +428,19 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/subagent-first-stamp.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/subagent-first-stamp.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/investigate-first-stamp.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/investigate-first-stamp.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/issue-status-autoflip.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/issue-status-autoflip.sh"
},
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/baton-handback-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/baton-handback-guard.sh"
}
]
},
@@ -449,7 +449,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/investigate-first-stamp.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/investigate-first-stamp.sh"
}
]
}
@@ -459,7 +459,7 @@
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/countdown-guard.sh"
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/lib/gate-log-wrap.sh ${CLAUDE_PLUGIN_ROOT}/hooks/countdown-guard.sh"
}
]
}
+116
View File
@@ -0,0 +1,116 @@
#!/bin/sh
# gate-log-wrap.sh — 透明記錄層:包在每一支閘外面,把「這支閘這一次判成什麼」留一筆。
# inkstone/InkStoneCo#4836 支閘對著虛空開火,沒有任何資料
# 說得出任一支擋對幾次、擋錯幾次、被逃生口繞過幾次。)
#
# ── 它解什麼 ────────────────────────────────────────────────────────────────
# 在此之前只有 2 支閘會記錄自己擋了什麼,六種逃生口(NOT_MY_BRANCH_OK=1
# no-ticket-neededwiki-secret-okcredential-oksolo-okkbdb-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"` 是子行程,所以閘內部的 $0BASH_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_LOGenv,測試/停用用) → $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
+144
View File
@@ -0,0 +1,144 @@
#!/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 "⑩ 記得下哪個 sessionQ3 要用)" || 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 envowner = 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 ]