fix(hooks): 補上 leo21c-write-guard.sh 第二、三次誤攔的修法(反向移植) #40

Merged
claude-code merged 3 commits from fix/one-copy-per-gate into main 2026-08-20 12:06:52 +00:00
Member

追蹤:inkstone/InkStoneCo#57inkstone/ISEP#32「同一件事只留一份」。

把 InkStoneCo 本機 .claude/hooks/ 收斂成只剩 ISEP 這份之前,先逐支比對兩邊內容(41 支同名 hook):36 支完全一致;4 支(github-contact-guardkbdb-api-wall-guardmain-and-prod-push-guardstage-before-prod-guard)ISEP 領先(PR #39 的 heredoc 修法);只有這一支 leo21c-write-guard.sh 方向相反——InkStoneCo 本機今天(08-20)已修過兩次誤攔(bc8a5295e62d28),ISEP 還停在上線當天的版本,會誤擋『git commit 訊息提到 leo21c』『Gitea PATCH 內文提到 leo21c』這種完全碰不到 CF 帳號的動作。

判準改成只認兩種真的會寫到那台的形狀:① 寫入請求打到 *.leo21c.workers.dev(POST/PUT/PATCH/DELETE/--data/-d/trigger)② 用它的 CF 帳號 id 跑 wrangler/acr。其餘一律放行。

實測 6/6(腳本見 commit,非交互):

[PASS] Gitea PATCH mentioning leo21c (false-positive fix) expect=0 got=0
[PASS] wrangler deploy with leo21c CF account id (real violation) expect=2 got=2
[PASS] POST to *.leo21c.workers.dev (real violation) expect=2 got=2
[PASS] GET to *.leo21c.workers.dev (read-only, should pass) expect=0 got=0
[PASS] git commit mentioning leo21c in message (should pass) expect=0 got=0
[PASS] editing the guard file itself (should pass) expect=0 got=0

先合這支,才能安全刪掉 InkStoneCo 本機 .claude/hooks/ 那份而不倒退保護力。

追蹤:`inkstone/InkStoneCo#57`/`inkstone/ISEP#32`「同一件事只留一份」。 把 InkStoneCo 本機 `.claude/hooks/` 收斂成只剩 ISEP 這份之前,先逐支比對兩邊內容(41 支同名 hook):36 支完全一致;4 支(`github-contact-guard`/`kbdb-api-wall-guard`/`main-and-prod-push-guard`/`stage-before-prod-guard`)ISEP 領先(PR #39 的 heredoc 修法);只有這一支 `leo21c-write-guard.sh` 方向相反——InkStoneCo 本機今天(08-20)已修過兩次誤攔(`bc8a529`/`5e62d28`),ISEP 還停在上線當天的版本,會誤擋『git commit 訊息提到 leo21c』『Gitea PATCH 內文提到 leo21c』這種完全碰不到 CF 帳號的動作。 判準改成只認兩種真的會寫到那台的形狀:① 寫入請求打到 `*.leo21c.workers.dev`(POST/PUT/PATCH/DELETE/--data/-d/trigger)② 用它的 CF 帳號 id 跑 wrangler/acr。其餘一律放行。 實測 6/6(腳本見 commit,非交互): ``` [PASS] Gitea PATCH mentioning leo21c (false-positive fix) expect=0 got=0 [PASS] wrangler deploy with leo21c CF account id (real violation) expect=2 got=2 [PASS] POST to *.leo21c.workers.dev (real violation) expect=2 got=2 [PASS] GET to *.leo21c.workers.dev (read-only, should pass) expect=0 got=0 [PASS] git commit mentioning leo21c in message (should pass) expect=0 got=0 [PASS] editing the guard file itself (should pass) expect=0 got=0 ``` 先合這支,才能安全刪掉 InkStoneCo 本機 `.claude/hooks/` 那份而不倒退保護力。
claude-code added 1 commit 2026-08-20 11:46:40 +00:00
InkStoneCo/.claude/hooks/leo21c-write-guard.sh 2026-08-20 當天已修過兩次
誤攔(bc8a529/5e62d28),但沒人把修法帶回 ISEP——ISEP 那份還是上線當天
的舊版,會誤擋「git commit 訊息提到 leo21c」「Gitea PATCH 內文提到
leo21c」這類完全碰不到 CF 帳號的動作。

發現於 inkstone/InkStoneCo#57/inkstone/ISEP#32「同一件事只留一份」:
要把 InkStoneCo 本機的閘收斂成只剩 ISEP 這份之前,先確認 ISEP 沒有落後
——結果這支剛好是唯一反向的(其餘 4 支已修過的閘 ISEP 都領先)。

判準改成只認「這個指令會不會真的寫到那台」:
① 寫入請求打到 *.leo21c.workers.dev(POST/PUT/PATCH/DELETE/--data/-d/trigger)
② 用它的 CF 帳號 id 跑 wrangler/acr
其餘一律放行,不管文字裡提到什麼。

實測 6/6(4 該放行/2 該擋,含這次要修的兩個誤攔案例):見 PR 說明。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
claude-code added 1 commit 2026-08-20 11:49:37 +00:00
發現於 inkstone/InkStoneCo#57/inkstone/ISEP#32:要把 InkStoneCo 本機
`.claude/hooks/arcrun-intent-guard.sh`(連同它同目錄的 arcrun_intent_guard.py)
移除、改吃 ISEP 這份之前,實測 ISEP 版才發現 `hooks/arcrun-intent-guard.sh`
呼叫的 `arcrun_intent_guard.py` 從未進過 ISEP 的 git 歷史(`git log --all` 0
命中)——`exec python3 "$DIR/arcrun_intent_guard.py"` 找不到檔案,
python3 直接噴 OS 層錯誤、exit 2,**每一次 Write/Edit/MultiEdit 都被無條件擋下**,
不是「規則判定違規才擋」,是檔案不存在導致的硬當機。

這比 kbdb_cmd_check.py 那次(PR #39)更嚴重:那次是「該擋的沒擋」(靜默放行),
這次是「不管寫什麼都擋」——方向相反,但同一個病根:hook 的 shell 外殼進了
git,Python 主體沒有。

修法:把 InkStoneCo 本機那份(唯一存在的正本)原樣搬進來。這支腳本本來就設計
成離開 InkStoneCo 語境會優雅放行(`rules_path` 不存在 → return 0),只是
之前連跑到那行都做不到。

實測 3 種情境:
- ISEP 語境(沒有 intent-rules.json):exit 0(修好前是 exit 2,任何寫入都被當機式擋下)
- InkStoneCo 語境、合法內容:exit 0
- InkStoneCo 語境、真違規(`ON_FAILURE` 這種不存在的邊):exit 2(行為不變,沒有變寬鬆)

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
claude-code added 1 commit 2026-08-20 12:06:26 +00:00
總管複驗 PR 時發現 subagent 只補了一個空殼,還有第二個同款的:

  arcrun-intent-guard.sh      → exec 不存在的 .py ⇒ 擋掉全部(吵,PR 已修)
  irreversible-dispatch-guard.sh → 同款,但寫法是
      python3 <不存在> 2>/dev/null || echo '{"verdict":"OK"}'
    ⇒ **靜默放行全部**(危險,本 commit 補)

實測同一份派工單「驗過了就把舊分支刪掉」:
  InkStoneCo 版(有 .py)exit=2 擋 / ISEP 版(缺 .py)exit=0 放行
補完後:不可逆派工 exit=2、正常派工 exit=0、合規工作流 exit=0。

系統性掃描 ISEP 全部 hooks 引用的同目錄檔案:補完後 0 個缺檔(InkStoneCo 本來就是 0)。
順帶把 InkStoneCo 的 hooks/tests/ 四支既有測試一併帶過來。

🔴 這件事很重要:若先併 InkStoneCo#64(刪掉 .claude/hooks/),
   這台機器會失去那支唯一還能用的副本——變成真的沒有那道閘。
claude-code merged commit 17de121017 into main 2026-08-20 12:06:52 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: inkstone/ISEP#40