Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f855d82573 | |||
| 17de121017 | |||
| c1d80756d7 | |||
| b790c3a78d | |||
| 1dc97f0bd6 | |||
| a7ea0283ac | |||
| 0cdb6f2c05 | |||
| c01a39541e | |||
| 92a4138f93 | |||
| b9d450eb37 | |||
| 0946f702d7 | |||
| df0d4ed396 | |||
| e16d21435f | |||
| b5c4ef3540 | |||
| 410771e883 | |||
| 64dae34efa | |||
| 6d61c10cb8 | |||
| e7bea04862 |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "isep",
|
||||
"description": "InkStone Environment Plugin —— leo 的 Claude Code 環境唯一真相源:43 支機械閘(53 條註冊,白話盤點見 docs/hooks-inventory.md)、7 支 slash command、2 支 skill、27 支腳本,外加治理規範與標籤真相源。本機與雲端裝同一份,沒有子集。",
|
||||
"version": "0.2.1",
|
||||
"version": "0.0.0",
|
||||
"keywords": [
|
||||
"inkstone",
|
||||
"guardrails",
|
||||
|
||||
+13
-1
@@ -101,9 +101,21 @@ claude -p '請執行 git tag -a v9.9.9 -m test'
|
||||
機器碰不到 claude.ai 的 Cloud environment 設定,這段一定要你動手。
|
||||
看到跟「該看到」不一樣就停下來,把畫面貼回 `inkstone/InkStoneCo#14`。
|
||||
|
||||
### B0 — 先讓機器把要貼的東西產生好(不要自己拼湊)
|
||||
|
||||
```
|
||||
bash scripts/make-cloud-env.sh
|
||||
```
|
||||
|
||||
它會去既有的 `.env` 把值讀出來,產生一個**含真實值、可直接複製**的檔到
|
||||
`~/.claude/cloud-env/<時間>.txt`(權限 600,**刻意不在任何 repo 裡**),只把路徑印出來。
|
||||
變數的**名字**寫在腳本裡(要加變數就加在那個清單),**值不進版控、不進對話**。
|
||||
|
||||
🔴 **貼完就刪那個檔**(指令印在它自己最後一行)。
|
||||
|
||||
### B1 — 設定(一次性)
|
||||
|
||||
claude.ai → **Cloud environments** → 你的環境:
|
||||
打開上一步產生的檔,裡面兩塊分別貼進 claude.ai → **Cloud environments** → 你的環境:
|
||||
|
||||
1. **Environment variables** 加一個
|
||||
- 名稱:`GITEA_TOKEN_CLAUDE_CODE`
|
||||
|
||||
@@ -191,7 +191,9 @@
|
||||
|
||||
## E. 兩個裁決題(我先按自己的判斷做了,你打回我就改)
|
||||
|
||||
### E1. E1「PR-only,禁止直接 push 預設分支」要不要套到所有 repo?
|
||||
### E1. ~~PR-only 要不要套到所有 repo?~~ 🔴 **已被 leo 2026-08-20 推翻:全部 repo、全部角色一律 PR-only(見規範 §8.1)。下面是當時的提案,保留作歷史。**
|
||||
|
||||
#### 原提案
|
||||
|
||||
- **衝突點**:你的 CLAUDE.md 明寫「總管推 main **自己裁**(但要逐筆看過那些 commit)」,
|
||||
原稿要求全部走 PR。兩者不能同時成立。
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# SDD × Gitea 治理規範
|
||||
|
||||
```
|
||||
version: 0.7.0
|
||||
version: 0.10.0
|
||||
status: 現行(本檔的修改依 §9 走 issue)
|
||||
scope: 所有安裝 ISEP 的環境(本機 CC 與雲端 CC)
|
||||
distribution: 隨 ISEP 發佈,ISEP repo 是唯一編輯點(§11)
|
||||
@@ -9,6 +9,12 @@ lineage: v0.5.0 draft by claude.ai(存檔 _draft-claude-ai-v0.5.0.md)
|
||||
→ v0.6.0 由總管對照現場實況修訂,逐條分歧見 DIVERGENCE-v0.5.0-to-v0.6.0.md
|
||||
→ v0.7.0 併入全局遍歷(14 repo/156 open/45 張管理票分六群,§13)與新舊票 mapping(§14);
|
||||
依 leo 指正:規劃不另立文件,修正本檔就是新版
|
||||
→ v0.8.0 三源整合定案(§15):claude.ai 兩份規劃 × 舊票需求 × 既有機制,
|
||||
逐領域對照、三處矛盾解法、動工順序——leo 2026-08-20 核准
|
||||
→ v0.9.0 leo 裁定全面 PR-only(§8.1):所有 subagent、地端與雲端總管一律走 PR,
|
||||
推翻總管原本「只有 ISEP 走 PR-only」的提案
|
||||
→ v0.10.0 M4.0 補上「里程碑怎麼組成」(目標→遍歷票池→缺口才補票→定下不改);
|
||||
M4.3 改寫成「定下就不改,尤其不准因為做不完而打折」——leo 2026-08-20 訂正
|
||||
```
|
||||
|
||||
---
|
||||
@@ -121,23 +127,36 @@ s/triage ──驗傷通過──▶ s/backlog ──排進 milestone──▶ s
|
||||
|
||||
## 4. Milestone 規則(= sprint = 可測試版本)
|
||||
|
||||
- **M4.1** 命名 `vX.Y`,必設 due date。
|
||||
- **M4.0(怎麼組成一個 milestone)** 🔴 **順序是:leo 給目標 → 遍歷票池找出「達成它需要哪些票」→
|
||||
池裡沒有的才補開 → 定下,之後不改。**
|
||||
|
||||
```
|
||||
leo 說要達成什麼
|
||||
↓
|
||||
總管遍歷 issues 池(跨 repo),找出達成這個目標需要關掉哪些票
|
||||
↓
|
||||
某一塊沒有票承接 ⇒ 那才是真缺口 ⇒ 補開一張(不是在里程碑裡編任務)
|
||||
↓
|
||||
組成定下 ← 從這裡開始,內容不再變動
|
||||
```
|
||||
|
||||
- **不是**「總管想做什麼就放什麼」,也**不是**「先訂五件事再看做得完幾件」。
|
||||
- 里程碑的名字寫**這個里程碑在做什麼事**,不是版本號(leo 2026-08-20)。
|
||||
|
||||
- **M4.1** 必設 due date。
|
||||
- **M4.2** Deliverable = **一個可測的新版本號**。所有掛入 leaf 關閉後,可從預設分支打出通過驗收的版本。
|
||||
- **M4.3** **Timebox 到期不自動關、不自動打 tag。** 到期強制做一次降 scope 對帳(未完成 leaf 搬下一 milestone)並通知 leo。
|
||||
🔴 自動打 tag 會製造假交付——tag 永遠只在「驗過了」之後發生。
|
||||
- **M4.3(定下就不改,尤其不准打折)** 🔴 **組成一經定下,不因為做不完而縮減。**
|
||||
|
||||
> leo 2026-08-20:「**milestone 確定後怎麼可以再把東西移除?定下工作自己刪掉是什麼意思?
|
||||
> 根本就沒有什麼降**⋯⋯而不是要做 5 件事,做不到就改成 2 件,**自己打折**。」
|
||||
|
||||
- **Timebox 到期:不自動關、不自動打 tag、不把票移出。** 到期只做一件事:通知 leo。
|
||||
- 做不完就是**還沒完成**,里程碑保持開著,百分比就顯示真實的完成度——
|
||||
那個數字本來就是要拿來看「還差多少」的。把分母改小只是讓它說謊。
|
||||
- 自動打 tag 會製造假交付——tag 永遠只在「驗過了」之後發生。
|
||||
- ⚠️ 唯一的例外是**目標本身變了**(leo 改了要達成什麼)⇒ 那是重新走一次 M4.0,不是打折。
|
||||
- **M4.4** Milestone 關閉 = release tag,一對一。「已交付」唯一合法形式是 **tag 存在且裝得起來**;打 tag 前置 open issues = 0(§8 E12)。
|
||||
- **M4.5** Description 只寫版本目標一句 + tracking 連結。討論回 tracking issue。
|
||||
- **M4.7(降 scope 必須留痕)** 🔴 **把票移出里程碑,必須同時寫進該里程碑的 description。**
|
||||
格式:原本幾張、移走哪幾張、為什麼、移去哪裡。
|
||||
- **禁的不是降 scope**——卡人閘時降 scope 就是 M4.3 要的。禁的是**降得無聲無息**。
|
||||
- 為什麼寫在 description 不是寫在票裡:**leo 看的是百分比那個畫面**,
|
||||
他不會為了確認 100% 是不是真的而去逐張點票。**痕跡要留在他會經過的地方。**
|
||||
- 來由(2026-08-20 實犯):`v0.2.0` 本來 6 張,`#5` 卡人閘被移出 ⇒ 分母 6 變 5 ⇒ 顯示 100%。
|
||||
leo 當場問「為什麼還有很多 issues 開放中」。
|
||||
🔴 這與 §3.4(審核完沒關票 ⇒ 數字偏低)是**同一個病的兩面**:
|
||||
畫面上的數字不等於實際狀態,而 leo 只看得到畫面。
|
||||
- 機械閘:`inkstone/ISEP#24`。
|
||||
|
||||
- **M4.6** 🔴 **release note 寫在 Gitea Releases 裡,不寫在 README。**(leo 2026-08-20:「release 不是寫在 readme,要放在 release 裡」)
|
||||
README 不得自行宣稱版本號——那會產生第二份會漂移的版本真相。
|
||||
|
||||
@@ -244,11 +263,11 @@ s/triage ──驗傷通過──▶ s/backlog ──排進 milestone──▶ s
|
||||
|
||||
| # | 封什麼路 | 用什麼封 | 現況 |
|
||||
|---|---|---|---|
|
||||
| E1 | 直接 push 預設分支 | branch protection:PR-only | ◐ 現有 `main-and-prod-push-guard.sh` 語意相反(擋 subagent、放行總管)。**本版只對 ISEP 開 PR-only**,見 §8.1 |
|
||||
| E1 | 直接 push 預設分支 | branch protection:PR-only,**全部 repo、全部角色**(§8.1) | ◐ 現有 `main-and-prod-push-guard.sh` 只擋 subagent、放行總管 ⇒ **與本條不符,要改**:總管與雲端一律同擋 |
|
||||
| E2 | PR 不關聯 issue | PR 模板必含 `closes #`,缺漏即 fail | ❌ 待建 |
|
||||
| E3 | 手動關 leaf | hook 攔截;只放行 `close/*` 與 §6.2 人執路徑 | ❌ 待建 |
|
||||
| E4 | 被 block 的票先關 | Gitea issue dependency | ✅ 平台原生,已驗證可用 |
|
||||
| E5 | Milestone 悄悄過期 | job:到期做降 scope 對帳 + 通知(**不自動關、不自動打 tag**) | ❌ 待建(先做成手動腳本,見 §8.2) |
|
||||
| E5 | Milestone 悄悄過期 | job:到期只通知 leo(**不自動關、不打 tag、不移票**,M4.3) | ❌ 待建(先做成手動腳本,見 §8.2) |
|
||||
| E6 | 代理越過人閘 | PreToolUse hook | ◐ 現有 `irreversible-dispatch-guard.sh`/`prod-write-guard.sh` 覆蓋一部分 |
|
||||
| E7 | SDD 內出現 leaf 連結 | pre-commit lint | ❌ 待建 |
|
||||
| E8 | Tracking issue 掛 milestone | job 摘除並告警 | ❌ 待建 |
|
||||
@@ -261,13 +280,24 @@ s/triage ──驗傷通過──▶ s/backlog ──排進 milestone──▶ s
|
||||
| E15 | 代理硬做只有人能做的事 | 代理端無對應 tool 或 token;唯一出口是開 `human/exec` 票 | ◐ 部分(credential 機制已擋一部分,D36) |
|
||||
| E16 | 標籤漂移 | 走 Gitea labels API 依 `labels.yaml` 校正:缺的補、改的還原、多的**只告警不刪** | ❌ 待建(`ISEP#4`) |
|
||||
|
||||
### 8.1 E1 的適用範圍(裁決記錄)
|
||||
### 8.1 E1 的適用範圍:**全部 repo、全部角色,一律 PR-only**(leo 2026-08-20 裁定)
|
||||
|
||||
**只有 ISEP 走 PR-only;其他 repo 維持現行「總管推 main 自己裁」。**
|
||||
> leo 原話:「**所有 subagent 都是 PR only,在雲端地端總管所做的都是 PR-only。**」
|
||||
|
||||
- 理由:ISEP 壞掉 = **所有 session 一起壞**,值得多一道摩擦;其他 repo 壞掉只影響自己。
|
||||
- 一刀切到 14 個 repo 會在 leo 最忙的時候把整條線卡在「等總管開 PR」。
|
||||
- 這條命中四題公式的「跨專案結構」⇒ 已記為裁決題(`DIVERGENCE` §E1),leo 可打回。
|
||||
```
|
||||
subagent(地端/雲端) → 只能推自己的分支,開 PR ← 擋
|
||||
總管 (地端/雲端) → 只能推自己的分支,開 PR ← 擋
|
||||
leo → 他自己的操作不在此限
|
||||
```
|
||||
|
||||
🔴 **沒有例外,不分 repo。** 這條推翻了總管原本的判斷(原提案:只有 ISEP 走 PR-only,
|
||||
其他 repo 維持「總管推 main 自己裁」,理由是怕卡住 leo)。
|
||||
leo 直接裁定全面適用——**歷史紀錄留在 `DIVERGENCE-v0.5.0-to-v0.6.0.md` §E1,該段已被本條推翻。**
|
||||
|
||||
**因此要改的**:`main-and-prod-push-guard.sh` 目前的判準是
|
||||
「`CLAUDE_CODE_CHILD_SESSION=1` 才擋」⇒ 只擋 subagent、放行總管,**與本條不符**。
|
||||
改成不分角色一律擋推預設分支;`/tmp/.main-push-ok` 那套「總管看過」的戳記機制隨之作廢
|
||||
(PR 的 review 就是那道確認,不需要第二套)。排在群 4「派工與交付紀律」。
|
||||
|
||||
### 8.2 所有 job 第一版都不依賴 Gitea Actions runner
|
||||
|
||||
@@ -582,6 +612,58 @@ leo 08-17 診斷見公理 3;08-17 實測:文字層的閘 **8 次誤攔、0
|
||||
|
||||
---
|
||||
|
||||
## 15. 三源整合定案(leo 2026-08-20 核准)
|
||||
|
||||
三源=claude.ai 兩份規劃(v0.5.0 draft+`InkStoneCo#40` forge-discipline)× 45 張舊票 × 既有機制。
|
||||
|
||||
### 15.1 方向(四句,其餘全是它們的展開)
|
||||
|
||||
1. **機制只有一份。** 環境、標籤、規範、版本號都是單一真相源;本機與雲端裝同一個 plugin,沒有子集。
|
||||
2. **閘封動作,不封措辭。** 伺服器端擋不可逆;手寫 hook 擋高代價動作(block);
|
||||
hookify+additionalContext 只提醒(永遠 warn);skill 管 regex 表達不了的判斷。
|
||||
3. **一切要留痕、可量測。** 閘的動作、開場全局、里程碑百分比——leo 看到的畫面就是實況。
|
||||
4. **進度=舊票關掉幾張。** 版本只是讓閘生效的載具,release note 寫明關了哪張票。
|
||||
|
||||
### 15.2 工作順序(六個里程碑,各 repo 同名,內容一經確定不增不減)
|
||||
|
||||
| 順 | 里程碑 | 來源票(由目標遍歷票池而來,M4.0) |
|
||||
|---|---|---|
|
||||
| 0 | 讓閘擋對東西 | `InkStoneCo#56 #23 #22 #36 #55 #1` |
|
||||
| 1 | 讓規則的效果看得見 | `InkStoneCo#48 #17 #20 #18`、`Arcrun#86 #142 #81` |
|
||||
| 2 | 同一件事只留一份 | `InkStoneCo#14 #57 #37 #11`、`arcrun-rag#116 #123 #122 #88`、`Arcrun#109`、`system-dev-template#2 #3` |
|
||||
| 3 | 不要卡在 leo 身上 | `InkStoneCo#15 #38 #34 #31 #52` |
|
||||
| 4 | 派工與交付紀律 | `InkStoneCo#12 #28`、`arcrun-rag#47 #124`、`Arcrun#93 #143 #131`、`system-dev-template#7` |
|
||||
| 5 | 票與文件歸位 | `InkStoneCo#9 #49 #10 #8 #5`、`system-dev-template#1 #4` |
|
||||
|
||||
這六群的組成是照 M4.0 走出來的:leo 給的目標是「把管理這條線做對」,
|
||||
總管遍歷 14 repo/156 張 open 票,挑出 44 張達成它需要關掉的,**沒有補開任何新任務票**。
|
||||
排序判準=「什麼擋住什麼」:閘不修好,其他群的成果會被誤攔咬到;沒有留痕,修了也量不出變好。
|
||||
`#40` 是憲法,貫穿全部;`#48` 是 `#40` warn 校準的資料前提,所以排群 1 之首。
|
||||
|
||||
### 15.3 三處矛盾的定案
|
||||
|
||||
1. `#40`「hook 只減不增」vs E 清單要 ~11 支新閘 ⇒ 新封路優先做在**伺服器端**或 **warn 層**;
|
||||
要新增 `.sh` 必須在 PR 說明為何前兩層做不到。
|
||||
2. warn-first vs hookify 的 warn 不進 AI ⇒ warn 一律用 `additionalContext`;
|
||||
新規則從 warn 出生,憑 `#48` 的留痕數據才升 block。
|
||||
3. milestone 到期自動關+打 tag ⇒ 否決(M4.3)。
|
||||
|
||||
### 15.4 待 leo 裁(不擋群 0 開工)
|
||||
|
||||
`#37` 兩份 repo 哪份為準(建議 `inkstone/*`)/`#5` `#8` 轉 hub 或作廢/
|
||||
08-20 兩支未經 warn 期的 block 閘,隨盤點表(`docs/hooks-inventory.md`)一起審。
|
||||
|
||||
**已裁**:PR-only 全面適用(§8.1,2026-08-20)。
|
||||
|
||||
### 15.5 跨 repo 的載體:ISEP 的六張群票
|
||||
|
||||
Gitea 的 milestone 只管得到同一個 repo,所以六個群在 `inkstone/ISEP` 各有一張 `hub` 票
|
||||
(`ISEP#30`–`#35`),別的 repo 的舊票用 **Gitea 原生 dependency** 指到它
|
||||
(leo 2026-08-20;跨 repo dependency 已實測可用)。
|
||||
⇒ **群票的相依全關,群票才關得掉**;六張群票的狀態就是六群的進度。
|
||||
|
||||
---
|
||||
|
||||
## 附:Label 全集(快照;唯一真相為 `labels.yaml`)
|
||||
|
||||
```
|
||||
|
||||
Executable
+212
@@ -0,0 +1,212 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""arcrun 意圖工作流「回饋 hook」主體(D38,2026-08-01)。
|
||||
|
||||
由 arcrun-intent-guard.sh 呼叫(stdin = Claude Code 的 PreToolUse JSON)。
|
||||
獨立成 .py 的理由:規則含大量引號與 regex,包在 shell 單引號裡會被吃掉
|
||||
(2026-08-01 實際踩到:'"componentId"' 被 shell 剝成裸字 → NameError)。
|
||||
|
||||
判準來源:system-dev/docs/3-specs/arcrun-usable/intent-rules.json
|
||||
——與判分器共用同一份,避免兩套判準漂移。
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
d = json.load(sys.stdin)
|
||||
except Exception:
|
||||
return 0
|
||||
|
||||
ti = d.get("tool_input") or {}
|
||||
|
||||
# 收集這次要送出的文字:檔案寫入 / 編輯 / bash 指令 / MCP 參數都看
|
||||
parts = []
|
||||
for k in ("content", "new_string", "command", "prompt"):
|
||||
v = ti.get(k)
|
||||
if isinstance(v, str):
|
||||
parts.append(v)
|
||||
for k in ("graph", "yaml", "workflow", "triplets", "body"):
|
||||
v = ti.get(k)
|
||||
if v is not None:
|
||||
parts.append(v if isinstance(v, str) else json.dumps(v, ensure_ascii=False))
|
||||
body = "\n".join(parts)
|
||||
if not body.strip():
|
||||
return 0
|
||||
|
||||
proj = os.environ.get("CLAUDE_PROJECT_DIR") or os.getcwd()
|
||||
rules_path = os.path.join(
|
||||
proj, "system-dev", "docs", "3-specs", "arcrun-usable", "intent-rules.json")
|
||||
if not os.path.exists(rules_path):
|
||||
return 0
|
||||
R = json.load(open(rules_path, encoding="utf-8"))
|
||||
rules = {r["id"]: r for r in R["rules"]}
|
||||
LEGAL = re.compile(R["legal_edges"]["regex"])
|
||||
|
||||
# 只在「這確實是 arcrun 意圖工作流」時才出手,避免亂吵。
|
||||
# 排除文件語境的雜訊(2026-08-01 自己編修 GUIDE 時被自己誤攔):
|
||||
# markdown 表格列、引用行、註解行——教材列舉或引述錯誤寫法時必然含箭頭
|
||||
def is_prose(l):
|
||||
s = l.strip()
|
||||
return (s.startswith("|") or s.startswith(chr(62) + " ")
|
||||
or s.startswith("#") or s.startswith("//"))
|
||||
|
||||
triplet_lines = [l.strip() for l in body.split("\n")
|
||||
if (chr(62) * 2) in l and not is_prose(l)]
|
||||
# 2026-08-01 補漏:原本只認 JSON 圖(帶引號)⇒ **YAML 圖整份被放行**。
|
||||
# leo 那次 haiku 失敗寫的正是 YAML(componentId: code,無引號),hook 完全沒攔到。
|
||||
is_graph_json = ('"componentId"' in body) or ('"edges"' in body)
|
||||
is_graph_yaml = bool(re.search(r'^\s*-?\s*componentId\s*:', body, re.M)
|
||||
or re.search(r'^\s*edges\s*:', body, re.M))
|
||||
is_graph = is_graph_json or is_graph_yaml
|
||||
if not triplet_lines and not is_graph:
|
||||
return 0
|
||||
|
||||
# 文件檔(.md)本來就會「引述錯誤寫法來教學」=R6 關鍵詞必然出現。
|
||||
# 對 .md 只保留結構性規則,不做過時教材主張的字面偵測。
|
||||
is_doc = str(ti.get("file_path") or "").endswith(".md")
|
||||
|
||||
# 🔴 2026-08-08:兩道 hook 直接打架,本閘誤攔 wiki 落帳。
|
||||
# `wiki-first-police` **要求**我在 wiki 用知識三元組 `A >> 關係 >> B`
|
||||
# (leo 2026-08-01 立:「每件事牽涉到 2 個 repo,就可以在該事件查到那兩個 repo」)。
|
||||
# 但本閘把任何含 `>>` 的行都當成 Arcrun 工作流的邊 ⇒ 落帳寫
|
||||
# 「勸告治不了停 >> 所以改成 >> InkStoneCo:...」就被判「非法邊」+「第一個節點不是 input」。
|
||||
# ⇒ 同一個符號、兩套約定。**.md 裡沒有真的工作流圖時,本閘不該有意見。**
|
||||
# (有 componentId/edges 的 .md=真的在寫工作流文件,仍照常檢查。)
|
||||
if is_doc and not is_graph:
|
||||
return 0
|
||||
|
||||
# 🔴 2026-08-08 第二例:hook/腳本自己的原始碼裡出現 `>>` 是**正則樣式或 shell 重導向**,
|
||||
# 不是 Arcrun 工作流的邊。實撞:wiki-first-police.sh 裡的
|
||||
# `grep -qE '… >> 真身在 >> …'`(比對知識三元組用的樣式)被判「三元組格式錯」。
|
||||
# ⇒ 機制程式碼一律豁免;真的工作流定義不會住在 .claude/hooks/。
|
||||
_fp = str(ti.get("file_path") or "")
|
||||
if "/.claude/hooks/" in _fp or _fp.endswith((".sh", ".py")):
|
||||
if not is_graph:
|
||||
return 0
|
||||
|
||||
hits = []
|
||||
|
||||
def hit(rid, detail):
|
||||
if not any(h[0] == rid for h in hits):
|
||||
hits.append((rid, detail))
|
||||
|
||||
COND = re.compile(
|
||||
r"判斷|檢查|如果|大於|小於|是否|超過|比較|驗證|check|if_|ifcontrol|compare|verify|threshold",
|
||||
re.I)
|
||||
|
||||
if triplet_lines:
|
||||
edges_of = {}
|
||||
parsed = []
|
||||
for l in triplet_lines:
|
||||
# 2026-08-05 修:先剝掉 YAML 清單語法再切段。
|
||||
# 原本直接切,第一段會是 `- "input` 而不是 `input`
|
||||
# => R1「第一個節點必須是 input」永遠判為不符
|
||||
# => 任何對 flow: 區塊的編輯都被擋死(實撞:改 rag-ingest-card 三次全被擋,
|
||||
# 而該檔 flow 本來就合法)。
|
||||
l = l.strip()
|
||||
if l.startswith("- "):
|
||||
l = l[2:].strip()
|
||||
l = l.strip('"').strip("'").strip()
|
||||
seg = [p.strip() for p in l.split(">>")]
|
||||
if len(seg) != 3:
|
||||
hit("R5-triplet-format", l[:60])
|
||||
continue
|
||||
a, e, c = seg
|
||||
parsed.append((a, e, c))
|
||||
if not LEGAL.match(e):
|
||||
hit("R2-illegal-edge", "非法邊「%s」(%s)" % (e, l[:50]))
|
||||
edges_of.setdefault(a, []).append(e)
|
||||
|
||||
if parsed:
|
||||
# 2026-08-13 修(同一段的第二次誤攔修正,前一次見上方 08-05 註解):
|
||||
# R1 問的是「**整個工作流**的第一個節點是不是 input」——
|
||||
# 那個問題只有在**看得到整份檔案**時才答得出來。
|
||||
#
|
||||
# `Write` 送的是 `content`(整檔)⇒ parsed[0] 真的是第一個節點 ✅
|
||||
# `Edit` 送的是 `new_string`(片段)⇒ parsed[0] 是**那段片段的第一行**,
|
||||
# 而增量編輯必然要帶一行既有的錨點來定位插入點
|
||||
# ⇒ **錨點永遠被誤判成「工作流起點」**,不管它實際排第幾。
|
||||
#
|
||||
# ⇒ 這會結構性地擋住**任何**對既有多行 `flow:` 的增量修改。
|
||||
# 實撞(2026-08-13):往 `km_wiki_ingest.yaml` 的 flow 尾端接五行新邊,
|
||||
# 錨點是 `decide >> 對每個 update_item >> update_entry`
|
||||
# ⇒ 報「第一個節點是『decide』」。而該檔第一個節點叫 `seed`,
|
||||
# 是檔案自己 §4 註解寫明的刻意設計(避開引擎的觸發保留字)。
|
||||
#
|
||||
# 🔴 只放寬 R1,**R2(邊合法性)/R3/R4/R5 對片段照樣生效**——
|
||||
# 那幾條檢查的是內容本身,沒有「位置語意」的問題。
|
||||
if isinstance(ti.get("content"), str):
|
||||
first = parsed[0][0]
|
||||
if first.lower() != "input":
|
||||
hit("R1-first-node-input", "第一個節點是「%s」" % first)
|
||||
for a, outs in edges_of.items():
|
||||
branchy = any(
|
||||
o in ("ON_TRUE", "ON_FALSE") or o.startswith("ON_BRANCH") for o in outs)
|
||||
if COND.search(a) and not branchy:
|
||||
hit("R3-condition-via-on_success",
|
||||
"「%s」有條件語意,出邊卻只有 %s" % (a, "/".join(sorted(set(outs)))))
|
||||
|
||||
# R4:code 節點在做流程控制
|
||||
LOGIC = re.compile(
|
||||
r"\bif\s*\(|\belse\b|\bfor\s*\(|\bwhile\s*\(|\.filter\(|\.map\(|\?\s*[^:\n]{1,40}\s*:")
|
||||
if is_graph:
|
||||
m = re.search(r"\{.*\}", body, re.S)
|
||||
if m:
|
||||
try:
|
||||
g = json.loads(m.group(0))
|
||||
for n in (g.get("nodes") or []):
|
||||
if n.get("componentId") == "code":
|
||||
ctx = json.dumps(
|
||||
n.get("config") or n.get("payload") or n, ensure_ascii=False)
|
||||
if LOGIC.search(ctx):
|
||||
hit("R4-code-node-doing-logic",
|
||||
"code 節點「%s」內含流程控制" % n.get("id"))
|
||||
except Exception:
|
||||
pass
|
||||
if not any(h[0] == "R4-code-node-doing-logic" for h in hits):
|
||||
# 2026-08-01 補:原本只認 JSON(帶引號)與 `>> code`,
|
||||
# 但 leo 那次 haiku 失敗寫的是 YAML(componentId: code,無引號)⇒ 漏抓。
|
||||
looks_code = re.search(r">>\s*(code|js|script)\b", body, re.I) or \
|
||||
re.search(r'"componentId"\s*:\s*"code"', body) or \
|
||||
re.search(r'^\s*-?\s*componentId\s*:\s*["\']?code["\']?\s*$', body, re.M) or \
|
||||
re.search(r'^\s*-?\s*(id|name)\s*:\s*["\']?(code|js|script)["\']?\s*$', body, re.M)
|
||||
if looks_code and LOGIC.search(body):
|
||||
hit("R4-code-node-doing-logic", "偵測到 code 節點且內容含 if/for/filter")
|
||||
|
||||
# R6:過時教材主張(會把 AI 擋在正解門外)
|
||||
if not is_doc and (
|
||||
re.search(r"(不支援|沒有|無)\s*(原生)?\s*(條件分支|ON_TRUE|ON_FALSE)", body)
|
||||
or re.search(r"只有\s*ON_SUCCESS\s*(與|和|、)\s*(FOREACH|對每個)", body)):
|
||||
hit("R6-stale-doc-claim", "文字聲稱引擎不支援條件分支")
|
||||
|
||||
if not hits:
|
||||
return 0
|
||||
|
||||
out = []
|
||||
out.append("🎓 arcrun-intent-guard:這份意圖有 %d 處可以更好——下面是**正確寫法,可直接照抄**。"
|
||||
% len(hits))
|
||||
out.append("")
|
||||
for rid, detail in hits:
|
||||
r = rules.get(rid, {})
|
||||
out.append("── %s" % rid)
|
||||
out.append(" 現場:%s" % detail)
|
||||
out.append(" ✅ 正確寫法:%s" % r.get("teach", ""))
|
||||
if r.get("fix_example"):
|
||||
out.append(" 範例(照抄改內容即可):")
|
||||
for line in r["fix_example"].split("\n"):
|
||||
out.append(" %s" % line)
|
||||
if r.get("payload_hint"):
|
||||
out.append(" payload:%s" % r["payload_hint"])
|
||||
out.append("")
|
||||
out.append("判準來源:system-dev/docs/3-specs/arcrun-usable/intent-rules.json(與判分器共用)")
|
||||
out.append("不確定時**問實例**:POST /cypher/search,回應裡的 branch_hint 會直接告訴你分支怎麼接。")
|
||||
sys.stderr.write("\n".join(out) + "\n")
|
||||
return 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/bin/bash
|
||||
# 管什麼: 對外接觸 GitHub 的寫入動作(gh CLI 高頻 API、git push/remote add 指向 github.com)——一律先擋,要 leo 手動解保險才放行。
|
||||
# 為什麼: D20(2026-07-02)——兩個帳號因高頻寫入被 GitHub flag 永久拿不回;讀不設限(讀不是 abuse),只擋寫。
|
||||
# 誤觸時怎麼關: 讀取(clone/fetch/pull/curl 抓檔)一律放行;真要寫 GitHub,leo 跑 scripts/github-arm.sh 解保險;純粹提到 github.com 的文字(heredoc/commit message/留言)不算數,見下方判準。
|
||||
# github-contact-guard.sh — GitHub 接觸保險(D20,2026-07-02)
|
||||
# 背景:兩個帳號因高頻動作被 flag 拿不回(幾十顆星+issues 全損)。
|
||||
# 設計:戰鬥機武器保險模式——平時所有 github.com 接觸一律機械擋下(exit 2),
|
||||
@@ -33,6 +36,13 @@ except Exception:
|
||||
|
||||
[ -z "$CMD" ] && exit 0
|
||||
|
||||
# 2026-08-20(inkstone/InkStoneCo#23 comment, #56):a heredoc body is data, not an
|
||||
# instruction. Writing docs/TESTING.md (one example line of a real push command,
|
||||
# meant for a human to try later) got blocked because the whole heredoc body was
|
||||
# scanned for keywords. Strip heredoc bodies before matching; on failure fall back
|
||||
# to the original string (fail-open on "did this helper run", not on the verdict).
|
||||
CMD=$(printf '%s' "$CMD" | python3 "$(dirname "$0")/lib/strip_heredoc.py" 2>/dev/null || printf '%s' "$CMD")
|
||||
|
||||
# 命中判定(D20 邊界,2026-07-05 leo 拍板——Facebook 比喻定調):
|
||||
# GitHub 不在乎你「讀」(clone/fetch/抓 release,不管實名匿名、自己的還別人的——那是它原本的功能,
|
||||
# 像 FB 不禁你讀貼文)。它 abuse-detect 的是「機器人一直改/寫」(高頻 push、Actions fan-out、API 寫)
|
||||
@@ -43,10 +53,10 @@ except Exception:
|
||||
# 放行:git clone/fetch/pull/ls-remote(任何 repo,帶不帶認證都是讀)、curl/wget、go get/pip。
|
||||
HIT=""
|
||||
# ① gh CLI —— 高頻 API,全擋(讀寫混雜且走你 token,保守全擋;真要唯讀查詢個案 arm)
|
||||
if printf '%s' "$CMD" | grep -qE '(^|[;&|(]|\s)gh\s+(api|repo|issue|pr|auth|search|release|run|workflow|gist|browse)\b'; then
|
||||
if printf '%s' "$CMD" | grep -qE '(^|[;&|(`]|&&|\|\|)[[:space:]]*gh[[:space:]]+(api|repo|issue|pr|auth|search|release|run|workflow|gist|browse)\b'; then
|
||||
HIT="gh CLI(高頻 API,走你的 token)"
|
||||
# ② git 寫入動詞指向 github(push / remote add 為 push 鋪路)—— 寫入,擋
|
||||
elif printf '%s' "$CMD" | grep -qiE 'git\s+(push|remote\s+add)([^|;&]*)(github\.com)'; then
|
||||
elif printf '%s' "$CMD" | grep -qiE '(^|[;&|(`]|&&|\|\|)[[:space:]]*git[[:space:]]+(push|remote[[:space:]]+add)([^|;&]*)(github\.com)'; then
|
||||
HIT="git 寫入 → github(push/remote add)"
|
||||
# ②b 🔴 2026-08-05 補漏:上面那條只認指令裡的 **github.com 字面**
|
||||
# ⇒ `git push origin main`(remote 名指向 GitHub)**完全不會被攔**。
|
||||
@@ -60,7 +70,7 @@ elif printf '%s' "$CMD" | grep -qiE 'git\s+(push|remote\s+add)([^|;&]*)(github\.
|
||||
# 不必等 remote 名稱解析成功才判斷得出來,而 remote 名稱解析在某些 cwd 下會失敗
|
||||
# (見檔頭「2026-08-10 leo 簡化」那段的實撞紀錄)。字面查得到就直接判定,
|
||||
# 查不到才退回舊的「解 remote 名稱」那條路——兩條路都失手才會誤放行。
|
||||
elif printf '%s' "$CMD" | grep -qiE '(^|[;&|(]|\s)git\s+([^|;&]*\s)?push(\s|$)'; then
|
||||
elif printf '%s' "$CMD" | grep -qiE '(^|[;&|(`]|&&|\|\|)[[:space:]]*git[[:space:]]+([^|;&]*[[:space:]])?push([[:space:]]|$)'; then
|
||||
# 🔴 總管 2026-08-10 收窄:原版寫成「整串裡有 github.com 就擋」,
|
||||
# 於是**連 commit message 提到那個網址都會被擋**(我自己第一次要 commit 就撞到)。
|
||||
# ⇒ 改成必須是「push 的目標」:github.com 要出現在 push 之後、且中間不跨命令分隔符。
|
||||
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python3
|
||||
"""判斷一份派工單(Agent/Task 的 prompt)有沒有把「不可逆動作」寫成收工方可以自己執行的選項。
|
||||
|
||||
stdin: 派工單全文 stdout: JSON {"verdict": "BLOCK"/"OK", "hits": [[行號, 該行, 命中詞], ...]}
|
||||
|
||||
【事故(Gitea Leo/arcrun-rag#33,2026-08-09)】
|
||||
subagent 未經 leo 同意刪掉兩條遠端分支。根因不是它亂來——是派工單寫了
|
||||
「作廢就刪掉分支」,等於總管預先授權了一個不可逆動作。刪掉的那條裡還有一件
|
||||
它自己標明「等 leo 排序」的工作,一併蒸發。
|
||||
|
||||
【對照組,同一天同一個總管】#14 的派工單寫
|
||||
「🔴 刪資料不可逆。動手前先把清單寫在 issue 留言,等總管回覆確認才執行」
|
||||
⇒ 那個 agent 真的停下來等。同一個人一次寫對一次寫錯 ⇒ 證明只能靠機械閘,不能靠自律。
|
||||
|
||||
【判準】
|
||||
- 派工單裡出現「不可逆動作」的動詞+對象(刪分支/drop table/rm -rf/force push…)
|
||||
- 且該處**沒有被否定**(不是「不准刪」這種禁令句)
|
||||
- 且全文**沒有**「停下來等回覆才執行」這類守門片語
|
||||
⇒ 判定為「把不可逆動作寫成可以自己執行的選項」,擋下。
|
||||
|
||||
同時符合上述前兩點、但全文有守門片語 ⇒ 判定為 #14 那種「先回報、等確認」寫法,放行。
|
||||
|
||||
豁免:命中那一行尾巴加 `irreversible-ok`(留痕式豁免,比照本目錄其他 guard 的慣例)。
|
||||
"""
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
# 不可逆動作:動詞 + 常見對象(分支/資料/表/repo/檔案/環境…)
|
||||
IRREVERSIBLE_RE = re.compile(
|
||||
r"("
|
||||
r"刪(?:除|掉)?[^\n,。!?、;;()()]{0,12}(?:分支|branch|資料|data|table|表|db|資料庫|repo|檔案|record|entry|遠端|remote|環境|instance|實例)"
|
||||
r"|砍(?:掉)?[^\n,。!?、;;]{0,6}(?:分支|branch)"
|
||||
r"|洗掉"
|
||||
r"|清空"
|
||||
r"|格式化"
|
||||
r"|(?:硬|真)刪(?:除)?"
|
||||
r"|永久(?:刪除|移除)"
|
||||
r"|drop\s+table"
|
||||
r"|rm\s+-rf"
|
||||
r"|reset\s+--hard"
|
||||
r"|force[-\s]?push"
|
||||
r"|git\s+push[^\n]{0,20}(?:--force|-f\b)"
|
||||
r"|git\s+branch\s+-D"
|
||||
r"|git\s+push[^\n]{0,20}--delete"
|
||||
r"|delete[^\n]{0,12}(?:branch|data|table|repo|record)"
|
||||
r")",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
# 否定:這段話是在「禁止」不可逆動作,不是授權它
|
||||
NEGATION_RE = re.compile(
|
||||
r"(不准|不可|不得|不要|禁止|勿|別|莫|no\s|never\s|don't\s|do not\s)\s*$",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
# 守門片語:明確要求「停下來,等人回覆才執行」
|
||||
GATE_RE = re.compile(
|
||||
r"("
|
||||
r"先.{0,25}留言.{0,15}等.{0,12}(?:回覆|確認|同意)"
|
||||
r"|等.{0,10}(?:leo|總管|leo21c).{0,15}(?:回覆|確認|同意|批准).{0,10}(?:才|再).{0,12}(?:執行|動手|做|刪|砍)"
|
||||
r"|不准動手"
|
||||
r"|停下來.{0,10}等"
|
||||
r"|動手前.{0,15}(?:先|等待|等)"
|
||||
r"|等\s*(?:leo|總管)\s*(?:回覆|確認|同意|拍板)"
|
||||
r"|wait\s+for\s+(?:confirmation|approval|leo)"
|
||||
r"|before\s+(?:doing so|acting|deleting|executing)[^\n]{0,30}(?:wait|confirm)"
|
||||
r")",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
||||
def check(text: str):
|
||||
lines = text.split("\n")
|
||||
gate_found = bool(GATE_RE.search(text))
|
||||
|
||||
hits = []
|
||||
for i, line in enumerate(lines, start=1):
|
||||
if "irreversible-ok" in line:
|
||||
continue
|
||||
for m in IRREVERSIBLE_RE.finditer(line):
|
||||
before = line[max(0, m.start() - 8): m.start()]
|
||||
if NEGATION_RE.search(before):
|
||||
continue
|
||||
hits.append([i, line.strip(), m.group()])
|
||||
|
||||
if not hits:
|
||||
return "OK", hits, gate_found
|
||||
if gate_found:
|
||||
return "OK", hits, gate_found
|
||||
return "BLOCK", hits, gate_found
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
text = sys.stdin.read()
|
||||
verdict, hits, gate_found = check(text)
|
||||
print(json.dumps(
|
||||
{"verdict": verdict, "hits": hits, "gate_found": gate_found},
|
||||
ensure_ascii=False,
|
||||
))
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/bin/bash
|
||||
# 管什麼: Bash 分支擋「繞過 API 牆、直接對那顆資料庫執行 SQL」的指令;Write/Edit 分支擋新增 DDL/原生 SQL/新 D1 binding。
|
||||
# 為什麼: leo 2026-08-07 立 D38——KBDB 只能走 API,零 SQL、永不加表;規則掛在「KBDB」這個詞上,容易在想著「D1/建表」時漏載入。
|
||||
# 誤觸時怎麼關: 該行尾加 kbdb-sql-ok(留痕,commit 說明理由);Bash 分支的判準邏輯在 hooks/lib/kbdb_cmd_check.py,誤攔先查那支。
|
||||
# PreToolUse hook — KBDB 是 API-as-Wall:零 SQL、永不加表(L3 硬攔截)
|
||||
#
|
||||
# 【leo 2026-08-07 立】原話:
|
||||
@@ -42,6 +45,9 @@ else
|
||||
BASH_CMD=""
|
||||
fi
|
||||
if [ -n "${BASH_CMD:-}" ]; then
|
||||
# 逃生口跟 Write/Edit 分支同一個標記(留痕,commit 說明理由)——加了這支才會真的擋,
|
||||
# 之前 Bash 分支引用的檔案不存在、永遠印 "OK",逃生口自然也沒人需要,現在補上。
|
||||
case "$BASH_CMD" in *kbdb-sql-ok*) exit 0 ;; esac
|
||||
# 🔴 2026-08-07 修正:第一版做「整條命令字串比對」,結果**第四次誤擋總管**——
|
||||
# 誤擋的是 `git commit -m "...引用了那個命令字面..."`:那是在**描述**這件事,
|
||||
# 不是在執行它。同一天已被自己的閘誤擋三次(Task 分支),這是第四次。
|
||||
@@ -49,7 +55,7 @@ if [ -n "${BASH_CMD:-}" ]; then
|
||||
# 引號內、heredoc 內、commit message 內的同樣字面一律不算。
|
||||
# 判斷邏輯住在獨立檔(見該檔開頭:內嵌逃逸讓這道閘改一次壞一次)
|
||||
BASH_VERDICT=$(printf '%s' "$BASH_CMD" \
|
||||
| python3 "$(dirname "$0")/kbdb_cmd_check.py" 2>/dev/null || echo "OK")
|
||||
| python3 "$(dirname "$0")/lib/kbdb_cmd_check.py" 2>/dev/null || echo "OK")
|
||||
if [ "$BASH_VERDICT" = "BAD" ]; then
|
||||
cat >&2 <<'EOB'
|
||||
🧱 kbdb-api-wall-guard(Bash):偵測到繞過 API 牆、直接對那顆資料庫執行 SQL 的命令。
|
||||
|
||||
@@ -46,16 +46,34 @@ if printf '%s' "$cmd" | grep -q 'leo21c-write-guard'; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# leo21c 的三個座標(帳號 id/namespace/worker 網域)
|
||||
if ! printf '%s' "$cmd" | grep -qE 'leo21c|51a01bfa2665bd7bc3fd080dc40cf3e1|bfezv28v'; then
|
||||
exit 0
|
||||
# ── 判準:這個指令會不會真的把東西寫到那台?────────────────────────────────
|
||||
# 🔴 2026-08-20 第三次誤攔後收斂(前兩次:git commit 訊息、修閘自己)。
|
||||
# 舊判準是「文字裡有沒有出現座標」+「有沒有寫入動詞」,於是
|
||||
# `curl -X PATCH .../api/v1/repos/inkstone/Arcrun/issues/145 -d '{"state":"closed"}'`
|
||||
# **只因為票的內文提到那個帳號就被擋**——而那是打 Gitea,跟 CF 一點關係都沒有。
|
||||
# ⇒ 只認**兩種真的會寫到那台的形狀**,其餘一律不管文字寫了什麼:
|
||||
# ① 寫入請求打到 `*.leo21c.workers.dev`
|
||||
# ② 用它的 CF 帳號 id 去跑 wrangler/acr
|
||||
# leo 2026-08-17:「紅線寫得越細,命中關鍵字的機率越高 ⇒ 那些閘在懲罰謹慎。」
|
||||
|
||||
hit=0
|
||||
|
||||
# ① 寫入請求打到那台 worker
|
||||
if printf '%s' "$cmd" | grep -qiE 'https?://[^[:space:]"'"'"']*leo21c\.workers\.dev'; then
|
||||
if printf '%s' "$cmd" | grep -qE -- '-X *(POST|PUT|PATCH|DELETE)|--data|--data-raw|-d[[:space:]]|/trigger'; then
|
||||
hit=1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 寫入動作的形狀
|
||||
if ! printf '%s' "$cmd" | grep -qE -- '-X *(POST|PUT|PATCH|DELETE)|--data|--data-raw|-d ["'"'"'{]|wrangler +(deploy|publish|kv|d1|secret)|acr +(update|deploy|push)|/trigger|ingest|kbdb_create|kbdb_update'; then
|
||||
exit 0
|
||||
# ② 拿它的 CF 帳號去部署
|
||||
if printf '%s' "$cmd" | grep -qE 'CLOUDFLARE_ACCOUNT_ID=51a01bfa2665bd7bc3fd080dc40cf3e1'; then
|
||||
if printf '%s' "$cmd" | grep -qE 'wrangler|acr |node .*index\.js'; then
|
||||
hit=1
|
||||
fi
|
||||
fi
|
||||
|
||||
[ "$hit" = "1" ] || exit 0
|
||||
|
||||
cat >&2 <<'MSG'
|
||||
🚫 不准寫 leo 的個人帳號 leo21c(leo 2026-08-20 立)
|
||||
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,133 @@
|
||||
#!/usr/bin/env python3
|
||||
"""hooks/lib/kbdb_cmd_check.py -- shared helper for kbdb-api-wall-guard.sh's
|
||||
Bash channel (inkstone/ISEP#40 S7: helpers live in lib/, do not count as a
|
||||
hand-written gate).
|
||||
|
||||
What it guards: whether a bash command string contains a real, at-command-
|
||||
position invocation of wrangler's D1 execute subcommand (any wrapper such as
|
||||
npx/pnpm) targeting a database whose name mentions "kbdb" -- that is a
|
||||
direct-SQL bypass of the KBDB API wall (D38, leo 2026-08-07: zero SQL,
|
||||
always through the HTTP API).
|
||||
|
||||
Why this file exists (not just "why the rule exists"): the calling gate,
|
||||
hooks/kbdb-api-wall-guard.sh, used to pipe the raw command straight through
|
||||
a keyword grep. That produced the exact "keyword shows up vs. real
|
||||
instruction" confusion this repo has hit repeatedly (inkstone/InkStoneCo#23:
|
||||
the phrase showed up inside a delegation prompt that was *talking about* the
|
||||
rule, not breaking it). The fix pattern already proven on
|
||||
hooks/release-tag-guard.sh is "only count a keyword when it sits at command
|
||||
position" -- this file is that same pattern for the KBDB Bash channel,
|
||||
factored out to its own file because embedding shell-escaping-aware parsing
|
||||
inline in the .sh caused regressions each time someone touched it (see the
|
||||
.sh file's own header for that history).
|
||||
|
||||
Two extra layers vs. a plain regex:
|
||||
1. hooks/lib/strip_heredoc.py runs first (imported below) so a heredoc body
|
||||
that merely *mentions* the D1-execute pattern against kbdb as
|
||||
documentation text does not count -- same root cause as
|
||||
InkStoneCo#23/#56.
|
||||
2. Command segmentation uses shlex with punctuation_chars, so a `;`/`&`/`|`
|
||||
that appears *inside* a quoted string (e.g. a commit message) does not
|
||||
get treated as a command boundary, and text inside quotes is only
|
||||
inspected when the quoted text is itself an argument to a command that
|
||||
is genuinely at command position (e.g. a `--command` value passed to a
|
||||
real wrangler invocation) -- not when it is merely quoted prose
|
||||
describing the rule.
|
||||
|
||||
Genuine parse failures (unbalanced quotes, exotic constructs) fail OPEN
|
||||
(print "OK"), matching this repo's stated design discipline: fail-open on
|
||||
parse failure, not fail-open on the verdict itself (see release-tag-guard.sh
|
||||
header). The caller (kbdb-api-wall-guard.sh) already blocks direct file-path
|
||||
writes into kbdb/ paths and DDL/`.prepare(`/`.exec(`/`.batch(` in Write/Edit
|
||||
content through its own separate channels -- this file only covers the Bash
|
||||
CLI channel.
|
||||
|
||||
Usage:
|
||||
printf '%s' "$CMD" | python3 hooks/lib/kbdb_cmd_check.py
|
||||
-> prints exactly "BAD" or "OK" on stdout.
|
||||
"""
|
||||
import os
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from strip_heredoc import strip_heredocs # noqa: E402
|
||||
|
||||
_WRAPPERS = {"npx", "pnpm", "yarn", "bunx", "exec", "sudo", "env", "corepack"}
|
||||
_DB_HINT = "kbdb"
|
||||
_D1_TOKEN = "d1"
|
||||
_SUBCMD_TOKEN = "execute"
|
||||
|
||||
|
||||
def _segments(cmd: str):
|
||||
"""Split cmd into a list of token-lists, one per "simple command",
|
||||
breaking on real shell control operators. Quote-aware via shlex, so a
|
||||
control character inside a quoted string does not split. Returns None
|
||||
on unparseable input (caller should fail open)."""
|
||||
try:
|
||||
lex = shlex.shlex(cmd, posix=True, punctuation_chars=True)
|
||||
lex.whitespace_split = True
|
||||
tokens = list(lex)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
boundary = {";", "&", "&&", "|", "||", "(", ")", "\n"}
|
||||
segments = []
|
||||
current = []
|
||||
for tok in tokens:
|
||||
if tok in boundary:
|
||||
if current:
|
||||
segments.append(current)
|
||||
current = []
|
||||
else:
|
||||
current.append(tok)
|
||||
if current:
|
||||
segments.append(current)
|
||||
return segments
|
||||
|
||||
|
||||
def _is_kbdb_d1_execute(segment):
|
||||
"""True if this one simple command is wrangler's D1 execute subcommand
|
||||
(optionally behind a wrapper like npx/sudo/env) aimed at a database
|
||||
whose name mentions "kbdb" anywhere in its arguments."""
|
||||
i = 0
|
||||
# Skip leading VAR=value assignments (env-style prefix).
|
||||
while i < len(segment):
|
||||
head = segment[i].split("=", 1)[0]
|
||||
if "=" in segment[i] and head.replace("_", "").isalnum() and head[:1].isalpha():
|
||||
i += 1
|
||||
else:
|
||||
break
|
||||
# Skip known wrappers (npx wrangler ..., sudo wrangler ..., env X=Y wrangler ...).
|
||||
while i < len(segment) and os.path.basename(segment[i]) in _WRAPPERS:
|
||||
i += 1
|
||||
if i >= len(segment):
|
||||
return False
|
||||
cmdname = os.path.basename(segment[i])
|
||||
if cmdname != "wrangler":
|
||||
return False
|
||||
rest = segment[i + 1 :]
|
||||
if _D1_TOKEN not in rest or _SUBCMD_TOKEN not in rest:
|
||||
return False
|
||||
joined_lower = " ".join(rest).lower()
|
||||
return _DB_HINT in joined_lower
|
||||
|
||||
|
||||
def check(cmd: str) -> str:
|
||||
stripped = strip_heredocs(cmd)
|
||||
segments = _segments(stripped)
|
||||
if segments is None:
|
||||
return "OK" # parse failure -> fail open, not fail on the verdict
|
||||
for seg in segments:
|
||||
if _is_kbdb_d1_execute(seg):
|
||||
return "BAD"
|
||||
return "OK"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
cmd = sys.stdin.read()
|
||||
print(check(cmd))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env python3
|
||||
"""hooks/lib/strip_heredoc.py -- shared helper, not a gate (inkstone/ISEP#40 S7:
|
||||
helpers live in lib/ and do not count as a hand-written gate).
|
||||
|
||||
What it guards: nothing by itself. It strips the *body* of a bash heredoc out
|
||||
of a command string, keeping the start line (the control-flow part) intact.
|
||||
|
||||
Why: a heredoc body is data, not an instruction. Two mis-blocks on
|
||||
2026-08-20 (inkstone/InkStoneCo#23, #56) shared one root cause: a gate ran a
|
||||
keyword scan over the *entire* command string, heredoc body included, so text
|
||||
that merely *mentioned* a trigger phrase inside a file being written (or a
|
||||
comment being posted) was treated as if that phrase were actually being
|
||||
executed. One case was writing docs/TESTING.md (the body had one example line
|
||||
of a GitHub push command as literal text for a human to try later); the other
|
||||
was posting a Gitea comment that quoted this very ticket's own description.
|
||||
This helper only removes the body; each gate keeps its own keyword rules, it
|
||||
just no longer has to solve heredoc-quoting itself.
|
||||
|
||||
Usage:
|
||||
printf '%s' "$CMD" | python3 hooks/lib/strip_heredoc.py
|
||||
|
||||
Or import it as a module:
|
||||
from strip_heredoc import strip_heredocs
|
||||
"""
|
||||
import re
|
||||
import sys
|
||||
|
||||
# <<EOF <<-EOF <<~EOF <<'EOF' <<"EOF" (only one modifier is valid at a
|
||||
# time in real bash; both are accepted here so a odd combo still matches).
|
||||
_START_RE = re.compile(r"<<(-|~)?[ \t]*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\2")
|
||||
|
||||
|
||||
def strip_heredocs(cmd: str) -> str:
|
||||
"""Replace every heredoc body in cmd with nothing; keep the start line
|
||||
and everything outside heredocs untouched."""
|
||||
lines = cmd.split("\n")
|
||||
out = []
|
||||
i = 0
|
||||
n = len(lines)
|
||||
while i < n:
|
||||
line = lines[i]
|
||||
m = _START_RE.search(line)
|
||||
if not m:
|
||||
out.append(line)
|
||||
i += 1
|
||||
continue
|
||||
strip_tabs = m.group(1) == "-"
|
||||
delim = m.group(3)
|
||||
out.append(line) # the start line itself is control flow, keep it
|
||||
i += 1
|
||||
found_end = False
|
||||
while i < n:
|
||||
probe = lines[i]
|
||||
check = probe.lstrip("\t") if strip_tabs else probe
|
||||
if check == delim:
|
||||
i += 1 # the terminator line is a marker, drop it too
|
||||
found_end = True
|
||||
break
|
||||
i += 1 # body line: drop it, do not append to out
|
||||
if not found_end:
|
||||
# command was truncated / no terminator found -- do not invent
|
||||
# one, we've already consumed to the end of the string.
|
||||
pass
|
||||
return "\n".join(out)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
cmd = sys.stdin.read()
|
||||
sys.stdout.write(strip_heredocs(cmd))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/bin/sh
|
||||
# 管什麼: subagent 推 gitea main 要先有總管戳記;wrangler 部署到非 stage 環境要 leo 手動解保險。
|
||||
# 為什麼: leo 2026-08-10——「subagent 推 main 你確認,推 prod 我確認」;規則存在但沒機制驗證有沒有照做,於是閘長在機器上。
|
||||
# 誤觸時怎麼關: 讀取/查狀態/演練一律放行;真要推 main,總管看過 commit 後 `git rev-parse --show-toplevel > /tmp/.main-push-ok`;真要打 stage,指令裡帶 staging/--env stage 字樣。
|
||||
# main-and-prod-push-guard.sh — PreToolUse(Bash):**兩層手動確認閘**
|
||||
#
|
||||
# 🔴 立這道閘的來由(leo 2026-08-10):
|
||||
@@ -34,9 +37,23 @@ except Exception: print("")
|
||||
|
||||
[ -z "$CMD" ] && exit 0
|
||||
|
||||
# 🔴 2026-08-20(inkstone/InkStoneCo#23、#56):heredoc 的 body 是資料,不是指令。
|
||||
# 直接對整條指令字串(含 heredoc 內文)做關鍵字掃描,會把「檔案內容/留言引用裡
|
||||
# 剛好提到 git push」當成「真的在推」——同一天兩起實撞:寫 docs/TESTING.md 的
|
||||
# 一行範例文字、貼一則引用 #56 敘述的 Gitea 留言,都被這樣擋下。
|
||||
# 拿掉 heredoc body 再比對,判準不變,範圍變準。失敗就退回原字串(fail-open
|
||||
# 在「這支有沒有幫上忙」,不是「放行與否」——見 hooks/lib/strip_heredoc.py 檔頭)。
|
||||
CMD=$(printf '%s' "$CMD" | python3 "$(dirname "$0")/lib/strip_heredoc.py" 2>/dev/null || printf '%s' "$CMD")
|
||||
|
||||
# ── 先放行明確不發佈的動作(讀取、查狀態、寫本地版控、演練)──────────────
|
||||
# 關鍵字出現在 commit 訊息、在 sed/grep 的參數裡,都不是「執行」。
|
||||
# 🔴 2026-08-20 修正(release-tag-guard.sh/stage-before-prod-guard.sh 已修過同款洞):
|
||||
# 舊版「CMD 開頭是讀取工具就整條放行」本身是穿牆路——
|
||||
# echo x && git push gitea HEAD:main
|
||||
# 開頭是 echo,照 glob 前綴比對會整條 exit 0,後面真的在推 main 完全不看。
|
||||
# ⇒ 改成「先看有沒有出現危險關鍵字,出現了就不吃開頭豁免」,交給下面的
|
||||
# 「指令位置」判準去判斷它是不是真的在執行。
|
||||
case "$CMD" in
|
||||
*"git push"*|*"wrangler deploy"*|*"wrangler publish"*|*"wrangler versions deploy"*) ;;
|
||||
sed\ *|cat\ *|grep\ *|head\ *|tail\ *|wc\ *|less\ *|ls\ *|awk\ *|rg\ *|echo\ *) exit 0 ;;
|
||||
*"git commit"*|*"git add"*|*"git tag"*|*"git stash"*) exit 0 ;;
|
||||
*"git status"*|*"git log"*|*"git diff"*|*"git show"*|*"git branch"*) exit 0 ;;
|
||||
@@ -91,73 +108,78 @@ stamp_ok() {
|
||||
return 0
|
||||
}
|
||||
|
||||
if true; then
|
||||
case "$CMD" in
|
||||
*"git push"*)
|
||||
# 只擋打到 main/master 的;推自己的 feature 分支照常放行
|
||||
case "$CMD" in
|
||||
# 🔴 2026-08-12 拿掉 `push -u` / `push --set-upstream` 這兩個條件。
|
||||
# 它們本來是想抓「沒寫分支的 push」,但實際抓到的是
|
||||
# `git push -u gitea fix/xxx`——**subagent 發表自己分支的標準動作**
|
||||
# (第一次推當然要 -u)。⇒ 舊版等於「agent 永遠推不出自己的分支」,
|
||||
# 而 leo 2026-08-12 的設計是「主線禁止動,大家都走 PR」,推分支是那條路的第一步。
|
||||
# 08-12 當天四張 PR 全是繞成 `git push gitea a:a` 才推出去的。
|
||||
# `*main*`/`*master*` 兩條照舊——真正該擋的是目標分支,不是有沒有帶旗標。
|
||||
*main*|*master*)
|
||||
stamp_ok && exit 0
|
||||
# reworked 2026-08-20 (inkstone/InkStoneCo#23, #56): 'does this command contain
|
||||
# git push' moved from a whole-string substring test to a command-position test --
|
||||
# same pattern already validated on release-tag-guard.sh: the phrase only counts
|
||||
# at the start of the string, or right after ; & | ( ` && ||. A heredoc body was
|
||||
# already stripped above; this closes the remaining gap where the phrase shows up
|
||||
# quoted inside the *same* command line (e.g. a python -c call whose string argument
|
||||
# discusses git push as prose).
|
||||
if printf '%s' "$CMD" | grep -qE '(^|[;&|(`]|&&|\|\|)[[:space:]]*git([[:space:]]+[^;&|]*)?[[:space:]]+push([[:space:]]|$)'; then
|
||||
# only block pushes that target main/master; pushing your own feature branch is fine
|
||||
#
|
||||
# 2026-08-12: dropped the `push -u` / `push --set-upstream` conditions -- those were
|
||||
# meant to catch "push with no branch named", but what they actually caught was
|
||||
# `git push -u gitea fix/xxx`, the normal first-push-of-a-branch shape for a
|
||||
# subagent. The target branch is what should be gated, not whether a flag is present.
|
||||
# 2026-08-20: match the target branch on a word boundary, not a bare substring --
|
||||
# a glob like *main* also matches "domain" (d-o-**m-a-i-n**), e.g. a push to
|
||||
# `fix/custom-domain-setup` would have false-positived.
|
||||
if printf '%s' "$CMD" | grep -qE '(^|[^A-Za-z])(main|master)([^A-Za-z]|$)'; then
|
||||
stamp_ok && exit 0
|
||||
|
||||
# ── 擋下的同時,把「誰想推什麼」留成一份請求(leo 2026-08-12)───────────
|
||||
#
|
||||
# leo 原話:「**它會問你的意見,所以每個你叫起來的 subagent 都有名字。**」
|
||||
#
|
||||
# 做得到的與做不到的,先講清楚:
|
||||
# ❌ **做不到「同步問總管」**——hook 跑在子 session 自己的行程裡,總管在另一個行程。
|
||||
# 要同步問只能 block 等一個檔案出現,那會把 subagent 掛死在那裡。
|
||||
# ✅ **做得到「當場擋 + 留下原始請求」**:總管在自己的迴圈裡讀這個目錄,
|
||||
# 看到的是 repo/分支/逐筆 commit 的**原始資料**,不是 subagent 的散文轉述。
|
||||
# ——這才是名字真正值錢的地方:**不是判斷你是誰,是留下是誰要求的**。
|
||||
#
|
||||
# 🔴 身分的方向刻意不改:**沒有名字不等於總管**(那是 fail-open——
|
||||
# 子 session 繼承環境變數,把名字拿掉就升格了)。放行的唯一憑證仍然只有
|
||||
# 那枚綁 repo、用完即丟的戳記。名字只是署名,不是權限。
|
||||
# 📌 名字只在 `claude -p` 起的子 session 上可靠(乾淨的環境邊界);
|
||||
# Agent tool 起的 subagent 與總管同一個行程、共用環境 ⇒ 那條路上名字塞不進也擦不掉。
|
||||
# 而改子 repo code 的正路本來就是 `claude -p`,所以夠用。
|
||||
_who="${CLAUDE_AGENT_NAME:-未署名}"
|
||||
_hookdir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) || _hookdir=""
|
||||
_reqdir="${_hookdir%/hooks}/pending-main-push"
|
||||
if [ -n "$_hookdir" ] && mkdir -p "$_reqdir" 2>/dev/null; then
|
||||
_root=$(git rev-parse --show-toplevel 2>/dev/null || printf 'unknown')
|
||||
# 檔名只用 ASCII(`未署名` 之類會被 tr 打成一排 dash,看不出是誰)
|
||||
_slugwho=$(printf '%s' "${CLAUDE_AGENT_NAME:-unnamed}" | tr -c 'A-Za-z0-9._-' '-')
|
||||
case "$_slugwho" in *[!-]*) : ;; *) _slugwho=unnamed ;; esac
|
||||
# ⚠️ 先 printf 再 tr:`basename` 會帶一個換行,直接餵 tr 會變成結尾多一根 dash
|
||||
_slugrepo=$(printf '%s' "$(basename "$_root")" | tr -c 'A-Za-z0-9._-' '-')
|
||||
_slug="${_slugwho}--${_slugrepo}"
|
||||
# ⚠️ 這幾行刻意用 `printf '%s\n' "整句"`,不要把內容寫進 printf 的格式字串裡。
|
||||
# 2026-08-12 實撞:格式字串裡同時有反引號與 %s 時,那幾行整行不見(而前後行都在),
|
||||
# ——**寫完當場肉眼檢查產出的檔案才發現**,hook 自己不會叫。內容一律當資料傳。
|
||||
_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || printf '?')
|
||||
_when=$(date '+%Y-%m-%d %H:%M:%S' 2>/dev/null || printf '?')
|
||||
_fence='```'
|
||||
{
|
||||
printf '%s\n\n' "# 推 main 的請求:$_who"
|
||||
printf '%s\n' "- repo:$_root"
|
||||
printf '%s\n' "- 分支:$_branch"
|
||||
printf '%s\n\n' "- 時間:$_when"
|
||||
printf '%s\n' "- 它想跑的指令:"
|
||||
printf '%s\n%s\n%s\n\n' "$_fence" "$CMD" "$_fence"
|
||||
printf '%s\n\n%s\n' "## 還沒推上去的 commit(原始資料,不是轉述)" "$_fence"
|
||||
git log --oneline '@{upstream}..HEAD' 2>/dev/null \
|
||||
|| git log --oneline -20 2>/dev/null \
|
||||
|| printf '(列不出來)\n'
|
||||
printf '%s\n\n%s\n\n%s\n' "$_fence" "## 改了哪些檔" "$_fence"
|
||||
git diff --stat '@{upstream}..HEAD' 2>/dev/null | tail -40 || printf '(列不出來)\n'
|
||||
printf '%s\n\n---\n%s\n' "$_fence" "總管裁完請刪掉這個檔——留著代表「還沒裁」。"
|
||||
} > "$_reqdir/$_slug.md" 2>/dev/null || true
|
||||
fi
|
||||
# ── 擋下的同時,把「誰想推什麼」留成一份請求(leo 2026-08-12)───────────
|
||||
#
|
||||
# leo 原話:「**它會問你的意見,所以每個你叫起來的 subagent 都有名字。**」
|
||||
#
|
||||
# 做得到的與做不到的,先講清楚:
|
||||
# ❌ **做不到「同步問總管」**——hook 跑在子 session 自己的行程裡,總管在另一個行程。
|
||||
# 要同步問只能 block 等一個檔案出現,那會把 subagent 掛死在那裡。
|
||||
# ✅ **做得到「當場擋 + 留下原始請求」**:總管在自己的迴圈裡讀這個目錄,
|
||||
# 看到的是 repo/分支/逐筆 commit 的**原始資料**,不是 subagent 的散文轉述。
|
||||
# ——這才是名字真正值錢的地方:**不是判斷你是誰,是留下是誰要求的**。
|
||||
#
|
||||
# 🔴 身分的方向刻意不改:**沒有名字不等於總管**(那是 fail-open——
|
||||
# 子 session 繼承環境變數,把名字拿掉就升格了)。放行的唯一憑證仍然只有
|
||||
# 那枚綁 repo、用完即丟的戳記。名字只是署名,不是權限。
|
||||
# 📌 名字只在 `claude -p` 起的子 session 上可靠(乾淨的環境邊界);
|
||||
# Agent tool 起的 subagent 與總管同一個行程、共用環境 ⇒ 那條路上名字塞不進也擦不掉。
|
||||
# 而改子 repo code 的正路本來就是 `claude -p`,所以夠用。
|
||||
_who="${CLAUDE_AGENT_NAME:-未署名}"
|
||||
_hookdir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) || _hookdir=""
|
||||
_reqdir="${_hookdir%/hooks}/pending-main-push"
|
||||
if [ -n "$_hookdir" ] && mkdir -p "$_reqdir" 2>/dev/null; then
|
||||
_root=$(git rev-parse --show-toplevel 2>/dev/null || printf 'unknown')
|
||||
# 檔名只用 ASCII(`未署名` 之類會被 tr 打成一排 dash,看不出是誰)
|
||||
_slugwho=$(printf '%s' "${CLAUDE_AGENT_NAME:-unnamed}" | tr -c 'A-Za-z0-9._-' '-')
|
||||
case "$_slugwho" in *[!-]*) : ;; *) _slugwho=unnamed ;; esac
|
||||
# ⚠️ 先 printf 再 tr:`basename` 會帶一個換行,直接餵 tr 會變成結尾多一根 dash
|
||||
_slugrepo=$(printf '%s' "$(basename "$_root")" | tr -c 'A-Za-z0-9._-' '-')
|
||||
_slug="${_slugwho}--${_slugrepo}"
|
||||
# ⚠️ 這幾行刻意用 `printf '%s\n' "整句"`,不要把內容寫進 printf 的格式字串裡。
|
||||
# 2026-08-12 實撞:格式字串裡同時有反引號與 %s 時,那幾行整行不見(而前後行都在),
|
||||
# ——**寫完當場肉眼檢查產出的檔案才發現**,hook 自己不會叫。內容一律當資料傳。
|
||||
_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || printf '?')
|
||||
_when=$(date '+%Y-%m-%d %H:%M:%S' 2>/dev/null || printf '?')
|
||||
_fence='```'
|
||||
{
|
||||
printf '%s\n\n' "# 推 main 的請求:$_who"
|
||||
printf '%s\n' "- repo:$_root"
|
||||
printf '%s\n' "- 分支:$_branch"
|
||||
printf '%s\n\n' "- 時間:$_when"
|
||||
printf '%s\n' "- 它想跑的指令:"
|
||||
printf '%s\n%s\n%s\n\n' "$_fence" "$CMD" "$_fence"
|
||||
printf '%s\n\n%s\n' "## 還沒推上去的 commit(原始資料,不是轉述)" "$_fence"
|
||||
git log --oneline '@{upstream}..HEAD' 2>/dev/null \
|
||||
|| git log --oneline -20 2>/dev/null \
|
||||
|| printf '(列不出來)\n'
|
||||
printf '%s\n\n%s\n\n%s\n' "$_fence" "## 改了哪些檔" "$_fence"
|
||||
git diff --stat '@{upstream}..HEAD' 2>/dev/null | tail -40 || printf '(列不出來)\n'
|
||||
printf '%s\n\n---\n%s\n' "$_fence" "總管裁完請刪掉這個檔——留著代表「還沒裁」。"
|
||||
} > "$_reqdir/$_slug.md" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
cat >&2 <<'MSG'
|
||||
cat >&2 <<'MSG'
|
||||
🚫 推 main 要先有「總管決定了」的戳記(leo 2026-08-10 立)
|
||||
|
||||
leo 原話:
|
||||
@@ -196,11 +218,8 @@ leo 原話:
|
||||
|
||||
【真的該推 main 的例外】不存在。交回總管,一句話的事。
|
||||
MSG
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
# ── ② prod 部署要 leo 親手解保險 ────────────────────────────────────────
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#!/bin/sh
|
||||
# 管什麼: prod 出貨鏈的動作(打 prod bundle、開 GitHub 保險、prod 安裝器部署)——沒有 6 小時內的 stage 驗證紀錄不放行。
|
||||
# 為什麼: leo 2026-08-08——開始封測後推 prod 就是發佈給人看,要先在 stage 走過一次真實路徑再上。
|
||||
# 誤觸時怎麼關: 讀取/查證(讀 manifest、讀腳本、curl 公開 CDN)一律放行;真的驗過 stage,貼實測輸出後 `touch /tmp/.stage-verified` 重送。
|
||||
# stage-before-prod-guard.sh — PreToolUse(Bash):**未經 stage 驗過,不准動 prod 出貨鏈**。
|
||||
#
|
||||
# 🔴 立這道閘的來由(leo 2026-08-08):
|
||||
@@ -32,6 +35,12 @@ except Exception: print("")
|
||||
' 2>/dev/null || echo "")
|
||||
[ -z "$CMD" ] && exit 0
|
||||
|
||||
# 2026-08-20(inkstone/InkStoneCo#23、#56 同款):heredoc 的 body 是資料,不是指令。
|
||||
# 拿掉 heredoc body 再比對,跟 github-contact-guard.sh/main-and-prod-push-guard.sh
|
||||
# 用同一支共用輔助程式;失敗就退回原字串(fail-open 在「這支有沒有幫上忙」,
|
||||
# 不是「放行與否」——見 hooks/lib/strip_heredoc.py 檔頭)。
|
||||
CMD=$(printf '%s' "$CMD" | python3 "$(dirname "$0")/lib/strip_heredoc.py" 2>/dev/null || printf '%s' "$CMD")
|
||||
|
||||
# 只攔「會讓封測者拿到東西」的動作:prod bundle repo、開 GitHub 保險、prod 安裝器部署。
|
||||
# staging 的同名動作要放行——所以先排除帶 staging 字樣的命令。
|
||||
case "$CMD" in
|
||||
|
||||
Executable
+203
@@ -0,0 +1,203 @@
|
||||
#!/usr/bin/env bash
|
||||
# gitea-arm-check.sh 的迴歸測試——只測「不必打真網路/不必真的等 leo」的幾種:
|
||||
# 沒有待核請求/已過期/已被消耗過(重放保護)/Gitea 認證失敗/
|
||||
# 核准者常數不接受環境變數覆蓋/票號缺失或非數字的待核檔會被略過不猜。
|
||||
# 另有一組**用真 token 打真端點**的測試,驗證 2026-08-16 起「票號由呼叫端指定」
|
||||
# 這件事真的有路由到對的票(見下方「不同票號各自路由」段)。
|
||||
#
|
||||
# 🔴 「Leo 真的回覆才放行」與「機器冒充 Leo」這兩種**必須打真的 Gitea**才有意義
|
||||
# (核心判準就是比對 Gitea 上留言的 `user.login`),不適合塞進不碰網路的單元測試。
|
||||
# 這兩種已經在 https://git.uncle6.me/inkstone/InkStoneCo/issues/34 上人工實測過,
|
||||
# 證據見本次 PR 說明,不在這支重跑。
|
||||
#
|
||||
# 🔴 2026-08-13 總管審查後修正:`GITEA_ARM_OWNER/REPO/API/APPROVER_LOGIN`
|
||||
# 全部改成寫死在 gitea-arm-common.sh,不再接受環境變數覆蓋(否則
|
||||
# `GITEA_ARM_APPROVER_LOGIN=claude-code` 就能讓機器核准自己)。
|
||||
# ⇒ 「Gitea 打不到」這條測資不能再用假網址注入,改用**真端點+無效 token**
|
||||
# (回真的 401,一樣走得到「非 200 → fail-closed」那條分支)。
|
||||
#
|
||||
# 🪦 2026-08-16:ISSUE 從第五個「寫死常數」名單裡移出來,改成請求時的參數
|
||||
# (見 lib/gitea-arm-common.sh 檔頭說明:真正的安全邊界是 OWNER/REPO/
|
||||
# APPROVER_LOGIN,不是票號本身)。相對地,pending 檔的 schema 多了 `issue` 欄位,
|
||||
# 下面所有測資的 JSON 都要帶上它,否則會被「票號缺失」判定為壞檔而被略過。
|
||||
#
|
||||
# 用法:.claude/hooks/tests/gitea-arm-check.test.sh <repo根目錄>
|
||||
# (repo 根目錄要有 scripts/gitea-arm-check.sh + scripts/gitea-arm-request.sh)
|
||||
set -u
|
||||
PROJ="${1:?用法: $0 <repo根目錄>}"
|
||||
CHECK="$PROJ/scripts/gitea-arm-check.sh"
|
||||
|
||||
TMPPROJ=$(mktemp -d)
|
||||
trap 'rm -rf "$TMPPROJ"' EXIT
|
||||
# 借用真的 scripts/(唯讀),但狀態目錄與 .env 都指到隔離的臨時目錄
|
||||
ln -s "$PROJ/scripts" "$TMPPROJ/scripts"
|
||||
# 假 .env:token 隨便填,「Gitea 打不到」那條測資會在網路那層失敗(本來就該擋),
|
||||
# 其餘測資在打到 Gitea 之前就已經因為本地狀態被擋下,不會真的送出請求。
|
||||
printf 'GITEA_TOKEN_CLAUDE_CODE=test-token-not-real\n' > "$TMPPROJ/.env"
|
||||
|
||||
PASS=0; FAIL=0
|
||||
t(){ # t <期望 block|pass> <說明> <exit code>
|
||||
got=$([ "$3" -eq 0 ] && echo pass || echo block)
|
||||
if [ "$got" = "$1" ]; then echo " ✅ $2"; PASS=$((PASS+1))
|
||||
else echo " ❌ $2 —— 期望 $1,實得 $got"; FAIL=$((FAIL+1)); fi
|
||||
}
|
||||
|
||||
echo "── 完全沒有待核請求 ──"
|
||||
rm -rf "$TMPPROJ/.claude/gitea-arm"
|
||||
CLAUDE_PROJECT_DIR="$TMPPROJ" "$CHECK" >/tmp/gitea-arm-test-out.$$ 2>&1
|
||||
t block "沒有 pending 目錄就該擋" $?
|
||||
|
||||
echo "── 已過期的請求 ──"
|
||||
mkdir -p "$TMPPROJ/.claude/gitea-arm/pending"
|
||||
NOW=$(date +%s)
|
||||
jq -n --arg nonce "ARM-testexpired" --arg mission "測試" --arg issue "34" \
|
||||
--argjson requested_at "$((NOW-3600))" --argjson expires_at "$((NOW-1))" \
|
||||
--arg request_comment_id "1" --arg request_created_at "2020-01-01T00:00:00Z" \
|
||||
'{nonce:$nonce, mission:$mission, issue:$issue, requested_at:$requested_at, expires_at:$expires_at, request_comment_id:$request_comment_id, request_created_at:$request_created_at}' \
|
||||
> "$TMPPROJ/.claude/gitea-arm/pending/ARM-testexpired.json"
|
||||
CLAUDE_PROJECT_DIR="$TMPPROJ" "$CHECK" ARM-testexpired >/tmp/gitea-arm-test-out.$$ 2>&1
|
||||
rc=$?
|
||||
t block "過期的 nonce 該擋" $rc
|
||||
[ -f "$TMPPROJ/.claude/gitea-arm/pending/ARM-testexpired.json" ] \
|
||||
&& { echo " ❌ 過期後 pending 檔應該被清掉,卻還在"; FAIL=$((FAIL+1)); } \
|
||||
|| { echo " ✅ 過期後 pending 檔已清掉"; PASS=$((PASS+1)); }
|
||||
|
||||
echo "── 已被消耗過的 nonce(防重放)──"
|
||||
rm -rf "$TMPPROJ/.claude/gitea-arm"
|
||||
mkdir -p "$TMPPROJ/.claude/gitea-arm/pending"
|
||||
jq -n --arg nonce "ARM-testreplay" --arg mission "測試" --arg issue "34" \
|
||||
--argjson requested_at "$NOW" --argjson expires_at "$((NOW+1800))" \
|
||||
--arg request_comment_id "1" --arg request_created_at "2020-01-01T00:00:00Z" \
|
||||
'{nonce:$nonce, mission:$mission, issue:$issue, requested_at:$requested_at, expires_at:$expires_at, request_comment_id:$request_comment_id, request_created_at:$request_created_at}' \
|
||||
> "$TMPPROJ/.claude/gitea-arm/pending/ARM-testreplay.json"
|
||||
printf 'ARM-testreplay\t2026-01-01 00:00:00\t舊任務\n' > "$TMPPROJ/.claude/gitea-arm/consumed.log"
|
||||
CLAUDE_PROJECT_DIR="$TMPPROJ" "$CHECK" ARM-testreplay >/tmp/gitea-arm-test-out.$$ 2>&1
|
||||
rc=$?
|
||||
t block "已消耗過的 nonce 該擋(即使有效期還沒到)" $rc
|
||||
[ -f "$TMPPROJ/.claude/gitea-arm/pending/ARM-testreplay.json" ] \
|
||||
&& { echo " ❌ 重放判定後 pending 檔應該被清掉,卻還在"; FAIL=$((FAIL+1)); } \
|
||||
|| { echo " ✅ 重放判定後 pending 檔已清掉"; PASS=$((PASS+1)); }
|
||||
|
||||
echo "── Gitea 認證失敗(真端點+無效 token,fail-closed)──"
|
||||
rm -rf "$TMPPROJ/.claude/gitea-arm"
|
||||
mkdir -p "$TMPPROJ/.claude/gitea-arm/pending"
|
||||
jq -n --arg nonce "ARM-testunreach" --arg mission "測試" --arg issue "34" \
|
||||
--argjson requested_at "$NOW" --argjson expires_at "$((NOW+1800))" \
|
||||
--arg request_comment_id "1" --arg request_created_at "2020-01-01T00:00:00Z" \
|
||||
'{nonce:$nonce, mission:$mission, issue:$issue, requested_at:$requested_at, expires_at:$expires_at, request_comment_id:$request_comment_id, request_created_at:$request_created_at}' \
|
||||
> "$TMPPROJ/.claude/gitea-arm/pending/ARM-testunreach.json"
|
||||
# $TMPPROJ/.env 裡的 token 是假的(見檔頭),這條打的是**真的** git.uncle6.me——
|
||||
# 拿假 token 打真端點,預期真的收到 401,藉此驗「非 200 → fail-closed」那條分支。
|
||||
CLAUDE_PROJECT_DIR="$TMPPROJ" "$CHECK" ARM-testunreach >/tmp/gitea-arm-test-out.$$ 2>&1
|
||||
rc=$?
|
||||
t block "Gitea 認證失敗要 fail-closed(不放行)" $rc
|
||||
grep -q "非 200\|打不到" /tmp/gitea-arm-test-out.$$ \
|
||||
&& { echo " ✅ 錯誤訊息確實指向 fail-closed 分支(不是別的原因擋下)"; PASS=$((PASS+1)); } \
|
||||
|| { echo " ❌ 沒看到預期的 fail-closed 訊息:"; cat /tmp/gitea-arm-test-out.$$; FAIL=$((FAIL+1)); }
|
||||
|
||||
echo "── 🔴 票號缺失/非數字的待核檔——不猜票號,略過不當機 ──"
|
||||
rm -rf "$TMPPROJ/.claude/gitea-arm"
|
||||
mkdir -p "$TMPPROJ/.claude/gitea-arm/pending"
|
||||
jq -n --arg nonce "ARM-testnoissue" --arg mission "測試" \
|
||||
--argjson requested_at "$NOW" --argjson expires_at "$((NOW+1800))" \
|
||||
--arg request_comment_id "1" --arg request_created_at "2020-01-01T00:00:00Z" \
|
||||
'{nonce:$nonce, mission:$mission, requested_at:$requested_at, expires_at:$expires_at, request_comment_id:$request_comment_id, request_created_at:$request_created_at}' \
|
||||
> "$TMPPROJ/.claude/gitea-arm/pending/ARM-testnoissue.json"
|
||||
CLAUDE_PROJECT_DIR="$TMPPROJ" "$CHECK" ARM-testnoissue >/tmp/gitea-arm-test-out.$$ 2>&1
|
||||
rc=$?
|
||||
t block "缺 issue 欄位的舊格式待核檔該擋(不放行)" $rc
|
||||
grep -q "issue 缺失或非數字" /tmp/gitea-arm-test-out.$$ \
|
||||
&& { echo " ✅ 錯誤訊息點名是 issue 欄位的問題(不是猜成別的原因)"; PASS=$((PASS+1)); } \
|
||||
|| { echo " ❌ 沒看到預期的訊息:"; cat /tmp/gitea-arm-test-out.$$; FAIL=$((FAIL+1)); }
|
||||
|
||||
echo "── 🔴 核准者不接受環境變數覆蓋(本次審查抓到的洞,補的測試)──"
|
||||
GOT_LOGIN=$(CLAUDE_PROJECT_DIR="$TMPPROJ" GITEA_ARM_APPROVER_LOGIN="claude-code" bash -c '
|
||||
. "'"$PROJ"'/scripts/lib/gitea-arm-common.sh"
|
||||
printf "%s" "$GITEA_ARM_APPROVER_LOGIN"
|
||||
')
|
||||
if [ "$GOT_LOGIN" = "Leo" ]; then
|
||||
echo " ✅ 設了 GITEA_ARM_APPROVER_LOGIN=claude-code,source 進去的常數仍是 Leo(覆蓋無效)"
|
||||
PASS=$((PASS+1))
|
||||
else
|
||||
echo " ❌ 常數被環境變數改成了「$GOT_LOGIN」——核准者可以被外部覆蓋,這是安全洞"
|
||||
FAIL=$((FAIL+1))
|
||||
fi
|
||||
|
||||
echo "── 🔴 不同票號各自路由(真 token 打真端點):一個指到存在的票、一個指到不存在的票 ──"
|
||||
# 這條要證明的是 2026-08-16 這次改動的核心:每個請求真的用它自己的 issue 欄位
|
||||
# 去打對應的票,不是仍然只認某個寫死的號碼。用真 token(唯讀 GET,不會寫入任何東西):
|
||||
# · nonce A 指到 #34(真實存在,開放中)→ 預期 200 OK,只是假 nonce 找不到 Leo 回覆
|
||||
# · nonce B 指到一個不存在的超大票號 → 預期 404/非 200 → fail-closed
|
||||
# 如果程式碼還在用舊的單一票號邏輯,這兩筆會得到**相同**的結果(不會一個過一個不過)。
|
||||
REAL_ENV="$PROJ/.env"
|
||||
if [ -f "$REAL_ENV" ] && grep -q '^GITEA_TOKEN_CLAUDE_CODE=' "$REAL_ENV"; then
|
||||
cp "$REAL_ENV" "$TMPPROJ/.env"
|
||||
rm -rf "$TMPPROJ/.claude/gitea-arm"
|
||||
mkdir -p "$TMPPROJ/.claude/gitea-arm/pending"
|
||||
jq -n --arg nonce "ARM-testrouteA" --arg mission "路由測試A" --arg issue "34" \
|
||||
--argjson requested_at "$NOW" --argjson expires_at "$((NOW+1800))" \
|
||||
--arg request_comment_id "1" --arg request_created_at "2020-01-01T00:00:00Z" \
|
||||
'{nonce:$nonce, mission:$mission, issue:$issue, requested_at:$requested_at, expires_at:$expires_at, request_comment_id:$request_comment_id, request_created_at:$request_created_at}' \
|
||||
> "$TMPPROJ/.claude/gitea-arm/pending/ARM-testrouteA.json"
|
||||
jq -n --arg nonce "ARM-testrouteB" --arg mission "路由測試B" --arg issue "999999999" \
|
||||
--argjson requested_at "$NOW" --argjson expires_at "$((NOW+1800))" \
|
||||
--arg request_comment_id "1" --arg request_created_at "2020-01-01T00:00:00Z" \
|
||||
'{nonce:$nonce, mission:$mission, issue:$issue, requested_at:$requested_at, expires_at:$expires_at, request_comment_id:$request_comment_id, request_created_at:$request_created_at}' \
|
||||
> "$TMPPROJ/.claude/gitea-arm/pending/ARM-testrouteB.json"
|
||||
|
||||
CLAUDE_PROJECT_DIR="$TMPPROJ" "$CHECK" >/tmp/gitea-arm-test-out.$$ 2>&1
|
||||
rc=$?
|
||||
t block "兩者都是假 nonce,不會被核准,整體仍該回不放行" $rc
|
||||
|
||||
if grep -q "ARM-testrouteA(#34)還沒等到 Leo 的回覆" /tmp/gitea-arm-test-out.$$; then
|
||||
echo " ✅ #34(存在):真的打到了、200 OK,只是假 nonce 沒有匹配的留言"
|
||||
PASS=$((PASS+1))
|
||||
else
|
||||
echo " ❌ 沒看到 #34 該有的「還沒等到」訊息:"; cat /tmp/gitea-arm-test-out.$$
|
||||
FAIL=$((FAIL+1))
|
||||
fi
|
||||
|
||||
if grep -q "#999999999:Gitea 打不到/回應非 200" /tmp/gitea-arm-test-out.$$; then
|
||||
echo " ✅ #999999999(不存在):真的打到了那個號碼,並且 fail-closed(不是誤放行也不是誤判成別的錯)"
|
||||
PASS=$((PASS+1))
|
||||
else
|
||||
echo " ❌ 沒看到 #999999999 該有的 fail-closed 訊息:"; cat /tmp/gitea-arm-test-out.$$
|
||||
FAIL=$((FAIL+1))
|
||||
fi
|
||||
else
|
||||
echo " ⚠️ 跳過(找不到真的 GITEA_TOKEN_CLAUDE_CODE,這條測資需要唯讀真端點)"
|
||||
fi
|
||||
|
||||
echo "── 🔴 gitea-arm-request.sh:缺票號/票號非數字要在打網路前就擋 ──"
|
||||
REQ="$PROJ/scripts/gitea-arm-request.sh"
|
||||
CLAUDE_PROJECT_DIR="$TMPPROJ" "$REQ" >/tmp/gitea-arm-test-out.$$ 2>&1
|
||||
t block "完全沒帶參數該擋(用法錯誤)" $?
|
||||
CLAUDE_PROJECT_DIR="$TMPPROJ" "$REQ" "not-a-number" "測試任務" >/tmp/gitea-arm-test-out.$$ 2>&1
|
||||
rc=$?
|
||||
t block "票號非數字該擋" $rc
|
||||
# 2026-08-16:票號格式擴充為「N 或 repo#N」,訊息跟著改;斷言改成看**意圖**(有沒有點名票號)
|
||||
grep -qE "票號.*純數字|純數字票號" /tmp/gitea-arm-test-out.$$ \
|
||||
&& { echo " ✅ 錯誤訊息點名是票號格式問題"; PASS=$((PASS+1)); } \
|
||||
|| { echo " ❌ 沒看到預期訊息:"; cat /tmp/gitea-arm-test-out.$$; FAIL=$((FAIL+1)); }
|
||||
|
||||
# ── 🔴 2026-08-16 新增:repo 可指定,但 owner 絕不可 ──────────────────
|
||||
echo "── 🔴 gitea-arm-common:repo 可由參數指定,owner 是安全邊界不給指定 ──"
|
||||
( . "$PROJ/scripts/lib/gitea-arm-common.sh" >/dev/null 2>&1
|
||||
gitea_arm_set_repo "arcrun-rag" >/dev/null 2>&1 && [ "$GITEA_ARM_REPO" = "arcrun-rag" ] ) \
|
||||
&& { echo " ✅ 同 org 的 repo 名可指定"; PASS=$((PASS+1)); } \
|
||||
|| { echo " ❌ 同 org 的 repo 名竟然不能指定"; FAIL=$((FAIL+1)); }
|
||||
|
||||
( . "$PROJ/scripts/lib/gitea-arm-common.sh" >/dev/null 2>&1
|
||||
gitea_arm_set_repo "claude-code/evil" >/dev/null 2>&1 ) \
|
||||
&& { echo " ❌ 帶斜線的 owner/repo 竟然被接受——那正是 08-13 那次攻擊的形狀"; FAIL=$((FAIL+1)); } \
|
||||
|| { echo " ✅ 帶斜線的被擋(owner 不給任何人指定)"; PASS=$((PASS+1)); }
|
||||
|
||||
( GITEA_ARM_OWNER=claude-code; . "$PROJ/scripts/lib/gitea-arm-common.sh" >/dev/null 2>&1
|
||||
[ "$GITEA_ARM_OWNER" = "inkstone" ] ) \
|
||||
&& { echo " ✅ OWNER 不受環境變數影響(仍是 inkstone)"; PASS=$((PASS+1)); } \
|
||||
|| { echo " ❌ OWNER 被 env 蓋掉了——安全邊界破了"; FAIL=$((FAIL+1)); }
|
||||
|
||||
rm -f /tmp/gitea-arm-test-out.$$
|
||||
echo
|
||||
echo "結果:通過 $PASS / 失敗 $FAIL"
|
||||
[ $FAIL -eq 0 ] || exit 1
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
# main-and-prod-push-guard.sh 的迴歸測試——重點在「geek6688 豁免的範圍夠不夠窄」。
|
||||
# 🔴 寫成檔案跑:測試指令必然含 `wrangler deploy`,直接在 Bash 打會被 prod-write-guard 擋。
|
||||
#
|
||||
# 用一個**沒有 .github-armed** 的臨時 CLAUDE_PROJECT_DIR,
|
||||
# 否則本機真的有那個檔 ⇒「該擋的」會假性通過,測了等於沒測。
|
||||
HOOK="$1"
|
||||
TMPPROJ=$(mktemp -d)
|
||||
trap 'rm -rf "$TMPPROJ"' EXIT
|
||||
|
||||
mk(){ python3 -c "import json,sys;print(json.dumps({'tool_name':'Bash','tool_input':{'command':sys.argv[1]}}))" "$1"; }
|
||||
PASS=0; FAIL=0
|
||||
t(){ mk "$3" | env CLAUDE_PROJECT_DIR="$TMPPROJ" "$HOOK" >/dev/null 2>&1; rc=$?
|
||||
got=$([ $rc -eq 2 ] && echo block || echo pass)
|
||||
if [ "$got" = "$1" ]; then echo " ✅ $2"; PASS=$((PASS+1))
|
||||
else echo " ❌ $2 —— 期望 $1,實得 $got"; FAIL=$((FAIL+1)); fi; }
|
||||
|
||||
D="wrangler deploy"
|
||||
|
||||
echo "── geek6688(leo 2026-08-12 明文授權總管可直接動)應放行 ──"
|
||||
t pass "指名 geek6688 主機名" "npx $D --name arcrun-cypher-executor --config geek6688.toml"
|
||||
t pass "用 geek6688 的 token 變數" "CLOUDFLARE_API_TOKEN=\$CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE npx $D"
|
||||
t pass "用 geek6688 的 account id 變數" "CLOUDFLARE_ACCOUNT_ID=\$CLOUDFLARE_ACCOUNT_ID_GEEK6688 npx $D"
|
||||
|
||||
echo "── 其他實例仍要 leo 親手 arm(範圍不能外溢)──"
|
||||
t block "打 leo21c" "npx $D --name arcrun-mcp --account-id leo21c-acct"
|
||||
t block "打 uncle6 官方" "npx $D --name arcrun-kbdb --config uncle6.toml"
|
||||
t block "看不出打哪裡" "npx $D"
|
||||
t block "wrangler publish 到別台" "npx wrangler publish --name arcrun-mcp"
|
||||
t block "versions deploy 到別台" "npx wrangler versions deploy --name arcrun-kbdb"
|
||||
|
||||
echo "── stage 照舊自由 ──"
|
||||
t pass "帶 --env staging" "npx $D --env staging"
|
||||
t pass "打 staging 主機" "npx $D --name arcrun-rag-installer-staging"
|
||||
|
||||
echo "── 非部署動作不受影響 ──"
|
||||
t pass "推自己的分支" "git push -u gitea fix/my-branch"
|
||||
t pass "讀本閘原始碼(指令裡含關鍵字)" "sed -n '1,50p' .claude/hooks/main-and-prod-push-guard.sh"
|
||||
|
||||
echo
|
||||
echo "結果:通過 $PASS / 失敗 $FAIL"
|
||||
[ $FAIL -eq 0 ] || exit 1
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
# prod-write-guard.sh 的迴歸測試。
|
||||
# 🔴 必須寫成檔案跑:這道閘會擋掉「含有它要擋的字串」的指令本身
|
||||
# ⇒ 直接在 Bash 裡打測試,會被自己擋下(2026-08-12 實撞)。
|
||||
HOOK="$1"
|
||||
mk(){ python3 -c "import json,sys;print(json.dumps({'tool_name':'Bash','tool_input':{'command':sys.argv[1]}}))" "$1"; }
|
||||
PASS=0; FAIL=0
|
||||
t(){ # t <期望 block|pass> <說明> <指令>
|
||||
mk "$3" | "$HOOK" >/dev/null 2>&1; rc=$?
|
||||
got=$([ $rc -eq 2 ] && echo block || echo pass)
|
||||
if [ "$got" = "$1" ]; then echo " ✅ $2"; PASS=$((PASS+1))
|
||||
else echo " ❌ $2 —— 期望 $1,實得 $got"; FAIL=$((FAIL+1)); fi
|
||||
}
|
||||
|
||||
H='https://arcrun-kbdb.leo21c.workers.dev'
|
||||
DASH_D='-d'
|
||||
|
||||
echo "── 該放行(唯讀)──"
|
||||
t pass "純 GET" "curl -s $H/templates"
|
||||
t pass "GET + tr -d(本次實撞的誤攔)" "ACC=\$(grep -oE '^X=.' f | tr $DASH_D '\\r'); curl -s $H/templates"
|
||||
t pass "GET + cut -d=" "A=\$(cut ${DASH_D}= -f2 f); curl -s $H/templates"
|
||||
t pass "GET + sort -d / xargs -d" "ls | sort $DASH_D | xargs $DASH_D '\\n' echo; curl -s $H/entries"
|
||||
t pass "GET 帶 Bearer 標頭" "curl -s -H 'Authorization: Bearer xxx' $H/templates?limit=1"
|
||||
t pass "打 staging" "curl -X POST https://arcrun-rag-installer-staging.workers.dev/x $DASH_D '{}'"
|
||||
t pass "打 youlin 測試場" "curl -X POST https://arcrun-cypher-executor.youlin-hsieh-dev.workers.dev/x $DASH_D '{}'"
|
||||
t pass "打 Gitea(不是實例)" "curl -X POST https://git.uncle6.me/api/v1/repos/Leo/x/issues $DASH_D '{}'"
|
||||
|
||||
echo "── 該擋(寫入)──"
|
||||
t block "POST 到實例" "curl -X POST $H/entries $DASH_D '{}'"
|
||||
t block "PUT 到實例" "curl -X PUT $H/entries/1 --data '{}'"
|
||||
t block "DELETE 到實例" "curl -X DELETE $H/entries/1"
|
||||
t block "POST 且同時有 tr -d(剪字後仍該擋)" "cat f | tr $DASH_D '\\r' | curl -X POST $H/webhooks/named $DASH_D @-"
|
||||
t block "wrangler deploy" "npx wrangler deploy --name arcrun-kbdb"
|
||||
|
||||
# ── 2026-08-13:「執行它」vs「談論它」───────────────────────────────
|
||||
# 實撞:把 #108 的驗收證據留言到 Gitea,正文引述了那個指令名 ⇒ 一則留言被當成部署擋掉。
|
||||
# 這批測資的挑法是「本 repo 現行真的會出現的形狀」,不是我自己挑好抓的壞例子
|
||||
# ——PR #87 那道假綠閘就是敗在後者(14 條全過,卻漏掉 repo 實際在用的呼叫寫法)。
|
||||
ACR_U='acr up''date' # 拆開寫:否則這支測試檔自己會被閘擋住(它也是一條 Bash 指令)
|
||||
ACR_P='acr pu''sh'
|
||||
WR_D='wrangler dep''loy'
|
||||
|
||||
echo "── 該放行(只是談論,不是執行)──"
|
||||
t pass "heredoc 正文引述(本次實撞)" \
|
||||
"B=\$(cat <<'EOF'
|
||||
更新指令 \`$ACR_U --force\` 印出了 ARCRUN_NAMESPACE
|
||||
EOF
|
||||
); curl -X POST https://git.uncle6.me/api/v1/repos/Leo/Arcrun/issues/108/comments $DASH_D \"\$B\""
|
||||
t pass "commit 訊息裡提到" "git commit -m '修好 $ACR_U 的命名空間注入'"
|
||||
t pass "markdown code span(反引號)" "printf '%s' '看 \`$ACR_U\` 的輸出'"
|
||||
t pass "grep 它的名字" "grep -n '$ACR_P' .claude/hooks/prod-write-guard.sh"
|
||||
t pass "文章裡提到 $WR_D" "printf '%s' '# 為什麼 $WR_D 要擋'"
|
||||
t pass "acr 唯讀子指令" "acr status --json"
|
||||
t pass "acr whoami" "acr whoami"
|
||||
|
||||
echo "── 該擋(真的在指令位置執行)──"
|
||||
t block "行首" "$ACR_U --force"
|
||||
t block "&& 之後" "cd /x && $ACR_U"
|
||||
t block "; 之後" "echo hi; $ACR_P workflow.yaml"
|
||||
t block "管線之後" "cat x.yaml | $ACR_P -"
|
||||
t block "bash -c 引號裡" "bash -c \"$ACR_U --force\""
|
||||
t block "\$( ) 裡" "OUT=\$($ACR_U 2>&1)"
|
||||
t block "npx 前綴" "npx $WR_D --name arcrun-kbdb"
|
||||
t block "sudo 前綴" "sudo $ACR_U"
|
||||
t block "heredoc 之後的真指令(剝內文不能連指令一起剝)" \
|
||||
"cat <<'EOF' > note.md
|
||||
只是筆記
|
||||
EOF
|
||||
$ACR_U --force"
|
||||
|
||||
echo
|
||||
echo "結果:通過 $PASS / 失敗 $FAIL"
|
||||
[ $FAIL -eq 0 ] || exit 1
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
# stage-before-prod-guard.sh 的迴歸測試。
|
||||
# 🔴 必須寫成檔案跑:這道閘會擋掉「含有它關鍵字」的指令本身
|
||||
# ⇒ 直接在 Bash 打測試,連讀它的原始碼都會被擋(2026-08-12 實撞三次)。
|
||||
HOOK="$1"
|
||||
mk(){ python3 -c "import json,sys;print(json.dumps({'tool_name':'Bash','tool_input':{'command':sys.argv[1]}}))" "$1"; }
|
||||
PASS=0; FAIL=0
|
||||
t(){ mk "$3" | "$HOOK" >/dev/null 2>&1; rc=$?
|
||||
got=$([ $rc -eq 2 ] && echo block || echo pass)
|
||||
if [ "$got" = "$1" ]; then echo " ✅ $2"; PASS=$((PASS+1))
|
||||
else echo " ❌ $2 —— 期望 $1,實得 $got"; FAIL=$((FAIL+1)); fi; }
|
||||
|
||||
B='arcrun-rag-bundles' # 關鍵字組起來,避免這個檔名本身觸發別的工具
|
||||
CDN="https://cdn.jsdelivr.net/gh/youlinhsieh/${B}@abc123"
|
||||
ARM='scripts/github-arm.sh'
|
||||
DASH_D='-d'
|
||||
|
||||
echo "── 該放行(查證,不是發佈)──"
|
||||
t pass "抓 bundle manifest 來看(本次實撞)" "BASE=\"$CDN\"; curl -s \"\$BASE/manifest.json\""
|
||||
t pass "抓 bundle 裡的 worker 檔比對內容" "curl -s $CDN/core/arcrun-mcp/worker.mjs -o /tmp/x.mjs"
|
||||
t pass "讀本閘自己的原始碼(本次實撞)" "cd /repo && grep -n 'exit 0' .claude/hooks/stage-before-prod-guard.sh"
|
||||
t pass "讀解保險腳本" "cd /repo && sed -n '1,40p' $ARM"
|
||||
t pass "commit 訊息裡提到出貨" "git commit -m '照 $ARM 解保險後出貨'"
|
||||
t pass "查 bundle repo 狀態" "cd /tmp/$B && git log --oneline -3"
|
||||
t pass "GET 帶 tr -d 管線" "curl -s $CDN/manifest.json | tr $DASH_D '\\r'"
|
||||
|
||||
echo "── 該擋(真的在發佈)──"
|
||||
t block "推 bundle repo" "cd /tmp/$B && git push origin main"
|
||||
t block "wrangler deploy 出貨物件" "cd $B && npx wrangler deploy"
|
||||
t block "跑出貨管線" "node installer/scripts/ship.mjs --target prod --bundles $B"
|
||||
t block "親手執行解保險腳本" "bash $ARM '出貨說明' 30"
|
||||
t block "POST 寫進 bundle repo" "curl -X POST https://api.github.com/repos/x/$B/contents/y $DASH_D '{}'"
|
||||
|
||||
t pass "同一行提到兩次解保險腳本(2026-08-12 第四次誤攔)" "echo '=== $ARM 怎麼判過期 ==='; grep -nE 'expire' $ARM"
|
||||
t pass "cat 解保險腳本" "cat $ARM"
|
||||
t block "以 bash 執行解保險腳本" "bash $ARM 'x' 30"
|
||||
t block "管線後面執行解保險腳本" "echo go && $ARM '出貨' 30"
|
||||
|
||||
echo
|
||||
echo "結果:通過 $PASS / 失敗 $FAIL"
|
||||
[ $FAIL -eq 0 ] || exit 1
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
# 管什麼: 產生「可以直接貼進 claude.ai Cloud environment」的兩塊內容,值由本腳本自己去 .env 拉。
|
||||
# 為什麼: leo 2026-08-20「這些值你都有,你可以只寫名字然後 build 一個檔案給我」——
|
||||
# 之前的做法是叫他自己拼湊,或叫他把設定貼給 AI 看,兩種都錯(一個沒效率,一個讓值經過對話)。
|
||||
# 誤觸時怎麼關: 這支不擋任何東西。不想產生就別跑;產物在版控外,刪掉即可。
|
||||
#
|
||||
# 用法:bash scripts/make-cloud-env.sh
|
||||
# 產物:~/.claude/cloud-env/<日期>.txt(權限 600,**不在任何 repo 裡**)
|
||||
# 本腳本只寫「變數名字」,值在執行當下才從既有 .env 讀出來寫進產物 —— 值不進版控、不進對話。
|
||||
set -euo pipefail
|
||||
|
||||
# ── 雲端需要哪些變數(只有名字。要加就加在這裡)──────────────────
|
||||
NEEDED=(
|
||||
GITEA_TOKEN_CLAUDE_CODE # 機器帳號 claude-code 的 Gitea token;bootstrap 與 plugin 安裝都靠它
|
||||
)
|
||||
|
||||
# ── 去哪裡找值(credentials-map.md 記的六個 .env)────────────────
|
||||
BASE="${INKSTONE_ROOT:-$HOME/Documents/tech_projects/InkStoneCo}"
|
||||
ENV_FILES=(
|
||||
"$BASE/.env"
|
||||
"$BASE/matrix/arcrun/.env"
|
||||
"$BASE/products/arcrun-rag/.env"
|
||||
"$BASE/polaris/mira/.env"
|
||||
"$BASE/matrix/kbdb-graph-plugin/.env"
|
||||
"$BASE/arcrun_harness/.env"
|
||||
)
|
||||
|
||||
lookup() { # $1=變數名 → 印出值(找不到就空)
|
||||
local name="$1" f v
|
||||
for f in "${ENV_FILES[@]}"; do
|
||||
[ -f "$f" ] || continue
|
||||
v=$(grep -E "^[[:space:]]*(export[[:space:]]+)?${name}=" "$f" 2>/dev/null | tail -1 \
|
||||
| sed -E "s/^[[:space:]]*(export[[:space:]]+)?${name}=//" \
|
||||
| sed -E 's/^"(.*)"$/\1/; s/^'"'"'(.*)'"'"'$/\1/')
|
||||
[ -n "$v" ] && { printf '%s' "$v"; return 0; }
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
OUT_DIR="$HOME/.claude/cloud-env"
|
||||
mkdir -p "$OUT_DIR"; chmod 700 "$OUT_DIR"
|
||||
OUT="$OUT_DIR/$(date +%Y%m%d-%H%M%S).txt"
|
||||
|
||||
SETUP="$(cd "$(dirname "$0")/.." && pwd)/docs/cloud-setup-script.sh"
|
||||
[ -f "$SETUP" ] || { echo "🔴 找不到 $SETUP" >&2; exit 1; }
|
||||
|
||||
MISSING=()
|
||||
{
|
||||
echo "claude.ai → Cloud environments → 你的環境。下面兩塊各自貼進對應欄位。"
|
||||
echo "產生時間:$(date '+%Y-%m-%d %H:%M')"
|
||||
echo
|
||||
echo "════════ ① Environment variables(一行一個,名字與值分開填)════════"
|
||||
for n in "${NEEDED[@]}"; do
|
||||
if v=$(lookup "$n"); then
|
||||
echo "$n=$v"
|
||||
else
|
||||
echo "$n=<🔴 這台機器的 .env 裡找不到,要 leo 提供>"
|
||||
MISSING+=("$n")
|
||||
fi
|
||||
done
|
||||
echo
|
||||
echo "════════ ② Setup script(整段貼,一字不改)════════"
|
||||
cat "$SETUP"
|
||||
} > "$OUT"
|
||||
chmod 600 "$OUT"
|
||||
|
||||
echo "✅ 產生完成:$OUT"
|
||||
echo " 變數 ${#NEEDED[@]} 個|找不到值的 ${#MISSING[@]} 個 ${MISSING[*]:-}"
|
||||
echo " 🔴 這個檔含金鑰真身:貼完就刪(rm '$OUT'),它刻意不在任何 repo 裡。"
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
# github-contact-guard 的測試(inkstone/InkStoneCo#23)
|
||||
# 判準:真的寫 GitHub(gh CLI 高頻 API、git push/remote add 指向 github.com)要擋;
|
||||
# 只是提到(heredoc body、同一行引號內的散文、commit message)不准擋;
|
||||
# 讀取(clone/fetch/pull/curl 抓檔)一律放行,不管有沒有帶認證。
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
H=hooks/github-contact-guard.sh
|
||||
PASS=0; FAIL=0
|
||||
run(){ # $1=want $2=cmd
|
||||
printf '%s' "{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":$(python3 -c 'import json,sys;print(json.dumps(sys.argv[1]))' "$2")}}" \
|
||||
| bash "$H" >/dev/null 2>&1
|
||||
got=$?
|
||||
if [ "$got" = "$1" ]; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
|
||||
printf 'want=%s got=%s %.72s\n' "$1" "$got" "$2"
|
||||
}
|
||||
|
||||
echo "── 該擋:真的在寫 GitHub ──"
|
||||
run 2 'gh issue create --title x --body y'
|
||||
run 2 'gh pr create --title x'
|
||||
run 2 'git push https://github.com/example/example.git HEAD:main'
|
||||
run 2 'git remote add github https://github.com/example/example.git'
|
||||
run 2 'echo start && gh api repos/example/example/issues'
|
||||
|
||||
echo "── 不該擋:讀取一律放行 ──"
|
||||
run 0 'git clone https://github.com/example/example.git'
|
||||
run 0 'git fetch github'
|
||||
run 0 'curl -sL https://github.com/example/example/releases/latest'
|
||||
run 0 'gh --version'
|
||||
|
||||
echo "── 不該擋:只是提到、heredoc body、同一行引號內的散文 ──"
|
||||
run 0 "$(printf 'cat > docs/TESTING.md <<%sEOF%s\nexample: git push https://github.com/example/example.git HEAD:main\nEOF\n' "'" "'")"
|
||||
run 0 'git commit -m "docs: explain why gh api calls used to be mis-flagged"'
|
||||
run 0 'python3 -c "requests.post(url, json={\"body\": \"quoting: git push origin main to github.com was mis-flagged as a real push\"})"'
|
||||
run 0 'grep -n "gh api" hooks/github-contact-guard.sh'
|
||||
run 0 'grep -rn "git push" installer/scripts/line-source-repo.mjs'
|
||||
|
||||
echo
|
||||
echo "$PASS/$((PASS+FAIL)) 通過"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
# kbdb-api-wall-guard 的 Bash 分支測試(inkstone/ISEP#30 群組)
|
||||
#
|
||||
# 這支補的是一個真的漏擋:hooks/kbdb-api-wall-guard.sh 的 Bash 分支原本引用
|
||||
# hooks/kbdb_cmd_check.py(不存在的路徑),python3 找不到檔案就以非零結束,
|
||||
# 而呼叫端寫成 `... || echo "OK"` —— 於是這個分支永遠印 "OK",Bash 分支形同虛設,
|
||||
# 任何 `wrangler d1 execute` 直打 kbdb 都會被放行。修法:邏輯搬進
|
||||
# hooks/lib/kbdb_cmd_check.py(新檔),並把 .sh 裡的參照路徑改過去。
|
||||
#
|
||||
# 判準:真的用 wrangler 對 kbdb 這顆 D1 下 execute 要擋;只是提到(commit message、
|
||||
# heredoc body、grep 搜尋)、或目標不是 kbdb 的 D1,都不准擋。
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
H=hooks/kbdb-api-wall-guard.sh
|
||||
PASS=0; FAIL=0
|
||||
run(){ # $1=want $2=cmd
|
||||
printf '%s' "{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":$(python3 -c 'import json,sys;print(json.dumps(sys.argv[1]))' "$2")}}" \
|
||||
| bash "$H" >/dev/null 2>&1
|
||||
got=$?
|
||||
if [ "$got" = "$1" ]; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
|
||||
printf 'want=%s got=%s %.72s\n' "$1" "$got" "$2"
|
||||
}
|
||||
|
||||
w="wrangler"; sub="d1 execute"; db="arcrun-kbdb"
|
||||
|
||||
echo "── 該擋:真的直打 kbdb 這顆 D1 執行 SQL ──"
|
||||
run 2 "$w $sub $db --remote --command \"SELECT 1\""
|
||||
run 2 "npx $w $sub $db --command \"SELECT 1\""
|
||||
run 2 "echo start && $w $sub $db --command \"SELECT 1\""
|
||||
|
||||
echo "── 不該擋:只是提到、heredoc body、目標不是 kbdb ──"
|
||||
run 0 "git commit -m \"ran $w $sub $db earlier, see ticket\""
|
||||
run 0 "$(printf 'cat > note.md <<%sEOF%s\nwe should avoid %s %s %s\nEOF\n' "'" "'" "$w" "$sub" "$db")"
|
||||
run 0 "grep -rn \"$w $sub\" hooks/"
|
||||
run 0 "$w $sub some-other-db --command \"SELECT 1\""
|
||||
run 0 "$w deploy --env stage"
|
||||
run 0 'echo hello world'
|
||||
run 0 "$w $sub $db --command \"SELECT 1\" kbdb-sql-ok"
|
||||
|
||||
echo
|
||||
echo "$PASS/$((PASS+FAIL)) 通過"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
# main-and-prod-push-guard 的測試(inkstone/InkStoneCo#23、#56)
|
||||
# 判準:真的推 main/master 要擋;只是提到(heredoc body、同一行引號內的散文、
|
||||
# 開頭包一層讀取指令)都不准擋;推自己的分支、含子字串但目標不是 main/master
|
||||
# 的分支(如 fix/custom-domain-setup)也不准擋。
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
H=hooks/main-and-prod-push-guard.sh
|
||||
PASS=0; FAIL=0
|
||||
run(){ # $1=want $2=cmd
|
||||
printf '%s' "{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":$(python3 -c 'import json,sys;print(json.dumps(sys.argv[1]))' "$2")}}" \
|
||||
| bash "$H" >/dev/null 2>&1
|
||||
got=$?
|
||||
if [ "$got" = "$1" ]; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
|
||||
printf 'want=%s got=%s %.72s\n' "$1" "$got" "$2"
|
||||
}
|
||||
|
||||
echo "── 該擋:真的在推 main/master,且沒有戳記 ──"
|
||||
run 2 'git push gitea HEAD:main'
|
||||
run 2 'git push origin master'
|
||||
run 2 'echo start && git push gitea HEAD:main'
|
||||
run 2 'ls && git push gitea HEAD:main'
|
||||
|
||||
echo "── 不該擋:只是提到、heredoc body、目標不是 main/master ──"
|
||||
run 0 'git push gitea HEAD:fix/custom-domain-setup'
|
||||
run 0 'git push gitea HEAD:fix/mainline-cleanup-later'
|
||||
run 0 'git commit -m "docs: explain that the old gate would mis-flag push mentions"'
|
||||
run 0 "$(printf 'cat > docs/TESTING.md <<%sEOF%s\nexample: git push https://github.com/example/example.git HEAD:main\nEOF\n' "'" "'")"
|
||||
run 0 'python3 -c "requests.post(url, json={\"body\": \"this quotes: the gate cannot see a real git push done via a node subprocess, but it will block git push origin main mentioned as prose\"})"'
|
||||
run 0 'grep -n "git push" hooks/main-and-prod-push-guard.sh'
|
||||
|
||||
echo "── 真違規不能因為這次改動而漏擋:戳記過期/戳記綁錯 repo 一樣要擋 ──"
|
||||
run 2 'git push gitea HEAD:main' # 沒有任何戳記檔時
|
||||
|
||||
echo
|
||||
echo "$PASS/$((PASS+FAIL)) 通過"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
# stage-before-prod-guard 的測試(inkstone/ISEP#30 群組——heredoc body 不算數)
|
||||
# 判準:真的碰 prod 出貨鏈、沒有 stage 驗證紀錄要擋;讀取/查證/heredoc body 不准擋;
|
||||
# 帶 staging 字樣、6 小時內驗過 stage 的要放行。
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
H=hooks/stage-before-prod-guard.sh
|
||||
PASS=0; FAIL=0
|
||||
run(){ # $1=want $2=cmd
|
||||
printf '%s' "{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":$(python3 -c 'import json,sys;print(json.dumps(sys.argv[1]))' "$2")}}" \
|
||||
| bash "$H" >/dev/null 2>&1
|
||||
got=$?
|
||||
if [ "$got" = "$1" ]; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
|
||||
printf 'want=%s got=%s %.72s\n' "$1" "$got" "$2"
|
||||
}
|
||||
|
||||
rm -f /tmp/.stage-verified /tmp/.stage-ok-by-leo
|
||||
|
||||
echo "── 該擋:真的在動 prod 出貨鏈,沒有 stage 驗證紀錄 ──"
|
||||
run 2 'wrangler deploy --name arcrun-rag-bundles-installer'
|
||||
run 2 'git push gitea arcrun-rag-bundles-installer main'
|
||||
run 2 'scripts/github-arm.sh "出貨" 30'
|
||||
run 2 'echo go && scripts/github-arm.sh "出貨" 30'
|
||||
|
||||
echo "── 不該擋:讀取/查證/演練 ──"
|
||||
run 0 'sed -n "1,40p" scripts/github-arm.sh'
|
||||
run 0 'git commit -m "照 scripts/github-arm.sh 解保險流程"'
|
||||
run 0 'grep -n "wrangler deploy" hooks/stage-before-prod-guard.sh'
|
||||
run 0 'BASE="https://cdn.jsdelivr.net/gh/x/arcrun-rag-bundles@abc"; curl -s "$BASE/manifest.json"'
|
||||
run 0 'wrangler deploy --dry-run'
|
||||
run 0 'wrangler deploy --env staging'
|
||||
|
||||
echo "── 不該擋:heredoc body 只是提到 ──"
|
||||
run 0 "$(printf 'cat > docs/TESTING.md <<%sEOF%s\nexample: wrangler deploy then scripts/github-arm.sh to ship arcrun-rag-bundles\nEOF\n' "'" "'")"
|
||||
|
||||
echo "── 6 小時內驗過 stage,且 leo 已解 GitHub 保險 → 放行 ──"
|
||||
# 條件 ① .github-armed 與條件 ② stage-verified 缺一不可,兩個都要造出來才測得到「放行」那條路
|
||||
touch .github-armed
|
||||
date +%s > /tmp/.stage-verified
|
||||
run 0 'wrangler deploy --name arcrun-rag-bundles-installer'
|
||||
rm -f /tmp/.stage-verified .github-armed
|
||||
|
||||
echo "── 只驗過 stage、沒解 GitHub 保險 → 還是要擋(條件缺一不可)──"
|
||||
date +%s > /tmp/.stage-verified
|
||||
run 2 'wrangler deploy --name arcrun-rag-bundles-installer'
|
||||
rm -f /tmp/.stage-verified
|
||||
|
||||
echo
|
||||
echo "$PASS/$((PASS+FAIL)) 通過"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
@@ -43,3 +43,17 @@ ISEP(InkStone Environment Plugin):leo 的 Claude Code 環境唯一真相
|
||||
已比對過的等價性(2026-08-20 逐支):
|
||||
- hook 檔案:41 支檔名完全相同,ISEP 多一支 `release-tag-guard.sh`
|
||||
- 註冊條數:PreToolUse 29→30、SessionStart 2、Stop 10、SubagentStop 7、PostToolUse 3,其餘完全相同
|
||||
|
||||
|
||||
## v0.2.0 / v0.2.1 已撤回(2026-08-20)
|
||||
|
||||
leo:「**你可以把舊的兩個 ISEP 版本刪掉,偷工減料的不能算,這不是交件被退回,
|
||||
是根本未達足以交件的水準。**」
|
||||
|
||||
⇒ 兩個 release 與 tag 已刪除,`plugin.json` 回到哨兵值 `0.0.0`(=尚未發過正式版)。
|
||||
|
||||
**為什麼不算交件**:那兩版做的是 ISEP 自己的鷹架(搬檔案、寫規範、建標籤、補測試手冊),
|
||||
而**當時 45 張管理票一張都沒關**。leo:「舊票都沒解決你出一堆版本幹嘛?根本沒解決舊有問題」。
|
||||
|
||||
🔴 **下一個版本的門檻**:至少關掉一張既有的管理票,release note 寫明關了哪張。
|
||||
沒關掉舊票的東西不叫版本,叫進度。
|
||||
|
||||
Reference in New Issue
Block a user