Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ee085c1854 |
@@ -8,7 +8,7 @@
|
|||||||
"plugins": [
|
"plugins": [
|
||||||
{
|
{
|
||||||
"name": "isep",
|
"name": "isep",
|
||||||
"description": "InkStone Environment Plugin —— leo 的 Claude Code 環境唯一真相源:61 支機械閘(85 條註冊,白話盤點見 docs/hooks-inventory.md)、7 支 slash command、2 支 skill、7 位有名字的工人(agents/,見 docs/governance/worker-roster.md)、56 支腳本,外加治理規範與標籤真相源。本機與雲端裝同一份,沒有子集。",
|
"description": "InkStone Environment Plugin —— leo 的 Claude Code 環境唯一真相源:51 支機械閘(64 條註冊,白話盤點見 docs/hooks-inventory.md)、7 支 slash command、2 支 skill、27 支腳本,外加治理規範與標籤真相源。本機與雲端裝同一份,沒有子集。",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Leo",
|
"name": "Leo",
|
||||||
"url": "https://uncle6.me"
|
"url": "https://uncle6.me"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "isep",
|
"name": "isep",
|
||||||
"description": "InkStone Environment Plugin —— leo 的 Claude Code 環境唯一真相源:61 支機械閘(85 條註冊,白話盤點見 docs/hooks-inventory.md)、7 支 slash command、2 支 skill、7 位有名字的工人(agents/,見 docs/governance/worker-roster.md)、56 支腳本,外加治理規範與標籤真相源。本機與雲端裝同一份,沒有子集。",
|
"description": "InkStone Environment Plugin —— leo 的 Claude Code 環境唯一真相源:61 支機械閘(84 條註冊,白話盤點見 docs/hooks-inventory.md)、7 支 slash command、2 支 skill、7 位有名字的工人(agents/,見 docs/governance/worker-roster.md)、49 支腳本,外加治理規範與標籤真相源。本機與雲端裝同一份,沒有子集。",
|
||||||
"version": "0.24.0",
|
"version": "0.21.0",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"inkstone",
|
"inkstone",
|
||||||
"guardrails",
|
"guardrails",
|
||||||
|
|||||||
@@ -23,11 +23,11 @@
|
|||||||
|
|
||||||
| | 數量 | 是什麼 |
|
| | 數量 | 是什麼 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `hooks/` | 61 支 + `hooks.json` | 全部機械閘(PreToolUse/Stop/SubagentStop/SessionStart/PostToolUse/UserPromptSubmit 共 85 條註冊)。**一支一行的白話盤點在 `docs/hooks-inventory.md`,那裡才是這兩個數字的家** |
|
| `hooks/` | 61 支 + `hooks.json` | 全部機械閘(PreToolUse/Stop/SubagentStop/SessionStart/PostToolUse/UserPromptSubmit 共 84 條註冊)。**一支一行的白話盤點在 `docs/hooks-inventory.md`,那裡才是這兩個數字的家** |
|
||||||
| `agents/` | 7 位 | **工人名單**(`inkstone/ISEP#86`)——派工時指名派給誰,規約見 `docs/governance/worker-roster.md` |
|
| `agents/` | 7 位 | **工人名單**(`inkstone/ISEP#86`)——派工時指名派給誰,規約見 `docs/governance/worker-roster.md` |
|
||||||
| `commands/` | 7 支 | `/wiki-recall` `/wiki-capture` `/cp-write` `/issue-handle` … |
|
| `commands/` | 7 支 | `/wiki-recall` `/ship-check` `/cp-write` … |
|
||||||
| `skills/` | 2 支 | `ship-check`(東西要出去之前)/`deep-recall`(把散落的枝葉還原成一棵樹)。🔴 **這兩支的內容不一定是在這裡寫的**——誰是真相源查 `docs/file-ownership.tsv` |
|
| `skills/` | 2 支 | |
|
||||||
| `scripts/` | 56 支 | `ticket`/`roster`/`isep-nag`/`wiki-compress`/`github-arm.sh` …(頂層檔案,不含 `lib/` 等子目錄) |
|
| `scripts/` | 49 支 | `ticket`/`roster`/`isep-nag`/`wiki-compress`/`github-arm.sh` …(頂層檔案,不含 `lib/` 等子目錄) |
|
||||||
|
|
||||||
> 🔴 這五個數字**每次都要在自己的樹上實數**,不准沿用上一版、也不准用加減推
|
> 🔴 這五個數字**每次都要在自己的樹上實數**,不准沿用上一版、也不准用加減推
|
||||||
> (`system-dev/wiki/mistakes.md`:那是 leo 的驗收介面,多報就是假綠):
|
> (`system-dev/wiki/mistakes.md`:那是 leo 的驗收介面,多報就是假綠):
|
||||||
@@ -70,13 +70,6 @@ hook 一律用官方的 `${CLAUDE_PLUGIN_ROOT}`,**不准寫死絕對路徑、
|
|||||||
🔴 **只改這裡,然後兩邊 `/plugin update`。**
|
🔴 **只改這裡,然後兩邊 `/plugin update`。**
|
||||||
不要再改 `InkStoneCo/.claude/hooks/`——那個目錄退場中。
|
不要再改 `InkStoneCo/.claude/hooks/`——那個目錄退場中。
|
||||||
|
|
||||||
🔴 **但有些檔案的內容不是在這裡寫的**(`inkstone/ISEP#122`):
|
|
||||||
`skills/`/`commands/`/`agents/` 底下有幾個檔案在 InkStoneCo 也有一份,
|
|
||||||
**誰是真相源、往哪個方向修,一律查 `docs/file-ownership.tsv`**,不要憑「ISEP 一定比較新」動手
|
|
||||||
——2026-09-02 實查,兩個方向都真的發生過(`ship-check` 是那邊新,`sdd-check` 是這邊新)。
|
|
||||||
改完那類檔案要把 commit/sha256 兩欄一起更新;沒更新的話,
|
|
||||||
`isep-presence-beacon.sh` 會在下一個 session 開場當著大家的面說它對不上。
|
|
||||||
|
|
||||||
## 這些閘各自在管什麼
|
## 這些閘各自在管什麼
|
||||||
|
|
||||||
**不用點開任何 `.sh`**——`docs/hooks-inventory.md` 一支一行白話,按「你會在什麼時候撞到它」分組。
|
**不用點開任何 `.sh`**——`docs/hooks-inventory.md` 一支一行白話,按「你會在什麼時候撞到它」分組。
|
||||||
|
|||||||
+41
-265
@@ -330,19 +330,11 @@ bash hooks/tests/unpushed-police.test.sh
|
|||||||
- B 群(⑦—⑩,該報)任一紅 ⇒ 為了不吵而改成放行了,那是把閘關掉不是修好
|
- B 群(⑦—⑩,該報)任一紅 ⇒ 為了不吵而改成放行了,那是把閘關掉不是修好
|
||||||
- 特別看 ④:問不到遠端(離線)**不准當成「你沒推」**
|
- 特別看 ④:問不到遠端(離線)**不准當成「你沒推」**
|
||||||
|
|
||||||
### A18 — 信標會講出雲端會壞掉的那幾件事:26 條
|
### A18 — 信標會講出雲端會壞掉的那三件事:14 條
|
||||||
```
|
```
|
||||||
bash hooks/tests/isep-presence-beacon.test.sh
|
bash hooks/tests/isep-presence-beacon.test.sh
|
||||||
```
|
```
|
||||||
**該看到**:`通過 26 條,失敗 0 條`。全離線。
|
**該看到**:`通過 14 條,失敗 0 條`。全離線。
|
||||||
|
|
||||||
> 📌 `inkstone/ISEP#122` 從 14 條加到 26 條:信標原本只掃 `scripts/`,
|
|
||||||
> 而**真正會自動載入的東西**(skill/command/agent)同樣兩邊各有一份。
|
|
||||||
> 實查:那 9 個檔案在 `0.1.0`(c263866)複製過來之後**一次都沒再同步**,
|
|
||||||
> 到 2026-09-02 已經分家兩個、而且**方向相反**——
|
|
||||||
> `skills/ship-check/SKILL.md` 是 InkStoneCo 那邊新,`commands/sdd-check.md` 是 ISEP 這邊新。
|
|
||||||
> ⇒ 所以新增的不只是「有沒有掃到」,還有「**說不說得出真相源是哪一份**」
|
|
||||||
> (`docs/file-ownership.tsv`),以及**雲端沒有專案那一份可比時**改用 sha256 單邊驗。
|
|
||||||
|
|
||||||
**它在守什麼**(inkstone/ISEP#90 ②③):信標原本只證明「有一份 plugin 載入了」,
|
**它在守什麼**(inkstone/ISEP#90 ②③):信標原本只證明「有一份 plugin 載入了」,
|
||||||
不證明「載入的是哪一份」——08-27 雲端載 0.3.9、main 0.9.0,差 7 個 release,
|
不證明「載入的是哪一份」——08-27 雲端載 0.3.9、main 0.9.0,差 7 個 release,
|
||||||
@@ -354,112 +346,6 @@ bash hooks/tests/isep-presence-beacon.test.sh
|
|||||||
- ⑤⑦ 紅 ⇒ 舊複本遮蔽正門抓不到(`InkStoneCo/scripts/ticket` 那件)
|
- ⑤⑦ 紅 ⇒ 舊複本遮蔽正門抓不到(`InkStoneCo/scripts/ticket` 那件)
|
||||||
- ⑥ 紅 ⇒ **誤攔**:同步過的複本被念,人就學會忽略它
|
- ⑥ 紅 ⇒ **誤攔**:同步過的複本被念,人就學會忽略它
|
||||||
- ⑪ 紅 ⇒ 內層迴圈變數撞名的回歸(同一個 `.claude` 下第二個殘骸會被靜靜跳過)
|
- ⑪ 紅 ⇒ 內層迴圈變數撞名的回歸(同一個 `.claude` 下第二個殘骸會被靜靜跳過)
|
||||||
- ⑮⑱⑲⑳ 任一紅 ⇒ 自動載入的分身抓不到(`ship-check` 那件會再發生一次)
|
|
||||||
- ⑰ 紅 ⇒ **誤攔**:同步過的複本被念,人就學會忽略它(跟 ⑥ 同一條線)
|
|
||||||
- ㉔ 紅 ⇒ 雲端唯一還作數的那個檢查失效(薄殼沒有 InkStoneCo 可以比)
|
|
||||||
- ㉕ 紅 ⇒ **誤攔**:還沒登記 sha256 的檔案被當成「被改過」
|
|
||||||
|
|
||||||
### A29 — 閘印出來的逃生門,照著打真的過得去:10 條
|
|
||||||
> 📌 編號跳過 A27/A28:那兩格被同一張票的 PR `inkstone/ISEP#124` 佔著(還沒併)。
|
|
||||||
```
|
|
||||||
bash hooks/tests/history-first-guard.test.sh
|
|
||||||
```
|
|
||||||
**該看到**:`通過 10 條,失敗 0 條`。全離線,全程用 `KBDB_STAMP_DIR` 指到 TMP,
|
|
||||||
**不碰這台機器真正的 `/tmp/.kbdb-*` 戳記**(清掉別人的戳記=把閘弄成隨機的)。
|
|
||||||
|
|
||||||
**它在守什麼**(`inkstone/ISEP#122`,2026-09-02 實撞):`history-first-guard.sh` 印的
|
|
||||||
`🚪 KBDB 真的連不上:touch /tmp/.kbdb-down 後重送` 是**假的**——
|
|
||||||
`touch` 造出來的是空檔,而那支閘讀的是**檔案內容**當時戳,空字串被當成 0
|
|
||||||
⇒ 「距今 17 億秒」⇒ 永遠不新鮮 ⇒ **照著訊息打完,被一模一樣地擋第二次**。
|
|
||||||
|
|
||||||
🔴 這跟本票 comment 6071、`inkstone/ISEP#125` 是同一句話:
|
|
||||||
**閘印出來的下一步,沒有人實際照著打過一次。**
|
|
||||||
|
|
||||||
**失敗**:
|
|
||||||
- ④ 紅 ⇒ 逃生門又是假的(這是本支唯一分辨得出新舊版的那一格,見檔頭)
|
|
||||||
- ⑦ 紅 ⇒ 逃生門變成永久後門(一次 `touch` 就免疫,過期不算數這件事沒了)
|
|
||||||
- ⑧⑨⑩ 任一紅 ⇒ **誤攔**:文件/新檔/測試檔本來就不該被這支碰
|
|
||||||
|
|
||||||
### A30 — 測試沙盒傳錯參數時要在**複製之前**收手:10 條
|
|
||||||
```
|
|
||||||
bash hooks/tests/hook-sandbox.test.sh
|
|
||||||
```
|
|
||||||
**該看到**:`通過 10 條,失敗 0 條`。全離線。
|
|
||||||
|
|
||||||
**它在守什麼**(`inkstone/ISEP#122`,2026-09-02 實撞,**兩次**):
|
|
||||||
`hooks/tests/lib/hook-sandbox.sh` 的 `hook_sandbox <hook 的檔案路徑>` 舊版**不驗參數**,
|
|
||||||
直接 `cp -R "$(dirname "$1")"`。順手把 repo 根目錄傳進去時:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ bash hooks/tests/main-and-prod-push-guard.test.sh "$PWD"
|
|
||||||
dirname → ~/Documents/tech_projects ← 上一層,不是 hooks/
|
|
||||||
cp -R → 整個 tech_projects(所有 repo、所有 worktree)搬進 mktemp
|
|
||||||
實測 一次 13 GB+一次 10 GB,磁碟可用從 25 GB 掉到 462 MB
|
|
||||||
印出來的 ❌ 沙盒建不起來 ← 只有這一句
|
|
||||||
```
|
|
||||||
|
|
||||||
🔴 **它沒說參數傳錯,也沒說它已經把磁碟寫滿了。**
|
|
||||||
判準用「要求某個東西在場」(`$1` 要是真的檔案;上一層要叫 `hooks`),
|
|
||||||
不是關鍵字比對——兩條任一不成立就在 `mktemp` 之前 `return 1`。
|
|
||||||
|
|
||||||
📌 **正確用法**(兩支需要傳參數的測試,`docs/TESTING.md` 之前沒寫過):
|
|
||||||
```
|
|
||||||
bash hooks/tests/main-and-prod-push-guard.test.sh hooks/main-and-prod-push-guard.sh
|
|
||||||
bash hooks/tests/main-and-prod-push-guard-cross-repo.test.sh hooks/main-and-prod-push-guard.sh
|
|
||||||
bash hooks/tests/prod-write-guard.test.sh hooks/prod-write-guard.sh
|
|
||||||
bash hooks/tests/stage-before-prod-guard.test.sh hooks/stage-before-prod-guard.sh
|
|
||||||
bash hooks/tests/gitea-arm-check.test.sh .
|
|
||||||
```
|
|
||||||
**不傳的後果不是報錯,是假綠**:`prod-write-guard.test.sh` 的 `HOOK="$1"` 空掉時
|
|
||||||
每一條都執行空指令回 0 ⇒ 「該擋」全部變成「實得 pass」,**19 條假紅**
|
|
||||||
(同一支傳對參數是 `通過 37 / 失敗 0`)。不必自己傳參數的包裝在
|
|
||||||
`scripts/test-main-and-prod-push-guard.sh`。
|
|
||||||
|
|
||||||
**失敗**:
|
|
||||||
- ①③⑤⑥ 任一紅 ⇒ 收手收得太晚,暫存區已經開始長東西(磁碟風險回來了)
|
|
||||||
- ② 紅 ⇒ 訊息沒給出走得通的那一行(本票整張票在講的就是這件事)
|
|
||||||
- ⑧⑨⑩ 任一紅 ⇒ **誤攔/複製錯**:正常用法被弄壞,或複本裡混進了 `hooks/` 以外的東西
|
|
||||||
### A31 — 雲端工人抓票的規則是機械可判的:48 條
|
|
||||||
```
|
|
||||||
bash scripts/test-ticket-pick.sh
|
|
||||||
```
|
|
||||||
**該看到**:`通過 48 條,失敗 0 條`。**全程離線**:假池子(3 個 repo、3 個 open milestone、
|
|
||||||
11 張票)餵給換掉的 `api()`,時鐘走 `ISEP_COUNTDOWN_NOW`,`TICKET_HOST` 指到連不上的位址
|
|
||||||
——任何一條真的走到網路會當場炸,不會靜靜變成假綠。**不開票、不改票、不留任何東西在 Gitea 上。**
|
|
||||||
|
|
||||||
**它在守什麼**(`inkstone/ISEP#131`):Routine 08-06 起讀 `journeys.md` 本 sprint 段,
|
|
||||||
08-19 到期沒續,**連續兩週讀到殘骸只能空轉**。09-07 把 `cloud-worker.md` 步驟 1 改成從
|
|
||||||
Gitea 主線里程碑抓票(`inkstone/InkStoneCo#118`),但那是一段給人讀的字。
|
|
||||||
這一支把規則做成 `scripts/ticket pick`/`claim` 兩個動詞,規則本體在 `pickable()` 一支純函式:
|
|
||||||
|
|
||||||
```
|
|
||||||
可抓 s/* 恰好是 {s/todo} + 沒有 assignee + 沒有 Human/human/* + 不是 hub + 里程碑=主線
|
|
||||||
主線抓盡才抓「逾期的 open 里程碑」;backlog/沒里程碑一律不抓
|
|
||||||
認領 claim = 指派 + s/doing + 第一行【身份】的留言,一個動作
|
|
||||||
完成 handback --label s/review(本來就有的那半,不重做)
|
|
||||||
```
|
|
||||||
|
|
||||||
**失敗**:
|
|
||||||
- ①「★」那四條任一紅 ⇒ 票上驗收第 1 條破了:Human/有 assignee/backlog 有一種會被抓走
|
|
||||||
- ①「s/todo+s/doing 同時掛著」紅 ⇒ 會把別人正在做的票抓走(09-07 實查 `inkstone/mira#6`
|
|
||||||
就是這個形狀——exclusive 只擋 UI 不擋 API)
|
|
||||||
- ②「主線抓盡 → 才輪到逾期」那兩條紅 ⇒ 順序壞了:要嘛主線還有票就去抓逾期的,
|
|
||||||
要嘛抓盡了還回 `Arcrun#8`(既不是主線也沒逾期)
|
|
||||||
- ②「離開碼 1」紅 ⇒ 「真的沒有票」與「讀不到」被講成同一句——後者要離開碼 2
|
|
||||||
- ②「沒有主線 → 離開碼 2 且一通 API 都沒打」紅 ⇒ 沒主線時去抓了別的
|
|
||||||
- ③「該擋」六條任一紅 ⇒ 規則只長在 `pick` 這端,手動 `claim` 一張 Human 的票照樣過
|
|
||||||
- ③「身份名不在名單上 → 一通都沒打」紅 ⇒ 名單以外的名字碰到了 Gitea
|
|
||||||
- ④ 第一條紅 ⇒ 連不上 Gitea 時回了離開碼 1,雲端會把「斷線」當「沒票」收工
|
|
||||||
|
|
||||||
📌 **真實 Gitea 唯讀實跑**(2026-09-07,isep-hand,不改任何票):
|
|
||||||
`ticket pick --mainline InkStoneCo/system-dev/mainline.json --all` 在主線
|
|
||||||
「AI 問一次就看得到全部」回 `ISEP#130`、`ISEP#131` 兩張(`Arcrun#175/176` 已有 assignee、
|
|
||||||
`Arcrun#86` 是 s/doing、`mira#6` s/todo+s/doing 都沒被抓);逾期里程碑組把 `ISEP#31–35`
|
|
||||||
五張 `hub` 排除後剩 `Arcrun#83`、`mira#5`、`arcrun-rag#14/27/37`。
|
|
||||||
**寫入那半**用 `claim inkstone/ISEP#131 --name isep-hand` 真的認領過一次:
|
|
||||||
assignee=`claude-code`、標籤 `s/todo → s/doing`、留言 6325 第一行【身份】——
|
|
||||||
之後再 `pick` 就不再回 #131(票上驗收第 2 條的 log 在票的留言裡)。
|
|
||||||
|
|
||||||
### A19 — 下游做完時頂層跟著關:49 條
|
### A19 — 下游做完時頂層跟著關:49 條
|
||||||
```
|
```
|
||||||
bash scripts/test-ticket-handoff-writeback.sh
|
bash scripts/test-ticket-handoff-writeback.sh
|
||||||
@@ -719,145 +605,54 @@ B 段拿這台機器真正的 `.env` 對帳——**`.env` 不在的機器(雲
|
|||||||
> ```
|
> ```
|
||||||
> ⇒ 第二條正是黑名單會放過去的形狀。
|
> ⇒ 第二條正是黑名單會放過去的形狀。
|
||||||
|
|
||||||
### A31 — leo21c 讀可以、寫不行,而且改法指到活著的 youlin:26 條
|
### A27 — 一次性戳記真的能放行一次:重複掛載清乾淨了,也不會靜靜復發(`inkstone/ISEP#122`)
|
||||||
```
|
```
|
||||||
bash hooks/tests/leo21c-write-guard.test.sh
|
bash hooks/tests/duplicate-hook-registration-guard.test.sh
|
||||||
|
bash hooks/tests/kv-write-guard.test.sh
|
||||||
```
|
```
|
||||||
**該看到**:`通過 26 條,失敗 0 條`。全程離線,這支閘不寫檔,直接跑真跡。
|
**該看到**:兩支各自 `8 通過 / 0 失敗`。全程用假的 plugin root/專案目錄,
|
||||||
|
不碰真正的 `InkStoneCo/.claude/` 或這台機器裝著的 ISEP plugin。
|
||||||
|
|
||||||
**它在守什麼**(inkstone/ISEP#130,2026-09-04 雲端 run log):`leo21c-write-guard.sh`
|
**它們在守什麼**(2026-09-01 實撞):總管三次要部署 uncle6.me,三次被
|
||||||
**連讀都擋**——Routine 讀 `notify_leo` 定義那一條被攔下,雲端於是什麼都拿不到。
|
`prod-write-guard.sh` 恆擋——蓋了戳記、確認戳記還在,執行動作時照樣被擋,
|
||||||
實查:舊判準 `-d[[:space:]]` 把 `| tr -d '\r'`、`cut -d=` 這種唯讀的 `-d` 當成 curl 的 body;
|
再看戳記已經不見。根因:`InkStoneCo/.claude/settings.json` 還登記著一份
|
||||||
`prod-write-guard.sh` 在 08-12 就修過同一個洞,這支漏了。另外它把 `notify_leo` 的 trigger
|
2026-08-20 立 ISEP plugin 之前的舊 hook(那時 `.claude/hooks/` 是唯一的家),
|
||||||
一律當寫入擋,而 `prod-write-guard.sh` 從 ISEP#63 起就放行它——**兩支閘對同一條指令說不同的話**。
|
跟 plugin 自己的 `hooks.json` 同時掛在同一個 `PreToolUse` 事件上——每個動作
|
||||||
這支之前**沒有任何測試**,「讀會不會被誤攔」從來沒被驗過。
|
都跑了**兩次**,一次由專案版、一次由 plugin。多數閘只是白跑一次沒感覺,
|
||||||
|
但一次性戳記(蓋了就消耗掉)被第一份吃光,第二份永遠看到空戳記,於是恆擋。
|
||||||
|
|
||||||
測資是 Routine 文件(`cloud-worker.md`/`progress-guard.md`)裡**真的會下的那幾條**。
|
**實查結果**(在這台機器的樹上實數,不是推算):`InkStoneCo/.claude/settings.json`
|
||||||
|
登記著 38 支專案版 hook——**34 支跟 plugin 完全同名同用途**(純殘骸)、
|
||||||
|
**3 支是已經退役的機制**(`claim-verify-police.sh`/`subagent-claim-worksheet.sh`/
|
||||||
|
`sdd-guard.sh`,`inkstone/ISEP#60`/`#91` 早已裁定退役,但專案版沒有跟著退),
|
||||||
|
**1 支(`kv-write-guard.sh`)是專案版有、plugin 當時沒有的真閘**(2026-08-25
|
||||||
|
立,長效資料不准寫進 KV)。前 37 支已從 `InkStoneCo/.claude/settings.json`
|
||||||
|
與 `.claude/hooks/` 刪除;第 38 支原樣搬進本 repo(同一輪 commit,見 B 組)。
|
||||||
|
|
||||||
**失敗**:
|
**失敗**:
|
||||||
- A 群任一紅 ⇒ **誤攔**,雲端又回到「連讀都讀不到」;③④⑤ 紅就是 09-04 那個形狀復發
|
- `kv-write-guard.test.sh` 任一「該擋」紅 ⇒ 搬過來時邏輯改壞了,
|
||||||
- ⑫ 紅 ⇒ 撞人閘時發 Telegram 叫 leo 又會被擋(inkstone/InkStoneCo#110 的病)
|
KV 寫入的偵測失靈
|
||||||
- B 群任一紅 ⇒ 寫得進 leo 的真庫(2026-08-20 那 8 張測試卡的病)。⑬ 特別看:
|
- `kv-write-guard.test.sh` 任一「不該擋」紅 ⇒ 誤攔,這比漏擋嚴重——
|
||||||
Routine 的心跳 POST **就是寫入**,它該被擋——那條指令要改,不是閘要放
|
正常的 `.get`/退休戰的刪除/`kv-ok` 豁免都要放得過
|
||||||
- ㉔㉕ 紅 ⇒ 閘印的「改法」教人打 09-02 起 DNS 已不存在的舊子網域,照著做只會拿到 000
|
- `duplicate-hook-registration-guard.test.sh` 的「該吵」任一紅 ⇒
|
||||||
|
重複掛載又會靜靜發生,**下一次會是另一支帶戳記語意的閘恆擋,
|
||||||
|
而且要等 leo 自己撞到才會被發現**
|
||||||
|
- `duplicate-hook-registration-guard.test.sh` 的「不該吵」任一紅 ⇒
|
||||||
|
誤攔,每個 session 開場都吵一次沒問題的環境,最後被學會忽略
|
||||||
|
|
||||||
**修之前用同一份測試跑舊閘(`git show main:hooks/leo21c-write-guard.sh`)**:③⑤⑫㉔㉕ 五條紅
|
### A28 — 收工前的實測:蓋一次戳記真的只用得掉一次(手動,這台機器)
|
||||||
——證明這五格是真的改到了,不是測試順著新閘寫的。
|
這一格驗的是**行為**,不是**檔案**——上面兩支測試證明「新機制自己邏輯對」,
|
||||||
|
這格證明「舊的重複掛載真的被拆掉了」。在**新開**的 session 裡跑(PreToolUse hook
|
||||||
### A32 — 主線那個檔隨 repo 走:17 條
|
是 session 啟動時載入的常駐清單,同一支閘改完不會讓已經在跑的 session 重新讀):
|
||||||
```
|
```
|
||||||
bash hooks/tests/mainline-repo-mirror.test.sh
|
bash "$CLAUDE_PLUGIN_ROOT/scripts/gate-ok" prod-write # 蓋一次戳記
|
||||||
|
# 執行一個會被 prod-write-guard.sh 擋的動作(例如 wrangler pages deploy 打非白名單目標)
|
||||||
```
|
```
|
||||||
**該看到**:`通過 17 條,失敗 0 條`。全程離線:家目錄那份走 `ISEP_COUNTDOWN_STATE_DIR`、
|
**該看到**:蓋戳記那個會被擋的動作**這次放行**(① 蓋一次戳記 → ② 動作通過);
|
||||||
repo 那份走 TMP 底下的假 `InkStoneCo/system-dev/`。
|
不蓋戳記重跑同一個動作 → **仍然被擋**(證明沒有把閘弄鬆,只是不再被自己的複本吃掉)。
|
||||||
|
**失敗**:蓋了戳記仍被擋 ⇒ 還有第三份複本沒清乾淨,去跑
|
||||||
**它在守什麼**(inkstone/ISEP#130;leo 09-05「routine 每天早上開啟後抓不到任務」):
|
`bash "$CLAUDE_PLUGIN_ROOT/hooks/duplicate-hook-registration-guard.sh"`
|
||||||
主線只住在家目錄,雲端是另一台機器 ⇒ 不知道主線是哪條。PR inkstone/InkStoneCo#118
|
(或直接開一個新 session 看它開場有沒有吵)先定位是哪一份。
|
||||||
把它放進 `system-dev/mainline.json`,這裡驗 ISEP 這一半:**家目錄沒有就讀 repo 那份;
|
|
||||||
兩份都在 `set_at` 較新的算數;`set`/`adopt`/`clear` 兩份一起動;`refresh` 只寫家目錄。**
|
|
||||||
|
|
||||||
**失敗**:
|
|
||||||
- ①②③ 紅 ⇒ 雲端(`$CLAUDE_PROJECT_DIR` 是薄殼根、真身在 `InkStoneCo/`)仍然讀不到主線
|
|
||||||
- ⑤⑥ 紅 ⇒ 誰後標的誰算數這條壞了:本機會把雲端剛標的蓋回去,或反過來
|
|
||||||
- ⑧ 紅 ⇒ **每開一個 session InkStoneCo 的工作樹就髒一次**,而髒的 diff 沒有人會去 commit
|
|
||||||
- ⑫ 紅 ⇒ `clear` 之後下一次讀又從 repo 那份長回來
|
|
||||||
- ⑮ 紅 ⇒ ISEP#82 第 4 條(沒有主線不能整組壞掉)被本票弄壞
|
|
||||||
|
|
||||||
雲端實跑(2026-09-07,本 session):`CLAUDE_PROJECT_DIR=/home/user/inkstoneco
|
|
||||||
ISEP_COUNTDOWN_STATE_DIR=$(mktemp -d) python3 scripts/mainline` → 印出
|
|
||||||
`🎯 現在的主線:inkstone/Arcrun#48「AI 問一次就看得到全部…」`——家目錄空的,只靠 repo 那份。
|
|
||||||
|
|
||||||
### A33 — 權限白名單住 ISEP 一份、兩台各自寫進家目錄:19 條
|
|
||||||
```
|
|
||||||
bash scripts/test-settings-allow-sync.sh
|
|
||||||
```
|
|
||||||
**該看到**:`19/19 通過`。全程在 TMP 底下的假 `settings.json` 上跑,不碰真的 `~/.claude/settings.json`。
|
|
||||||
|
|
||||||
**它在守什麼**(inkstone/ISEP#130 → comment 6120/6121):leo 09-07 親手加進本機
|
|
||||||
`InkStoneCo/.claude/settings.json` 的四條(`ticket`/`mainline`/`gate-ok`/`gitea-pr-merge`)
|
|
||||||
雲端沒有 ⇒ 同樣動作被分類器擋(09-04 `permission_denials=6`)。雲端真正讀的薄殼 repo
|
|
||||||
要 D20 開閘才推得動 ⇒ 清單住 ISEP `docs/permissions-allow.json`,`scripts/settings-allow-sync`
|
|
||||||
在那台機器上寫進 `~/.claude/settings.json`:雲端由 `docs/cloud-setup-script.sh` 裝完 plugin 跑一次、
|
|
||||||
之後每個 SessionStart 再對一次;本機同一支。
|
|
||||||
|
|
||||||
**失敗**:
|
|
||||||
- A1 紅 ⇒ 清單裡混進了整類放行(`Bash(python3 *)`)或少了正門工具
|
|
||||||
- B3/B4 紅 ⇒ `~` 沒換成那台的家目錄——雲端是 `/root` 不是 `/Users/youlinhsieh`,規則會對不上
|
|
||||||
- B7 紅 ⇒ 不冪等,每個 session 都改一次 settings.json
|
|
||||||
- **C1 紅 ⇒ 動到了別人手加的規則**。這支只准加不准減
|
|
||||||
- E1 紅 ⇒ 目標壞掉時炸了——它掛在 SessionStart,炸了 session 就沒閘
|
|
||||||
- F1/F2 紅 ⇒ 沒接線:清單對了但沒人會去跑它
|
|
||||||
|
|
||||||
⚠️ **這支驗不了「分類器真的不擋」**——那要在雲端一趟 run 裡看 `permission_denials`。
|
|
||||||
規則的形狀(`Bash(python3 …/isep/*/scripts/ticket *)`)沿用 leo 09-07 親手加、實測有效的那四條。
|
|
||||||
|
|
||||||
### A34 — 收件 repo 寫 `owner/repo` 不該是 404:7 條
|
|
||||||
```
|
|
||||||
bash scripts/test-ticket-repo-arg.sh
|
|
||||||
```
|
|
||||||
**該看到**:`通過 7 條,失敗 0 條`。把 `scripts/ticket` 當模組載進來、`api()` 換成只記路徑的假貨——
|
|
||||||
不打 Gitea、不開票、不留戳記。
|
|
||||||
|
|
||||||
**它在守什麼**(inkstone/ISEP#130 → comment 6120 第 2 件):09-07 `ticket new inkstone/ISEP`
|
|
||||||
回 404。不是 ISEP 不存在,是 `inkstone/ISEP` 被原樣塞進 `/repos/inkstone/{repo}/issues`
|
|
||||||
⇒ 打到 `/repos/inkstone/inkstone/ISEP/issues`。**正門壞了人就走側門**——那天四張票是直接打 API 開的。
|
|
||||||
|
|
||||||
**失敗**:② 紅 ⇒ 那個 404 復發;③ 紅 ⇒ 寫錯 org 又變成一個要人猜的 404;⑦ 紅 ⇒ 路徑裡出現 `inkstone/inkstone`。
|
|
||||||
|
|
||||||
### A35 — 雲端唯一通的通知路(Bot API 直送):10 條
|
|
||||||
```
|
|
||||||
bash scripts/test-isep-notify-botapi.sh
|
|
||||||
```
|
|
||||||
**該看到**:`10/10 通過`。Bot API 指到本機一個假伺服器、實例那條也指到它——不打真 Telegram、不打實例。
|
|
||||||
|
|
||||||
**它在守什麼**(inkstone/ISEP#130,2026-09-07 從雲端實測):
|
|
||||||
```
|
|
||||||
notify_leo @ leo21c → HTTP 404「找不到 workflow」(08-28 起就斷;修它是 leo 的人閘)
|
|
||||||
notify_leo @ youlin → 雲端 egress proxy 回 403(policy denial;要 leo 在 Cloud environment 放行主機)
|
|
||||||
api.telegram.org → 302,通
|
|
||||||
```
|
|
||||||
⇒ 雲端唯一走得通的是 Bot API 直送,只缺 `TELEGRAM_BOT_TOKEN`/`TELEGRAM_CHAT_ID` 兩個環境變數。
|
|
||||||
有就先走它(不碰實例,閘管不到也不必管);沒有要**點名缺哪兩個**,不能靜默。
|
|
||||||
|
|
||||||
**失敗**:A1 紅 ⇒ 沒憑證時不講缺什麼,leo 不知道要在 Cloud environment 加哪兩個;
|
|
||||||
B3 紅 ⇒ 送到了還去打實例;C1 紅 ⇒ 401 被講成送到;D1 紅 ⇒ 舊版閘 block 時直送也被連坐。
|
|
||||||
|
|
||||||
### A36 — 雲端對 stage 的寫入有正門,而且只寫得進 stage:45 條
|
|
||||||
```
|
|
||||||
bash scripts/test-stage.sh
|
|
||||||
```
|
|
||||||
**該看到**:`45/45 通過`。CF API 與 stage 實例都指到本機一個假伺服器——不打真 Cloudflare、不碰任何 worker。
|
|
||||||
假伺服器對 secret PUT 回 **201**(真 CF 就是 201)。
|
|
||||||
|
|
||||||
**它在守什麼**(inkstone/ISEP#137,2026-09-07 三條主線工人在雲端撞的同一面牆):
|
|
||||||
```
|
|
||||||
printf … | npx wrangler secret put … ← 分類器擋(複合指令對不上白名單任何一條前綴)
|
|
||||||
python3 scripts/stage-deploy-artifacts.py all --confirm ← 分類器擋
|
|
||||||
curl -X POST …arcrun-yuga3bse.workers.dev/records ← 分類器擋;0.21.0 的 prod-write-guard 又當它是 prod
|
|
||||||
```
|
|
||||||
⇒ `scripts/stage`:`secret put/list/delete`(直接打 CF API,不經 npx)與 `api <METHOD> <worker>/<path>`
|
|
||||||
(curl 打實例,標頭與 body 走 stdin,不走 argv)。**只寫 stage**:secret 先 `GET /accounts` 看這把 token
|
|
||||||
打得到誰、URL 永遠只帶 `1129efd7…`;api 的主機只會長在 `*.arcrun-yuga3bse.workers.dev`。
|
|
||||||
值只從環境變數名讀(`--from-env`/`--bearer-env`/`--header-env`/`--data-env`),`--value`/`--bearer`/`--header` 一律拒收。
|
|
||||||
Arcrun 的 `stage-deploy-artifacts.py` 自己已寫死只認 youlin 帳號 ID、不收 `--account`/`--token`,
|
|
||||||
白名單直接放它從 Arcrun 根目錄跑的相對形狀,不重造一支。
|
|
||||||
|
|
||||||
**失敗**:
|
|
||||||
- A1/B1/B2/D1/D2 紅 ⇒ **非 stage 也寫得進去**——這是本工具存在的唯一理由
|
|
||||||
- A4/D3 紅 ⇒ 值可以從指令列進來(會進 shell 歷史與 session log)
|
|
||||||
- C1 紅 ⇒ 又把 201 講成失敗(第一次實跑就是這樣:CF 種好了、工具說失敗)
|
|
||||||
- C7/C9 紅 ⇒ 只信 PUT 的回應不去列
|
|
||||||
- **E2 紅 ⇒ ISEP 自己的閘誤攔正門**——誤攔比漏擋嚴重,被擋的人會去走側門
|
|
||||||
- E4 紅 ⇒ 又長出第二支平行的工具
|
|
||||||
|
|
||||||
**真實跑(2026-09-07,雲端 session,isep-hand)**:
|
|
||||||
`stage secret put` 把隨機值的 `ISEP_137_PROBE` 種進 youlin `arcrun-cypher-executor` → 不經工具用 CF API 列到
|
|
||||||
`["ISEP_137_PROBE","KBDB_INTERNAL_TOKEN"]` → `stage secret delete` → 再列剩 `["KBDB_INTERNAL_TOKEN"]`(stage 恢復原狀)。
|
|
||||||
`stage api GET arcrun-cypher-executor/health` → HTTP 200;`stage api POST arcrun-kbdb/map/recompute…` 不帶 Bearer → HTTP 401、離開碼 1(打到了、沒寫);
|
|
||||||
完整網址指到 leo21c → 拒絕、離開碼 2、零請求。
|
|
||||||
⚠️ **帶 Bearer 真的寫進 stage KBDB** 這格沒跑——雲端 Cloud environment 沒有 `KBDB_INTERNAL_TOKEN`(它只住在安裝器中心側 KV,Arcrun#176 comment 6487 步驟 0);
|
|
||||||
`CF_SECRETS_API_TOKEN` 的真值是主線 B-3(Arcrun#86)的東西,由總管用 `stage secret put` 種,本票不編一個假的塞進去。
|
|
||||||
⚠️ 「分類器真的不擋」與 A33 同款:要下一版裝進雲端之後,看一趟 run 的 `permission_denials`。
|
|
||||||
|
|
||||||
### A5 — 開票前的搜尋是跨 repo 的
|
### A5 — 開票前的搜尋是跨 repo 的
|
||||||
```
|
```
|
||||||
@@ -1134,14 +929,7 @@ B2(信標那行)/B3(setup 輸出)/B4(閘的訊息)三個畫面
|
|||||||
| **A17 未推警察不誤攔雲端分支** | 總管 | ✅ 10/10(2026-08-28,inkstone/ISEP#90) |
|
| **A17 未推警察不誤攔雲端分支** | 總管 | ✅ 10/10(2026-08-28,inkstone/ISEP#90) |
|
||||||
| **A18 信標會報雲端接線缺陷** | 總管 | ✅ 14/14(2026-08-28,inkstone/ISEP#90) |
|
| **A18 信標會報雲端接線缺陷** | 總管 | ✅ 14/14(2026-08-28,inkstone/ISEP#90) |
|
||||||
| **A19 下游做完頂層跟著關** | 總管 | ✅ 49/49(2026-08-28,inkstone/ISEP#92) |
|
| **A19 下游做完頂層跟著關** | 總管 | ✅ 49/49(2026-08-28,inkstone/ISEP#92) |
|
||||||
| **A31 雲端工人抓票規則機械可判** | isep-hand | ✅ 48/48(2026-09-07,inkstone/ISEP#131)+真實 Gitea 唯讀實跑+一次真認領 |
|
|
||||||
| **A20 舊票有固定管道被撈** | 總管 | ✅ 47/47(2026-08-28,inkstone/ISEP#83)+真實 229 張唯讀實跑 |
|
| **A20 舊票有固定管道被撈** | 總管 | ✅ 47/47(2026-08-28,inkstone/ISEP#83)+真實 229 張唯讀實跑 |
|
||||||
| **A31 leo21c 讀放寫擋+改法指活的 youlin** | isep-hand | ✅ 26/26(2026-09-07,inkstone/ISEP#130)+舊閘實跑 5 條紅 |
|
|
||||||
| **A32 主線檔隨 repo 走** | isep-hand | ✅ 17/17(2026-09-07,inkstone/ISEP#130)+雲端 session 實跑讀到主線 |
|
|
||||||
| **A33 權限白名單住 ISEP 一份** | isep-hand | ✅ 19/19(2026-09-07,inkstone/ISEP#130);「分類器真的不擋」要雲端 run 的 `permission_denials` 才驗得到 |
|
|
||||||
| **A34 收件 repo 寫 owner/repo 不 404** | isep-hand | ✅ 7/7(2026-09-07,inkstone/ISEP#130) |
|
|
||||||
| **A35 Bot API 直送** | isep-hand | ✅ 10/10(2026-09-07);**真的到 leo 手機**要 Cloud environment 先有 `TELEGRAM_BOT_TOKEN`/`TELEGRAM_CHAT_ID`(leo) |
|
|
||||||
| **A36 雲端對 stage 的寫入有正門、只寫得進 stage** | isep-hand | ✅ 45/45(2026-09-07,inkstone/ISEP#137)+真實種進 youlin 一把探針再刪掉、真打 stage GET 200/無 Bearer POST 401;「帶 Bearer 真寫 KBDB」缺 `KBDB_INTERNAL_TOKEN` 沒跑 |
|
|
||||||
| A7 plugin 裝得起來 | 總管 | ✅ |
|
| A7 plugin 裝得起來 | 總管 | ✅ |
|
||||||
| **A8 新 session 閘會觸發** | 總管 | 見本版 release note |
|
| **A8 新 session 閘會觸發** | 總管 | 見本版 release note |
|
||||||
| **B1–B5 雲端** | **leo** | 還沒跑(機器碰不到 Cloud environment) |
|
| **B1–B5 雲端** | **leo** | 還沒跑(機器碰不到 Cloud environment) |
|
||||||
@@ -1186,15 +974,3 @@ arcrun_search_workflows(通知 leo Telegram) → 只回 ship_refresh_cdn 一
|
|||||||
(`#issuecomment-5182`、`#issuecomment-5184`),並把原文印在眼前。
|
(`#issuecomment-5182`、`#issuecomment-5184`),並把原文印在眼前。
|
||||||
**發不出去而靜默,等於沒做;發不出去但講出來並留下退路,就是這支的規格。**
|
**發不出去而靜默,等於沒做;發不出去但講出來並留下退路,就是這支的規格。**
|
||||||
通道修好之後不必改任何程式碼,重跑 `python3 scripts/isep-nag --notify` 即可補驗這一格。
|
通道修好之後不必改任何程式碼,重跑 `python3 scripts/isep-nag --notify` 即可補驗這一格。
|
||||||
|
|
||||||
### 2026-09-07 從雲端 session 再量一次(inkstone/ISEP#130)
|
|
||||||
|
|
||||||
| 路 | 結果 | 誰能修 |
|
|
||||||
|---|---|---|
|
|
||||||
| `notify_leo` @ leo21c(`…/webhooks/named/leo/notify_leo`) | **HTTP 404**,跟 08-28 一樣 | leo(leo21c 寫入是人閘) |
|
|
||||||
| `notify_leo` @ youlin(`*.arcrun-yuga3bse.workers.dev`) | **連不到:egress proxy 對 CONNECT 回 403**(`/__agentproxy/status` 記為 policy denial)。不是 DNS、不是 000 | leo(Cloud environment 的 allowed network hosts) |
|
|
||||||
| `api.telegram.org` | **302,通** | — |
|
|
||||||
|
|
||||||
⇒ 雲端能走的只有 Bot API 直送(`scripts/isep-notify` 現在會先試它),缺的只是兩個環境變數
|
|
||||||
`TELEGRAM_BOT_TOKEN`/`TELEGRAM_CHAT_ID`——Routine 文件 `cloud-worker.md` 檔頭本來就列著它們,
|
|
||||||
只是這個 environment 沒有。**這一格仍然是 leo 的:加變數,然後回一個詞。**
|
|
||||||
|
|||||||
@@ -160,52 +160,6 @@ GitHub、不是 Gitea):
|
|||||||
驗 `claude plugin list` 顯示 `isep@inkstone enabled`,且照 §逐條對照 那張表
|
驗 `claude plugin list` 顯示 `isep@inkstone enabled`,且照 §逐條對照 那張表
|
||||||
再核一次數字。
|
再核一次數字。
|
||||||
|
|
||||||
## 雲端要全權處理的三樣:票、主線、通知(inkstone/ISEP#130,2026-09-07)
|
|
||||||
|
|
||||||
leo 09-07:「雲端回覆的問題你首要解決⋯⋯僅有需要依賴 Mac 環境的東西要求地端處理,其他全部需要可以從雲端全權處理。」
|
|
||||||
09-04 兩支 Routine 的 run log 實查出四件雲端拿不到的東西,ISEP 這一半的解法:
|
|
||||||
|
|
||||||
| 拿不到什麼 | 為什麼 | ISEP 這一半 | 還缺誰 |
|
|
||||||
|---|---|---|---|
|
|
||||||
| **主線是哪條** | 主線檔只在本機 `~/.claude` | `hooks/lib/mainline.py`:家目錄沒有就讀 repo 的 `InkStoneCo/system-dev/mainline.json`(雲端形狀:`$CLAUDE_PROJECT_DIR` 是薄殼根、真身在 `InkStoneCo/`);`mainline set`/`adopt`/`clear` 兩份一起寫 | 總管 `set` 之後要把 repo 那份 commit/併 main |
|
|
||||||
| **正門工具被分類器擋**(`permission_denials=6`) | leo 09-07 親手加的四條只在本機 settings | `docs/permissions-allow.json` 一份清單;`scripts/settings-allow-sync` 寫進那台的 `~/.claude/settings.json`(setup script 裝完 plugin 跑一次,SessionStart 每次再對一次) | 雲端一趟 run 看 `permission_denials`=0 才算驗到 |
|
|
||||||
| **讀 leo21c 也被擋** | `leo21c-write-guard.sh` 把 `tr -d` 的 `-d` 當 body | 唯讀 `-d` 先剪掉再判;`notify_leo` trigger 放行(同 `prod-write-guard` 白名單);改法段改印現役 youlin 子網域 | — |
|
|
||||||
| **收工摘要到不了手機** | 雲端沒 `TELEGRAM_*`;leo21c 的 `notify_leo` 404;youlin 被 egress proxy 擋 | `scripts/isep-notify` 有 `TELEGRAM_BOT_TOKEN`/`TELEGRAM_CHAT_ID` 就先走 Bot API 直送(`api.telegram.org` 從雲端是通的) | **leo**:在 Cloud environment 加那兩個變數 |
|
|
||||||
|
|
||||||
### 雲端連不到 youlin 不是 000,是 proxy 403(2026-09-07 實查)
|
|
||||||
|
|
||||||
```
|
|
||||||
$ curl -sS -o /dev/null -w '%{http_code}' https://arcrun-cypher-executor.arcrun-yuga3bse.workers.dev/health
|
|
||||||
curl: (56) CONNECT tunnel failed, response 403 ← egress policy denial
|
|
||||||
$ curl -sS "$HTTPS_PROXY/__agentproxy/status" | jq .recentRelayFailures
|
|
||||||
{ "kind": "connect_rejected", "host": "arcrun-cypher-executor.arcrun-yuga3bse.workers.dev:443",
|
|
||||||
"detail": "gateway answered 403 to CONNECT (policy denial or upstream failure)" }
|
|
||||||
$ curl … https://arcrun-cypher-executor.leo21c.workers.dev/health → 200
|
|
||||||
$ curl … https://api.telegram.org/ → 302
|
|
||||||
$ curl … https://git.uncle6.me/api/v1/version → 200
|
|
||||||
```
|
|
||||||
|
|
||||||
⇒ 09-04 log 寫的「youlin 從雲端 HTTP 000」有兩層:舊子網域 `youlin-hsieh-dev` DNS 已死(總管 09-07 查到),
|
|
||||||
**而新子網域從雲端是被 policy 擋**——`/root/.ccr/README.md` 明寫「403/407 = 你組織的 egress policy
|
|
||||||
不允許這個主機,不要重試、不要繞路,回報主機名」。leo21c 通、youlin 不通,差別只在主機有沒有被放行。
|
|
||||||
**這格是 leo 的**:Cloud environment 的 allowed network hosts 加 `*.arcrun-yuga3bse.workers.dev`;
|
|
||||||
在那之前雲端做不了 stage 驗證,所有要打 youlin 的驗證一律交回地端或標 `Human`。
|
|
||||||
|
|
||||||
### 只有「要 Mac」的事才交回地端(給 `cloud-worker.md` 的清單草稿)
|
|
||||||
|
|
||||||
判準一句話:**這件事依賴的東西隨 repo clone 走得到嗎?走得到就雲端做。**
|
|
||||||
|
|
||||||
| 交回地端 | 為什麼雲端做不了 |
|
|
||||||
|---|---|
|
|
||||||
| 打包 DMG/簽章/MS Store 送件 | 要 macOS 工具鏈與簽章身分(Keychain),不隨 clone 走 |
|
|
||||||
| 本機 daemon(`~/.arcrun-rag`、`~/.arcrun/config.yaml`)的改與驗 | 住在 leo 的家目錄 |
|
|
||||||
| 用 `~/.wrangler` OAuth 登入態出貨到 uncle6 | 登入態不隨 clone 走(`make-cloud-env.sh` 檔頭記過) |
|
|
||||||
| 要 leo 親手輸入的互動閘(`acr recipe push` 的暴露同意、密碼打進登入欄) | surface 層硬規則,誰都不能代 |
|
|
||||||
| ~~打 youlin stage 的驗證~~ | 09-07 已回到雲端:`*.arcrun-yuga3bse.workers.dev` 從雲端 curl 200。**寫入走 `scripts/stage`**(secret/api,inkstone/ISEP#137),不再交回地端 |
|
|
||||||
|
|
||||||
其餘(讀票、認領、留言、handback、寫 code、跑測試、開 PR、對 leo21c 唯讀查詢、發 Telegram、**種 secret/直推成品/POST 到 stage 實例**——走 `scripts/stage` 與 Arcrun 的 `stage-deploy-artifacts.py`)雲端全做。
|
|
||||||
📌 這份清單的家是 `inkstone/InkStoneCo` 的 `cloud-worker.md`(票上驗收第 4 條),ISEP 只放草稿;併進去由總管做。
|
|
||||||
|
|
||||||
## 這張票沒動、也不會動的東西
|
## 這張票沒動、也不會動的東西
|
||||||
|
|
||||||
- 沒有動 `youlinhsieh/inkstoneco`(GitHub 薄殼 repo)——這個新機制**完全不需要
|
- 沒有動 `youlinhsieh/inkstoneco`(GitHub 薄殼 repo)——這個新機制**完全不需要
|
||||||
|
|||||||
@@ -28,17 +28,6 @@ set -uo pipefail
|
|||||||
claude plugin marketplace add https://git.uncle6.me/inkstone/ISEP.git --scope user 2>&1 || true
|
claude plugin marketplace add https://git.uncle6.me/inkstone/ISEP.git --scope user 2>&1 || true
|
||||||
claude plugin install isep@inkstone --scope user 2>&1 || true
|
claude plugin install isep@inkstone --scope user 2>&1 || true
|
||||||
|
|
||||||
# 🔴 權限白名單(inkstone/ISEP#130):四個 Gitea 正門工具(ticket/mainline/gate-ok/gitea-pr-merge)
|
|
||||||
# 要進這台的 ~/.claude/settings.json,auto mode 的分類器才不擋(09-04 run log:permission_denials=6)。
|
|
||||||
# 清單住 ISEP `docs/permissions-allow.json` 一份,本機與雲端都由同一支腳本寫——薄殼 repo 不再各養一份。
|
|
||||||
# plugin 快取的路徑帶版本號,挑最新的那份跑;沒裝成也不擋門,SessionStart 會再對一次。
|
|
||||||
ISEP_DIR=$(ls -d "$HOME"/.claude/plugins/cache/inkstone/isep/*/ 2>/dev/null | sort -V | tail -1)
|
|
||||||
if [ -n "$ISEP_DIR" ] && [ -f "$ISEP_DIR/scripts/settings-allow-sync" ]; then
|
|
||||||
python3 "$ISEP_DIR/scripts/settings-allow-sync" 2>&1 || true
|
|
||||||
else
|
|
||||||
echo "⚠️ 找不到裝好的 ISEP,白名單沒寫進 ~/.claude/settings.json——session 開頭 SessionStart 會再試一次。"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if claude plugin marketplace list 2>/dev/null | grep -q "inkstone"; then
|
if claude plugin marketplace list 2>/dev/null | grep -q "inkstone"; then
|
||||||
echo "✅ marketplace inkstone 已就位"
|
echo "✅ marketplace inkstone 已就位"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
# file-ownership.tsv — 同一個檔案兩邊都有時,**哪一份是真相源**(inkstone/ISEP#122)
|
|
||||||
#
|
|
||||||
# 為什麼要有這張表(2026-09-02 實查,兩個方向都真的發生過):
|
|
||||||
# skills/ship-check/SKILL.md InkStoneCo 那份前進到 651 行,ISEP 停在 595 行
|
|
||||||
# commands/sdd-check.md ISEP 那份前進到 81 行,InkStoneCo 停在 65 行
|
|
||||||
# (InkStoneCo 那份還在教已經退役的「唯一 active SDD」)
|
|
||||||
# ⇒ 「ISEP 一定比較新」是錯的,「InkStoneCo 一定比較新」也是錯的。
|
|
||||||
# 兩邊都會被就地編輯,所以歸屬**不能靠人記得**,要寫下來、而且要有東西去比對。
|
|
||||||
#
|
|
||||||
# 誰在用這張表:`hooks/lib/beacon_report.py`(SessionStart 信標,只報告、不擋人)
|
|
||||||
# ① 兩邊內容不同時 → 照這張表講出「真相源是哪一份、該往哪個方向修」
|
|
||||||
# ② 表上有 sha256 時 → 順便驗 ISEP 這份有沒有被就地改過(雲端沒有 InkStoneCo
|
|
||||||
# 可以比,這一格是那時唯一還能作數的檢查)
|
|
||||||
#
|
|
||||||
# 規約三條:
|
|
||||||
# 1. **只有內容會分家的檔案才需要一列。** 兩邊一模一樣時不必登記,信標也不會出聲。
|
|
||||||
# 2. 真相源是 `inkstone/InkStoneCo` ⇒ **內容要改就改在那裡**,改完把檔案原樣搬過來、
|
|
||||||
# 更新 ④⑤ 兩欄、升版。**不要在 ISEP 這邊改內容**(改了兩邊就各自演化,就是本表要解的病)。
|
|
||||||
# 3. 真相源是 `inkstone/ISEP` ⇒ 專案那份是退場中的舊複本,該被同步或刪掉;
|
|
||||||
# ③④⑤ 三欄填 `-`。
|
|
||||||
#
|
|
||||||
# 欄位(TAB 分隔,5 欄):
|
|
||||||
# ① plugin 內路徑
|
|
||||||
# ② 真相源 repo
|
|
||||||
# ③ 真相源在那個 repo 裡的路徑(真相源就是 ISEP 時填 `-`)
|
|
||||||
# ④ 這一份是從哪顆 commit 搬過來的(同上,填 `-`)
|
|
||||||
# ⑤ 搬過來的當下 sha256(同上,填 `-`)
|
|
||||||
#
|
|
||||||
skills/ship-check/SKILL.md inkstone/InkStoneCo .claude/skills/ship-check/SKILL.md bd52fa3a508cbfb29755ddc24923c6fea8c3fbf7 847967830007e804a16dec9adfc5d4120c233445649d4d5cdd34b04550fb3270
|
|
||||||
commands/sdd-check.md inkstone/ISEP - - -
|
|
||||||
|
+27
-16
@@ -1,4 +1,4 @@
|
|||||||
# 61 支閘,白話盤點表
|
# 63 支閘,白話盤點表
|
||||||
|
|
||||||
> 回應 `inkstone/InkStoneCo#40`:「如果加入了,我應該可以白話文看到 hooks 的內容?」
|
> 回應 `inkstone/InkStoneCo#40`:「如果加入了,我應該可以白話文看到 hooks 的內容?」
|
||||||
> 這份表就是那個「白話文」——不用點開任何 `.sh` 檔,一行看懂一支閘在管什麼。
|
> 這份表就是那個「白話文」——不用點開任何 `.sh` 檔,一行看懂一支閘在管什麼。
|
||||||
@@ -7,14 +7,31 @@
|
|||||||
|
|
||||||
## 一句話結論
|
## 一句話結論
|
||||||
|
|
||||||
`hooks/` 底下有 **61 個 `.sh` 檔**,`hooks.json` 實際掛上 **85 條註冊**(同一支閘常被多種情境同時掛上);
|
`hooks/` 底下有 **63 個 `.sh` 檔**,`hooks.json` 實際掛上 **86 條註冊**(同一支閘常被多種情境同時掛上);
|
||||||
其中 **3 支檔案存在但沒被掛上**(2 支是待人填的空範本、1 支是刻意留著沒開的止血帶,見下面「未生效」表)。
|
其中 **3 支檔案存在但沒被掛上**(2 支是待人填的空範本、1 支是刻意留著沒開的止血帶,見下面「未生效」表)。
|
||||||
下面按「你會在什麼時候撞到它」分組,一支一行。
|
下面按「你會在什麼時候撞到它」分組,一支一行。
|
||||||
|
|
||||||
|
> 📌 **`inkstone/ISEP#122`(2026-09-02)進來兩支、+2 條**:`kv-write-guard.sh`(B 組,
|
||||||
|
> 2026-08-25 立於 InkStoneCo 專案版,原樣搬進來)與 `duplicate-hook-registration-guard.sh`
|
||||||
|
> (E 組,這次新寫)。61→**63** 支、84→**86** 條,兩個數字都是加完之後**在自己的樹上當場數出來的**
|
||||||
|
> (`ls hooks/*.sh | wc -l`/`grep -c '"command":' hooks/hooks.json`),不是拿上一版加二。
|
||||||
|
>
|
||||||
|
> 這張票查的是「總管三次要部署被 `prod-write-guard.sh` 恆擋、蓋了戳記也放不了行」,
|
||||||
|
> 根因不在 `prod-write-guard.sh` 本身,而在 `InkStoneCo/.claude/settings.json`
|
||||||
|
> 還登記著一份跟 ISEP plugin 同名的舊 hook——每個 `PreToolUse` 事件都跑了**兩次**,
|
||||||
|
> 一次性戳記被第一份消耗掉,第二份永遠看到空戳記、恆擋。實查:專案版登記著 38 支,
|
||||||
|
> **34 支跟 plugin 完全同名同用途**(純殘骸,已從 `InkStoneCo/.claude/settings.json`
|
||||||
|
> 刪除登記)、**3 支是已經退役的機制**(`claim-verify-police.sh`/
|
||||||
|
> `subagent-claim-worksheet.sh`/`sdd-guard.sh`,同樣刪除)、
|
||||||
|
> **1 支(`kv-write-guard.sh`)是專案版有、plugin 當時沒有的真閘**——原樣搬進本 repo,
|
||||||
|
> 這就是這次 B 組新增的那一支。`duplicate-hook-registration-guard.sh` 是防復發的機械閘:
|
||||||
|
> 下次任何專案的 `settings.json` 又長出跟 plugin 同名的登記,SessionStart 就會點名,
|
||||||
|
> 不必再靠「戳記莫名其妙失效」這種事後除錯才發現。
|
||||||
|
>
|
||||||
> 🔴 **這兩個數字上一版是錯的(2026-08-26 實際數過才發現)**:本頁原本寫「43 個檔、53 條註冊」,
|
> 🔴 **這兩個數字上一版是錯的(2026-08-26 實際數過才發現)**:本頁原本寫「43 個檔、53 條註冊」,
|
||||||
> 而當時真實是 **45 個檔、55 條註冊**——中間有兩支閘進來時沒有回頭改這裡。
|
> 而當時真實是 **45 個檔、55 條註冊**——中間有兩支閘進來時沒有回頭改這裡。
|
||||||
> 現在的寫法是實際數出來的:
|
> 現在的寫法是實際數出來的:
|
||||||
> `ls hooks/*.sh | wc -l` = 61;`grep -c '"command":' hooks/hooks.json` = 85。
|
> `ls hooks/*.sh | wc -l` = 61;`grep -c '"command":' hooks/hooks.json` = 84。
|
||||||
> ⚠️ **冒號不能省**:`grep -c '"command"'`(沒冒號)會連 `"type": "command"` 一起數到,回 **120**。
|
> ⚠️ **冒號不能省**:`grep -c '"command"'`(沒冒號)會連 `"type": "command"` 一起數到,回 **120**。
|
||||||
> 本頁 2026-08-27 之前寫的是沒冒號那版——**照著它跑會拿到一個跟本頁不符的數字**。
|
> 本頁 2026-08-27 之前寫的是沒冒號那版——**照著它跑會拿到一個跟本頁不符的數字**。
|
||||||
> **一份會偷偷過期的盤點表,跟沒有盤點表差不多**——見本頁最後「怎麼跟實況對帳」那段。
|
> **一份會偷偷過期的盤點表,跟沒有盤點表差不多**——見本頁最後「怎麼跟實況對帳」那段。
|
||||||
@@ -32,13 +49,6 @@
|
|||||||
> **兩個事件是同一件事的兩半**:只注入 = 又一個會被忽略的提醒;只查核 = 罰它做一件拿不到資料的事。
|
> **兩個事件是同一件事的兩半**:只注入 = 又一個會被忽略的提醒;只查核 = 罰它做一件拿不到資料的事。
|
||||||
> 這兩個數字是併之前當場數出來的,不是從上一版加減推出來的。
|
> 這兩個數字是併之前當場數出來的,不是從上一版加減推出來的。
|
||||||
|
|
||||||
> 📌 **`inkstone/ISEP#130`(2026-09-07)+0 支、+1 條**:SessionStart 多掛一條
|
|
||||||
> `scripts/settings-allow-sync --quiet`(不是閘,是腳本:把 ISEP 的權限白名單寫進這台的
|
|
||||||
> `~/.claude/settings.json`,雲端才不會每個正門工具都被分類器擋)。
|
|
||||||
> **61 支不變、84→85 條,兩個數字是掛完之後當場數出來的**(`ls hooks/*.sh | wc -l`=61、
|
|
||||||
> `grep -c '"command":' hooks/hooks.json`=85)。同票順手:`leo21c-write-guard.sh` 補了
|
|
||||||
> 唯讀 `-d` 與 notify_leo 的放行、三支閘認得 youlin 09-02 起的新子網域——**都是改判準不是加閘**。
|
|
||||||
|
|
||||||
> 📌 **`inkstone/ISEP#82`(2026-08-28)+1 支、+3 條**:`mainline-focus-guard.sh`
|
> 📌 **`inkstone/ISEP#82`(2026-08-28)+1 支、+3 條**:`mainline-focus-guard.sh`
|
||||||
> 同時掛在 `Agent` 與 `Task`(派工的兩個入口都要守,只守一個等於沒守),
|
> 同時掛在 `Agent` 與 `Task`(派工的兩個入口都要守,只守一個等於沒守),
|
||||||
> 加上 SessionStart 多掛一條 `scripts/mainline refresh`(更新主線的進度/期限,不是閘)。
|
> 加上 SessionStart 多掛一條 `scripts/mainline refresh`(更新主線的進度/期限,不是閘)。
|
||||||
@@ -129,7 +139,7 @@
|
|||||||
| `main-and-prod-push-guard.sh` | 兩層確認:① subagent 想推 Gitea `main` 分支 → 一定要交回總管,總管確認過才放行;② 任何 `wrangler deploy` 打正式環境 → 一定要你親手解鎖。 | 🛑 擋 |
|
| `main-and-prod-push-guard.sh` | 兩層確認:① subagent 想推 Gitea `main` 分支 → 一定要交回總管,總管確認過才放行;② 任何 `wrangler deploy` 打正式環境 → 一定要你親手解鎖。 | 🛑 擋 |
|
||||||
| `prod-write-guard.sh` | AI 想做任何「會真的改到線上正式帳號(leo21c)」的操作(不只是 push,也包含直接呼叫會寫入的工具)就擋下,交回總管處理。 | 🛑 擋 |
|
| `prod-write-guard.sh` | AI 想做任何「會真的改到線上正式帳號(leo21c)」的操作(不只是 push,也包含直接呼叫會寫入的工具)就擋下,交回總管處理。 | 🛑 擋 |
|
||||||
| `not-my-branch-guard.sh` | AI 想 commit 到「別的 subagent 正在施工中」的分支(登記在 `branch-holds.md`)就擋下,避免兩個 AI 互踩同一條分支。 | 🛑 擋 |
|
| `not-my-branch-guard.sh` | AI 想 commit 到「別的 subagent 正在施工中」的分支(登記在 `branch-holds.md`)就擋下,避免兩個 AI 互踩同一條分支。 | 🛑 擋 |
|
||||||
| `leo21c-write-guard.sh` | AI 想寫東西到你私人帳號 `leo21c` 就擋下——這個帳號只准你自己用,AI 的實驗一律走別的測試帳號。**讀一律放行**(含 `tr -d`/`cut -d=` 這種唯讀的 `-d`,09-04 雲端就是被這個誤攔到「連讀都讀不到」),發一則 `notify_leo`(只送訊息、什麼都沒改)也放行——跟 `prod-write-guard.sh` 同一份白名單(inkstone/ISEP#130)。 | 🛑 擋 |
|
| `leo21c-write-guard.sh` | AI 想寫東西到你私人帳號 `leo21c` 就擋下——這個帳號只准你自己用,AI 的實驗一律走別的測試帳號。 | 🛑 擋 |
|
||||||
| `release-tag-guard.sh` | AI 想打版本 tag,但 `plugin.json` 裡寫的版本號跟 tag 對不上就擋下——避免「這裡說 0.2.0、那裡說 0.1.0」各說各話。 | 🛑 擋 |
|
| `release-tag-guard.sh` | AI 想打版本 tag,但 `plugin.json` 裡寫的版本號跟 tag 對不上就擋下——避免「這裡說 0.2.0、那裡說 0.1.0」各說各話。 | 🛑 擋 |
|
||||||
| `ticket-api-bypass-guard.sh` | AI 想繞過 `scripts/ticket` 工具、直接打 API 新增 Gitea 東西(開新票/milestone/label/PR,會漏掉「新增前先搜過」這道檢查)就擋下——不管是隱式 POST(urllib 傳 data= 沒寫 method)還是小寫 `requests.post(...)`。 | 🛑 擋 |
|
| `ticket-api-bypass-guard.sh` | AI 想繞過 `scripts/ticket` 工具、直接打 API 新增 Gitea 東西(開新票/milestone/label/PR,會漏掉「新增前先搜過」這道檢查)就擋下——不管是隱式 POST(urllib 傳 data= 沒寫 method)還是小寫 `requests.post(...)`。 | 🛑 擋 |
|
||||||
| `milestone-due-guard.sh` | AI 想開一個新的里程碑(milestone)卻沒填期限就擋下,**填 `9999-01-01` 一樣擋**——那是「沒有期限」穿了一件期限的衣服,盤點時每一格看起來都有值,其實一格都沒有。只管「建里程碑」這個動作,查詢/改別的欄位都放行。 | 🛑 擋 |
|
| `milestone-due-guard.sh` | AI 想開一個新的里程碑(milestone)卻沒填期限就擋下,**填 `9999-01-01` 一樣擋**——那是「沒有期限」穿了一件期限的衣服,盤點時每一格看起來都有值,其實一格都沒有。只管「建里程碑」這個動作,查詢/改別的欄位都放行。 | 🛑 擋 |
|
||||||
@@ -152,6 +162,7 @@
|
|||||||
| `mistake-needs-ticket-guard.sh` | AI 想往 `mistakes.md`(教訓紀錄)新增一條「機制可以防止」的教訓,卻沒附對應票號就擋下——沒有票號的教訓沒有人會回頭處理。 | 🛑 擋 |
|
| `mistake-needs-ticket-guard.sh` | AI 想往 `mistakes.md`(教訓紀錄)新增一條「機制可以防止」的教訓,卻沒附對應票號就擋下——沒有票號的教訓沒有人會回頭處理。 | 🛑 擋 |
|
||||||
| `wiki-size-guard.sh` | AI 想**一口氣砍掉 wiki 檔一大半內容**(淨縮水超過 800 字且超過原本 45%)就擋一次——那不是一次編輯,那是一次壓縮,而**壓縮會弄丟東西,弄丟的當下沒有人會發現**。出路是走 `scripts/wiki-compress`:它逼你附票號、把壓掉了什麼寫進 `.compress-log.md`,並用內文雜湊**逐條對帳**證明沒弄丟。只是改字、加字、小修一律不碰;真要手改就在內容裡放 `wiki-compress-ok` 留痕。 | 🛑 擋(至多攔一次) |
|
| `wiki-size-guard.sh` | AI 想**一口氣砍掉 wiki 檔一大半內容**(淨縮水超過 800 字且超過原本 45%)就擋一次——那不是一次編輯,那是一次壓縮,而**壓縮會弄丟東西,弄丟的當下沒有人會發現**。出路是走 `scripts/wiki-compress`:它逼你附票號、把壓掉了什麼寫進 `.compress-log.md`,並用內文雜湊**逐條對帳**證明沒弄丟。只是改字、加字、小修一律不碰;真要手改就在內容裡放 `wiki-compress-ok` 留痕。 | 🛑 擋(至多攔一次) |
|
||||||
| `pending-changes-retired.sh` | AI 想寫東西進已經廢除的 `pending-changes.md` 檔案就擋下——這個檔案已停用,規格變更一律改開 Gitea 票。 | 🛑 擋 |
|
| `pending-changes-retired.sh` | AI 想寫東西進已經廢除的 `pending-changes.md` 檔案就擋下——這個檔案已停用,規格變更一律改開 Gitea 票。 | 🛑 擋 |
|
||||||
|
| `kv-write-guard.sh` | AI 想新增一行「往 KV 綁定寫入」的程式碼(`大寫識別字.put(`/`.delete(`)就擋下——長效資料一律要走 KBDB API,KV 只是暫存。判準是形狀(全大寫識別字 + `.put`/`.delete`),不是列名字清單;只讀(`.get`/`.list`)放行,刪除既有 KV 寫入(退休戰)也放行。真的是短命資料(session/nonce/有 TTL 的快取)在那一行尾端加 `kv-ok: <為什麼>` 留痕放行。2026-08-25 立於 InkStoneCo 專案版,`inkstone/ISEP#122` 原樣搬進本 repo。 | 🛑 擋 |
|
||||||
|
|
||||||
> 🔴 **`sdd-guard.sh` 已於 `inkstone/ISEP#91` 退役**(原本掛在這一組)。
|
> 🔴 **`sdd-guard.sh` 已於 `inkstone/ISEP#91` 退役**(原本掛在這一組)。
|
||||||
> 它擋的是「動 code 檔時,`status: active` 的 SDD 不是恰好一份」。
|
> 它擋的是「動 code 檔時,`status: active` 的 SDD 不是恰好一份」。
|
||||||
@@ -210,13 +221,13 @@
|
|||||||
|
|
||||||
| 閘名 | 對你意味著什麼 | 動作 |
|
| 閘名 | 對你意味著什麼 | 動作 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `isep-presence-beacon.sh` | 對話一開始印一行 `🟢 ISEP vX.Y.Z 已載入(N 支閘|來源:…)`。**這行不是裝飾,是唯一能證明「這個 session 真的有閘」的東西**——它自己就住在 plugin 裡,看得到它就表示 plugin 載入了;某個 session 從頭到尾沒有這行,那個 session 是零閘狀態,先修 plugin 再做事。同一台機器可能同時有兩份 ISEP(marketplace 裝的、repo 裡 vendor 的),所以那行會講出這次是哪一份在說話。它另外會報四件「這一份是不是還有效」:①這一份落後 ISEP main 幾版 ②專案裡有沒有內容不同的同名**腳本**②b 專案裡有沒有內容不同的同名**skill/command/agent**——這些是**自動載入**的,載到舊的那份不會有任何症狀,只會安靜地教錯的東西(`docs/file-ownership.tsv` 說得出每一組的真相源是哪一份、往哪個方向修)②c 本身的內容跟那張歸屬表對不對得上(雲端沒有專案那一份可比時,這是唯一還作數的檢查)③工作區有沒有已退役機制留下的產物。**全部只講不擋。** | 📝 記錄(context 注入) |
|
| `isep-presence-beacon.sh` | 對話一開始印一行 `🟢 ISEP vX.Y.Z 已載入(N 支閘|來源:…)`。**這行不是裝飾,是唯一能證明「這個 session 真的有閘」的東西**——它自己就住在 plugin 裡,看得到它就表示 plugin 載入了;某個 session 從頭到尾沒有這行,那個 session 是零閘狀態,先修 plugin 再做事。同一台機器可能同時有兩份 ISEP(marketplace 裝的、repo 裡 vendor 的),所以那行會講出這次是哪一份在說話。 | 📝 記錄(context 注入) |
|
||||||
| `session-start-recall.sh` | 對話一開始就自動把「全局現況」(Gitea 各 repo 的票、KBDB 的藏書地圖)推到 AI 眼前,不必等它自己想到要查。 | 📝 記錄(context 注入) |
|
| `session-start-recall.sh` | 對話一開始就自動把「全局現況」(Gitea 各 repo 的票、KBDB 的藏書地圖)推到 AI 眼前,不必等它自己想到要查。 | 📝 記錄(context 注入) |
|
||||||
| `scripts/settings-allow-sync --quiet` | (不是閘,是腳本)對話一開始把 ISEP 的權限白名單(`docs/permissions-allow.json`:`ticket`/`mainline`/`gate-ok`/`gitea-pr-merge`/`stage`(inkstone/ISEP#137 起,雲端對 stage 寫入的正門)五個正門工具,外加 Arcrun 的 `stage-deploy-artifacts.py`)寫進**這台機器**的 `~/.claude/settings.json`。只加不減、冪等;目標檔壞掉就不碰它、講一聲。**為什麼**:leo 09-07 親手加的四條只在本機,雲端沒有 ⇒ 同樣的動作被分類器擋(09-04 run log `permission_denials=6`);薄殼 repo 要 D20 開閘才推得動,所以清單住 ISEP 一份、兩台各自寫進自己的家目錄(inkstone/ISEP#130)。 | 📝 記錄(寫 settings) |
|
|
||||||
| `scripts/mainline refresh` | (不是閘,是腳本)對話一開始把**現在的主線**那條 milestone 的進度與期限更新一次,好讓每回合眼前那一行講的是今天的數字。拿不到 Gitea 就原封不動——**寧可資料舊,不要把主線弄丟**。跑一次就結束,不輪詢。 | 📝 記錄 |
|
| `scripts/mainline refresh` | (不是閘,是腳本)對話一開始把**現在的主線**那條 milestone 的進度與期限更新一次,好讓每回合眼前那一行講的是今天的數字。拿不到 Gitea 就原封不動——**寧可資料舊,不要把主線弄丟**。跑一次就結束,不輪詢。 | 📝 記錄 |
|
||||||
| `overdue-nag-guard.sh` | 對話一開始就去 Gitea 撈**沒有人會叫的事**:逾期的 milestone、掛著等你的票(標「等了幾天」)、標著「有人在做」卻好幾天沒動的票;撈完用白話講出來,**有事就發 Telegram 給你**。沒東西可報時它會說「查過了,沒有」——**安靜跟壞掉長得一模一樣**。發不出去時不會靜默:它會先問這個 session 的 `prod-write-guard` 會不會擋(舊版把「發通知」誤認成「部署」),擋就改貼回票上並把原文印在眼前。只在開 session 時跑一次,**不輪詢、不掛排程**。 | 📝 記錄(context 注入 + Telegram) |
|
| `overdue-nag-guard.sh` | 對話一開始就去 Gitea 撈**沒有人會叫的事**:逾期的 milestone、掛著等你的票(標「等了幾天」)、標著「有人在做」卻好幾天沒動的票;撈完用白話講出來,**有事就發 Telegram 給你**。沒東西可報時它會說「查過了,沒有」——**安靜跟壞掉長得一模一樣**。發不出去時不會靜默:它會先問這個 session 的 `prod-write-guard` 會不會擋(舊版把「發通知」誤認成「部署」),擋就改貼回票上並把原文印在眼前。只在開 session 時跑一次,**不輪詢、不掛排程**。 | 📝 記錄(context 注入 + Telegram) |
|
||||||
| `wiki-size-guard.sh` | 對話一開始講出「哪幾個 wiki 檔已經沒有人讀得完了」(預設超過 1200 行就點名)。**讀不完的必讀檔,跟沒有那個檔的差別只在於它讓人以為有。** 另一半掛在寫檔上,見 B 組。 | 📝 記錄(context 注入) |
|
| `wiki-size-guard.sh` | 對話一開始講出「哪幾個 wiki 檔已經沒有人讀得完了」(預設超過 1200 行就點名)。**讀不完的必讀檔,跟沒有那個檔的差別只在於它讓人以為有。** 另一半掛在寫檔上,見 B 組。 | 📝 記錄(context 注入) |
|
||||||
| `skill-deploy-drift-guard.sh` | 如果「全機真正在用的 skill」跟「repo 裡版控的正本」內容對不上,就在開場講出來——避免用著一份沒人知道已經跟正本分家的舊拷貝。 | 📝 記錄 |
|
| `skill-deploy-drift-guard.sh` | 如果「全機真正在用的 skill」跟「repo 裡版控的正本」內容對不上,就在開場講出來——避免用著一份沒人知道已經跟正本分家的舊拷貝。 | 📝 記錄 |
|
||||||
|
| `duplicate-hook-registration-guard.sh` | 如果這個專案自己的 `.claude/settings.json` 還登記著跟 ISEP plugin 同名的舊 hook,就在開場點名是哪幾支——**同一個動作跑兩次**,多數閘只是白跑,但帶「蓋一次戳記只放行一次」語意的閘會被第一份吃光,第二份永遠看到空戳記、恆擋(`inkstone/ISEP#122` 就是這樣,2026-09-01 撞了三次才被抓到)。判準是「有沒有真的註冊」,不是「檔案存不存在」。 | 📝 記錄(context 注入) |
|
||||||
|
|
||||||
## F. AI 想結束這一輪、要收工的時候(Stop)
|
## F. AI 想結束這一輪、要收工的時候(Stop)
|
||||||
|
|
||||||
@@ -260,7 +271,7 @@
|
|||||||
|
|
||||||
| 閘名 | 對你意味著什麼 | 動作 |
|
| 閘名 | 對你意味著什麼 | 動作 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `history-first-guard.sh` | AI 要改一個舊檔案之前,先把這個檔案過去被改過幾次、被誰在什麼情況下改過的紀錄攤在它眼前,逼它回答「這是不是已經修過的老問題」再動手。前面還有第 0 道:這一小時內有沒有問過 KBDB。**KBDB 連不上時 `touch /tmp/.kbdb-down` 就放行**——這條逃生門 2026-09-02 之前是壞的(`touch` 造的是空檔,而它讀的是檔案內容)**照著訊息打完還是被擋**,`inkstone/ISEP#122` 修好並補了迴歸測試。 | 🛑 擋 |
|
| `history-first-guard.sh` | AI 要改一個舊檔案之前,先把這個檔案過去被改過幾次、被誰在什麼情況下改過的紀錄攤在它眼前,逼它回答「這是不是已經修過的老問題」再動手。 | 🛑 擋 |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -296,8 +307,8 @@ countdown-milestone-refresh.sh ← 假警報:它在 scripts/ 不在 hooks/
|
|||||||
🔴 **上面那一筆是假警報,不是「指向空氣」的閘**:`inkstone/ISEP#63` 之後,
|
🔴 **上面那一筆是假警報,不是「指向空氣」的閘**:`inkstone/ISEP#63` 之後,
|
||||||
SessionStart 上掛的東西不全是 `hooks/*.sh`——`scripts/countdown-milestone-refresh.sh`
|
SessionStart 上掛的東西不全是 `hooks/*.sh`——`scripts/countdown-milestone-refresh.sh`
|
||||||
是腳本不是閘。這組指令只比檔名、不看目錄,所以它會出現在這裡。
|
是腳本不是閘。這組指令只比檔名、不看目錄,所以它會出現在這裡。
|
||||||
(`inkstone/ISEP#82` 又多掛一條 `scripts/mainline refresh`、`inkstone/ISEP#130` 多掛一條
|
(`inkstone/ISEP#82` 又多掛一條 `scripts/mainline refresh`,那一條沒有 `.sh`
|
||||||
`scripts/settings-allow-sync --quiet`,這兩條沒有 `.sh` 副檔名,所以不會落進這個名單。)**照著跑會看到它,這裡先講清楚,
|
副檔名,所以不會落進這個名單。)**照著跑會看到它,這裡先講清楚,
|
||||||
免得下一個人以為是自己弄壞的。**
|
免得下一個人以為是自己弄壞的。**
|
||||||
|
|
||||||
🔴 **上面那兩行驗不出「表格漏列」**——它們比的是 `hooks.json`,不是這張表。
|
🔴 **上面那兩行驗不出「表格漏列」**——它們比的是 `hooks.json`,不是這張表。
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
"_what": "Claude Code 權限白名單(permissions.allow)的唯一清單——本機與雲端都從這裡讀,不各養一份(inkstone/ISEP#130)",
|
|
||||||
"_why": [
|
|
||||||
"leo 09-07 親手把四個 Gitea 正門工具(ticket/mainline/gate-ok/gitea-pr-merge)加進本機 InkStoneCo/.claude/settings.json,auto mode 的分類器才不擋。",
|
|
||||||
"雲端 session 沒有那四條,同樣的動作照樣被擋(09-04 progress-guard run log:permission_denials=6)。",
|
|
||||||
"薄殼 repo(GitHub)要 D20 開閘才推得動 ⇒ 白名單住 ISEP,`scripts/settings-allow-sync` 開工時寫進那台機器的 ~/.claude/settings.json。",
|
|
||||||
"以後加規則只改這個檔、出一版,雲端下一趟就有。",
|
|
||||||
"inkstone/ISEP#137:09-07 雲端對 stage 的三種寫入(`npx wrangler secret put`/`stage-deploy-artifacts.py`/curl POST 到 arcrun-yuga3bse)全被分類器擋——複合指令與任意 curl 對不上任何一條前綴。收成 `scripts/stage`(secret/api 兩個子命令,只寫 stage、值只從環境變數名讀)四種形狀,外加 Arcrun 自己那支 `scripts/stage-deploy-artifacts.py`(它已寫死只認 youlin 帳號 ID、不收 --account/--token)從 Arcrun repo 根目錄的相對形狀。不放 `Bash(npx *)`/`Bash(wrangler *)`/`Bash(curl *)`。"
|
|
||||||
],
|
|
||||||
"_rules": [
|
|
||||||
"開頭的 `~` 由 settings-allow-sync 換成那台機器的家目錄(本機 /Users/…、雲端 /root),其餘一字不改。",
|
|
||||||
"只放「正門工具」:每一條都要說得出它是哪支腳本的哪種呼叫形狀。不放 Bash(python3 *) 這種整類放行。",
|
|
||||||
"同一支工具幾種呼叫形狀就幾條(快取路徑/$CLAUDE_PLUGIN_ROOT/相對路徑)——權限規則是逐條完全比對,形狀差一個字就落在規則之外(scripts/gate-ok 檔頭記過這一課)。",
|
|
||||||
"別的 repo 的正門工具也可以進來(例 Arcrun 的 `scripts/stage-deploy-artifacts.py`),條件一樣:那支腳本自己把「只打哪台」寫死在程式裡,本清單放的是它從那個 repo 根目錄跑的相對形狀。"
|
|
||||||
],
|
|
||||||
"allow": [
|
|
||||||
"Bash(python3 ~/.claude/plugins/cache/inkstone/isep/*/scripts/ticket *)",
|
|
||||||
"Bash(python3 \"$CLAUDE_PLUGIN_ROOT/scripts/ticket\" *)",
|
|
||||||
"Bash(python3 \"$CLAUDE_PLUGIN_ROOT\"/scripts/ticket *)",
|
|
||||||
"Bash(python3 scripts/ticket *)",
|
|
||||||
"Bash(python3 ~/.claude/plugins/cache/inkstone/isep/*/scripts/mainline *)",
|
|
||||||
"Bash(python3 \"$CLAUDE_PLUGIN_ROOT/scripts/mainline\" *)",
|
|
||||||
"Bash(python3 \"$CLAUDE_PLUGIN_ROOT\"/scripts/mainline *)",
|
|
||||||
"Bash(python3 scripts/mainline *)",
|
|
||||||
"Bash(bash ~/.claude/plugins/cache/inkstone/isep/*/scripts/gate-ok *)",
|
|
||||||
"Bash(bash \"$CLAUDE_PLUGIN_ROOT/scripts/gate-ok\" *)",
|
|
||||||
"Bash(bash \"$CLAUDE_PLUGIN_ROOT\"/scripts/gate-ok *)",
|
|
||||||
"Bash(bash scripts/gate-ok *)",
|
|
||||||
"Bash(bash scripts/gitea-pr-merge.sh *)",
|
|
||||||
"Bash(python3 ~/.claude/plugins/cache/inkstone/isep/*/scripts/stage *)",
|
|
||||||
"Bash(python3 \"$CLAUDE_PLUGIN_ROOT/scripts/stage\" *)",
|
|
||||||
"Bash(python3 \"$CLAUDE_PLUGIN_ROOT\"/scripts/stage *)",
|
|
||||||
"Bash(python3 scripts/stage *)",
|
|
||||||
"Bash(python3 scripts/stage-deploy-artifacts.py *)"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Executable
+68
@@ -0,0 +1,68 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# duplicate-hook-registration-guard.sh — SessionStart:這個專案自己的 .claude/settings.json
|
||||||
|
# 是不是還在登記一支跟 ISEP plugin 同名的舊 hook(inkstone/ISEP#122)
|
||||||
|
#
|
||||||
|
# 為什麼存在(2026-09-01 實撞):
|
||||||
|
# 總管三次要部署 uncle6.me,三次被 prod-write-guard.sh 擋。leo 問「你沒有權限?」
|
||||||
|
# ——不是沒權限,是 InkStoneCo/.claude/settings.json 裡還留著 ISEP 立 plugin 之前
|
||||||
|
# 的舊登記,跟 plugin 自己的 hooks.json 同時掛在同一個事件上,於是每個 PreToolUse
|
||||||
|
# 都跑了**兩次**:一次由專案版、一次由 plugin。多數閘只是白跑一次沒感覺,
|
||||||
|
# 但**帶「蓋一次戳記只放行一次」語意的閘會被第一份吃光**——第二份永遠看到空的戳記,
|
||||||
|
# 於是恆擋。查證見 ISEP#122:37 支專案版登記裡,34 支跟 plugin 完全同名同用途、
|
||||||
|
# 3 支是已經退役的機制(`claim-verify-police.sh`/`subagent-claim-worksheet.sh`/
|
||||||
|
# `sdd-guard.sh`),全部清掉;剩下 1 支(`kv-write-guard.sh`)是專案版有、plugin
|
||||||
|
# 當時沒有的真閘,已原樣搬進本 repo(同一輪 commit)。
|
||||||
|
#
|
||||||
|
# 🔑 這支 hook 的用途不是清除,是**讓「又長出重複掛載」這件事有人立刻知道**。
|
||||||
|
# 上一次它能存活 13 天沒被發現,就是因為除了「戳記莫名其妙失效」以外沒有任何
|
||||||
|
# 訊號會指出來——一支天天在跑的閘,跟一支不存在的閘,行為長得一模一樣。
|
||||||
|
#
|
||||||
|
# 三條設計約束(跟 skill-deploy-drift-guard.sh 同一個形狀):
|
||||||
|
# 1. 沒事不出聲——乾淨時完全靜音。
|
||||||
|
# 2. 從不擋人——SessionStart 一律 exit 0,這是通知,不是閘。
|
||||||
|
# 3. 判準是「登記在不在」,不是關鍵字——比對的是 hooks.json/settings.json
|
||||||
|
# 裡實際出現的檔名,不是靠猜或列黑名單(isep-hand 紅線:不准用關鍵字黑名單)。
|
||||||
|
|
||||||
|
set -uo pipefail
|
||||||
|
|
||||||
|
ROOT="${CLAUDE_PLUGIN_ROOT:-}"
|
||||||
|
[ -n "$ROOT" ] || exit 0
|
||||||
|
[ -f "$ROOT/hooks/hooks.json" ] || exit 0
|
||||||
|
|
||||||
|
PROJ="${CLAUDE_PROJECT_DIR:-}"
|
||||||
|
[ -n "$PROJ" ] || exit 0
|
||||||
|
SETTINGS="$PROJ/.claude/settings.json"
|
||||||
|
[ -f "$SETTINGS" ] || exit 0
|
||||||
|
|
||||||
|
# ISEP plugin 自己「真的註冊了」的 hook 檔名(不是目錄列表——目錄裡可能有沒掛的樣板)
|
||||||
|
PLUGIN_NAMES="$(grep -oE 'hooks/[a-zA-Z0-9._-]+\.sh' "$ROOT/hooks/hooks.json" 2>/dev/null \
|
||||||
|
| sed 's|.*/||' | sort -u)"
|
||||||
|
[ -n "$PLUGIN_NAMES" ] || exit 0
|
||||||
|
|
||||||
|
# 這個專案自己的 settings.json 裡,指向 .claude/hooks/ 底下的登記
|
||||||
|
PROJECT_NAMES="$(grep -oE '\.claude/hooks/[a-zA-Z0-9_.-]+\.sh' "$SETTINGS" 2>/dev/null \
|
||||||
|
| sed 's|.*/||' | sort -u)"
|
||||||
|
[ -n "$PROJECT_NAMES" ] || exit 0
|
||||||
|
|
||||||
|
DUPES="$(comm -12 <(printf '%s\n' "$PLUGIN_NAMES") <(printf '%s\n' "$PROJECT_NAMES") 2>/dev/null || true)"
|
||||||
|
[ -n "$DUPES" ] || exit 0
|
||||||
|
|
||||||
|
N=$(printf '%s\n' "$DUPES" | grep -c .)
|
||||||
|
LIST="$(printf '%s\n' "$DUPES" | sed 's/^/ • /')"
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
🔁 重複掛載警報:\`$SETTINGS\` 還登記著 ${N} 支跟 ISEP plugin 同名的舊 hook。
|
||||||
|
|
||||||
|
$LIST
|
||||||
|
|
||||||
|
⇒ 每個對應的動作都會**跑兩次**——一次由這份專案版複本、一次由 plugin。
|
||||||
|
多數閘只是白跑一次;**帶「蓋一次戳記只放行一次」語意的閘會被第一份吃光**,
|
||||||
|
第二份永遠看到空戳記,於是恆擋——這正是 inkstone/ISEP#122 那次的形狀。
|
||||||
|
|
||||||
|
出路(二選一,不是「留著沒關係」):
|
||||||
|
① 這幾支 plugin 已經覆蓋 → 從 \`$SETTINGS\` 的 hooks 區段刪掉這幾條登記。
|
||||||
|
② 專案版身上還有 plugin 沒有的邏輯 → 先把那段邏輯併進 ISEP(開票、比照
|
||||||
|
kv-write-guard.sh 那次的搬法),plugin 升版裝上之後再刪專案版登記。
|
||||||
|
**不要讓兩份同時掛著**——那正是這支閘存在的理由。
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
@@ -56,32 +56,15 @@ STAMP="/tmp/.history-guard-$(printf '%s' "$FILE_PATH" | shasum | cut -c1-12)"
|
|||||||
#
|
#
|
||||||
# 時戳由 kbdb-asked-stamp.sh(PostToolUse,matcher 對 kbdb_* 工具)寫下。
|
# 時戳由 kbdb-asked-stamp.sh(PostToolUse,matcher 對 kbdb_* 工具)寫下。
|
||||||
# 逃生口:KBDB 真的連不上時 `touch /tmp/.kbdb-down`——放行但留痕,且回覆裡要說明。
|
# 逃生口:KBDB 真的連不上時 `touch /tmp/.kbdb-down`——放行但留痕,且回覆裡要說明。
|
||||||
#
|
KBDB_STAMP=/tmp/.kbdb-asked
|
||||||
# 🔴 **逃生門要真的走得通**(inkstone/ISEP#122,2026-09-02 實撞,本檔第二次修):
|
KBDB_DOWN=/tmp/.kbdb-down
|
||||||
# 上面那句訊息叫人 `touch /tmp/.kbdb-down`,而 `touch` 造出來的是**空檔**
|
|
||||||
# ⇒ 舊版 `t=$(cat "$f")` 讀到空字串 ⇒ 算式當成 0 ⇒ 「距今 17 億秒」
|
|
||||||
# ⇒ 永遠不新鮮 ⇒ **照著訊息打完,還是被擋**。
|
|
||||||
# 實測(2026-09-02,KBDB 兩支工具都回 Connection closed 時):
|
|
||||||
# $ touch /tmp/.kbdb-down → 再送同一個編輯 → 一模一樣的擋,訊息一字不差
|
|
||||||
# ⇒ 那行逃生門是印出來好看的,**沒有人照著打過一次**
|
|
||||||
# (同族:ISEP#125 worktree 閘印的逃生門原文照打 rc=2;本票 comment 6071)。
|
|
||||||
#
|
|
||||||
# 改法:**內容不是數字就用檔案的 mtime**——`touch` 做的正是更新 mtime,
|
|
||||||
# 所以訊息裡那一行從此真的走得通,而 `kbdb-asked-stamp.sh` 寫數字的舊格式照樣相容。
|
|
||||||
# 路徑用 `KBDB_STAMP_DIR` 可覆寫,**只為了讓迴歸測試不去動這台機器真正的戳記**
|
|
||||||
# (測試把別的 session 的戳記清掉=把閘弄成隨機的)。
|
|
||||||
KBDB_STAMP="${KBDB_STAMP_DIR:-/tmp}/.kbdb-asked"
|
|
||||||
KBDB_DOWN="${KBDB_STAMP_DIR:-/tmp}/.kbdb-down"
|
|
||||||
kbdb_fresh=0
|
kbdb_fresh=0
|
||||||
now=$(date +%s)
|
now=$(date +%s)
|
||||||
for f in "$KBDB_STAMP" "$KBDB_DOWN"; do
|
for f in "$KBDB_STAMP" "$KBDB_DOWN"; do
|
||||||
[ -f "$f" ] || continue
|
if [ -f "$f" ]; then
|
||||||
t=$(cat "$f" 2>/dev/null || true)
|
t=$(cat "$f" 2>/dev/null || echo 0)
|
||||||
case "$t" in
|
[ $((now - t)) -lt 3600 ] && kbdb_fresh=1
|
||||||
''|*[!0-9]*) t=$(date -r "$f" +%s 2>/dev/null || stat -c %Y "$f" 2>/dev/null || echo 0) ;;
|
fi
|
||||||
esac
|
|
||||||
[ "${t:-0}" -gt 0 ] || continue
|
|
||||||
[ $((now - t)) -lt 3600 ] && kbdb_fresh=1
|
|
||||||
done
|
done
|
||||||
if [ "$kbdb_fresh" -eq 0 ]; then
|
if [ "$kbdb_fresh" -eq 0 ]; then
|
||||||
cat >&2 <<'KEOF'
|
cat >&2 <<'KEOF'
|
||||||
|
|||||||
+8
-4
@@ -126,6 +126,10 @@
|
|||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
|
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "command",
|
||||||
|
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/kv-write-guard.sh"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -281,10 +285,6 @@
|
|||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "\"${CLAUDE_PLUGIN_ROOT}\"/scripts/mainline refresh"
|
"command": "\"${CLAUDE_PLUGIN_ROOT}\"/scripts/mainline refresh"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "\"${CLAUDE_PLUGIN_ROOT}\"/scripts/settings-allow-sync --quiet"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/overdue-nag-guard.sh"
|
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/overdue-nag-guard.sh"
|
||||||
@@ -292,6 +292,10 @@
|
|||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
|
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/wiki-size-guard.sh"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "command",
|
||||||
|
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/duplicate-hook-registration-guard.sh"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,5 @@
|
|||||||
# KBDB(一次看所有庫,最便宜)→ 該 repo 的 wiki/tasks → git log -S → 讀源碼(最貴,
|
# KBDB(一次看所有庫,最便宜)→ 該 repo 的 wiki/tasks → git log -S → 讀源碼(最貴,
|
||||||
# 只看得到「現在長怎樣」,看不到「為什麼變成這樣」)
|
# 只看得到「現在長怎樣」,看不到「為什麼變成這樣」)
|
||||||
set -eu
|
set -eu
|
||||||
# 路徑跟 history-first-guard.sh 用同一個覆寫變數,否則測試會兩邊指到不同地方
|
date +%s > /tmp/.kbdb-asked
|
||||||
date +%s > "${KBDB_STAMP_DIR:-/tmp}/.kbdb-asked"
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Executable
+115
@@ -0,0 +1,115 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# PreToolUse hook(Write|Edit|MultiEdit)— 長效資料不准寫進 KV,一律走 KBDB API
|
||||||
|
#
|
||||||
|
# 【portage 記錄,inkstone/ISEP#122】本檔 2026-08-25 立於
|
||||||
|
# `InkStoneCo/.claude/hooks/kv-write-guard.sh`(那時 ISEP 還沒吸收它),
|
||||||
|
# 2026-09-02 原樣搬進 ISEP——它是那次盤點揪出來的**唯一一支**「專案版有、
|
||||||
|
# plugin 沒有」的真閘(另外 3 支同名殘骸是已退役機制,直接刪掉,不搬)。
|
||||||
|
# 搬完之後 `InkStoneCo/.claude/hooks/kv-write-guard.sh` 就是廢棄複本,
|
||||||
|
# 待這裡升版、`/plugin update` 裝上之後即可從專案版與 settings.json 一併移除。
|
||||||
|
#
|
||||||
|
# 【leo 2026-08-25 立】原話(三句,一句比一句尖):
|
||||||
|
# 「已經禁止寫入 KV 了,這是太貴的資源,應該都去寫入 KBDB,到底寫入 KV 做什麼?」
|
||||||
|
# 「上次刪掉一堆東西,現在又寫入,**你沒有規範嗎**」
|
||||||
|
# 「**我強制禁止寫 SQL,要用 KBDB API,你就讓它繞過寫 KV 代替?**」
|
||||||
|
#
|
||||||
|
# ── 為什麼存在(2026-08-25 實查,這是本閘的正身)─────────────────────────
|
||||||
|
# 規則早就在:`system-dev/wiki/decisions-summary.md:133`
|
||||||
|
# 「**KV =暫存(cache / transient),不是長期真相源。**」
|
||||||
|
# 而且打過一場「KV 退休戰」(同檔 254 行,SUBMISSIONS_KV 併入那一役)。
|
||||||
|
#
|
||||||
|
# 🔴 **但 `.claude/hooks/` 底下跟 KV 有關的閘:0 支。**
|
||||||
|
# ⇒ 規則被讀到了,卻沒有任何機制驗證有沒有照做——與 2026-08-25 一整天挖出來的
|
||||||
|
# 四層 migration 缺陷、以及 08-10 抓到的 history-first/KBDB-first/stage-first
|
||||||
|
# **完全同一個形狀**。
|
||||||
|
#
|
||||||
|
# 🔴 **更糟的是 leo 指出的因果**(總管用 git 查證屬實):
|
||||||
|
# 禁 SQL 的牆 2026-08-07
|
||||||
|
# app-system.ts 誕生 2026-08-24 ← 17 天之後,**從第一行就在寫 KV**
|
||||||
|
# 而 `kbdbFetch()` 裡的 KV 字樣是 **0** ⇒ 走 KBDB API 根本不碰 KV
|
||||||
|
# ⇒ 那些 KV 寫入**每一處都是繞過**,沒有一處經過知識庫。
|
||||||
|
# **牆立起來了,水從旁邊流走了。**
|
||||||
|
#
|
||||||
|
# ── 判準(封動作,不封措辭)──────────────────────────────────────────
|
||||||
|
# 新增一行「往 KV 寫入」的程式碼 ⇒ 擋一次,要求說明它為什麼不是長效資料
|
||||||
|
# 只是讀(.get/.list) ⇒ 放行
|
||||||
|
# 刪除既有的 KV 寫入(退休戰) ⇒ 放行(那正是我們要的方向)
|
||||||
|
#
|
||||||
|
# ── 豁免(留痕,不是後門)────────────────────────────────────────────
|
||||||
|
# 那一行尾端加 `kv-ok: <理由>`。
|
||||||
|
# 合法的理由只有一種形狀:**這筆資料本來就是短命的**(session、一次性 nonce、
|
||||||
|
# 有 TTL 的快取)。寫「暫時先這樣」「之後再搬」都不算——
|
||||||
|
# 那是把債留給下一個人,而 2026-08-25 證明了沒人會回來還。
|
||||||
|
set -uo pipefail
|
||||||
|
|
||||||
|
payload=$(cat)
|
||||||
|
read -r tool content file <<<"$(printf '%s' "$payload" | python3 -c "
|
||||||
|
import json,sys
|
||||||
|
try:
|
||||||
|
d=json.load(sys.stdin); ti=d.get('tool_input') or {}
|
||||||
|
# Write 用 content;Edit 用 new_string;MultiEdit 把每筆 new_string 串起來
|
||||||
|
parts=[ti.get('content') or '', ti.get('new_string') or '']
|
||||||
|
for e in (ti.get('edits') or []): parts.append(e.get('new_string') or '')
|
||||||
|
body='\n'.join(p for p in parts if p)
|
||||||
|
print(d.get('tool_name','') or 'x', len(body), ti.get('file_path','') or 'x')
|
||||||
|
sys.stderr.write(body)
|
||||||
|
except Exception:
|
||||||
|
print('x 0 x')
|
||||||
|
" 2>/tmp/.kv-guard-body)" || exit 0
|
||||||
|
|
||||||
|
body=$(cat /tmp/.kv-guard-body 2>/dev/null)
|
||||||
|
rm -f /tmp/.kv-guard-body
|
||||||
|
[ -z "$body" ] && exit 0
|
||||||
|
|
||||||
|
# 只管程式碼檔;文件、設定、測試裡提到 KV 不算違規
|
||||||
|
case "$file" in
|
||||||
|
*.ts|*.js|*.mjs|*.tsx|*.jsx) ;;
|
||||||
|
*) exit 0 ;;
|
||||||
|
esac
|
||||||
|
# 閘自己、與退休戰的測試檔放行(否則永遠改不動它)
|
||||||
|
case "$file" in
|
||||||
|
*kv-write-guard*|*.test.*|*/tests/*) exit 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# 命中的行:往 KV 綁定寫入,且**該行沒有 kv-ok 豁免**
|
||||||
|
# 判準是形狀不是名字:**全大寫的 binding 後面接 .put(/.delete(**。
|
||||||
|
# 為什麼不列名字清單(第一版就是這樣寫壞的):名字會長出新的(下一個 KV 綁定叫什麼沒人知道),
|
||||||
|
# 而清單只認得已知的那幾個 ⇒ 新的 KV 從清單的縫隙走過去,本閘就變成裝飾。
|
||||||
|
# 全大寫識別字 + .put/.delete 這個形狀,在 Workers 裡就是 KV(D1 沒有 .put,JS 物件用 .set)。
|
||||||
|
hits=$(printf '%s' "$body" | grep -nE '\b[A-Z][A-Z0-9_]{1,}\.(put|delete)\(' \
|
||||||
|
| grep -v 'kv-ok' || true)
|
||||||
|
[ -z "$hits" ] && exit 0
|
||||||
|
|
||||||
|
cat >&2 <<EOF
|
||||||
|
🚫 長效資料不准寫進 KV——一律走 KBDB API(leo 2026-08-25 立)
|
||||||
|
|
||||||
|
leo 原話:
|
||||||
|
「**我強制禁止寫 SQL,要用 KBDB API,你就讓它繞過寫 KV 代替?**」
|
||||||
|
「上次刪掉一堆東西,現在又寫入,**你沒有規範嗎**」
|
||||||
|
|
||||||
|
━━ 你這次要寫的 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
$(printf '%s' "$hits" | head -6 | sed 's/^/ /')
|
||||||
|
|
||||||
|
━━ 為什麼擋 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
規則早就在(\`system-dev/wiki/decisions-summary.md:133\`):
|
||||||
|
**KV =暫存(cache / transient),不是長期真相源。**
|
||||||
|
而 2026-08-25 實查:\`.claude/hooks/\` 底下跟 KV 有關的閘 **0 支**
|
||||||
|
⇒ 規則被讀到了,卻沒有機制驗證有沒有照做。本閘就是補那一格。
|
||||||
|
|
||||||
|
🔴 **並且**:\`kbdbFetch()\` 裡的 KV 字樣是 **0**——走 KBDB API 根本不碰 KV。
|
||||||
|
所以「寫 KV」在這個系統裡**必定意味著繞過知識庫**,不是一種實作選擇。
|
||||||
|
禁 SQL 的牆 2026-08-07 立,而 app-system 2026-08-24 誕生就在寫 KV
|
||||||
|
——**牆立起來了,水從旁邊流走了。**
|
||||||
|
|
||||||
|
━━ 怎麼過 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
① **本來就該走 KBDB**(絕大多數)→ 改成 KBDB API。
|
||||||
|
新資料類型=seed 一列 template,資料展開成完整 record,
|
||||||
|
**不准打包進 metadata_json**(D91/D93)。讀 \`arcrun-kbdb-guardrails\` skill。
|
||||||
|
② **這筆資料真的是短命的**(session/一次性 nonce/有 TTL 的快取)
|
||||||
|
→ 那一行尾端加 \`kv-ok: <為什麼它是短命的>\`,留痕放行。
|
||||||
|
③ **你在做的是退休戰(刪掉 KV 寫入)** → 本閘不擋刪除,只擋新增。
|
||||||
|
|
||||||
|
🔴 \`kv-ok: 暫時先這樣\` / \`之後再搬\` **不算理由**——那是把債留給下一個人,
|
||||||
|
而 2026-08-25 已經證明了沒人會回來還。
|
||||||
|
EOF
|
||||||
|
exit 2
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
# 判準(封動作,不封措辭 —— 同 empty-handed-stop-guard 的哲學):
|
# 判準(封動作,不封措辭 —— 同 empty-handed-stop-guard 的哲學):
|
||||||
# 命中 leo21c 的座標 + 這是一個寫入動作 ⇒ 擋
|
# 命中 leo21c 的座標 + 這是一個寫入動作 ⇒ 擋
|
||||||
# 只是讀(GET/查詢/grep 到那個字串) ⇒ 放行
|
# 只是讀(GET/查詢/grep 到那個字串) ⇒ 放行
|
||||||
# 發一則 notify_leo(通知型 trigger,什麼都沒改)⇒ 放行(同 prod-write-guard 的白名單)
|
|
||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
payload=$(cat)
|
payload=$(cat)
|
||||||
cmd=$(printf '%s' "$payload" | python3 -c "
|
cmd=$(printf '%s' "$payload" | python3 -c "
|
||||||
@@ -61,34 +60,8 @@ hit=0
|
|||||||
|
|
||||||
# ① 寫入請求打到那台 worker
|
# ① 寫入請求打到那台 worker
|
||||||
if printf '%s' "$cmd" | grep -qiE 'https?://[^[:space:]"'"'"']*leo21c\.workers\.dev'; then
|
if printf '%s' "$cmd" | grep -qiE 'https?://[^[:space:]"'"'"']*leo21c\.workers\.dev'; then
|
||||||
# 🔴 (a) 通知型 trigger 放行(inkstone/ISEP#130;判準與 prod-write-guard.sh 同一份):
|
if printf '%s' "$cmd" | grep -qE -- '-X *(POST|PUT|PATCH|DELETE)|--data|--data-raw|-d[[:space:]]|/trigger'; then
|
||||||
# `…/webhooks/named/<ns>/notify_leo/trigger` = 發一則 Telegram 給 leo,**什麼都沒改**。
|
hit=1
|
||||||
# wiki `agent-memory.md` 寫明它是找 leo 的正式通道;prod-write-guard 在 ISEP#63 就放行了它,
|
|
||||||
# 本閘卻因為路徑尾巴是 `/trigger` 照擋 ⇒ 兩支閘對同一條指令說不同的話,
|
|
||||||
# 而「發通知」被擋的結果是**雲端撞到人閘也叫不動 leo**(inkstone/InkStoneCo#110)。
|
|
||||||
# 放行的範圍刻意只有一個名字:指令裡打到 leo21c 的**每一個**網址都得是它,
|
|
||||||
# 混進部署端點(`…/webhooks/named` 無名字)或別的工作流 ⇒ 照擋。
|
|
||||||
NOTIFY_ONLY=$(printf '%s' "$cmd" | python3 -c '
|
|
||||||
import re, sys
|
|
||||||
cmd = sys.stdin.read()
|
|
||||||
ALLOW = {"notify_leo"}
|
|
||||||
urls = [u for u in re.findall(r"https?://[^\s\"\x27<>]+", cmd) if "leo21c.workers.dev" in u.lower()]
|
|
||||||
PAT = re.compile(r"https?://[^/]+/webhooks/named/[^/]+/([A-Za-z0-9_-]+)/trigger/?$")
|
|
||||||
def notify(u):
|
|
||||||
m = PAT.match(u.rstrip(",;)"))
|
|
||||||
return bool(m) and m.group(1) in ALLOW
|
|
||||||
print("notify-only" if urls and all(notify(u) for u in urls) else "")
|
|
||||||
' 2>/dev/null || printf '')
|
|
||||||
if [ "$NOTIFY_ONLY" != "notify-only" ]; then
|
|
||||||
# 🔴 (b) 先剪掉唯讀工具的 `-d`(inkstone/ISEP#130,09-04 雲端實撞):
|
|
||||||
# `curl -s https://…leo21c…/x | tr -d '\r'`、`cut -d= -f2`、`sort -d`、`date -d` ……
|
|
||||||
# 這些 `-d` 沒有一個會寫到那台,舊判準 `-d[[:space:]]` 卻把整條純 GET 擋下
|
|
||||||
# ⇒ 「連讀都被擋」。prod-write-guard.sh 在 2026-08-12 就修過同一個洞,本閘漏了。
|
|
||||||
# 剪法與那支同一句 sed,剪完剩下的 `-d` 才是 curl 的 body。
|
|
||||||
cmd_w=$(printf '%s' "$cmd" | sed -E 's/(^|[|;&( ])(tr|cut|sort|uniq|date|xargs|paste|join|du|logger|split|comm)[[:space:]]+-d/\1\2 __READONLY_D__/g')
|
|
||||||
if printf '%s' "$cmd_w" | grep -qE -- '-X *(POST|PUT|PATCH|DELETE)|--request *(POST|PUT|PATCH|DELETE)|--data|--data-raw|-d[[:space:]]|/trigger'; then
|
|
||||||
hit=1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -114,8 +87,7 @@ leo 原話:「**leo21c 就是我這個普通用戶,不應該讓你去操控
|
|||||||
改法:把目標明寫成 youlin,不要吃 `~/.arcrun/config.yaml` 的預設——
|
改法:把目標明寫成 youlin,不要吃 `~/.arcrun/config.yaml` 的預設——
|
||||||
那個檔至今仍指著 leo21c(KV id 與 encryption_key 是該實例專屬,換不過去)。
|
那個檔至今仍指著 leo21c(KV id 與 encryption_key 是該實例專屬,換不過去)。
|
||||||
|
|
||||||
cypher : https://arcrun-cypher-executor.arcrun-yuga3bse.workers.dev
|
cypher : https://arcrun-cypher-executor.youlin-hsieh-dev.workers.dev
|
||||||
(09-02 重裝後的子網域;舊名 youlin-hsieh-dev 的 DNS 已不存在,打它一律 000)
|
|
||||||
ns : yuga3bse
|
ns : yuga3bse
|
||||||
CF : 1129efd7df2e8899d537e9c8fbabb6cb
|
CF : 1129efd7df2e8899d537e9c8fbabb6cb
|
||||||
token : 頂層 .env 的 CLOUDFLARE_API_TOKEN_YOULIN_CC_USE
|
token : 頂層 .env 的 CLOUDFLARE_API_TOKEN_YOULIN_CC_USE
|
||||||
|
|||||||
+2
-141
@@ -1,7 +1,6 @@
|
|||||||
# ── 以下五格是「這一份是不是還有效」自檢 ─────────────────────────────
|
# ── 以下三格是 inkstone/ISEP#90 加的「這一份是不是還有效」自檢 ──────────
|
||||||
# ①②③ inkstone/ISEP#90 立;②b②c inkstone/ISEP#122 補(會自動載入的東西也有分身)
|
|
||||||
# 都**只是報告,不擋任何事**(SessionStart 本來就不該擋),而且每一格拿不到答案就閉嘴。
|
# 都**只是報告,不擋任何事**(SessionStart 本來就不該擋),而且每一格拿不到答案就閉嘴。
|
||||||
import hashlib, json, os, re, subprocess, sys, time, urllib.request
|
import json, os, re, subprocess, sys, time, urllib.request
|
||||||
|
|
||||||
ROOT = os.environ.get("CLAUDE_PLUGIN_ROOT", "")
|
ROOT = os.environ.get("CLAUDE_PLUGIN_ROOT", "")
|
||||||
PROJ = os.environ.get("CLAUDE_PROJECT_DIR") or os.getcwd()
|
PROJ = os.environ.get("CLAUDE_PROJECT_DIR") or os.getcwd()
|
||||||
@@ -104,144 +103,6 @@ if sh:
|
|||||||
"在雲端一律死在「拿不到 gitea token」。要嘛刪掉複本改叫 "
|
"在雲端一律死在「拿不到 gitea token」。要嘛刪掉複本改叫 "
|
||||||
"`\"$CLAUDE_PLUGIN_ROOT\"/scripts/<名字>`,要嘛把複本同步回 ISEP。" % "、".join(sh))
|
"`\"$CLAUDE_PLUGIN_ROOT\"/scripts/<名字>`,要嘛把複本同步回 ISEP。" % "、".join(sh))
|
||||||
|
|
||||||
# ══ ②b 會**自動載入**的東西(skill/command/agent)兩邊各有一份而內容不同 ══
|
|
||||||
#
|
|
||||||
# 🔴 為什麼上面那一格抓不到(inkstone/ISEP#122,2026-09-02 實查):
|
|
||||||
# ② 只掃 `scripts/`。而真正會**自動載入**的東西住在別的目錄,同樣兩邊各有一份:
|
|
||||||
# plugin `skills/<名>/SKILL.md` ↔ 專案 `.claude/skills/<名>/SKILL.md`
|
|
||||||
# plugin `commands/<名>.md` ↔ 專案 `.claude/commands/<名>.md`
|
|
||||||
# plugin `agents/<名>.md` ↔ 專案 `.claude/agents/<名>.md`
|
|
||||||
#
|
|
||||||
# 實況:這 9 個檔案在 ISEP `0.1.0`(c263866)從 InkStoneCo 複製過來**一次**,
|
|
||||||
# 之後再也沒有同步過。到 2026-09-02 已經分家兩個,而且**方向相反**:
|
|
||||||
# `skills/ship-check/SKILL.md` InkStoneCo 651 行 / ISEP 595 行
|
|
||||||
# `commands/sdd-check.md` ISEP 81 行 / InkStoneCo 65 行
|
|
||||||
# (InkStoneCo 那份還在教 ISEP#91 已退役的「唯一 active SDD」)
|
|
||||||
# ⇒ 「ISEP 一定比較新」與「InkStoneCo 一定比較新」**兩句都是錯的**。
|
|
||||||
# 兩份都會被就地編輯 ⇒ 歸屬只能寫下來(`docs/file-ownership.tsv`)並且要有東西去比。
|
|
||||||
#
|
|
||||||
# 🔴 這一格比 ② 嚴重:腳本要有人叫它才會跑,**skill/command 是自動載入的**——
|
|
||||||
# 載到舊的那份不會報錯、不會變慢、不會有任何症狀,只會安靜地教錯的東西。
|
|
||||||
# (ship-check 就是這樣:舊描述在「我要發一篇部落格文章」時根本不會被觸發。)
|
|
||||||
#
|
|
||||||
# 判準與 ② 同一條:**檔名一樣而內容不同**才出聲,同步過的不吵。
|
|
||||||
LOADABLE_PAIRS = [("skills", ".claude/skills", True),
|
|
||||||
("commands", ".claude/commands", False),
|
|
||||||
("agents", ".claude/agents", False)]
|
|
||||||
|
|
||||||
|
|
||||||
def ownership():
|
|
||||||
"""讀 docs/file-ownership.tsv → {plugin 內路徑: (真相源, 真相源路徑, commit, sha256)}"""
|
|
||||||
out = {}
|
|
||||||
try:
|
|
||||||
with open(os.path.join(ROOT, "docs", "file-ownership.tsv"), encoding="utf-8") as f:
|
|
||||||
for line in f:
|
|
||||||
if not line.strip() or line.lstrip().startswith("#"):
|
|
||||||
continue
|
|
||||||
c = line.rstrip("\n").split("\t")
|
|
||||||
if len(c) >= 2 and c[0].strip():
|
|
||||||
out[c[0].strip()] = tuple((c[1:5] + ["-", "-", "-", "-"])[:4])
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
OWN = ownership()
|
|
||||||
|
|
||||||
|
|
||||||
def loadable_pairs():
|
|
||||||
"""產生 (plugin 內相對路徑, 專案內相對路徑)——只列 plugin 真的有的那些"""
|
|
||||||
for pdir, jdir, nested in LOADABLE_PAIRS:
|
|
||||||
src = os.path.join(ROOT, pdir)
|
|
||||||
if not os.path.isdir(src):
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
names = sorted(os.listdir(src))
|
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
for name in names:
|
|
||||||
if nested:
|
|
||||||
if os.path.isfile(os.path.join(src, name, "SKILL.md")):
|
|
||||||
yield "%s/%s/SKILL.md" % (pdir, name), "%s/%s/SKILL.md" % (jdir, name)
|
|
||||||
elif name.endswith(".md") and os.path.isfile(os.path.join(src, name)):
|
|
||||||
yield "%s/%s" % (pdir, name), "%s/%s" % (jdir, name)
|
|
||||||
|
|
||||||
|
|
||||||
def whose(rel):
|
|
||||||
"""真相源是誰 → 一句照著做就會走到的話。表上沒有就誠實說未定,不要猜。"""
|
|
||||||
row = OWN.get(rel)
|
|
||||||
if not row:
|
|
||||||
return "歸屬未定 ⇒ 兩份都看一眼,決定之後補一列進 docs/file-ownership.tsv"
|
|
||||||
src, spath, _commit, _sha = row
|
|
||||||
if src == "inkstone/ISEP":
|
|
||||||
return "真相源=ISEP 這一份 ⇒ 專案那份是舊複本,同步過去或刪掉它"
|
|
||||||
return ("真相源=%s:%s ⇒ 內容改在那裡,改完原樣搬進 ISEP、"
|
|
||||||
"更新 docs/file-ownership.tsv 的 commit/sha256、升版" % (src, spath or "?"))
|
|
||||||
|
|
||||||
|
|
||||||
def shadow_loadables():
|
|
||||||
out = []
|
|
||||||
roots = [PROJ, os.path.join(PROJ, "InkStoneCo")]
|
|
||||||
for prel, jrel in loadable_pairs():
|
|
||||||
a = os.path.join(ROOT, prel)
|
|
||||||
try:
|
|
||||||
ab = open(a, "rb").read()
|
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
for base in roots:
|
|
||||||
b = os.path.join(base, jrel)
|
|
||||||
try:
|
|
||||||
if os.path.realpath(b) == os.path.realpath(a) or not os.path.isfile(b):
|
|
||||||
continue
|
|
||||||
if open(b, "rb").read() != ab:
|
|
||||||
out.append("%s ↔ %s(%s)"
|
|
||||||
% (prel, os.path.relpath(b, PROJ), whose(prel)))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
ld = shadow_loadables()
|
|
||||||
if ld:
|
|
||||||
notes.append(
|
|
||||||
"🟡 **會自動載入的東西兩邊各有一份,而且內容不同**:\n - %s\n"
|
|
||||||
" 自動載入的東西載到舊的那份**不會有任何症狀**——不報錯、不變慢,"
|
|
||||||
"只會安靜地教錯的東西(`ship-check` 的舊描述在「我要發一篇部落格文章」時"
|
|
||||||
"根本不會被觸發)。歸屬表:docs/file-ownership.tsv(inkstone/ISEP#122)。"
|
|
||||||
% "\n - ".join(ld))
|
|
||||||
|
|
||||||
# ══ ②c ISEP 自己這一份,跟歸屬表記的那顆對不對得上 ══════════════════════
|
|
||||||
#
|
|
||||||
# 🔴 為什麼要有這一格:②b 要「專案那一份」在磁碟上才比得出來,
|
|
||||||
# 而**雲端的 project dir 是薄殼,根本沒有那一份**(ISEP#90 記過同一件事)。
|
|
||||||
# 這一格只比「檔案 vs 表上寫的 sha256」——離線、單邊、不依賴任何別的 repo,
|
|
||||||
# 是雲端唯一還作數的那個檢查。
|
|
||||||
def off_manifest():
|
|
||||||
out = []
|
|
||||||
for rel, (src, spath, commit, sha) in OWN.items():
|
|
||||||
if not sha or sha == "-":
|
|
||||||
continue
|
|
||||||
p = os.path.join(ROOT, rel)
|
|
||||||
if not os.path.isfile(p):
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
h = hashlib.sha256(open(p, "rb").read()).hexdigest()
|
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
if h != sha:
|
|
||||||
out.append("%s(表記 %s 的 %s…,實際 %s…;真相源 %s:%s)"
|
|
||||||
% (rel, (commit or "?")[:7], sha[:12], h[:12], src, spath or "?"))
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
om = off_manifest()
|
|
||||||
if om:
|
|
||||||
notes.append(
|
|
||||||
"🟡 **ISEP 這一份跟歸屬表對不上**:%s。兩種可能,兩種都要動手:"
|
|
||||||
"① 它被就地改過 ⇒ 內容要改在真相源那邊,這裡只放原樣搬過來的複本;"
|
|
||||||
"② 它是同步過的新內容、只是沒更新 docs/file-ownership.tsv 的 commit/sha256 ⇒ 補上那兩欄。"
|
|
||||||
% "、".join(om))
|
|
||||||
|
|
||||||
# ══ ③ 工作區有沒有「已退役機制」留下的產物 ══════════════════════════════
|
# ══ ③ 工作區有沒有「已退役機制」留下的產物 ══════════════════════════════
|
||||||
#
|
#
|
||||||
# 判準是機械的、而且會自己長大:**plugin 自己的原始碼裡有沒有任何一個字提到這個目錄**。
|
# 判準是機械的、而且會自己長大:**plugin 自己的原始碼裡有沒有任何一個字提到這個目錄**。
|
||||||
|
|||||||
+12
-91
@@ -58,57 +58,14 @@ def path() -> str:
|
|||||||
return os.path.join(state_dir(), STATE_NAME)
|
return os.path.join(state_dir(), STATE_NAME)
|
||||||
|
|
||||||
|
|
||||||
# ── repo 裡的那一份(inkstone/ISEP#130)──────────────────────────────
|
def load():
|
||||||
#
|
"""讀主線。沒有/壞掉 ⇒ None(=現在沒有主線),**不是例外**。
|
||||||
# 主線原本只住在 `~/.claude/isep-countdown/mainline.json`——**這台機器的家目錄**。
|
|
||||||
# 雲端 session 是另一台機器:家目錄是空的,clone 下來的 repo 才是它唯一拿得到的東西。
|
|
||||||
# 2026-09-05 leo:「routine 每天早上開啟後抓不到任務」——不是 Gitea 沒票,
|
|
||||||
# 是雲端根本不知道主線是哪一條。
|
|
||||||
# ⇒ `inkstone/InkStoneCo` 的 `system-dev/mainline.json` 是**隨 repo 走的那一份**
|
|
||||||
# (PR inkstone/InkStoneCo#118 放進去的)。這裡的規矩:
|
|
||||||
# · 讀:家目錄那份沒有 ⇒ 讀 repo 那份(雲端就是這個形狀)。
|
|
||||||
# 兩份都在 ⇒ 用 `set_at` 較新的(誰後標的誰算數,不分本機雲端)。
|
|
||||||
# · 寫:`set`/`adopt`/`clear` 這種「主線是誰」的改動 ⇒ 兩份一起寫(`mirror=True`)。
|
|
||||||
# `refresh`/閘順手學到成員 ⇒ 只寫家目錄那份——否則每開一個 session
|
|
||||||
# InkStoneCo 的工作樹就髒一次,而髒的 diff 沒有人會去 commit。
|
|
||||||
# · repo 那份要 commit/開 PR 才到得了雲端;這支不碰 git。
|
|
||||||
REPO_REL = os.path.join("system-dev", STATE_NAME)
|
|
||||||
|
|
||||||
|
「沒有主線」是一個正常狀態,不是故障:ISEP#82 驗收第 4 條寫死了
|
||||||
def repo_candidates():
|
「沒有任何主線時不能整組壞掉」。所以這支從不 raise。
|
||||||
"""repo 那一份可能在哪:明指 > 專案根 > 專案根底下的 InkStoneCo/(雲端薄殼的形狀)> cwd 同兩層。"""
|
"""
|
||||||
out = []
|
|
||||||
forced = os.environ.get("ISEP_MAINLINE_REPO_FILE", "").strip()
|
|
||||||
if forced == "none":
|
|
||||||
return [] # 測試用:把「repo 那份」整個拿掉,外界定住
|
|
||||||
if forced:
|
|
||||||
out.append(forced)
|
|
||||||
roots = []
|
|
||||||
for r in (os.environ.get("CLAUDE_PROJECT_DIR", "").strip(), os.getcwd()):
|
|
||||||
if r:
|
|
||||||
roots += [r, os.path.join(r, "InkStoneCo")]
|
|
||||||
for r in roots:
|
|
||||||
p = os.path.join(r, REPO_REL)
|
|
||||||
if p not in out:
|
|
||||||
out.append(p)
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def repo_path(for_write=False):
|
|
||||||
"""讀:第一個**存在**的檔。寫:第一個 `system-dev/` 目錄存在的位置(檔可以還沒有)。
|
|
||||||
找不到 ⇒ None(雲端沒 clone InkStoneCo、或 cwd 在別的 repo 時都是正常狀態)。"""
|
|
||||||
for p in repo_candidates():
|
|
||||||
if for_write:
|
|
||||||
if os.path.isdir(os.path.dirname(p)):
|
|
||||||
return p
|
|
||||||
elif os.path.isfile(p):
|
|
||||||
return p
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _read(p):
|
|
||||||
try:
|
try:
|
||||||
with open(p) as f:
|
with open(path()) as f:
|
||||||
d = json.load(f)
|
d = json.load(f)
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
@@ -117,59 +74,23 @@ def _read(p):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
def load():
|
def save(d) -> bool:
|
||||||
"""讀主線。沒有/壞掉 ⇒ None(=現在沒有主線),**不是例外**。
|
|
||||||
|
|
||||||
「沒有主線」是一個正常狀態,不是故障:ISEP#82 驗收第 4 條寫死了
|
|
||||||
「沒有任何主線時不能整組壞掉」。所以這支從不 raise。
|
|
||||||
|
|
||||||
家目錄那份與 repo 那份都在時,`set_at` 較新的算數(格式固定 `YYYY-MM-DD HH:MM`,
|
|
||||||
字串比大小就是時間比大小);一樣新 ⇒ 家目錄那份(它才有 refresh 過的進度)。
|
|
||||||
"""
|
|
||||||
local = _read(path())
|
|
||||||
rp = repo_path()
|
|
||||||
remote = _read(rp) if rp else None
|
|
||||||
if local and remote:
|
|
||||||
return remote if (remote.get("set_at") or "") > (local.get("set_at") or "") else local
|
|
||||||
return local or remote
|
|
||||||
|
|
||||||
|
|
||||||
def save(d, mirror=False) -> bool:
|
|
||||||
"""寫家目錄那份;`mirror=True` 時同時寫 repo 那份(只有「主線是誰」變了才這樣叫)。
|
|
||||||
回 True/False 只看家目錄那份——repo 那份寫不寫得進去用 `repo_path(for_write=True)` 另外問。"""
|
|
||||||
try:
|
try:
|
||||||
with open(path(), "w") as f:
|
with open(path(), "w") as f:
|
||||||
json.dump(d, f, ensure_ascii=False, indent=2)
|
json.dump(d, f, ensure_ascii=False, indent=2)
|
||||||
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
if mirror:
|
|
||||||
rp = repo_path(for_write=True)
|
|
||||||
if rp:
|
|
||||||
try:
|
|
||||||
with open(rp, "w") as f:
|
|
||||||
json.dump(d, f, ensure_ascii=False, indent=2)
|
|
||||||
f.write("\n")
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def clear(mirror=False) -> bool:
|
def clear() -> bool:
|
||||||
ok = True
|
|
||||||
try:
|
try:
|
||||||
os.remove(path())
|
os.remove(path())
|
||||||
|
return True
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
ok = False
|
return False
|
||||||
if mirror:
|
|
||||||
rp = repo_path()
|
|
||||||
if rp:
|
|
||||||
try:
|
|
||||||
os.remove(rp)
|
|
||||||
except Exception:
|
|
||||||
ok = False
|
|
||||||
return ok
|
|
||||||
|
|
||||||
|
|
||||||
def parse_ts(raw):
|
def parse_ts(raw):
|
||||||
|
|||||||
@@ -315,13 +315,12 @@ fi
|
|||||||
#
|
#
|
||||||
# 整套測試環境=下列任一出現在命令裡:
|
# 整套測試環境=下列任一出現在命令裡:
|
||||||
# · `youlin-hsieh-dev` ── 帳號名(D37 定的 stage 帳號)
|
# · `youlin-hsieh-dev` ── 帳號名(D37 定的 stage 帳號)
|
||||||
# · `arcrun-yuga3bse` ── 該帳號 09-02 重裝後的 workers.dev 子網域(inkstone/ISEP#130;舊名 DNS 已死)
|
|
||||||
# · `1129efd7df2e8899d537e9c8fbabb6cb` ── 該帳號 ID(用 env 指過去時只有它看得見)
|
# · `1129efd7df2e8899d537e9c8fbabb6cb` ── 該帳號 ID(用 env 指過去時只有它看得見)
|
||||||
# · `_YOULIN_` ── 憑證變數名(如 `CLOUDFLARE_API_TOKEN_YOULIN_CC_USE`)
|
# · `_YOULIN_` ── 憑證變數名(如 `CLOUDFLARE_API_TOKEN_YOULIN_CC_USE`)
|
||||||
# · `X-Arcrun-API-Key: youlin` ── 打該實例 API 時的身分標頭
|
# · `X-Arcrun-API-Key: youlin` ── 打該實例 API 時的身分標頭
|
||||||
case "$CMD" in
|
case "$CMD" in
|
||||||
*staging*|*-staging*|*"--env stage"*|*"--env=stage"*|*stage.*) exit 0 ;;
|
*staging*|*-staging*|*"--env stage"*|*"--env=stage"*|*stage.*) exit 0 ;;
|
||||||
*youlin-hsieh-dev*|*arcrun-yuga3bse*|*1129efd7df2e8899d537e9c8fbabb6cb*|*_YOULIN_*|*"X-Arcrun-API-Key: youlin"*) exit 0 ;;
|
*youlin-hsieh-dev*|*1129efd7df2e8899d537e9c8fbabb6cb*|*_YOULIN_*|*"X-Arcrun-API-Key: youlin"*) exit 0 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# 🔴 2026-08-12 leo 拍板「加閘」:**geek6688(出貨機)是明文授權「總管可以直接動」的那一台。**
|
# 🔴 2026-08-12 leo 拍板「加閘」:**geek6688(出貨機)是明文授權「總管可以直接動」的那一台。**
|
||||||
|
|||||||
@@ -227,9 +227,6 @@ fi
|
|||||||
case "$CMD" in
|
case "$CMD" in
|
||||||
*staging*|*-staging*|*"--env stage"*|*"--env=stage"*|*stage.*|*"-staging"*) exit 0 ;;
|
*staging*|*-staging*|*"--env stage"*|*"--env=stage"*|*stage.*|*"-staging"*) exit 0 ;;
|
||||||
*youlin-hsieh-dev*|*"X-Arcrun-API-Key: youlin"*) exit 0 ;;
|
*youlin-hsieh-dev*|*"X-Arcrun-API-Key: youlin"*) exit 0 ;;
|
||||||
# 🔴 2026-09-02 youlin 重裝後 workers.dev 子網域換成 `arcrun-yuga3bse`(inkstone/ISEP#130):
|
|
||||||
# 舊名 DNS 已不存在。認不得新名 ⇒ 打 stage 做實驗又會被當成 prod 擋——同一個誤攔第二次。
|
|
||||||
*arcrun-yuga3bse*) exit 0 ;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ HOOK="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/countdown-guard.sh}"
|
|||||||
TMP=$(mktemp -d)
|
TMP=$(mktemp -d)
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
trap 'rm -rf "$TMP"' EXIT
|
||||||
export ISEP_COUNTDOWN_STATE_DIR="$TMP/state"
|
export ISEP_COUNTDOWN_STATE_DIR="$TMP/state"
|
||||||
export ISEP_MAINLINE_REPO_FILE=none # 把 repo 那份鏡像拿掉(inkstone/ISEP#130):這支測的是家目錄那份
|
|
||||||
mkdir -p "$ISEP_COUNTDOWN_STATE_DIR"
|
mkdir -p "$ISEP_COUNTDOWN_STATE_DIR"
|
||||||
|
|
||||||
PASS=0; FAIL=0
|
PASS=0; FAIL=0
|
||||||
|
|||||||
+111
@@ -0,0 +1,111 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# duplicate-hook-registration-guard.sh 的迴歸測試(inkstone/ISEP#122)
|
||||||
|
#
|
||||||
|
# 這支閘的價值是「不吵的時候真的不吵,該吵的時候真的吵得出正確清單」——
|
||||||
|
# 兩邊都要驗,而且全程用假的 plugin root/專案目錄,不碰真正的
|
||||||
|
# InkStoneCo/.claude/ 或這台機器裝著的 ISEP plugin。
|
||||||
|
set -u
|
||||||
|
HOOK="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/duplicate-hook-registration-guard.sh}"
|
||||||
|
PASS=0; FAIL=0; N=0
|
||||||
|
|
||||||
|
check() { # check <說明> <輸出> <exit碼> <該出現|!不該出現>...
|
||||||
|
desc="$1"; out="$2"; code="$3"; shift 3; N=$((N+1)); ok=1; why=""
|
||||||
|
if [ "$code" != "0" ]; then ok=0; why="exit 應該是 0(這支從不擋人),實際是 $code"; fi
|
||||||
|
for w in "$@"; do
|
||||||
|
case "$w" in
|
||||||
|
"!"*) if printf '%s' "$out" | grep -qF -- "${w#!}"; then ok=0; why="不該出現卻出現了:${w#!}"; fi ;;
|
||||||
|
*) if ! printf '%s' "$out" | grep -qF -- "$w"; then ok=0; why="少了:$w"; fi ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
if [ "$ok" = 1 ]; then printf ' ✅ %s\n' "$desc"; PASS=$((PASS+1))
|
||||||
|
else printf ' ❌ %s —— %s\n' "$desc" "$why"; printf '%s\n' "$out" | sed 's/^/ /'; FAIL=$((FAIL+1)); fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# mkroot <名字...> → 造一份假 plugin root,hooks.json 裡真的註冊這些檔名
|
||||||
|
mkroot() {
|
||||||
|
d="$TMP/root-$RANDOM"; mkdir -p "$d/hooks"
|
||||||
|
{
|
||||||
|
printf '{"hooks":{"PreToolUse":[{"matcher":"Bash","hooks":['
|
||||||
|
first=1
|
||||||
|
for n in "$@"; do
|
||||||
|
[ "$first" = 1 ] || printf ','
|
||||||
|
printf '{"type":"command","command":"${CLAUDE_PLUGIN_ROOT}/hooks/%s"}' "$n"
|
||||||
|
first=0
|
||||||
|
done
|
||||||
|
printf ']}]}}\n'
|
||||||
|
} > "$d/hooks/hooks.json"
|
||||||
|
printf '%s\n' "$d"
|
||||||
|
}
|
||||||
|
|
||||||
|
# mkproj <名字...> → 造一份假專案目錄,settings.json 裡登記這些檔名
|
||||||
|
mkproj() {
|
||||||
|
d="$TMP/proj-$RANDOM"; mkdir -p "$d/.claude"
|
||||||
|
{
|
||||||
|
printf '{"hooks":{"PreToolUse":[{"matcher":"Bash","hooks":['
|
||||||
|
first=1
|
||||||
|
for n in "$@"; do
|
||||||
|
[ "$first" = 1 ] || printf ','
|
||||||
|
printf '{"type":"command","command":"$CLAUDE_PROJECT_DIR/.claude/hooks/%s"}' "$n"
|
||||||
|
first=0
|
||||||
|
done
|
||||||
|
printf ']}]}}\n'
|
||||||
|
} > "$d/.claude/settings.json"
|
||||||
|
printf '%s\n' "$d"
|
||||||
|
}
|
||||||
|
|
||||||
|
run() { # run <root> <proj>
|
||||||
|
out=$(CLAUDE_PLUGIN_ROOT="$1" CLAUDE_PROJECT_DIR="$2" bash "$HOOK" 2>&1)
|
||||||
|
code=$?
|
||||||
|
printf '%s\x1e%s' "$out" "$code"
|
||||||
|
}
|
||||||
|
|
||||||
|
TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT
|
||||||
|
|
||||||
|
echo "── 該吵 ──────────────────────────────────────────────────────"
|
||||||
|
|
||||||
|
R=$(mkroot prod-write-guard.sh github-contact-guard.sh)
|
||||||
|
P=$(mkproj prod-write-guard.sh other-thing.sh)
|
||||||
|
o=$(run "$R" "$P"); out="${o%$'\x1e'*}"; code="${o##*$'\x1e'}"
|
||||||
|
check "① 專案版跟 plugin 同名一支 → 點名那一支" "$out" "$code" \
|
||||||
|
"重複掛載警報" "1 支" "prod-write-guard.sh" "!github-contact-guard.sh" "!other-thing.sh"
|
||||||
|
|
||||||
|
R=$(mkroot a.sh b.sh c.sh)
|
||||||
|
P=$(mkproj a.sh b.sh c.sh)
|
||||||
|
o=$(run "$R" "$P"); out="${o%$'\x1e'*}"; code="${o##*$'\x1e'}"
|
||||||
|
check "② 全部同名 → 三支都點名" "$out" "$code" "3 支" "a.sh" "b.sh" "c.sh"
|
||||||
|
|
||||||
|
echo "── 不該吵(誤攔比漏擋嚴重)───────────────────────────────────"
|
||||||
|
|
||||||
|
R=$(mkroot a.sh)
|
||||||
|
P=$(mkproj z.sh)
|
||||||
|
o=$(run "$R" "$P"); out="${o%$'\x1e'*}"; code="${o##*$'\x1e'}"
|
||||||
|
check "③ 完全不重疊 → 靜音" "$out" "$code" "!重複掛載"
|
||||||
|
|
||||||
|
R=$(mkroot a.sh)
|
||||||
|
d="$TMP/proj-empty-$RANDOM"; mkdir -p "$d/.claude"; echo '{"hooks":{}}' > "$d/.claude/settings.json"
|
||||||
|
o=$(run "$R" "$d"); out="${o%$'\x1e'*}"; code="${o##*$'\x1e'}"
|
||||||
|
check "④ 專案沒登記任何 .claude/hooks/*.sh → 靜音" "$out" "$code" "!重複掛載"
|
||||||
|
|
||||||
|
d="$TMP/proj-nosettings-$RANDOM"; mkdir -p "$d/.claude"
|
||||||
|
o=$(run "$R" "$d"); out="${o%$'\x1e'*}"; code="${o##*$'\x1e'}"
|
||||||
|
check "⑤ 專案根本沒有 settings.json → 靜音" "$out" "$code" "!重複掛載"
|
||||||
|
|
||||||
|
o=$(CLAUDE_PROJECT_DIR="$(mkproj a.sh)" bash "$HOOK" 2>&1); code=$?
|
||||||
|
check "⑥ 沒有 CLAUDE_PLUGIN_ROOT(不是 plugin 環境)→ 靜音" "$o" "$code" "!重複掛載"
|
||||||
|
|
||||||
|
d="$TMP/root-nohooksjson-$RANDOM"; mkdir -p "$d/hooks"
|
||||||
|
o=$(CLAUDE_PLUGIN_ROOT="$d" CLAUDE_PROJECT_DIR="$(mkproj a.sh)" bash "$HOOK" 2>&1); code=$?
|
||||||
|
check "⑦ plugin root 沒有 hooks.json(環境不完整)→ 靜音" "$o" "$code" "!重複掛載"
|
||||||
|
|
||||||
|
echo "── 判準是「登記」不是「檔案存在」──────────────────────────────"
|
||||||
|
|
||||||
|
R=$(mkroot pre-write-guard.template.sh) # 有這個檔但 hooks.json 沒收(樣板慣例)
|
||||||
|
d="$TMP/root-unreg-$RANDOM"; mkdir -p "$d/hooks"; echo '{"hooks":{}}' > "$d/hooks/hooks.json"
|
||||||
|
touch "$d/hooks/pre-write-guard.template.sh"
|
||||||
|
P=$(mkproj pre-write-guard.template.sh)
|
||||||
|
o=$(run "$d" "$P"); out="${o%$'\x1e'*}"; code="${o##*$'\x1e'}"
|
||||||
|
check "⑧ plugin 有這個檔但沒真的註冊 → 不算重複,靜音" "$out" "$code" "!重複掛載"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "── 結果:$PASS 通過 / $FAIL 失敗(共 $N)──"
|
||||||
|
[ "$FAIL" -eq 0 ]
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# history-first-guard.sh 的迴歸測試 —— 重點在**逃生門真的走得通**(inkstone/ISEP#122)
|
|
||||||
#
|
|
||||||
# ── 這支在守什麼 ────────────────────────────────────────────────────
|
|
||||||
# 2026-09-02 實撞:KBDB 兩支工具都回 `Connection closed`,照這支閘印出來的那行
|
|
||||||
# `touch /tmp/.kbdb-down`
|
|
||||||
# 打完再送同一個編輯,**被一模一樣地擋第二次**——因為 `touch` 造的是空檔,
|
|
||||||
# 而舊版是 `cat` 檔案內容當時戳,空字串被當成 0 ⇒ 「距今 17 億秒」⇒ 永遠不新鮮。
|
|
||||||
#
|
|
||||||
# 🔴 一道閘印出來的出路走不通,比沒有出路更糟:人照做了、還是被擋,
|
|
||||||
# 下一步就是去繞過這道閘(本 repo 的 ticket-api-bypass-guard.sh 檔頭記過同一課)。
|
|
||||||
# 所以這支測試的第一等公民是**逃生門那一條**,不是「擋不擋得住」。
|
|
||||||
#
|
|
||||||
# 🔴 **這支測試自己怎麼被證明有鑑別力**(不要只看它全綠):
|
|
||||||
# 把修好之前那一版拿來跑,第 ④ 條要紅。因為舊版沒有 KBDB_STAMP_DIR,
|
|
||||||
# 直接餵它會去讀這台機器真正的 /tmp 戳記而「剛好過關」,所以要先把路徑隔離:
|
|
||||||
# git show <修好前的 commit>:hooks/history-first-guard.sh > /tmp/old.sh
|
|
||||||
# sed 's#/tmp/\.kbdb-asked#${KBDB_STAMP_DIR:-/tmp}/.kbdb-asked#;
|
|
||||||
# s#/tmp/\.kbdb-down#${KBDB_STAMP_DIR:-/tmp}/.kbdb-down#' /tmp/old.sh > /tmp/old-iso.sh
|
|
||||||
# bash hooks/tests/history-first-guard.test.sh /tmp/old-iso.sh
|
|
||||||
# 2026-09-02 實跑:舊版 9/10(④ 紅),修好後 10/10。
|
|
||||||
# ⚠️ 第 ③ 條**兩版都是綠的**——它只驗離開碼 2,而過了第 0 道之後歷史警察照樣會擋。
|
|
||||||
# 真正分辨得出來的是 ④「擋人的是誰」。這一格是本支最容易寫成假綠的地方。
|
|
||||||
#
|
|
||||||
# 🔴 全程用 KBDB_STAMP_DIR 指到 TMP,**不碰這台機器真正的 /tmp/.kbdb-* 戳記**
|
|
||||||
# (把別的 session 的戳記清掉=把閘弄成隨機的)。不打網路。
|
|
||||||
set -u
|
|
||||||
HOOK="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/history-first-guard.sh}"
|
|
||||||
TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT
|
|
||||||
export KBDB_STAMP_DIR="$TMP/stamps"; mkdir -p "$KBDB_STAMP_DIR"
|
|
||||||
|
|
||||||
PASS=0; FAIL=0; N=0
|
|
||||||
|
|
||||||
# 造一個「有前科」的 code 檔:放在一個有 git 歷史的假 repo 裡
|
|
||||||
REPO="$TMP/repo"; mkdir -p "$REPO"
|
|
||||||
( cd "$REPO" && git init -q && git config user.email t@t && git config user.name t \
|
|
||||||
&& printf 'echo old\n' > victim.sh && git add . && git commit -qm "第一版" ) >/dev/null 2>&1
|
|
||||||
VICTIM="$REPO/victim.sh"
|
|
||||||
|
|
||||||
# run <檔案> → 印出離開碼(送一份 Edit 的 payload 進去)
|
|
||||||
run() {
|
|
||||||
printf '{"tool_input":{"file_path":"%s"}}' "$1" \
|
|
||||||
| CLAUDE_PROJECT_DIR="$REPO" bash "$HOOK" >/dev/null 2>"$TMP/err"
|
|
||||||
printf '%s' "$?"
|
|
||||||
}
|
|
||||||
|
|
||||||
check() { # check <說明> <實際> <期望>
|
|
||||||
N=$((N+1))
|
|
||||||
if [ "$2" = "$3" ]; then printf ' ✅ %s\n' "$1"; PASS=$((PASS+1))
|
|
||||||
else printf ' ❌ %s —— 期望離開碼 %s,實際 %s\n' "$1" "$3" "$2"; sed 's/^/ /' "$TMP/err" | head -6; FAIL=$((FAIL+1)); fi
|
|
||||||
}
|
|
||||||
|
|
||||||
clean_stamps() { rm -f "$KBDB_STAMP_DIR/.kbdb-asked" "$KBDB_STAMP_DIR/.kbdb-down"; rm -f /tmp/.history-guard-*; }
|
|
||||||
|
|
||||||
echo "── 第 0 道:問過 KBDB 了沒 ──────────────────────────────────"
|
|
||||||
clean_stamps
|
|
||||||
check "① 沒有任何戳記 → 擋" "$(run "$VICTIM")" 2
|
|
||||||
grep -q "KBDB" "$TMP/err" && printf ' ✅ ② 擋下時訊息講得出是哪一道\n' && PASS=$((PASS+1)) || { printf ' ❌ ② 訊息沒提到 KBDB\n'; FAIL=$((FAIL+1)); }; N=$((N+1))
|
|
||||||
|
|
||||||
echo "── 🔴 逃生門:照訊息打那一行,就要真的過得去 ──────────────────"
|
|
||||||
clean_stamps
|
|
||||||
touch "$KBDB_STAMP_DIR/.kbdb-down" # ← 訊息裡原文那一行做的事
|
|
||||||
check "③ touch 出來的空檔(本票的實撞)→ 要放行過第 0 道" "$(run "$VICTIM")" 2
|
|
||||||
# ↑ 期望仍是 2:過了第 0 道之後會被「歷史警察」擋(這個檔真的有前科),
|
|
||||||
# 所以要看訊息換人了沒——這是這支測試最容易寫錯的一格。
|
|
||||||
grep -q "歷史警察" "$TMP/err" && printf ' ✅ ④ 擋人的換成歷史警察 ⇒ 第 0 道確實被逃生門放過了\n' && PASS=$((PASS+1)) || { printf ' ❌ ④ 還是卡在 KBDB 那一道 ⇒ 逃生門是假的\n'; sed 's/^/ /' "$TMP/err" | head -4; FAIL=$((FAIL+1)); }; N=$((N+1))
|
|
||||||
|
|
||||||
clean_stamps
|
|
||||||
date +%s > "$KBDB_STAMP_DIR/.kbdb-down" # 舊格式(檔案內容是時戳)
|
|
||||||
run "$VICTIM" >/dev/null
|
|
||||||
grep -q "歷史警察" "$TMP/err" && printf ' ✅ ⑤ 舊格式(內容寫時戳)照樣認得 ⇒ 沒有把既有的弄壞\n' && PASS=$((PASS+1)) || { printf ' ❌ ⑤ 舊格式壞了\n'; FAIL=$((FAIL+1)); }; N=$((N+1))
|
|
||||||
|
|
||||||
clean_stamps
|
|
||||||
date +%s > "$KBDB_STAMP_DIR/.kbdb-asked"
|
|
||||||
run "$VICTIM" >/dev/null
|
|
||||||
grep -q "歷史警察" "$TMP/err" && printf ' ✅ ⑥ 真的問過 KBDB(kbdb-asked-stamp.sh 寫的戳記)→ 過第 0 道\n' && PASS=$((PASS+1)) || { printf ' ❌ ⑥ 問過了還被擋\n'; FAIL=$((FAIL+1)); }; N=$((N+1))
|
|
||||||
|
|
||||||
echo "── 過期的戳記不算數(逃生門不能變成永久後門)──────────────────"
|
|
||||||
clean_stamps
|
|
||||||
touch -t "$(date -v-2H '+%Y%m%d%H%M' 2>/dev/null || date -d '2 hours ago' '+%Y%m%d%H%M')" "$KBDB_STAMP_DIR/.kbdb-down"
|
|
||||||
run "$VICTIM" >/dev/null
|
|
||||||
grep -q "KBDB" "$TMP/err" && printf ' ✅ ⑦ 兩小時前的空戳記 → 過期,回到擋\n' && PASS=$((PASS+1)) || { printf ' ❌ ⑦ 過期的戳記還在放行 ⇒ 一次 touch 就永久免疫\n'; FAIL=$((FAIL+1)); }; N=$((N+1))
|
|
||||||
|
|
||||||
echo "── 不該擋的(誤攔比漏擋嚴重)────────────────────────────────"
|
|
||||||
clean_stamps
|
|
||||||
printf '# doc\n' > "$REPO/readme.md"
|
|
||||||
check "⑧ 文件檔(.md)→ 一路放行,連第 0 道都不該碰" "$(run "$REPO/readme.md")" 0
|
|
||||||
clean_stamps
|
|
||||||
check "⑨ 不存在的新檔 → 放行" "$(run "$REPO/brand-new.sh")" 0
|
|
||||||
clean_stamps
|
|
||||||
mkdir -p "$REPO/tests"; printf 'echo t\n' > "$REPO/tests/a.sh"
|
|
||||||
check "⑩ 測試檔 → 放行" "$(run "$REPO/tests/a.sh")" 0
|
|
||||||
|
|
||||||
echo
|
|
||||||
printf '通過 %s 條,失敗 %s 條(共 %s 條)\n' "$PASS" "$FAIL" "$N"
|
|
||||||
[ "$FAIL" = 0 ] || exit 1
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# hooks/tests/lib/hook-sandbox.sh 的迴歸測試(inkstone/ISEP#122)
|
|
||||||
#
|
|
||||||
# 🔴 為什麼有這支(2026-09-02 實撞,證據在票上):
|
|
||||||
# `hook_sandbox` 的第一個參數是「那支 hook 的檔案路徑」,傳錯時舊版不檢查就
|
|
||||||
# `cp -R "$(dirname "$1")"` ⇒ 複製的是上一層。傳 repo 根目錄進去,
|
|
||||||
# 複製的就是**整個 tech_projects**:兩次吃掉 23 GB,磁碟剩 462 MB,
|
|
||||||
# 而它只印一句「沙盒建不起來」——**沒說參數錯,也沒說它已經把磁碟寫滿**。
|
|
||||||
#
|
|
||||||
# 所以這支測的不是「錯誤訊息好不好看」,是**收手的時機**:
|
|
||||||
# ④⑤ 兩條驗「複製之前就 return 1」——暫存區裡不准留下任何東西。
|
|
||||||
#
|
|
||||||
# 用法:bash hooks/tests/hook-sandbox.test.sh
|
|
||||||
set -u
|
|
||||||
HERE=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
||||||
ROOT=$(CDPATH= cd -- "$HERE/.." && pwd) # …/hooks
|
|
||||||
REPO=$(CDPATH= cd -- "$ROOT/.." && pwd)
|
|
||||||
PASS=0; FAIL=0
|
|
||||||
ok(){ printf ' ✅ %s\n' "$1"; PASS=$((PASS+1)); }
|
|
||||||
no(){ printf ' ❌ %s —— %s\n' "$1" "$2"; FAIL=$((FAIL+1)); }
|
|
||||||
|
|
||||||
# 每一條都在自己的子殼裡跑:hook_sandbox 會設全域變數,不隔離會互相污染。
|
|
||||||
run(){ # run <參數> → 印 "rc|沙盒路徑|訊息"
|
|
||||||
( . "$HERE/lib/hook-sandbox.sh"
|
|
||||||
msg=$(hook_sandbox "$1" 2>&1); rc=$?
|
|
||||||
printf '%s|%s|%s' "$rc" "${HOOK_SANDBOX:-}" "$(printf '%s' "$msg" | tr '\n' ' ')"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "── 該收手(傳錯參數)──────────────────────────────────────"
|
|
||||||
|
|
||||||
r=$(run "$REPO"); rc=${r%%|*}; rest=${r#*|}; sb=${rest%%|*}; msg=${rest#*|}
|
|
||||||
[ "$rc" = "1" ] && ok "① 傳 repo 根目錄(本票的實撞)→ return 1" \
|
|
||||||
|| no "① 傳 repo 根目錄(本票的實撞)→ return 1" "實得 rc=$rc"
|
|
||||||
case "$msg" in *"hooks/main-and-prod-push-guard.sh"*)
|
|
||||||
ok "② 訊息給得出一行**真的跑得起來**的用法" ;;
|
|
||||||
*) no "② 訊息給得出一行**真的跑得起來**的用法" "訊息:$msg" ;;
|
|
||||||
esac
|
|
||||||
if [ -z "$sb" ] || [ ! -d "$sb" ]; then ok "③ 收手在 mktemp 之前,暫存區沒有殘骸"
|
|
||||||
else no "③ 收手在 mktemp 之前,暫存區沒有殘骸" "留下了 $sb"; fi
|
|
||||||
|
|
||||||
r=$(run ""); [ "${r%%|*}" = "1" ] && ok "④ 空參數 → return 1(不是拿空字串去 dirname)" \
|
|
||||||
|| no "④ 空參數 → return 1" "實得 rc=${r%%|*}"
|
|
||||||
|
|
||||||
r=$(run "$REPO/scripts/ticket"); rc=${r%%|*}; rest=${r#*|}; sb=${rest%%|*}
|
|
||||||
if [ "$rc" = "1" ]; then ok "⑤ 檔案存在但上一層不是 hooks/ → 一樣收手"
|
|
||||||
else no "⑤ 檔案存在但上一層不是 hooks/ → 一樣收手" "實得 rc=$rc"; fi
|
|
||||||
if [ -z "$sb" ] || [ ! -d "$sb" ]; then ok "⑥ ⑤ 這條也沒把 scripts/ 複製出去"
|
|
||||||
else no "⑥ ⑤ 這條也沒把 scripts/ 複製出去" "留下了 $sb"; fi
|
|
||||||
|
|
||||||
r=$(run "$ROOT/沒有這支.sh"); [ "${r%%|*}" = "1" ] && ok "⑦ 路徑不存在 → return 1" \
|
|
||||||
|| no "⑦ 路徑不存在 → return 1" "實得 rc=${r%%|*}"
|
|
||||||
|
|
||||||
echo "── 不准把本來會過的弄壞(誤攔比漏擋嚴重)────────────────────"
|
|
||||||
( . "$HERE/lib/hook-sandbox.sh"
|
|
||||||
hook_sandbox "$ROOT/main-and-prod-push-guard.sh"; rc=$?
|
|
||||||
if [ "$rc" != "0" ]; then echo "RC=$rc"; exit 0; fi
|
|
||||||
[ -f "$HOOK_SANDBOX_HOOK" ] && echo "HOOKOK"
|
|
||||||
[ -d "$HOOK_SANDBOX/hooks/lib" ] && echo "LIBOK"
|
|
||||||
# 只複製 hooks/,不該把 repo 的其他目錄帶進來
|
|
||||||
[ -d "$HOOK_SANDBOX/hooks/scripts" ] && echo "LEAK"
|
|
||||||
hook_sandbox_cleanup
|
|
||||||
) > /tmp/.hs-ok.$$ 2>&1
|
|
||||||
grep -q HOOKOK /tmp/.hs-ok.$$ && ok "⑧ 正常用法照樣建得起來,複本裡有那支 hook" \
|
|
||||||
|| no "⑧ 正常用法照樣建得起來" "$(cat /tmp/.hs-ok.$$)"
|
|
||||||
grep -q LIBOK /tmp/.hs-ok.$$ && ok "⑨ 整個 hooks/(含 lib/)都在複本裡" \
|
|
||||||
|| no "⑨ 整個 hooks/(含 lib/)都在複本裡" "$(cat /tmp/.hs-ok.$$)"
|
|
||||||
grep -q LEAK /tmp/.hs-ok.$$ && no "⑩ 只複製 hooks/,沒有把 repo 其他目錄帶進去" "複本裡出現 scripts/" \
|
|
||||||
|| ok "⑩ 只複製 hooks/,沒有把 repo 其他目錄帶進去"
|
|
||||||
rm -f /tmp/.hs-ok.$$
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "通過 $PASS 條,失敗 $FAIL 條(共 $((PASS+FAIL)) 條)"
|
|
||||||
[ "$FAIL" -eq 0 ]
|
|
||||||
@@ -25,21 +25,9 @@ mkplugin() {
|
|||||||
cp "$HOOK" "$d/hooks/$(basename "$HOOK")"
|
cp "$HOOK" "$d/hooks/$(basename "$HOOK")"
|
||||||
cp "$REAL_HOOKS/lib/beacon_report.py" "$d/hooks/lib/beacon_report.py"
|
cp "$REAL_HOOKS/lib/beacon_report.py" "$d/hooks/lib/beacon_report.py"
|
||||||
printf '#!/bin/sh\necho real\n' > "$d/scripts/ticket"
|
printf '#!/bin/sh\necho real\n' > "$d/scripts/ticket"
|
||||||
# inkstone/ISEP#122:會自動載入的東西(skill/command/agent)也要造得出來
|
|
||||||
mkdir -p "$d/skills/demo" "$d/commands" "$d/agents" "$d/docs"
|
|
||||||
printf 'PLUGIN 版的 skill\n' > "$d/skills/demo/SKILL.md"
|
|
||||||
printf 'PLUGIN 版的 command\n' > "$d/commands/demo.md"
|
|
||||||
printf 'PLUGIN 版的 agent\n' > "$d/agents/demo.md"
|
|
||||||
printf '%s\n' "$d"
|
printf '%s\n' "$d"
|
||||||
}
|
}
|
||||||
|
|
||||||
# mkown <plugin root> <列...> → 寫一份 docs/file-ownership.tsv(欄位用真正的 TAB)
|
|
||||||
mkown() {
|
|
||||||
d="$1"; shift; mkdir -p "$d/docs"
|
|
||||||
{ printf '# 測試用\n'; for row in "$@"; do printf '%s\n' "$row"; done; } \
|
|
||||||
| sed 's/|/\t/g' > "$d/docs/file-ownership.tsv"
|
|
||||||
}
|
|
||||||
|
|
||||||
# run <plugin root> <project dir> → 印出 systemMessage(JSON 壞掉就印 __BADJSON__)
|
# run <plugin root> <project dir> → 印出 systemMessage(JSON 壞掉就印 __BADJSON__)
|
||||||
run() {
|
run() {
|
||||||
CLAUDE_PLUGIN_ROOT="$1" CLAUDE_PROJECT_DIR="$2" bash "$1/hooks/$(basename "$HOOK")" 2>/dev/null \
|
CLAUDE_PLUGIN_ROOT="$1" CLAUDE_PROJECT_DIR="$2" bash "$1/hooks/$(basename "$HOOK")" 2>/dev/null \
|
||||||
@@ -124,72 +112,6 @@ printf '#!/bin/sh\necho "OLD"\n' > "$J6/scripts/ticket"
|
|||||||
out=$(run "$P" "$J6")
|
out=$(run "$P" "$J6")
|
||||||
check "⑭ 報告內容含引號 → JSON 仍然合法" "$out" "🟢 ISEP" "!__BADJSON__"
|
check "⑭ 報告內容含引號 → JSON 仍然合法" "$out" "🟢 ISEP" "!__BADJSON__"
|
||||||
|
|
||||||
P2=$(mkplugin 1.0.0) # ⑫⑬ 會刪掉 $P 的 report,這一組要自己一份
|
|
||||||
echo "── ②b 會自動載入的東西也有分身(inkstone/ISEP#122)──────────────"
|
|
||||||
# 🔴 這一組守的是 ship-check 那件:plugin 帶著舊描述,而舊描述在「我要發部落格文章」
|
|
||||||
# 的情境根本不會被觸發 ⇒ 那個 session 永遠載不到出貨流程,而且不會有任何症狀。
|
|
||||||
JS="$TMP/proj-skill"; mkdir -p "$JS/.claude/skills/demo"
|
|
||||||
printf '專案版的 skill(比較舊)\n' > "$JS/.claude/skills/demo/SKILL.md"
|
|
||||||
out=$(run "$P2" "$JS")
|
|
||||||
check "⑮ 專案有同名 skill 而內容不同 → 要點名" "$out" \
|
|
||||||
"會自動載入的東西兩邊各有一份" "skills/demo/SKILL.md" ".claude/skills/demo/SKILL.md"
|
|
||||||
check "⑯ 歸屬表沒登記 → 誠實說未定,不要替人猜方向" "$out" "歸屬未定"
|
|
||||||
|
|
||||||
JS2="$TMP/proj-skill-same"; mkdir -p "$JS2/.claude/skills/demo"
|
|
||||||
cp "$P2/skills/demo/SKILL.md" "$JS2/.claude/skills/demo/SKILL.md"
|
|
||||||
out=$(run "$P2" "$JS2")
|
|
||||||
check "⑰ 內容一模一樣 → 不吵(誤攔比漏擋嚴重)" "$out" "!會自動載入的東西兩邊各有一份"
|
|
||||||
|
|
||||||
JC="$TMP/proj-cmd"; mkdir -p "$JC/.claude/commands"
|
|
||||||
printf '專案版的 command(比較舊)\n' > "$JC/.claude/commands/demo.md"
|
|
||||||
out=$(run "$P2" "$JC")
|
|
||||||
check "⑱ command 也要掃(sdd-check 那件)" "$out" "commands/demo.md" ".claude/commands/demo.md"
|
|
||||||
|
|
||||||
JA="$TMP/proj-agent"; mkdir -p "$JA/.claude/agents"
|
|
||||||
printf '專案版的 agent(比較舊)\n' > "$JA/.claude/agents/demo.md"
|
|
||||||
out=$(run "$P2" "$JA")
|
|
||||||
check "⑲ agent 也要掃" "$out" "agents/demo.md" ".claude/agents/demo.md"
|
|
||||||
|
|
||||||
JCL="$TMP/proj-cloud"; mkdir -p "$JCL/InkStoneCo/.claude/skills/demo"
|
|
||||||
printf '專案版的 skill(比較舊)\n' > "$JCL/InkStoneCo/.claude/skills/demo/SKILL.md"
|
|
||||||
out=$(run "$P2" "$JCL")
|
|
||||||
check "⑳ 雲端排法:真身在 \$TOP/InkStoneCo/ 底下也要抓到" "$out" \
|
|
||||||
"InkStoneCo/.claude/skills/demo/SKILL.md"
|
|
||||||
|
|
||||||
echo "── 歸屬表要講得出「往哪個方向修」──────────────────────────────"
|
|
||||||
PO=$(mkplugin 1.0.1)
|
|
||||||
mkown "$PO" "skills/demo/SKILL.md|inkstone/InkStoneCo|.claude/skills/demo/SKILL.md|abc1234|-"
|
|
||||||
out=$(run "$PO" "$JS")
|
|
||||||
check "㉑ 真相源=InkStoneCo → 說「內容改在那裡」並給得出路徑" "$out" \
|
|
||||||
"真相源=inkstone/InkStoneCo:.claude/skills/demo/SKILL.md" "內容改在那裡" "!歸屬未定"
|
|
||||||
|
|
||||||
mkown "$PO" "skills/demo/SKILL.md|inkstone/ISEP|-|-|-"
|
|
||||||
out=$(run "$PO" "$JS")
|
|
||||||
check "㉒ 真相源=ISEP → 說「專案那份是舊複本」" "$out" \
|
|
||||||
"真相源=ISEP 這一份" "舊複本" "!歸屬未定"
|
|
||||||
|
|
||||||
echo "── ②c 沒有專案那一份也要驗得出來(雲端唯一作數的檢查)────────────"
|
|
||||||
# 雲端的 project dir 是薄殼,沒有 InkStoneCo 可以比 ⇒ 只剩「檔案 vs 表上的 sha256」
|
|
||||||
SHA=$(shasum -a 256 "$PO/skills/demo/SKILL.md" | cut -d" " -f1)
|
|
||||||
mkown "$PO" "skills/demo/SKILL.md|inkstone/InkStoneCo|.claude/skills/demo/SKILL.md|abc1234|$SHA"
|
|
||||||
out=$(run "$PO" "$J")
|
|
||||||
check "㉓ sha256 對得上(而且專案那份不存在)→ 一個字都不說" "$out" \
|
|
||||||
"🟢 ISEP v1.0.1 已載入" "!跟歸屬表對不上" "!會自動載入的東西兩邊各有一份"
|
|
||||||
|
|
||||||
printf '被就地改過\n' >> "$PO/skills/demo/SKILL.md"
|
|
||||||
out=$(run "$PO" "$J")
|
|
||||||
check "㉔ 檔案被就地改過 → 就算沒有專案那份,也要抓得到" "$out" \
|
|
||||||
"跟歸屬表對不上" "skills/demo/SKILL.md" "abc1234"
|
|
||||||
|
|
||||||
mkown "$PO" "skills/demo/SKILL.md|inkstone/InkStoneCo|.claude/skills/demo/SKILL.md|abc1234|-"
|
|
||||||
out=$(run "$PO" "$J")
|
|
||||||
check "㉕ 表上 sha 欄是 \`-\` → 這一格閉嘴(還沒登記不是錯)" "$out" "!跟歸屬表對不上"
|
|
||||||
|
|
||||||
echo "── 加了這兩格也不准讓信標消失 ────────────────────────────────"
|
|
||||||
out=$(run "$P2" "$JS")
|
|
||||||
check "㉖ ②b 有報告時,那行綠色信標仍在且 JSON 合法" "$out" \
|
|
||||||
"🟢 ISEP v1.0.0 已載入" "!__BADJSON__"
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
printf '通過 %s 條,失敗 %s 條(共 %s 條)\n' "$PASS" "$FAIL" "$N"
|
printf '通過 %s 條,失敗 %s 條(共 %s 條)\n' "$PASS" "$FAIL" "$N"
|
||||||
[ "$FAIL" = 0 ] || exit 1
|
[ "$FAIL" = 0 ] || exit 1
|
||||||
|
|||||||
Executable
+62
@@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# kv-write-guard.sh 的迴歸測試(inkstone/ISEP#122 搬進 ISEP 時補上——
|
||||||
|
# 原檔 2026-08-25 立於 InkStoneCo 專案版,搬過來之前沒有自動化測試)。
|
||||||
|
set -u
|
||||||
|
HOOK="${1:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/kv-write-guard.sh}"
|
||||||
|
PASS=0; FAIL=0; N=0
|
||||||
|
|
||||||
|
# run <tool> <file_path> <content> → 送一個 Write 事件的 payload
|
||||||
|
run() {
|
||||||
|
python3 -c '
|
||||||
|
import json,sys
|
||||||
|
tool, fp, content = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||||
|
print(json.dumps({"tool_name": tool, "tool_input": {"file_path": fp, "content": content}}))
|
||||||
|
' "$1" "$2" "$3" | bash "$HOOK" 2>&1
|
||||||
|
echo "EXIT:$?"
|
||||||
|
}
|
||||||
|
|
||||||
|
check() { # check <說明> <輸出+EXIT行> <該擋(2)|該放行(0)> <該出現|!不該出現>...
|
||||||
|
desc="$1"; out="$2"; want="$3"; shift 3
|
||||||
|
code="$(printf '%s\n' "$out" | grep -oE 'EXIT:[0-9]+' | tail -1 | cut -d: -f2)"
|
||||||
|
N=$((N+1)); ok=1; why=""
|
||||||
|
if [ "$code" != "$want" ]; then ok=0; why="要 exit $want,實際 $code"; fi
|
||||||
|
for w in "$@"; do
|
||||||
|
case "$w" in
|
||||||
|
"!"*) if printf '%s' "$out" | grep -qF -- "${w#!}"; then ok=0; why="$why 不該出現卻出現:${w#!}"; fi ;;
|
||||||
|
*) if ! printf '%s' "$out" | grep -qF -- "$w"; then ok=0; why="$why 少了:$w"; fi ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
if [ "$ok" = 1 ]; then printf ' ✅ %s\n' "$desc"; PASS=$((PASS+1))
|
||||||
|
else printf ' ❌ %s ——%s\n' "$desc" "$why"; printf '%s\n' "$out" | sed 's/^/ /'; FAIL=$((FAIL+1)); fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "── 該擋:往 KV binding 寫入 ──────────────────────────────────"
|
||||||
|
out=$(run "Write" "src/app-system.ts" $'export async function save() {\n await MY_KV.put("k", "v");\n}')
|
||||||
|
check "① 全大寫 binding.put( → 擋" "$out" 2 "長效資料不准寫進 KV" "MY_KV"
|
||||||
|
|
||||||
|
out=$(run "Edit" "src/app-system.ts" $'const x = 1;\nSESSION_KV.delete(id);')
|
||||||
|
check "② .delete( 一樣擋" "$out" 2 "長效資料不准寫進 KV"
|
||||||
|
|
||||||
|
echo "── 不該擋(誤攔比漏擋嚴重)───────────────────────────────────"
|
||||||
|
|
||||||
|
out=$(run "Write" "src/app-system.ts" 'const v = await MY_KV.get("k");')
|
||||||
|
check "③ 只是讀(.get)→ 放行" "$out" 0 "!長效資料不准寫進 KV"
|
||||||
|
|
||||||
|
out=$(run "Write" "src/app-system.ts" 'MY_KV.put("k", v); // kv-ok: session nonce,有 TTL')
|
||||||
|
check "④ 加了 kv-ok 豁免留痕的那行 → 放行" "$out" 0 "!長效資料不准寫進 KV"
|
||||||
|
|
||||||
|
out=$(run "Write" "README.md" 'MY_KV.put("k", "v")')
|
||||||
|
check "⑤ 非程式碼檔(.md)→ 放行" "$out" 0 "!長效資料不准寫進 KV"
|
||||||
|
|
||||||
|
out=$(run "Write" "src/kv-write-guard.test.ts" 'MY_KV.put("k", "v")')
|
||||||
|
check "⑥ 閘自己的測試檔 → 放行" "$out" 0 "!長效資料不准寫進 KV"
|
||||||
|
|
||||||
|
out=$(run "Write" "src/app-system.ts" 'const config = { retries: 3 };')
|
||||||
|
check "⑦ 完全不提 KV 的一般程式碼 → 放行" "$out" 0 "!長效資料不准寫進 KV"
|
||||||
|
|
||||||
|
out=$(run "Write" "src/app-system.ts" 'this.myKv.put("k", "v"); // 小寫 binding,不是本閘要的形狀')
|
||||||
|
check "⑧ 小寫變數名(不是「全大寫識別字」形狀)→ 放行" "$out" 0 "!長效資料不准寫進 KV"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "── 結果:$PASS 通過 / $FAIL 失敗(共 $N)──"
|
||||||
|
[ "$FAIL" -eq 0 ]
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# leo21c-write-guard.sh 的迴歸測試(inkstone/ISEP#130)
|
|
||||||
#
|
|
||||||
# ── 這支在守什麼 ──────────────────────────────────────────────────────
|
|
||||||
# 閘的判準是「**讀可以,寫不行**」(leo 2026-08-20:leo21c 是他本人在用的知識庫)。
|
|
||||||
# 2026-09-04 雲端 Routine 的 run log:**讀 notify_leo 的定義被擋** ——
|
|
||||||
# 讀都讀不到,雲端就什麼都拿不到(inkstone/ISEP#130 開票的第一件)。
|
|
||||||
#
|
|
||||||
# 這支之前**沒有任何測試**,所以「讀會不會被誤攔」從來沒被驗過。
|
|
||||||
# 下面的測資是 Routine 文件(cloud-worker.md/progress-guard.md)裡**真的會下的那幾條指令**,
|
|
||||||
# 不是想像出來的例子。
|
|
||||||
#
|
|
||||||
# 🔴 三個方向都要驗,缺一個就是假綠:
|
|
||||||
# A 讀 ⇒ 放行(含 `tr -d`/`cut -d=` 這種唯讀的 -d,那正是 09-04 被擋的形狀)
|
|
||||||
# B 寫 ⇒ 擋(心跳 POST/PATCH 收件匣/部署端點/別的 trigger)
|
|
||||||
# C 閘印出來的「改法」指的是**現役**的 youlin 網址,不是 09-02 已死的舊名
|
|
||||||
#
|
|
||||||
# 這支閘不寫任何檔案,直接跑真跡即可;全程離線。
|
|
||||||
# 用法:bash hooks/tests/leo21c-write-guard.test.sh
|
|
||||||
set -u
|
|
||||||
HERE=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
||||||
HOOK="$HERE/../leo21c-write-guard.sh"
|
|
||||||
PASS=0; FAIL=0
|
|
||||||
mk(){ python3 -c "import json,sys;print(json.dumps({'tool_name':'Bash','tool_input':{'command':sys.argv[1]}}))" "$1"; }
|
|
||||||
t(){ # t <期望 pass|block> <說明> <指令>
|
|
||||||
LAST_ERR=$(mk "$3" | bash "$HOOK" 2>&1 >/dev/null); rc=$?
|
|
||||||
got=$([ "$rc" -eq 2 ] && echo block || echo pass)
|
|
||||||
if [ "$got" = "$1" ]; then echo " ✅ $2"; PASS=$((PASS+1))
|
|
||||||
else echo " ❌ $2 —— 期望 $1,實得 $got(rc=$rc)"; FAIL=$((FAIL+1)); fi
|
|
||||||
}
|
|
||||||
|
|
||||||
L='https://arcrun-cypher-executor.leo21c.workers.dev'
|
|
||||||
K='-H "X-Arcrun-API-Key: leo"'
|
|
||||||
D='-d'
|
|
||||||
|
|
||||||
echo "── A. 讀 ⇒ 放行(雲端 Routine 真的會下的形狀)──"
|
|
||||||
t pass "① 讀收件匣(progress-guard.md 步驟 0 原句)" "curl -s \"$L/kbdb/entries?entry_type=inbox&limit=20\" $K"
|
|
||||||
t pass "② 讀 notify_leo 定義(09-04 被擋的那一條)" "curl -s $L/webhooks/named/leo/notify_leo $K"
|
|
||||||
t pass "③ 讀 + tr -d(唯讀的 -d,不是 body)" "curl -s $L/workflows/notify_leo $K | tr $D '\\r'"
|
|
||||||
t pass "④ 讀 + cut -d=" "NS=\$(grep ns cfg | cut ${D}= -f2); curl -s $L/kbdb/entries?limit=1 $K"
|
|
||||||
t pass "⑤ 讀 + sort -d / date -d" "curl -s $L/health | sort $D; date $D yesterday"
|
|
||||||
t pass "⑥ 明寫 -X GET" "curl -s -X GET $L/kbdb/entries?entry_type=dash_beat $K"
|
|
||||||
t pass "⑦ 讀心跳(progress-guard 2.6 原句)" "curl -s \"$L/kbdb/entries?entry_type=dash_beat&limit=30\" $K"
|
|
||||||
t pass "⑧ git commit 訊息提到 leo21c 與 POST(git 寫不到那台)" "git commit -m 'fix: curl -X POST $L/kbdb/entries 會被擋'"
|
|
||||||
t pass "⑨ 修這道閘自己" "sed -i 's/a/b/' hooks/leo21c-write-guard.sh"
|
|
||||||
t pass "⑩ 打 youlin(09-02 起的新子網域)POST,不是 leo21c" "curl -X POST https://arcrun-cypher-executor.arcrun-yuga3bse.workers.dev/webhooks/named $D '{}'"
|
|
||||||
t pass "⑪ 用 youlin 的 CF 帳號部署" "CLOUDFLARE_ACCOUNT_ID=1129efd7df2e8899d537e9c8fbabb6cb npx wrangler deploy"
|
|
||||||
t pass "⑫ 發一則 notify_leo(通知型 trigger,什麼都沒改;同 prod-write-guard 白名單)" "curl -s -X POST $L/webhooks/named/leo/notify_leo/trigger -H 'Content-Type: application/json' $D '{\"text\":\"[總管] hi\"}'"
|
|
||||||
|
|
||||||
echo "── B. 寫 ⇒ 擋 ──"
|
|
||||||
t block "⑬ 打心跳 POST(cloud-worker.md 步驟 0 原句——它寫進 leo 的庫)" "curl -s -X POST \"$L/kbdb/entries\" $K -H 'Content-Type: application/json' $D '{\"entry_type\":\"dash_beat\"}'"
|
|
||||||
t block "⑭ PATCH 收件匣" "curl -s -X PATCH \"$L/kbdb/entries/123\" $K $D '{\"content\":\"x\"}'"
|
|
||||||
t block "⑮ DELETE" "curl -X DELETE $L/kbdb/entries/1 $K"
|
|
||||||
t block "⑯ 只帶 -d 的隱式 POST" "curl $L/kbdb/entries $D '{}'"
|
|
||||||
t block "⑰ --data-urlencode" "curl $L/kbdb/entries --data-urlencode text=hi"
|
|
||||||
t block "⑱ --request PUT" "curl --request PUT $L/kbdb/entries/1 $D '{}'"
|
|
||||||
t block "⑲ 別的工作流 trigger(ship_refresh_cdn 會動線上狀態)" "curl -X POST $L/webhooks/named/leo/ship_refresh_cdn/trigger $D '{}'"
|
|
||||||
t block "⑳ 部署端點(無名字的 named webhook)" "curl -X POST $L/webhooks/named $D @def.yaml"
|
|
||||||
t block "㉑ notify_leo 旁邊夾一個部署端點" "curl -X POST $L/webhooks/named/leo/notify_leo/trigger $D '{}' && curl -X POST $L/webhooks/named $D @x"
|
|
||||||
t block "㉒ 寫 + tr -d(剪掉唯讀 -d 之後仍該擋)" "cat f | tr $D '\\r' | curl -X POST $L/kbdb/entries $D @-"
|
|
||||||
t block "㉓ 用 leo21c 的 CF 帳號部署" "CLOUDFLARE_ACCOUNT_ID=51a01bfa2665bd7bc3fd080dc40cf3e1 npx wrangler deploy"
|
|
||||||
|
|
||||||
echo "── C. 擋下時印的改法要指到活著的 youlin ──"
|
|
||||||
mk "curl -X POST $L/kbdb/entries $D '{}'" | bash "$HOOK" 2>"$HERE/.leo21c-msg.$$" >/dev/null
|
|
||||||
MSG=$(cat "$HERE/.leo21c-msg.$$"); rm -f "$HERE/.leo21c-msg.$$"
|
|
||||||
if printf '%s' "$MSG" | grep -q 'arcrun-cypher-executor.arcrun-yuga3bse.workers.dev'; then
|
|
||||||
echo " ✅ ㉔ 改法段印的是現役子網域 arcrun-yuga3bse"; PASS=$((PASS+1))
|
|
||||||
else echo " ❌ ㉔ 改法段沒有現役子網域 arcrun-yuga3bse"; FAIL=$((FAIL+1)); fi
|
|
||||||
if printf '%s' "$MSG" | grep -q 'cypher : https://arcrun-cypher-executor.youlin-hsieh-dev'; then
|
|
||||||
echo " ❌ ㉕ 改法段還教人打 09-02 已死的 youlin-hsieh-dev"; FAIL=$((FAIL+1))
|
|
||||||
else echo " ✅ ㉕ 改法段不再把死的舊名當網址教人"; PASS=$((PASS+1)); fi
|
|
||||||
if printf '%s' "$MSG" | grep -q '讀可以,寫不行'; then
|
|
||||||
echo " ✅ ㉖ 訊息講得出判準(讀可以,寫不行)"; PASS=$((PASS+1))
|
|
||||||
else echo " ❌ ㉖ 訊息沒講判準"; FAIL=$((FAIL+1)); fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "通過 $PASS 條,失敗 $FAIL 條"
|
|
||||||
[ "$FAIL" -eq 0 ]
|
|
||||||
@@ -39,38 +39,9 @@
|
|||||||
# ⇒ hostsum 兩次都回 `NODIR`(相等)、沙盒的請求數當然是 0
|
# ⇒ hostsum 兩次都回 `NODIR`(相等)、沙盒的請求數當然是 0
|
||||||
# ⇒ **第一條斷言變成「拿空的比空的」的假綠**。
|
# ⇒ **第一條斷言變成「拿空的比空的」的假綠**。
|
||||||
# 所以改成「設變數、不印」,而且 hook_sandbox_assert 開頭會擋空值(見下)。
|
# 所以改成「設變數、不印」,而且 hook_sandbox_assert 開頭會擋空值(見下)。
|
||||||
#
|
|
||||||
# 🔴 **先驗參數再複製**(inkstone/ISEP#122,2026-09-02 實撞,本檔第二次修):
|
|
||||||
# `$1` 是「那支 hook 的路徑」。傳錯(例如順手傳了 repo 根目錄)時,舊版不檢查就
|
|
||||||
# `cp -R "$(dirname "$1")" …` ⇒ **複製的是那個目錄的上一層**。
|
|
||||||
# 當天實測:`bash hooks/tests/main-and-prod-push-guard.test.sh "$PWD"`
|
|
||||||
# ⇒ dirname 變成 ~/Documents/tech_projects
|
|
||||||
# ⇒ 把 **整個 tech_projects**(所有 repo、所有 worktree)複製進 mktemp
|
|
||||||
# ⇒ 兩次就吃掉 23 GB,磁碟從 25 GB 剩到 462 MB,`cp` 一路吐
|
|
||||||
# `No space left on device`,最後才印一句「❌ 沙盒建不起來」。
|
|
||||||
# ⇒ 訊息只說「建不起來」,**沒說是參數傳錯,也沒說它已經把磁碟寫滿了**。
|
|
||||||
# 判準用「要求某個東西在場」,不是關鍵字比對:
|
|
||||||
# ① `$1` 要指到一個**真的檔案**(傳目錄、傳空字串都不算)
|
|
||||||
# ② 它的上一層目錄名要叫 `hooks`(沙盒的前提就是「複製一整個 hooks/」)
|
|
||||||
# 兩條任一不成立就**在複製之前**收手,並印出走得通的那一行。
|
|
||||||
hook_sandbox() {
|
hook_sandbox() {
|
||||||
_hs_real=$1
|
_hs_real=$1
|
||||||
if [ -z "${_hs_real:-}" ] || [ ! -f "$_hs_real" ]; then
|
|
||||||
printf '❌ hook_sandbox:第一個參數要是「那支 hook 的檔案路徑」,實得 %s\n' \
|
|
||||||
"${_hs_real:-(空的)}" >&2
|
|
||||||
printf ' 例:bash hooks/tests/main-and-prod-push-guard.test.sh hooks/main-and-prod-push-guard.sh\n' >&2
|
|
||||||
printf ' (不必自己傳的版本:bash scripts/test-main-and-prod-push-guard.sh)\n' >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
_hs_hooks=$(CDPATH= cd -- "$(dirname -- "$_hs_real")" && pwd) || return 1
|
_hs_hooks=$(CDPATH= cd -- "$(dirname -- "$_hs_real")" && pwd) || return 1
|
||||||
if [ "$(basename "$_hs_hooks")" != "hooks" ]; then
|
|
||||||
printf '❌ hook_sandbox:%s 的上一層不是 hooks/,而沙盒要複製的就是那個目錄。\n' \
|
|
||||||
"$_hs_real" >&2
|
|
||||||
printf ' 算出來的來源是 %s——照複製下去會把它整個搬進暫存區(2026-09-02 這樣寫滿過磁碟)。\n' \
|
|
||||||
"$_hs_hooks" >&2
|
|
||||||
printf ' 例:bash hooks/tests/main-and-prod-push-guard.test.sh hooks/main-and-prod-push-guard.sh\n' >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
HOOK_SANDBOX=$(mktemp -d) || return 1
|
HOOK_SANDBOX=$(mktemp -d) || return 1
|
||||||
cp -R "$_hs_hooks" "$HOOK_SANDBOX/hooks" || return 1
|
cp -R "$_hs_hooks" "$HOOK_SANDBOX/hooks" || return 1
|
||||||
HOOK_SANDBOX_HOST="${_hs_hooks%/hooks}/pending-main-push"
|
HOOK_SANDBOX_HOST="${_hs_hooks%/hooks}/pending-main-push"
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ MAINLINE="$ROOT/../scripts/mainline"
|
|||||||
TMP=$(mktemp -d)
|
TMP=$(mktemp -d)
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
trap 'rm -rf "$TMP"' EXIT
|
||||||
export ISEP_COUNTDOWN_STATE_DIR="$TMP/state"
|
export ISEP_COUNTDOWN_STATE_DIR="$TMP/state"
|
||||||
export ISEP_MAINLINE_REPO_FILE=none # 把 repo 那份鏡像拿掉(inkstone/ISEP#130):這支測的是家目錄那份
|
|
||||||
export TICKET_HOST="http://127.0.0.1:9" # 連不上:走到網路就會馬上失敗
|
export TICKET_HOST="http://127.0.0.1:9" # 連不上:走到網路就會馬上失敗
|
||||||
mkdir -p "$ISEP_COUNTDOWN_STATE_DIR"
|
mkdir -p "$ISEP_COUNTDOWN_STATE_DIR"
|
||||||
unset ISEP_MAINLINE_FIXTURE
|
unset ISEP_MAINLINE_FIXTURE
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# 主線那個檔「隨 repo 走」的迴歸測試(inkstone/ISEP#130)
|
|
||||||
#
|
|
||||||
# ── 這支在守什麼 ──────────────────────────────────────────────────────
|
|
||||||
# 主線原本只住在家目錄(`~/.claude/isep-countdown/mainline.json`)。雲端是另一台機器,
|
|
||||||
# 家目錄空的、clone 下來的 repo 才是它拿得到的東西 ⇒ 2026-09-05 leo:
|
|
||||||
# 「routine 每天早上開啟後抓不到任務」。PR inkstone/InkStoneCo#118 把主線檔放進
|
|
||||||
# `InkStoneCo/system-dev/mainline.json`,這裡驗 ISEP 這一半:
|
|
||||||
# A 讀:家目錄沒有 ⇒ 讀 repo 那份(雲端的形狀:$CLAUDE_PROJECT_DIR 是薄殼根,真身在 InkStoneCo/)
|
|
||||||
# B 兩份都在 ⇒ `set_at` 較新的算數,不分本機雲端
|
|
||||||
# C 寫:`set`/`adopt`/`clear` 兩份一起動;`refresh` 那種只寫家目錄(不弄髒 InkStoneCo 工作樹)
|
|
||||||
# D 哪裡都沒有 ⇒ 仍然答得出「現在沒有主線」(ISEP#82 驗收第 4 條沒有被本票弄壞)
|
|
||||||
#
|
|
||||||
# 用法:bash hooks/tests/mainline-repo-mirror.test.sh
|
|
||||||
# 🔴 全程離線:狀態走 ISEP_COUNTDOWN_STATE_DIR、repo 那份走 TMP 底下的假 InkStoneCo、
|
|
||||||
# TICKET_HOST 指到連不上的位址。不碰真家目錄、不碰真 InkStoneCo。
|
|
||||||
set -u
|
|
||||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
||||||
MAINLINE="$ROOT/../scripts/mainline"
|
|
||||||
LIB="$ROOT/lib/mainline.py"
|
|
||||||
TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT
|
|
||||||
export ISEP_COUNTDOWN_STATE_DIR="$TMP/home-state"; mkdir -p "$ISEP_COUNTDOWN_STATE_DIR"
|
|
||||||
export TICKET_HOST="http://127.0.0.1:9"
|
|
||||||
unset ISEP_MAINLINE_REPO_FILE ISEP_MAINLINE_FIXTURE
|
|
||||||
SHELL_ROOT="$TMP/shell"; HUB="$SHELL_ROOT/InkStoneCo"; mkdir -p "$HUB/system-dev"
|
|
||||||
PASS=0; FAIL=0
|
|
||||||
ok(){ printf ' ✅ %s\n' "$1"; PASS=$((PASS+1)); }
|
|
||||||
no(){ printf ' ❌ %s —— %s\n' "$1" "$2"; FAIL=$((FAIL+1)); }
|
|
||||||
|
|
||||||
write_ms(){ # write_ms <檔> <標題> <set_at>
|
|
||||||
python3 - "$1" "$2" "$3" <<'PY'
|
|
||||||
import json, sys
|
|
||||||
json.dump({"ref": "inkstone/Arcrun#48", "owner": "inkstone", "repo": "Arcrun", "id": 48,
|
|
||||||
"title": sys.argv[2], "description": "測試用。", "due_on": "2026-09-13T23:59:59Z",
|
|
||||||
"open_issues": 3, "closed_issues": 0, "members": ["inkstone/ISEP#130"],
|
|
||||||
"set_at": sys.argv[3], "refreshed_at": sys.argv[3]},
|
|
||||||
open(sys.argv[1], "w"), ensure_ascii=False, indent=2)
|
|
||||||
PY
|
|
||||||
}
|
|
||||||
show(){ CLAUDE_PROJECT_DIR="$1" python3 "$MAINLINE" 2>&1 | head -1; }
|
|
||||||
|
|
||||||
echo "── A. 家目錄沒有 ⇒ 讀 repo 那份 ──"
|
|
||||||
write_ms "$HUB/system-dev/mainline.json" "雲端才讀得到的那一條" "2026-09-07 07:30"
|
|
||||||
OUT=$(show "$SHELL_ROOT")
|
|
||||||
case "$OUT" in *"雲端才讀得到的那一條"*) ok "① \$CLAUDE_PROJECT_DIR 是薄殼根、真身在 InkStoneCo/(雲端的形狀)⇒ 答得出主線" ;;
|
|
||||||
*) no "① 薄殼根形狀讀不到 repo 那份" "$OUT" ;; esac
|
|
||||||
OUT=$(show "$HUB")
|
|
||||||
case "$OUT" in *"雲端才讀得到的那一條"*) ok "② \$CLAUDE_PROJECT_DIR 直接是 InkStoneCo ⇒ 也答得出" ;;
|
|
||||||
*) no "② InkStoneCo 根讀不到" "$OUT" ;; esac
|
|
||||||
OUT=$(cd "$HUB" && env -u CLAUDE_PROJECT_DIR python3 "$MAINLINE" 2>&1 | head -1)
|
|
||||||
case "$OUT" in *"雲端才讀得到的那一條"*) ok "③ 沒設 \$CLAUDE_PROJECT_DIR、只是 cwd 在 InkStoneCo ⇒ 也答得出" ;;
|
|
||||||
*) no "③ cwd 形狀讀不到" "$OUT" ;; esac
|
|
||||||
[ ! -e "$ISEP_COUNTDOWN_STATE_DIR/mainline.json" ] && ok "④ 只是讀,家目錄那份沒有被順手建出來" \
|
|
||||||
|| no "④ 讀的時候寫了家目錄" "$(ls "$ISEP_COUNTDOWN_STATE_DIR")"
|
|
||||||
|
|
||||||
echo "── B. 兩份都在 ⇒ set_at 較新的算數 ──"
|
|
||||||
write_ms "$ISEP_COUNTDOWN_STATE_DIR/mainline.json" "本機舊的" "2026-09-01 10:00"
|
|
||||||
OUT=$(show "$SHELL_ROOT")
|
|
||||||
case "$OUT" in *"雲端才讀得到的那一條"*) ok "⑤ repo 那份較新(別台機器後標的)⇒ 用 repo 那份" ;;
|
|
||||||
*) no "⑤ 沒用較新的 repo 那份" "$OUT" ;; esac
|
|
||||||
write_ms "$ISEP_COUNTDOWN_STATE_DIR/mainline.json" "本機新的" "2026-09-08 09:00"
|
|
||||||
OUT=$(show "$SHELL_ROOT")
|
|
||||||
case "$OUT" in *"本機新的"*) ok "⑥ 家目錄那份較新 ⇒ 用家目錄那份" ;;
|
|
||||||
*) no "⑥ 沒用較新的家目錄那份" "$OUT" ;; esac
|
|
||||||
write_ms "$ISEP_COUNTDOWN_STATE_DIR/mainline.json" "同時標的(家目錄)" "2026-09-07 07:30"
|
|
||||||
OUT=$(show "$SHELL_ROOT")
|
|
||||||
case "$OUT" in *"同時標的(家目錄)"*) ok "⑦ 一樣新 ⇒ 家目錄那份(它才有 refresh 過的進度)" ;;
|
|
||||||
*) no "⑦ 平手沒選家目錄" "$OUT" ;; esac
|
|
||||||
|
|
||||||
echo "── C. 寫:誰該動 repo 那份 ──"
|
|
||||||
R=$(CLAUDE_PROJECT_DIR="$SHELL_ROOT" python3 - "$LIB" "$HUB/system-dev/mainline.json" <<'PY'
|
|
||||||
import importlib.util, json, os, sys
|
|
||||||
spec = importlib.util.spec_from_file_location("ml", sys.argv[1]); ML = importlib.util.module_from_spec(spec); spec.loader.exec_module(ML)
|
|
||||||
rp = sys.argv[2]
|
|
||||||
before = open(rp).read()
|
|
||||||
d = ML.load(); d["refreshed_at"] = "2026-09-09 00:00"; d["open_issues"] = 1
|
|
||||||
ML.save(d) # refresh 的形狀:只寫家目錄
|
|
||||||
r1 = open(rp).read() == before
|
|
||||||
d["title"] = "set 之後的新主線"; d["set_at"] = "2026-09-09 00:01"
|
|
||||||
ML.save(d, mirror=True) # set/adopt 的形狀:兩份一起
|
|
||||||
r2 = json.load(open(rp)).get("title") == "set 之後的新主線"
|
|
||||||
r3 = json.load(open(ML.path())).get("title") == "set 之後的新主線"
|
|
||||||
r4 = open(rp).read().endswith("\n")
|
|
||||||
print("|".join(str(x) for x in (r1, r2, r3, r4)))
|
|
||||||
PY
|
|
||||||
)
|
|
||||||
[ "${R%%|*}" = "True" ] && ok "⑧ save()(refresh 的形狀)不碰 repo 那份——不弄髒 InkStoneCo 工作樹" || no "⑧ refresh 動了 repo 那份" "$R"
|
|
||||||
R2=${R#*|}; [ "${R2%%|*}" = "True" ] && ok "⑨ save(mirror=True)(set/adopt 的形狀)寫進 repo 那份" || no "⑨ mirror 沒寫 repo" "$R"
|
|
||||||
R3=${R2#*|}; [ "${R3%%|*}" = "True" ] && ok "⑩ 同一次也寫了家目錄那份" || no "⑩ 家目錄沒寫" "$R"
|
|
||||||
[ "${R##*|}" = "True" ] && ok "⑪ repo 那份收尾有換行(diff 才不會每次多一行 no newline)" || no "⑪ 沒換行" "$R"
|
|
||||||
|
|
||||||
OUT=$(CLAUDE_PROJECT_DIR="$SHELL_ROOT" python3 "$MAINLINE" clear 2>&1)
|
|
||||||
if [ ! -e "$ISEP_COUNTDOWN_STATE_DIR/mainline.json" ] && [ ! -e "$HUB/system-dev/mainline.json" ]; then
|
|
||||||
ok "⑫ clear ⇒ 兩份都拿掉(否則下次讀又從 repo 那份長回來)"
|
|
||||||
else no "⑫ clear 沒清乾淨" "$(ls "$ISEP_COUNTDOWN_STATE_DIR" "$HUB/system-dev" 2>&1 | tr '\n' ' ')"; fi
|
|
||||||
case "$OUT" in *"repo 那份也刪了"*) ok "⑬ clear 講得出 repo 那份也動了(要 commit 才到雲端)" ;; *) no "⑬ clear 沒講 repo 那份" "$OUT" ;; esac
|
|
||||||
|
|
||||||
# set 要打網路,這裡只驗它印出來的那段「repo 那份寫了沒」是接在 repo_path 上的
|
|
||||||
R=$(CLAUDE_PROJECT_DIR="$SHELL_ROOT" python3 - "$LIB" "$HUB" <<'PY'
|
|
||||||
import importlib.util, os, sys
|
|
||||||
spec = importlib.util.spec_from_file_location("ml", sys.argv[1]); ML = importlib.util.module_from_spec(spec); spec.loader.exec_module(ML)
|
|
||||||
print(ML.repo_path(for_write=True) == os.path.join(sys.argv[2], "system-dev", "mainline.json"))
|
|
||||||
PY
|
|
||||||
)
|
|
||||||
[ "$R" = "True" ] && ok "⑭ 檔還不存在時,寫的目標仍指到 InkStoneCo/system-dev/(set 建得出它)" || no "⑭ 寫的目標不對" "$R"
|
|
||||||
|
|
||||||
echo "── D. 哪裡都沒有 ⇒ 仍然答得出「現在沒有主線」 ──"
|
|
||||||
OUT=$(show "$SHELL_ROOT")
|
|
||||||
case "$OUT" in *"現在沒有主線"*) ok "⑮ 兩份都沒有 ⇒ 「現在沒有主線」(ISEP#82 第 4 條沒被弄壞)" ;; *) no "⑮ 沒主線時答不出來" "$OUT" ;; esac
|
|
||||||
OUT=$(ISEP_MAINLINE_REPO_FILE=none show "$SHELL_ROOT")
|
|
||||||
case "$OUT" in *"現在沒有主線"*) ok "⑯ ISEP_MAINLINE_REPO_FILE=none ⇒ 不看 repo(既有測試靠它把外界定住)" ;; *) no "⑯ none 沒生效" "$OUT" ;; esac
|
|
||||||
printf 'not json' > "$HUB/system-dev/mainline.json"
|
|
||||||
OUT=$(show "$SHELL_ROOT")
|
|
||||||
case "$OUT" in *"現在沒有主線"*) ok "⑰ repo 那份壞掉 ⇒ 當成沒有,不炸" ;; *) no "⑰ 壞檔炸了" "$OUT" ;; esac
|
|
||||||
|
|
||||||
echo; echo "通過 $PASS 條,失敗 $FAIL 條"
|
|
||||||
[ "$FAIL" -eq 0 ]
|
|
||||||
@@ -23,7 +23,6 @@ t pass "GET + sort -d / xargs -d" "ls | sort $DASH_D | xargs $DASH_D '\\n' echo;
|
|||||||
t pass "GET 帶 Bearer 標頭" "curl -s -H 'Authorization: Bearer xxx' $H/templates?limit=1"
|
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 "打 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 "打 youlin 測試場" "curl -X POST https://arcrun-cypher-executor.youlin-hsieh-dev.workers.dev/x $DASH_D '{}'"
|
||||||
t pass "打 youlin 測試場(09-02 重裝後的子網域 arcrun-yuga3bse,inkstone/ISEP#130)" "curl -X POST https://arcrun-cypher-executor.arcrun-yuga3bse.workers.dev/webhooks/named $DASH_D @def.yaml"
|
|
||||||
t pass "打 Gitea(不是實例)" "curl -X POST https://git.uncle6.me/api/v1/repos/Leo/x/issues $DASH_D '{}'"
|
t pass "打 Gitea(不是實例)" "curl -X POST https://git.uncle6.me/api/v1/repos/Leo/x/issues $DASH_D '{}'"
|
||||||
|
|
||||||
echo "── 該擋(寫入)──"
|
echo "── 該擋(寫入)──"
|
||||||
|
|||||||
+1
-57
@@ -42,8 +42,6 @@
|
|||||||
1 = 兩條路都沒走通(這時 stderr 一定有一段紅字,不會安靜)
|
1 = 兩條路都沒走通(這時 stderr 一定有一段紅字,不會安靜)
|
||||||
|
|
||||||
環境變數(都有預設,測試才需要動):
|
環境變數(都有預設,測試才需要動):
|
||||||
TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID 有就先走 Bot API 直送(雲端唯一通的路,ISEP#130)
|
|
||||||
ISEP_NOTIFY_BOT_API Bot API 的主機(預設 https://api.telegram.org;測試指到假的)
|
|
||||||
ISEP_NOTIFY_URL notify_leo 的 trigger 網址
|
ISEP_NOTIFY_URL notify_leo 的 trigger 網址
|
||||||
ISEP_NOTIFY_IDENTITY 貼票時的【身份】欄
|
ISEP_NOTIFY_IDENTITY 貼票時的【身份】欄
|
||||||
ISEP_NOTIFY_STATE_DIR 閘判定快取的位置(預設 ~/.claude/isep-nag)
|
ISEP_NOTIFY_STATE_DIR 閘判定快取的位置(預設 ~/.claude/isep-nag)
|
||||||
@@ -254,52 +252,6 @@ def send_telegram(text):
|
|||||||
return False, "外層通了但**內層沒 ok**:%s" % raw[:300]
|
return False, "外層通了但**內層沒 ok**:%s" % raw[:300]
|
||||||
|
|
||||||
|
|
||||||
# ══ 二之一、直送 Bot API(雲端的路,inkstone/ISEP#130)═══════════════════════
|
|
||||||
#
|
|
||||||
# 2026-09-07 從雲端 session 實測三條路:
|
|
||||||
# notify_leo @ leo21c → HTTP 404「找不到 workflow」(08-28 起就斷,修它是 leo 的人閘)
|
|
||||||
# notify_leo @ youlin → 連不到:雲端 egress proxy 對 *.arcrun-yuga3bse.workers.dev 回 403
|
|
||||||
# (policy denial,不是 DNS、不是 000;要 leo 在 Cloud environment 放行主機)
|
|
||||||
# api.telegram.org → 302,**通的**
|
|
||||||
# ⇒ 雲端唯一走得通的是 Bot API 直送,而它只缺兩個環境變數:
|
|
||||||
# TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID(Routine 文件 cloud-worker.md 檔頭本來就列著它們)。
|
|
||||||
# 有 ⇒ 先走這條(它不碰任何實例,閘管不到也不必管);沒有 ⇒ 講清楚缺哪兩個,走原本那條。
|
|
||||||
BOT_API = os.environ.get("ISEP_NOTIFY_BOT_API", "https://api.telegram.org")
|
|
||||||
|
|
||||||
|
|
||||||
def bot_creds():
|
|
||||||
tok = (os.environ.get("TELEGRAM_BOT_TOKEN") or "").strip()
|
|
||||||
chat = (os.environ.get("TELEGRAM_CHAT_ID") or "").strip()
|
|
||||||
return (tok, chat) if tok and chat else (None, None)
|
|
||||||
|
|
||||||
|
|
||||||
def send_bot_api(text):
|
|
||||||
"""回 (ok, 說明)。Telegram 的回應要 `ok: true` 才算送到。"""
|
|
||||||
tok, chat = bot_creds()
|
|
||||||
if not tok:
|
|
||||||
return False, "沒有 TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID(雲端要 leo 在 Cloud environment 加這兩個變數)"
|
|
||||||
if os.environ.get("ISEP_NOTIFY_OFFLINE") == "1":
|
|
||||||
return False, "ISEP_NOTIFY_OFFLINE=1:刻意不打網路"
|
|
||||||
req = urllib.request.Request(
|
|
||||||
"%s/bot%s/sendMessage" % (BOT_API, tok),
|
|
||||||
data=json.dumps({"chat_id": chat, "text": text}).encode(), method="POST",
|
|
||||||
headers={"Content-Type": "application/json",
|
|
||||||
"User-Agent": "isep-notify/1.0 (+inkstone/ISEP#130)"})
|
|
||||||
try:
|
|
||||||
raw = urllib.request.urlopen(req, timeout=30).read().decode()
|
|
||||||
except urllib.error.HTTPError as e:
|
|
||||||
return False, "Bot API HTTP %s:%s" % (e.code, e.read().decode()[:200])
|
|
||||||
except Exception as e:
|
|
||||||
return False, "Bot API 連不上:%s" % e
|
|
||||||
try:
|
|
||||||
d = json.loads(raw)
|
|
||||||
except Exception:
|
|
||||||
return False, "Bot API 回應不是 JSON:%s" % raw[:200]
|
|
||||||
if d.get("ok") is True:
|
|
||||||
return True, "送到了(Bot API 直送,message_id=%s)" % ((d.get("result") or {}).get("message_id"))
|
|
||||||
return False, "Bot API 回 ok=false:%s" % raw[:200]
|
|
||||||
|
|
||||||
|
|
||||||
# ══ 三、退路:貼回票上 ═══════════════════════════════════════════════════
|
# ══ 三、退路:貼回票上 ═══════════════════════════════════════════════════
|
||||||
def gitea_token():
|
def gitea_token():
|
||||||
for env in ("GITEA_TOKEN_CLAUDE_CODE", "GITEA_TOKEN"):
|
for env in ("GITEA_TOKEN_CLAUDE_CODE", "GITEA_TOKEN"):
|
||||||
@@ -399,20 +351,12 @@ def notify(text, fallback_ticket=None, dry_run=False):
|
|||||||
out.append(text)
|
out.append(text)
|
||||||
return 0, "\n".join(out)
|
return 0, "\n".join(out)
|
||||||
|
|
||||||
# ① Bot API 直送:不碰任何實例,閘的判定管不到它(inkstone/ISEP#130)
|
|
||||||
sent, why_bot = send_bot_api(text)
|
|
||||||
out.append(("✅ Telegram(Bot API 直送):%s" if sent else "⏭️ Bot API 直送:%s") % why_bot)
|
|
||||||
if sent:
|
|
||||||
return 0, "\n".join(out)
|
|
||||||
|
|
||||||
# ② 走實例上的 notify_leo 工作流(原本那條;閘說會擋就不送)
|
|
||||||
if fact["verdict"] == "block":
|
if fact["verdict"] == "block":
|
||||||
out.append("⛔ 閘說會擋 ⇒ **本支不繞路**,直接走退路。")
|
out.append("⛔ 閘說會擋 ⇒ **本支不繞路**,直接走退路。")
|
||||||
sent, why = False, "閘會擋,而繞過去等於拆了那道閘 ⇒ 沒有嘗試送出"
|
sent, why = False, "閘會擋,而繞過去等於拆了那道閘 ⇒ 沒有嘗試送出"
|
||||||
else:
|
else:
|
||||||
sent, why = send_telegram(text)
|
sent, why = send_telegram(text)
|
||||||
out.append(("✅ Telegram(notify_leo):%s" if sent else "❌ Telegram(notify_leo):%s") % why)
|
out.append(("✅ Telegram:%s" if sent else "❌ Telegram:%s") % why)
|
||||||
why = "Bot API 直送:%s;notify_leo:%s" % (why_bot, why)
|
|
||||||
|
|
||||||
if sent:
|
if sent:
|
||||||
return 0, "\n".join(out)
|
return 0, "\n".join(out)
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ YOULIN_ACCOUNT = "1129efd7df2e8899d537e9c8fbabb6cb"
|
|||||||
# ⇒ 判準:防呆要比對「**決定後果的那一項**」,不是「剛好看得到的那一項」。
|
# ⇒ 判準:防呆要比對「**決定後果的那一項**」,不是「剛好看得到的那一項」。
|
||||||
# namespace 才是資料的歸屬鍵 ⇒ 三項一起驗,缺一不可。
|
# namespace 才是資料的歸屬鍵 ⇒ 三項一起驗,缺一不可。
|
||||||
YOULIN_NAMESPACE = "yuga3bse"
|
YOULIN_NAMESPACE = "yuga3bse"
|
||||||
YOULIN_CYPHER = "arcrun-cypher-executor.arcrun-yuga3bse.workers.dev" # 09-02 重裝後的子網域(inkstone/ISEP#130);舊名 youlin-hsieh-dev 的 DNS 已不存在
|
YOULIN_CYPHER = "arcrun-cypher-executor.youlin-hsieh-dev.workers.dev"
|
||||||
|
|
||||||
|
|
||||||
class Acr:
|
class Acr:
|
||||||
|
|||||||
+3
-20
@@ -23,8 +23,6 @@ leo 2026-08-27:「**14 個里程碑同時亮著卻不知道該看哪個**」
|
|||||||
|
|
||||||
── 答案為什麼唯一 ─────────────────────────────────────────────────
|
── 答案為什麼唯一 ─────────────────────────────────────────────────
|
||||||
主線住在一個檔裡(`~/.claude/isep-countdown/mainline.json`),那個檔**放得下一條**。
|
主線住在一個檔裡(`~/.claude/isep-countdown/mainline.json`),那個檔**放得下一條**。
|
||||||
(inkstone/ISEP#130 起它有一份隨 repo 走的鏡像:`InkStoneCo/system-dev/mainline.json`——
|
|
||||||
雲端沒有家目錄那份,讀的就是它;`set`/`adopt`/`clear` 兩份一起寫,`refresh` 只寫家目錄。)
|
|
||||||
沒有清單、沒有優先序、沒有「前三名」——`set` 覆蓋掉的那條就不再是主線。
|
沒有清單、沒有優先序、沒有「前三名」——`set` 覆蓋掉的那條就不再是主線。
|
||||||
⇒ 問一次只會拿到 0 或 1 個答案,不會拿到 14 個。
|
⇒ 問一次只會拿到 0 或 1 個答案,不會拿到 14 個。
|
||||||
|
|
||||||
@@ -214,36 +212,22 @@ def cmd_set(argv):
|
|||||||
"closed_issues": m.get("closed_issues") or 0,
|
"closed_issues": m.get("closed_issues") or 0,
|
||||||
"members": refs,
|
"members": refs,
|
||||||
"set_at": now, "refreshed_at": now,
|
"set_at": now, "refreshed_at": now,
|
||||||
}, mirror=True)
|
})
|
||||||
if not ok:
|
if not ok:
|
||||||
die("🔴 寫不進 %s——主線沒有被標上。" % ML.path())
|
die("🔴 寫不進 %s——主線沒有被標上。" % ML.path())
|
||||||
print("✅ 主線已標定:%s/%s#%d「%s」" % (owner, repo, mid, title))
|
print("✅ 主線已標定:%s/%s#%d「%s」" % (owner, repo, mid, title))
|
||||||
if scanned:
|
if scanned:
|
||||||
print(" 跨 repo 收到同名 milestone 的票 %d 張:%s"
|
print(" 跨 repo 收到同名 milestone 的票 %d 張:%s"
|
||||||
% (len(refs), "、".join("%s %d" % (r, n) for r, n in scanned)))
|
% (len(refs), "、".join("%s %d" % (r, n) for r, n in scanned)))
|
||||||
print(mirror_line())
|
|
||||||
print()
|
print()
|
||||||
cmd_show([])
|
cmd_show([])
|
||||||
|
|
||||||
|
|
||||||
def mirror_line():
|
|
||||||
"""repo 那份有沒有跟著寫(inkstone/ISEP#130):寫了要人去 commit,沒寫要講為什麼。"""
|
|
||||||
rp = ML.repo_path(for_write=True)
|
|
||||||
if rp and os.path.isfile(rp):
|
|
||||||
return (" 已同步寫進 repo 那份:%s\n"
|
|
||||||
" 📌 這份要 commit/開 PR 併進 inkstone/InkStoneCo,雲端 clone 才拿得到" % rp)
|
|
||||||
return (" ⚠️ 這台找不到 InkStoneCo 的 system-dev/(CLAUDE_PROJECT_DIR 或 cwd 底下都沒有),"
|
|
||||||
"repo 那份沒更新——雲端仍會讀到舊主線")
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_clear(argv):
|
def cmd_clear(argv):
|
||||||
had = ML.load()
|
had = ML.load()
|
||||||
rp = ML.repo_path()
|
ML.clear()
|
||||||
ML.clear(mirror=True)
|
|
||||||
print("✅ 已清掉主線%s。現在沒有主線——每回合的 🎯 那一行會照實說。"
|
print("✅ 已清掉主線%s。現在沒有主線——每回合的 🎯 那一行會照實說。"
|
||||||
% ("(原本是 %s「%s」)" % (ML.ref_of(had), had.get("title")) if had else ""))
|
% ("(原本是 %s「%s」)" % (ML.ref_of(had), had.get("title")) if had else ""))
|
||||||
if rp:
|
|
||||||
print(" repo 那份也刪了:%s(要 commit 才會到雲端)" % rp)
|
|
||||||
|
|
||||||
|
|
||||||
# ── refresh ──────────────────────────────────────────────────────────────
|
# ── refresh ──────────────────────────────────────────────────────────────
|
||||||
@@ -294,9 +278,8 @@ def cmd_adopt(argv):
|
|||||||
T.api("/repos/%s/%s/issues/%d" % (owner, repo, num), {"milestone": mid}, method="PATCH")
|
T.api("/repos/%s/%s/issues/%d" % (owner, repo, num), {"milestone": mid}, method="PATCH")
|
||||||
ref = "%s/%s#%d" % (owner, repo, num)
|
ref = "%s/%s#%d" % (owner, repo, num)
|
||||||
ms["members"] = sorted(set(ms.get("members") or []) | {ref})
|
ms["members"] = sorted(set(ms.get("members") or []) | {ref})
|
||||||
ML.save(ms, mirror=True)
|
ML.save(ms)
|
||||||
print("✅ 補收:%s 已掛進「%s」(%s/%s#%d)" % (ref, ms["title"], owner, repo, mid))
|
print("✅ 補收:%s 已掛進「%s」(%s/%s#%d)" % (ref, ms["title"], owner, repo, mid))
|
||||||
print(mirror_line())
|
|
||||||
|
|
||||||
|
|
||||||
# ── has ──────────────────────────────────────────────────────────────────
|
# ── has ──────────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -1,146 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""settings-allow-sync — 把 ISEP 的權限白名單寫進**這台機器**的 ~/.claude/settings.json
|
|
||||||
(inkstone/ISEP#130)
|
|
||||||
|
|
||||||
━━ 為什麼有這支 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
leo 09-07 親手把四個 Gitea 正門工具(`ticket`/`mainline`/`gate-ok`/`gitea-pr-merge`)
|
|
||||||
加進本機 `InkStoneCo/.claude/settings.json` 的 `permissions.allow`,auto mode 的分類器
|
|
||||||
才不擋。**雲端 session 沒有那四條** ⇒ 同樣的動作在雲端照樣被擋
|
|
||||||
(09-04 progress-guard run log:permission_denials=6)。
|
|
||||||
|
|
||||||
雲端真正讀的是薄殼 repo(GitHub)的 settings——推它要 D20 開閘(leo 親跑 github-arm)。
|
|
||||||
⇒ 白名單不住薄殼、也不住 InkStoneCo,**住 ISEP 一份**(`docs/permissions-allow.json`),
|
|
||||||
由本支在那台機器上寫進 `~/.claude/settings.json`(user scope,跟 cwd 無關)。
|
|
||||||
雲端:`docs/cloud-setup-script.sh` 裝完 plugin 就跑一次;之後每個 SessionStart 再對一次,
|
|
||||||
plugin 更新帶進新規則時不必等快照重拍。本機:同一支、同一份清單。
|
|
||||||
|
|
||||||
━━ 規矩 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
· 只加不減:settings.json 裡本來就有的東西一個字不動(別人手加的規則不是本支的地盤)。
|
|
||||||
· 冪等:跑第二次 +0 條,檔案一個位元組都不變。
|
|
||||||
· 清單裡開頭的 `~` 換成這台的家目錄(本機 /Users/…、雲端 /root),其餘照抄。
|
|
||||||
· 原子寫:先寫暫存檔再 rename,中途斷掉不會留下半個 JSON。
|
|
||||||
· 讀不懂目標(不是 JSON)⇒ **不碰它**、印出來、離開碼 0——這支掛在 SessionStart,
|
|
||||||
不准因為它把 session 弄壞;`--check` 才會用離開碼講話。
|
|
||||||
|
|
||||||
━━ 用法 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
settings-allow-sync 寫進 ~/.claude/settings.json
|
|
||||||
settings-allow-sync --dry-run 只印會加哪幾條,不寫
|
|
||||||
settings-allow-sync --check 對帳:缺任何一條 ⇒ 離開碼 1(測試/驗收用)
|
|
||||||
settings-allow-sync --target <檔> --home <家目錄> 測試用:指到別的檔、別的家目錄
|
|
||||||
settings-allow-sync --quiet 沒事就閉嘴(SessionStart 用)
|
|
||||||
"""
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
SOURCE = os.path.join(HERE, "..", "docs", "permissions-allow.json")
|
|
||||||
|
|
||||||
|
|
||||||
def wanted(home):
|
|
||||||
with open(SOURCE, encoding="utf-8") as f:
|
|
||||||
d = json.load(f)
|
|
||||||
out = []
|
|
||||||
for rule in d.get("allow") or []:
|
|
||||||
if not isinstance(rule, str) or not rule.startswith("Bash(") or not rule.endswith(")"):
|
|
||||||
raise ValueError("清單裡有一條不是 Bash(…) 的形狀:%r" % (rule,))
|
|
||||||
inner = rule[len("Bash("):-1]
|
|
||||||
# 只換「路徑開頭」的 ~:`python3 ~/.claude/…` 這種。`~` 出現在別處不動。
|
|
||||||
parts = inner.split(" ")
|
|
||||||
parts = [home + p[1:] if p.startswith("~/") else p for p in parts]
|
|
||||||
out.append("Bash(" + " ".join(parts) + ")")
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
|
||||||
target = os.path.join(os.path.expanduser("~"), ".claude", "settings.json")
|
|
||||||
home = os.path.expanduser("~")
|
|
||||||
dry = check = quiet = False
|
|
||||||
i = 0
|
|
||||||
while i < len(argv):
|
|
||||||
a = argv[i]
|
|
||||||
if a == "--target":
|
|
||||||
i += 1; target = argv[i]
|
|
||||||
elif a == "--home":
|
|
||||||
i += 1; home = argv[i].rstrip("/")
|
|
||||||
elif a == "--dry-run":
|
|
||||||
dry = True
|
|
||||||
elif a == "--check":
|
|
||||||
check = True
|
|
||||||
elif a == "--quiet":
|
|
||||||
quiet = True
|
|
||||||
elif a in ("-h", "--help"):
|
|
||||||
print(__doc__); return 0
|
|
||||||
else:
|
|
||||||
print("不認得的參數:%s(--help 看用法)" % a, file=sys.stderr); return 2
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
try:
|
|
||||||
rules = wanted(home)
|
|
||||||
except Exception as e:
|
|
||||||
print("🔴 讀不了白名單清單 %s:%s" % (SOURCE, e), file=sys.stderr)
|
|
||||||
return 1 if check else 0
|
|
||||||
|
|
||||||
cur = {}
|
|
||||||
if os.path.exists(target):
|
|
||||||
try:
|
|
||||||
with open(target, encoding="utf-8") as f:
|
|
||||||
cur = json.load(f)
|
|
||||||
if not isinstance(cur, dict):
|
|
||||||
raise ValueError("最外層不是物件")
|
|
||||||
except Exception as e:
|
|
||||||
print("🔴 %s 讀不懂(%s)——**沒有動它**。修好它再跑一次。" % (target, e), file=sys.stderr)
|
|
||||||
return 1 if check else 0
|
|
||||||
|
|
||||||
perms = cur.get("permissions")
|
|
||||||
if not isinstance(perms, dict):
|
|
||||||
perms = {}
|
|
||||||
allow = perms.get("allow")
|
|
||||||
if not isinstance(allow, list):
|
|
||||||
allow = []
|
|
||||||
have = set(a for a in allow if isinstance(a, str))
|
|
||||||
missing = [r for r in rules if r not in have]
|
|
||||||
|
|
||||||
if check:
|
|
||||||
if missing:
|
|
||||||
print("🔴 %s 缺 %d 條:" % (target, len(missing)))
|
|
||||||
for r in missing:
|
|
||||||
print(" " + r)
|
|
||||||
return 1
|
|
||||||
if not quiet:
|
|
||||||
print("✅ %s 已有全部 %d 條" % (target, len(rules)))
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if not missing:
|
|
||||||
if not quiet:
|
|
||||||
print("✅ 白名單已齊(%d 條):%s" % (len(rules), target))
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if dry:
|
|
||||||
print("🧪 --dry-run:會加 %d 條進 %s:" % (len(missing), target))
|
|
||||||
for r in missing:
|
|
||||||
print(" " + r)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
perms["allow"] = allow + missing
|
|
||||||
cur["permissions"] = perms
|
|
||||||
try:
|
|
||||||
os.makedirs(os.path.dirname(target) or ".", exist_ok=True)
|
|
||||||
fd, tmp = tempfile.mkstemp(prefix=".settings-", suffix=".json", dir=os.path.dirname(target) or ".")
|
|
||||||
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
||||||
json.dump(cur, f, ensure_ascii=False, indent=2)
|
|
||||||
f.write("\n")
|
|
||||||
os.replace(tmp, target)
|
|
||||||
except Exception as e:
|
|
||||||
print("🔴 寫不進 %s:%s" % (target, e), file=sys.stderr)
|
|
||||||
return 0
|
|
||||||
print("✅ 白名單 +%d 條 → %s(共 %d 條來自 ISEP)" % (len(missing), target, len(rules)))
|
|
||||||
if not quiet:
|
|
||||||
for r in missing:
|
|
||||||
print(" " + r)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main(sys.argv[1:]))
|
|
||||||
-410
@@ -1,410 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""stage — 雲端對 **stage(youlin)** 寫入的正門(inkstone/ISEP#137)
|
|
||||||
|
|
||||||
━━ 為什麼有這支 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
09-07 三條主線工人在雲端對 stage 的寫入全被 Claude Code auto mode 的分類器擋(不是 ISEP 的閘):
|
|
||||||
① `printf … | npx wrangler secret put CF_SECRETS_API_TOKEN --name arcrun-cypher-executor`
|
|
||||||
② `python3 scripts/stage-deploy-artifacts.py all --confirm`(Arcrun 的成品直推,CF API 上傳)
|
|
||||||
③ `curl -X POST …arcrun-yuga3bse.workers.dev/records`/`/graph/canonicalize-entities`/`/map/recompute`
|
|
||||||
權限白名單(docs/permissions-allow.json)是**逐條完全比對前綴**:複合指令(`cd … && printf … | VAR=… npx …`)
|
|
||||||
與任意寫法的 curl 永遠對不上任何一條;放整類 `Bash(npx *)`/`Bash(curl *)` 又是紅線。
|
|
||||||
leo 09-07:「為什麼會擋你,這就是要修復的問題」「本機環境跟你不同應該不行」。
|
|
||||||
|
|
||||||
⇒ 每一種寫入收成**一支固定形狀**,白名單放它的四種呼叫形狀:
|
|
||||||
`stage secret …` = ①(打 api.cloudflare.com,不經 npx——雲端每次要重抓 wrangler,
|
|
||||||
而且 wrangler 會讀 ~/.wrangler 的登入態:本機是 uncle6、雲端沒有,兩台行為不同)
|
|
||||||
`stage api …` = ③(用 curl 打 stage 實例;youlin 邊緣對 python-urllib UA 回 403 code 1010,
|
|
||||||
Arcrun#176 comment 6487——所以這一段**不用 urllib**)
|
|
||||||
② = Arcrun 自己那支已經寫死只認 youlin 帳號 ID、憑證只從
|
|
||||||
CLOUDFLARE_API_TOKEN_YOULIN_CC_USE 讀、不收 --account/--token;
|
|
||||||
白名單直接放它的形狀(`python3 scripts/stage-deploy-artifacts.py *`),不重造一支。
|
|
||||||
|
|
||||||
━━ 只寫 stage,判準是唯一識別碼往放行方向比對,不是名字 ━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
stage 隨便炸;出貨機(geek6688/uncle6)與 leo 的實例(leo21c)不是。
|
|
||||||
secret:這把 token 打得到的帳號(GET /accounts 現查)裡要有 1129efd7df2e8899d537e9c8fbabb6cb,
|
|
||||||
而且寫入的 URL 永遠只帶這個 ID。打不到 ⇒ 拒絕、印出它打得到誰、離開碼 2。
|
|
||||||
api :URL 只會長在 `<worker>.arcrun-yuga3bse.workers.dev`(09-02 重裝後的 stage 子網域)。
|
|
||||||
給完整網址時主機必須等於它,否則拒絕、離開碼 2——不管那個主機叫 leo21c 還是別的什麼。
|
|
||||||
不看變數名字裡有沒有 `leo21c`/`geek6688`——名字改了黑名單就漏,ID 與主機改不了。
|
|
||||||
|
|
||||||
━━ 值不進指令列 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
secret 的值、Bearer、任何標頭值都只從**環境變數名**讀(--from-env/--bearer-env/--header-env);
|
|
||||||
不落磁碟、不 echo、不進 git、不進 shell 歷史。curl 的標頭與 body 走 stdin 設定檔+管線,不走 argv。
|
|
||||||
|
|
||||||
━━ 用法 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
||||||
stage secret put --worker <script> --secret <NAME> --from-env <VAR> [--token-env VAR] [--account ID]
|
|
||||||
stage secret list --worker <script>
|
|
||||||
stage secret delete --worker <script> --secret <NAME>
|
|
||||||
--token-env <VAR> CF token 的環境變數名(預設 CLOUDFLARE_API_TOKEN_YOULIN_CC_USE,雲端就有)
|
|
||||||
--account <ID> 目標帳號(預設 stage;給別的 ID 一律拒絕、不打網路)
|
|
||||||
|
|
||||||
stage api <METHOD> <worker>/<path>[?query] [--json '<body>' | --data-env <VAR> | --data-file <檔>]
|
|
||||||
[--bearer-env <VAR>] [--header-env <Name>=<VAR>]…
|
|
||||||
<worker>/<path> 例 arcrun-kbdb/records、arcrun-cypher-executor/webhooks/named/yuga3bse/x/trigger
|
|
||||||
也收完整網址,但主機必須是 *.arcrun-yuga3bse.workers.dev
|
|
||||||
--bearer-env VAR Authorization: Bearer <VAR 的值>(stage KBDB 的 POST 要 KBDB_INTERNAL_TOKEN)
|
|
||||||
--header-env N=VAR 任一標頭,值從環境變數讀(例 X-Arcrun-API-Key=ARCRUN_NS_YOULIN)
|
|
||||||
body 有給就自動帶 Content-Type: application/json
|
|
||||||
印 `HTTP <code>` + 回應;2xx 離開碼 0,其餘 1;curl 連不上印它的錯誤字串(不記成 000)
|
|
||||||
|
|
||||||
例(雲端):
|
|
||||||
python3 "$CLAUDE_PLUGIN_ROOT/scripts/stage" secret put --worker arcrun-cypher-executor \\
|
|
||||||
--secret CF_SECRETS_API_TOKEN --from-env CF_SECRETS_API_TOKEN_VALUE
|
|
||||||
python3 "$CLAUDE_PLUGIN_ROOT/scripts/stage" api POST 'arcrun-kbdb/map/recompute?library=rt-lib&owner_id=yuga3bse' \\
|
|
||||||
--bearer-env KBDB_INTERNAL_TOKEN
|
|
||||||
|
|
||||||
離開碼:0 成功 / 2 被本工具拒絕(非 stage、缺變數、值在指令列)/ 1 API・網路失敗
|
|
||||||
測試用:STAGE_SECRET_PUT_API_BASE(CF API)、STAGE_API_BASE_OVERRIDE(實例)指到假伺服器——scripts/test-stage.sh
|
|
||||||
"""
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import urllib.error
|
|
||||||
import urllib.parse
|
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
STAGE_ACCOUNT_ID = "1129efd7df2e8899d537e9c8fbabb6cb" # youlin(D37 定的 stage 帳號)
|
|
||||||
STAGE_LABEL = "youlin(stage)"
|
|
||||||
STAGE_HOST_SUFFIX = ".arcrun-yuga3bse.workers.dev" # 09-02 重裝後的 stage 子網域(ISEP#130)
|
|
||||||
DEFAULT_TOKEN_ENV = "CLOUDFLARE_API_TOKEN_YOULIN_CC_USE"
|
|
||||||
CF_API_BASE = os.environ.get("STAGE_SECRET_PUT_API_BASE", "https://api.cloudflare.com/client/v4").rstrip("/")
|
|
||||||
API_BASE_OVERRIDE = os.environ.get("STAGE_API_BASE_OVERRIDE", "").rstrip("/") # 測試用:整個實例指到假伺服器
|
|
||||||
|
|
||||||
EXIT_OK, EXIT_API, EXIT_REFUSED = 0, 1, 2
|
|
||||||
FORBIDDEN_VALUE_FLAGS = ("--value", "--text", "--bearer", "--token", "--header")
|
|
||||||
|
|
||||||
|
|
||||||
def die(code, msg):
|
|
||||||
print(msg, file=sys.stderr)
|
|
||||||
return code
|
|
||||||
|
|
||||||
|
|
||||||
class Refuse(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# ───────────────────────── secret(CF API,api.cloudflare.com)─────────────────────────
|
|
||||||
|
|
||||||
def parse_secret(argv):
|
|
||||||
if not argv or argv[0] not in ("put", "list", "delete"):
|
|
||||||
raise Refuse("secret 後面要接 put/list/delete,不是 %r(--help 看用法)" % (argv[:1] or [""])[0])
|
|
||||||
cmd = argv[0]
|
|
||||||
o = {"worker": None, "secret": None, "from_env": None, "token_env": DEFAULT_TOKEN_ENV, "account": STAGE_ACCOUNT_ID}
|
|
||||||
keys = {"--worker": "worker", "--secret": "secret", "--from-env": "from_env", "--token-env": "token_env", "--account": "account"}
|
|
||||||
i = 1
|
|
||||||
while i < len(argv):
|
|
||||||
a = argv[i]
|
|
||||||
if a in FORBIDDEN_VALUE_FLAGS:
|
|
||||||
raise Refuse("本工具不收 %s:值只從環境變數名讀(--from-env/--token-env),不准出現在指令列" % a)
|
|
||||||
if a not in keys:
|
|
||||||
raise Refuse("不認得的參數:%s(--help 看用法)" % a)
|
|
||||||
if i + 1 >= len(argv):
|
|
||||||
raise Refuse("%s 後面要接一個值" % a)
|
|
||||||
o[keys[a]] = argv[i + 1]
|
|
||||||
i += 2
|
|
||||||
if not o["worker"]:
|
|
||||||
raise Refuse("缺 --worker <script 名>")
|
|
||||||
if cmd in ("put", "delete") and not o["secret"]:
|
|
||||||
raise Refuse("缺 --secret <SECRET 名>")
|
|
||||||
if cmd == "put" and not o["from_env"]:
|
|
||||||
raise Refuse("缺 --from-env <環境變數名>(值只從這裡讀)")
|
|
||||||
return cmd, o
|
|
||||||
|
|
||||||
|
|
||||||
def cf(method, path, token, body=None):
|
|
||||||
"""回 (http_status, parsed_json);網路層失敗回 (None, 錯誤字串)——不把三種病都記成 000。"""
|
|
||||||
data = None
|
|
||||||
headers = {"Authorization": "Bearer " + token, "User-Agent": "isep-stage/1 (+inkstone/ISEP#137)"}
|
|
||||||
if body is not None:
|
|
||||||
data = json.dumps(body).encode("utf-8")
|
|
||||||
headers["Content-Type"] = "application/json"
|
|
||||||
req = urllib.request.Request(CF_API_BASE + path, data=data, headers=headers, method=method)
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(req, timeout=60) as resp:
|
|
||||||
return resp.status, json.loads(resp.read().decode("utf-8") or "{}")
|
|
||||||
except urllib.error.HTTPError as e:
|
|
||||||
try:
|
|
||||||
return e.code, json.loads(e.read().decode("utf-8") or "{}")
|
|
||||||
except Exception:
|
|
||||||
return e.code, {"success": False, "errors": [{"message": "HTTP %d(非 JSON 回應)" % e.code}]}
|
|
||||||
except Exception as e:
|
|
||||||
return None, "%s: %s" % (type(e).__name__, e)
|
|
||||||
|
|
||||||
|
|
||||||
def cf_ok(status, d):
|
|
||||||
# CF 對「建立」回 201(secret PUT 實測就是 201,inkstone/ISEP#137 第一次實跑抓到的)——2xx + success 才算好
|
|
||||||
return status is not None and 200 <= status < 300 and isinstance(d, dict) and bool(d.get("success"))
|
|
||||||
|
|
||||||
|
|
||||||
def cf_errors(d):
|
|
||||||
if isinstance(d, dict):
|
|
||||||
errs = d.get("errors") or []
|
|
||||||
return ";".join("%s(code %s)" % (e.get("message"), e.get("code")) for e in errs) or "(CF 沒給錯誤訊息)"
|
|
||||||
return str(d)
|
|
||||||
|
|
||||||
|
|
||||||
def refuse_account(given):
|
|
||||||
return die(EXIT_REFUSED, "\n".join([
|
|
||||||
"🛑 本工具只種 stage,不種 %s。" % given,
|
|
||||||
"",
|
|
||||||
" stage = %s,帳號 ID %s" % (STAGE_LABEL, STAGE_ACCOUNT_ID),
|
|
||||||
" 你給的 = %s" % given,
|
|
||||||
"",
|
|
||||||
"【為什麼】stage 隨便炸;出貨機(geek6688/uncle6)與 leo 的實例(leo21c)不是(inkstone/ISEP#137)。",
|
|
||||||
"【出路】要種進那兩類帳號 ⇒ 交回地端,由 leo 親手在 Mac 上 `wrangler secret put`;",
|
|
||||||
" 雲端這支不會、也不該會。要種 stage ⇒ 把 --account 拿掉(預設就是 stage)。",
|
|
||||||
]))
|
|
||||||
|
|
||||||
|
|
||||||
def check_token_reaches_stage(token, token_env):
|
|
||||||
status, d = cf("GET", "/accounts", token)
|
|
||||||
if status is None:
|
|
||||||
return die(EXIT_API, "🔴 連不到 CF API(%s):%s\n 雲端看到這個先查 `curl -sS \"$HTTPS_PROXY/__agentproxy/status\"`(policy 拒絕 vs DNS vs 對方沒回,三種修法不同)。" % (CF_API_BASE, d))
|
|
||||||
if not cf_ok(status, d):
|
|
||||||
return die(EXIT_API, "🔴 CF 不認這把 token(%s,HTTP %s):%s" % (token_env, status, cf_errors(d)))
|
|
||||||
accounts = [(a.get("id"), a.get("name")) for a in (d.get("result") or []) if isinstance(a, dict)]
|
|
||||||
if STAGE_ACCOUNT_ID not in [i for i, _ in accounts]:
|
|
||||||
reach = "\n".join(" · %s %s" % (i, n) for i, n in accounts) or " ·(一個都沒有)"
|
|
||||||
return die(EXIT_REFUSED, "\n".join([
|
|
||||||
"🛑 這把 token(%s)打不到 stage,拒絕。" % token_env,
|
|
||||||
"",
|
|
||||||
" stage = %s,帳號 ID %s" % (STAGE_LABEL, STAGE_ACCOUNT_ID),
|
|
||||||
" 這把 token 打得到的帳號:",
|
|
||||||
reach,
|
|
||||||
"",
|
|
||||||
"【為什麼】本工具只種 stage;token 是誰的就會種進誰的帳號,所以先問 CF 它打得到誰(inkstone/ISEP#137)。",
|
|
||||||
"【出路】用 stage 的那把:--token-env %s(雲端 Cloud environment 就有,本機在頂層 .env)。" % DEFAULT_TOKEN_ENV,
|
|
||||||
" 真要種出貨機/leo21c ⇒ 交回地端由 leo 親手做。",
|
|
||||||
]))
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def list_names(token, account, worker):
|
|
||||||
status, d = cf("GET", "/accounts/%s/workers/scripts/%s/secrets" % (account, worker), token)
|
|
||||||
if status is None:
|
|
||||||
return None, "連不到 CF API(%s):%s" % (CF_API_BASE, d)
|
|
||||||
if not cf_ok(status, d):
|
|
||||||
return None, "列 secrets 失敗(HTTP %s):%s" % (status, cf_errors(d))
|
|
||||||
return sorted(s.get("name") for s in (d.get("result") or []) if isinstance(s, dict) and s.get("name")), None
|
|
||||||
|
|
||||||
|
|
||||||
def run_secret(argv):
|
|
||||||
try:
|
|
||||||
cmd, o = parse_secret(argv)
|
|
||||||
except Refuse as e:
|
|
||||||
return die(EXIT_REFUSED, "🛑 %s" % e)
|
|
||||||
|
|
||||||
if o["account"] != STAGE_ACCOUNT_ID:
|
|
||||||
return refuse_account(o["account"])
|
|
||||||
token = os.environ.get(o["token_env"], "")
|
|
||||||
if not token:
|
|
||||||
return die(EXIT_REFUSED, "🛑 環境變數 %s 沒有值(CF token)。\n【出路】雲端:Cloud environment 要有它(scripts/make-cloud-env.sh 的清單裡就有);本機:從頂層 .env 匯出。" % o["token_env"])
|
|
||||||
value = None
|
|
||||||
if cmd == "put":
|
|
||||||
value = os.environ.get(o["from_env"], "")
|
|
||||||
if not value:
|
|
||||||
return die(EXIT_REFUSED, "🛑 環境變數 %s 沒有值(要種進去的 secret 本身)。\n【出路】把值放進這個環境變數再跑;不要改成把值寫在指令列——那是紅線(值不落磁碟、不進指令歷史)。" % o["from_env"])
|
|
||||||
|
|
||||||
rc = check_token_reaches_stage(token, o["token_env"])
|
|
||||||
if rc is not None:
|
|
||||||
return rc
|
|
||||||
acct, worker = o["account"], o["worker"]
|
|
||||||
|
|
||||||
if cmd == "list":
|
|
||||||
names, err = list_names(token, acct, worker)
|
|
||||||
if err:
|
|
||||||
return die(EXIT_API, "🔴 %s" % err)
|
|
||||||
print("✅ %s@%s 現有 %d 把 secret:%s" % (worker, STAGE_LABEL, len(names), "、".join(names) or "(沒有)"))
|
|
||||||
return EXIT_OK
|
|
||||||
|
|
||||||
if cmd == "delete":
|
|
||||||
status, d = cf("DELETE", "/accounts/%s/workers/scripts/%s/secrets/%s" % (acct, worker, o["secret"]), token)
|
|
||||||
if status is None:
|
|
||||||
return die(EXIT_API, "🔴 連不到 CF API:%s" % d)
|
|
||||||
if not cf_ok(status, d):
|
|
||||||
return die(EXIT_API, "🔴 刪 %s 失敗(HTTP %s):%s" % (o["secret"], status, cf_errors(d)))
|
|
||||||
names, err = list_names(token, acct, worker)
|
|
||||||
if err:
|
|
||||||
return die(EXIT_API, "🔴 刪了但列不出來確認:%s" % err)
|
|
||||||
if o["secret"] in names:
|
|
||||||
return die(EXIT_API, "🔴 CF 說刪了,列表卻還有 %s" % o["secret"])
|
|
||||||
print("✅ 已刪 %s ← %s@%s;剩 %d 把:%s" % (o["secret"], worker, STAGE_LABEL, len(names), "、".join(names) or "(沒有)"))
|
|
||||||
return EXIT_OK
|
|
||||||
|
|
||||||
body = {"name": o["secret"], "text": value, "type": "secret_text"}
|
|
||||||
status, d = cf("PUT", "/accounts/%s/workers/scripts/%s/secrets" % (acct, worker), token, body)
|
|
||||||
del value, body
|
|
||||||
if status is None:
|
|
||||||
return die(EXIT_API, "🔴 連不到 CF API:%s" % d)
|
|
||||||
if not cf_ok(status, d):
|
|
||||||
return die(EXIT_API, "🔴 種 %s → %s 失敗(HTTP %s):%s" % (o["secret"], worker, status, cf_errors(d)))
|
|
||||||
names, err = list_names(token, acct, worker)
|
|
||||||
if err:
|
|
||||||
return die(EXIT_API, "🔴 CF 說種好了,但列不出來確認:%s" % err)
|
|
||||||
if o["secret"] not in names:
|
|
||||||
return die(EXIT_API, "🔴 CF 說種好了,列表卻沒有 %s(有的是:%s)" % (o["secret"], "、".join(names)))
|
|
||||||
print("✅ 已種 %s → %s@%s(值來自環境變數 %s,沒印、沒落地)" % (o["secret"], worker, STAGE_LABEL, o["from_env"]))
|
|
||||||
print(" 現有 %d 把:%s" % (len(names), "、".join(names)))
|
|
||||||
return EXIT_OK
|
|
||||||
|
|
||||||
|
|
||||||
# ───────────────────────── api(curl 打 stage 實例)─────────────────────────
|
|
||||||
|
|
||||||
def parse_api(argv):
|
|
||||||
if len(argv) < 2:
|
|
||||||
raise Refuse("api 後面要接 <METHOD> <worker>/<path>(--help 看用法)")
|
|
||||||
method, target = argv[0].upper(), argv[1]
|
|
||||||
if method not in ("GET", "POST", "PUT", "PATCH", "DELETE"):
|
|
||||||
raise Refuse("METHOD 要是 GET/POST/PUT/PATCH/DELETE,不是 %r" % argv[0])
|
|
||||||
o = {"json": None, "data_env": None, "data_file": None, "bearer_env": None, "header_envs": []}
|
|
||||||
i = 2
|
|
||||||
while i < len(argv):
|
|
||||||
a = argv[i]
|
|
||||||
if a in FORBIDDEN_VALUE_FLAGS:
|
|
||||||
raise Refuse("本工具不收 %s:標頭值只從環境變數名讀(--bearer-env/--header-env Name=VAR),不准出現在指令列" % a)
|
|
||||||
if i + 1 >= len(argv):
|
|
||||||
raise Refuse("%s 後面要接一個值" % a)
|
|
||||||
v = argv[i + 1]
|
|
||||||
if a == "--json":
|
|
||||||
o["json"] = v
|
|
||||||
elif a == "--data-env":
|
|
||||||
o["data_env"] = v
|
|
||||||
elif a == "--data-file":
|
|
||||||
o["data_file"] = v
|
|
||||||
elif a == "--bearer-env":
|
|
||||||
o["bearer_env"] = v
|
|
||||||
elif a == "--header-env":
|
|
||||||
if "=" not in v:
|
|
||||||
raise Refuse("--header-env 的形狀是 Name=VAR(例 X-Arcrun-API-Key=ARCRUN_NS_YOULIN),不是 %r" % v)
|
|
||||||
o["header_envs"].append(tuple(v.split("=", 1)))
|
|
||||||
else:
|
|
||||||
raise Refuse("不認得的參數:%s(--help 看用法)" % a)
|
|
||||||
i += 2
|
|
||||||
if sum(1 for k in ("json", "data_env", "data_file") if o[k]) > 1:
|
|
||||||
raise Refuse("--json/--data-env/--data-file 只能給一個")
|
|
||||||
return method, target, o
|
|
||||||
|
|
||||||
|
|
||||||
def stage_url(target):
|
|
||||||
"""把 <worker>/<path> 或完整網址變成 stage 的網址;主機不是 stage 就拒絕。"""
|
|
||||||
if "://" in target:
|
|
||||||
u = urllib.parse.urlsplit(target)
|
|
||||||
host = (u.hostname or "").lower()
|
|
||||||
if not host.endswith(STAGE_HOST_SUFFIX) or host == STAGE_HOST_SUFFIX.lstrip("."):
|
|
||||||
raise Refuse("\n".join([
|
|
||||||
"本工具只打 stage,不打 %s。" % host,
|
|
||||||
"",
|
|
||||||
" stage = %s,主機一律是 <worker>%s" % (STAGE_LABEL, STAGE_HOST_SUFFIX),
|
|
||||||
" 你給的 = %s" % target,
|
|
||||||
"",
|
|
||||||
"【為什麼】stage 隨便炸;leo21c 是 leo 本人在用的實例、geek6688/uncle6 是出貨機(inkstone/ISEP#137)。",
|
|
||||||
"【出路】打 stage ⇒ 寫成 <worker>/<path>(例 arcrun-kbdb/records),主機由本工具補。",
|
|
||||||
" 對 leo21c 唯讀查詢 ⇒ 直接 curl GET(leo21c-write-guard 放行讀);要寫 ⇒ 交回地端由 leo 親手做。",
|
|
||||||
]))
|
|
||||||
if API_BASE_OVERRIDE:
|
|
||||||
return API_BASE_OVERRIDE + "/" + host.split(".")[0] + (u.path or "/") + ("?" + u.query if u.query else "")
|
|
||||||
return urllib.parse.urlunsplit(("https", host, u.path or "/", u.query, ""))
|
|
||||||
if "/" not in target:
|
|
||||||
raise Refuse("目標要寫成 <worker>/<path>(例 arcrun-kbdb/records),不是 %r" % target)
|
|
||||||
worker, rest = target.split("/", 1)
|
|
||||||
if not worker or any(c in worker for c in ".:@ "):
|
|
||||||
raise Refuse("<worker> 只能是 worker 名(例 arcrun-kbdb),不是 %r" % worker)
|
|
||||||
if API_BASE_OVERRIDE:
|
|
||||||
return API_BASE_OVERRIDE + "/" + worker + "/" + rest
|
|
||||||
return "https://" + worker + STAGE_HOST_SUFFIX + "/" + rest
|
|
||||||
|
|
||||||
|
|
||||||
def curl_quote(s):
|
|
||||||
return '"' + s.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n").replace("\t", "\\t") + '"'
|
|
||||||
|
|
||||||
|
|
||||||
def run_api(argv):
|
|
||||||
try:
|
|
||||||
method, target, o = parse_api(argv)
|
|
||||||
url = stage_url(target)
|
|
||||||
except Refuse as e:
|
|
||||||
return die(EXIT_REFUSED, "🛑 %s" % e)
|
|
||||||
|
|
||||||
headers = []
|
|
||||||
if o["bearer_env"]:
|
|
||||||
v = os.environ.get(o["bearer_env"], "")
|
|
||||||
if not v:
|
|
||||||
return die(EXIT_REFUSED, "🛑 環境變數 %s 沒有值(Bearer)。\n【出路】把值放進這個環境變數再跑;不要改成寫在指令列。" % o["bearer_env"])
|
|
||||||
headers.append("Authorization: Bearer " + v)
|
|
||||||
for name, var in o["header_envs"]:
|
|
||||||
v = os.environ.get(var, "")
|
|
||||||
if not v:
|
|
||||||
return die(EXIT_REFUSED, "🛑 環境變數 %s 沒有值(標頭 %s)。" % (var, name))
|
|
||||||
headers.append(name + ": " + v)
|
|
||||||
|
|
||||||
body = None
|
|
||||||
if o["json"] is not None:
|
|
||||||
body = o["json"]
|
|
||||||
elif o["data_env"]:
|
|
||||||
body = os.environ.get(o["data_env"], "")
|
|
||||||
if not body:
|
|
||||||
return die(EXIT_REFUSED, "🛑 環境變數 %s 沒有值(body)。" % o["data_env"])
|
|
||||||
elif o["data_file"]:
|
|
||||||
try:
|
|
||||||
with open(o["data_file"], encoding="utf-8") as f:
|
|
||||||
body = f.read()
|
|
||||||
except OSError as e:
|
|
||||||
return die(EXIT_REFUSED, "🛑 讀不了 --data-file %s:%s" % (o["data_file"], e))
|
|
||||||
if body is not None:
|
|
||||||
headers.append("Content-Type: application/json")
|
|
||||||
|
|
||||||
# 標頭與 body 都不走 argv:設定檔從 stdin 進,body 從一條管線(/dev/fd/N)進
|
|
||||||
rfd, wfd = os.pipe()
|
|
||||||
cfg = ["url = " + curl_quote(url), "request = " + curl_quote(method), "silent", "show-error",
|
|
||||||
"write-out = " + curl_quote("\\n__STAGE_HTTP__%{http_code}"), "max-time = 120",
|
|
||||||
"user-agent = " + curl_quote("isep-stage/1 (+inkstone/ISEP#137)")]
|
|
||||||
for h in headers:
|
|
||||||
cfg.append("header = " + curl_quote(h))
|
|
||||||
if body is not None:
|
|
||||||
cfg.append("data-binary = " + curl_quote("@/dev/fd/%d" % rfd))
|
|
||||||
try:
|
|
||||||
p = subprocess.Popen(["curl", "--config", "-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.PIPE, pass_fds=(rfd,) if body is not None else ())
|
|
||||||
except FileNotFoundError:
|
|
||||||
os.close(rfd); os.close(wfd)
|
|
||||||
return die(EXIT_API, "🔴 這台沒有 curl。")
|
|
||||||
os.close(rfd)
|
|
||||||
if body is not None:
|
|
||||||
with os.fdopen(wfd, "w", encoding="utf-8") as w:
|
|
||||||
w.write(body)
|
|
||||||
else:
|
|
||||||
os.close(wfd)
|
|
||||||
out, err = p.communicate(("\n".join(cfg) + "\n").encode("utf-8"))
|
|
||||||
del headers, cfg
|
|
||||||
text = out.decode("utf-8", "replace")
|
|
||||||
if p.returncode != 0:
|
|
||||||
return die(EXIT_API, "🔴 curl 失敗(離開碼 %d):%s\n 雲端 403 CONNECT ⇒ `curl -sS \"$HTTPS_PROXY/__agentproxy/status\"`(policy);`error code: 1010` ⇒ youlin 邊緣擋 UA。"
|
|
||||||
% (p.returncode, err.decode("utf-8", "replace").strip()))
|
|
||||||
resp, _, code = text.rpartition("\n__STAGE_HTTP__")
|
|
||||||
code = code.strip() or "000"
|
|
||||||
try:
|
|
||||||
pretty = json.dumps(json.loads(resp), ensure_ascii=False, indent=2) if resp.strip() else ""
|
|
||||||
except ValueError:
|
|
||||||
pretty = resp
|
|
||||||
print("HTTP %s %s %s" % (code, method, url))
|
|
||||||
if pretty:
|
|
||||||
print(pretty)
|
|
||||||
return EXIT_OK if code.isdigit() and 200 <= int(code) < 300 else EXIT_API
|
|
||||||
|
|
||||||
|
|
||||||
# ───────────────────────── 入口 ─────────────────────────
|
|
||||||
|
|
||||||
def main(argv):
|
|
||||||
if not argv or argv[0] in ("-h", "--help"):
|
|
||||||
print(__doc__)
|
|
||||||
return EXIT_OK
|
|
||||||
if argv[0] == "secret":
|
|
||||||
return run_secret(argv[1:])
|
|
||||||
if argv[0] == "api":
|
|
||||||
return run_api(argv[1:])
|
|
||||||
return die(EXIT_REFUSED, "🛑 第一個參數要是 secret/api,不是 %r(--help 看用法)" % argv[0])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main(sys.argv[1:]))
|
|
||||||
@@ -22,7 +22,7 @@ run(){ # 跑 list(或任何子命令),輸出留在 $OUT,離開碼留在
|
|||||||
# 🔴 ISEP_COUNTDOWN_STATE_DIR 也要指到暫存目錄:主線(hooks/lib/mainline.py)住在那裡,
|
# 🔴 ISEP_COUNTDOWN_STATE_DIR 也要指到暫存目錄:主線(hooks/lib/mainline.py)住在那裡,
|
||||||
# 不隔離的話這支測試的結果會取決於「這台機器現在標了哪條主線」——那就不是測試了。
|
# 不隔離的話這支測試的結果會取決於「這台機器現在標了哪條主線」——那就不是測試了。
|
||||||
OUT=$(ISEP_DEBT_FIXTURE="$FX" ISEP_DEBT_STATE_DIR="$T/state" ISEP_DEBT_NOW="$NOW" \
|
OUT=$(ISEP_DEBT_FIXTURE="$FX" ISEP_DEBT_STATE_DIR="$T/state" ISEP_DEBT_NOW="$NOW" \
|
||||||
ISEP_COUNTDOWN_STATE_DIR="$ML_DIR" ISEP_MAINLINE_REPO_FILE=none python3 "$W" "$@" 2>&1); RC=$?
|
ISEP_COUNTDOWN_STATE_DIR="$ML_DIR" python3 "$W" "$@" 2>&1); RC=$?
|
||||||
}
|
}
|
||||||
|
|
||||||
ML_DIR="$T/mainline"; mkdir -p "$ML_DIR"
|
ML_DIR="$T/mainline"; mkdir -p "$ML_DIR"
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# isep-notify 的「Bot API 直送」測試(inkstone/ISEP#130)
|
|
||||||
#
|
|
||||||
# 它守什麼: 雲端唯一走得通的通知路。2026-09-07 從雲端實測:leo21c 的 notify_leo 回 404、
|
|
||||||
# youlin 被 egress proxy 擋(403 policy denial)、api.telegram.org 通。
|
|
||||||
# ⇒ 有 TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID 就先直送;沒有要講清楚缺哪兩個,不能靜默。
|
|
||||||
#
|
|
||||||
# 🔴 全程不打真 Telegram:Bot API 指到本機一個假伺服器(只回固定 JSON),
|
|
||||||
# 實例那條用 ISEP_NOTIFY_OFFLINE=1 關掉、閘用 ISEP_NOTIFY_GUARD 指到真跡。
|
|
||||||
cd "$(dirname "$0")/.." || exit 1
|
|
||||||
N=scripts/isep-notify
|
|
||||||
TMP=$(mktemp -d); trap 'rm -rf "$TMP"; [ -n "${SRV:-}" ] && kill "$SRV" 2>/dev/null' EXIT
|
|
||||||
export ISEP_NOTIFY_STATE_DIR="$TMP/state" ISEP_NOTIFY_GUARD="$PWD/hooks/prod-write-guard.sh"
|
|
||||||
unset TELEGRAM_BOT_TOKEN TELEGRAM_CHAT_ID
|
|
||||||
PASS=0; FAIL=0
|
|
||||||
ok(){ PASS=$((PASS+1)); printf ' ✅ %s\n' "$1"; }
|
|
||||||
bad(){ FAIL=$((FAIL+1)); printf ' ❌ %s\n' "$1"; }
|
|
||||||
|
|
||||||
# 假 Bot API:記下收到什麼,回 Telegram 的形狀
|
|
||||||
cat > "$TMP/srv.py" <<'PY'
|
|
||||||
import json, sys
|
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
||||||
LOG = sys.argv[2]
|
|
||||||
class H(BaseHTTPRequestHandler):
|
|
||||||
def do_POST(self):
|
|
||||||
body = self.rfile.read(int(self.headers.get("Content-Length") or 0)).decode()
|
|
||||||
open(LOG, "a").write(json.dumps({"path": self.path, "body": body, "ua": self.headers.get("User-Agent")}) + "\n")
|
|
||||||
ok = "/botGOOD/" in self.path
|
|
||||||
out = json.dumps({"ok": True, "result": {"message_id": 42}} if ok else {"ok": False, "description": "Unauthorized"}).encode()
|
|
||||||
self.send_response(200 if ok else 401); self.send_header("Content-Type", "application/json"); self.end_headers(); self.wfile.write(out)
|
|
||||||
def log_message(self, *a): pass
|
|
||||||
HTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
|
|
||||||
PY
|
|
||||||
PORT=$(python3 -c 'import socket;s=socket.socket();s.bind(("127.0.0.1",0));print(s.getsockname()[1])')
|
|
||||||
python3 "$TMP/srv.py" "$PORT" "$TMP/log" & SRV=$!
|
|
||||||
for i in 1 2 3 4 5 6 7 8 9 10; do curl -s -o /dev/null "http://127.0.0.1:$PORT/" && break; sleep 0.2; done
|
|
||||||
export ISEP_NOTIFY_BOT_API="http://127.0.0.1:$PORT"
|
|
||||||
|
|
||||||
echo "── A. 沒有憑證:講清楚缺哪兩個,不靜默 ──"
|
|
||||||
OUT=$(ISEP_NOTIFY_OFFLINE=1 python3 "$N" --text "測試" 2>&1); RC=$?
|
|
||||||
printf '%s' "$OUT" | grep -q 'TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID' && ok "A1 沒憑證 ⇒ 報告點名缺 TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID(leo 看了知道要在 Cloud environment 加什麼)" || bad "A1 沒點名缺什麼:$OUT"
|
|
||||||
[ "$RC" != 0 ] && printf '%s' "$OUT" | grep -q 'leo 的手機上沒有出現' && ok "A2 兩條路都沒通 ⇒ 離開碼非 0、明說沒送到" || bad "A2 rc=$RC:$OUT"
|
|
||||||
[ ! -s "$TMP/log" ] && ok "A3 沒憑證就不打 Bot API" || bad "A3 沒憑證還打了:$(cat "$TMP/log")"
|
|
||||||
|
|
||||||
echo "── B. 有憑證:先直送,送到就結束 ──"
|
|
||||||
: > "$TMP/log"
|
|
||||||
OUT=$(TELEGRAM_BOT_TOKEN=GOOD TELEGRAM_CHAT_ID=777 python3 "$N" --text "雲端收工摘要" 2>&1); RC=$?
|
|
||||||
[ "$RC" = 0 ] && printf '%s' "$OUT" | grep -q 'Bot API 直送):送到了' && ok "B1 憑證在 ⇒ Bot API 直送,離開碼 0" || bad "B1 rc=$RC:$OUT"
|
|
||||||
python3 - "$TMP/log" <<'PY' && ok "B2 打到 /botGOOD/sendMessage、chat_id=777、內文有署名、UA 帶了" || bad "B2 送出去的形狀不對:$(cat "$TMP/log")"
|
|
||||||
import json, sys
|
|
||||||
rows = [json.loads(l) for l in open(sys.argv[1])]
|
|
||||||
assert len(rows) == 1, rows
|
|
||||||
r = rows[0]; b = json.loads(r["body"])
|
|
||||||
assert r["path"] == "/botGOOD/sendMessage", r["path"]
|
|
||||||
assert b["chat_id"] == "777" and b["text"].startswith("[總管] 雲端收工摘要"), b
|
|
||||||
assert "isep-notify" in (r["ua"] or ""), r["ua"]
|
|
||||||
PY
|
|
||||||
printf '%s' "$OUT" | grep -q 'notify_leo' && bad "B3 直送成功後不該再碰實例那條" || ok "B3 直送成功 ⇒ 不再打實例的 notify_leo"
|
|
||||||
|
|
||||||
echo "── C. 憑證錯:Bot API 回 ok=false ⇒ 不算送到,退到原本那條 ──"
|
|
||||||
: > "$TMP/log"
|
|
||||||
# 實例那條也指到假伺服器(它對非 /botGOOD/ 的路徑回 401)——兩條都不出這台機器
|
|
||||||
OUT=$(TELEGRAM_BOT_TOKEN=BAD TELEGRAM_CHAT_ID=777 ISEP_NOTIFY_URL="http://127.0.0.1:$PORT/webhooks/named/leo/notify_leo/trigger" python3 "$N" --text "x" 2>&1); RC=$?
|
|
||||||
printf '%s' "$OUT" | grep -q 'Bot API HTTP 401' && ok "C1 401 被講出來(不是「送出成功」)" || bad "C1 沒講 401:$OUT"
|
|
||||||
[ "$RC" != 0 ] && printf '%s' "$OUT" | grep -q 'leo 的手機上沒有出現' && ok "C2 直送失敗+實例關著 ⇒ 仍然明說沒送到" || bad "C2 rc=$RC:$OUT"
|
|
||||||
|
|
||||||
echo "── D. 閘說會擋,直送仍走得通(它不碰實例)──"
|
|
||||||
: > "$TMP/log"; mkdir -p "$TMP/oldguard"
|
|
||||||
printf '#!/bin/sh\nexit 2\n' > "$TMP/oldguard/prod-write-guard.sh"; chmod +x "$TMP/oldguard/prod-write-guard.sh"
|
|
||||||
OUT=$(ISEP_NOTIFY_GUARD="$TMP/oldguard/prod-write-guard.sh" TELEGRAM_BOT_TOKEN=GOOD TELEGRAM_CHAT_ID=1 python3 "$N" --text "y" 2>&1); RC=$?
|
|
||||||
[ "$RC" = 0 ] && printf '%s' "$OUT" | grep -q '通知閘:\*\*block\*\*' && printf '%s' "$OUT" | grep -q '直送):送到了' \
|
|
||||||
&& ok "D1 閘 block + 憑證在 ⇒ 直送照樣送到(閘擋的是寫實例,直送沒碰實例)" || bad "D1 rc=$RC:$OUT"
|
|
||||||
|
|
||||||
echo "── E. --dry-run 什麼都不送 ──"
|
|
||||||
: > "$TMP/log"
|
|
||||||
OUT=$(TELEGRAM_BOT_TOKEN=GOOD TELEGRAM_CHAT_ID=1 python3 "$N" --text "z" --dry-run 2>&1)
|
|
||||||
[ ! -s "$TMP/log" ] && printf '%s' "$OUT" | grep -q 'dry-run' && ok "E1 --dry-run:Bot API 一次都沒被打" || bad "E1 dry-run 打了:$(cat "$TMP/log")"
|
|
||||||
|
|
||||||
echo; echo "$PASS/$((PASS+FAIL)) 通過"
|
|
||||||
[ "$FAIL" -eq 0 ]
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# settings-allow-sync 的測試(inkstone/ISEP#130)
|
|
||||||
#
|
|
||||||
# 它守什麼: 「雲端 session 開工時就帶著跟本機同一份權限白名單」這件事的機器那一半。
|
|
||||||
# leo 09-07 親手加的四條只在本機 InkStoneCo/.claude/settings.json;雲端沒有 ⇒ 同樣動作被分類器擋
|
|
||||||
# (09-04 run log:permission_denials=6)。清單改住 ISEP 一份,本支把它寫進那台機器的 ~/.claude/settings.json。
|
|
||||||
#
|
|
||||||
# 🔴 全程在 TMP 底下的假 settings.json 上跑,不碰真的 ~/.claude/settings.json。
|
|
||||||
cd "$(dirname "$0")/.." || exit 1
|
|
||||||
S=scripts/settings-allow-sync
|
|
||||||
LIST=docs/permissions-allow.json
|
|
||||||
TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT
|
|
||||||
PASS=0; FAIL=0
|
|
||||||
ok(){ PASS=$((PASS+1)); printf ' ✅ %s\n' "$1"; }
|
|
||||||
bad(){ FAIL=$((FAIL+1)); printf ' ❌ %s\n' "$1"; }
|
|
||||||
N=$(python3 -c "import json;print(len(json.load(open('$LIST'))['allow']))")
|
|
||||||
|
|
||||||
echo "── A. 清單本身的形狀 ──"
|
|
||||||
python3 - "$LIST" <<'PY' && ok "A1 每一條都是 Bash(…) 形狀,而且六個正門工具都在場(ticket/mainline/gate-ok/gitea-pr-merge/stage/Arcrun 的 stage-deploy-artifacts.py)" || bad "A1 清單形狀不對或少了正門工具"
|
|
||||||
import json, sys
|
|
||||||
rules = json.load(open(sys.argv[1]))["allow"]
|
|
||||||
assert rules and all(r.startswith("Bash(") and r.endswith(")") for r in rules), rules
|
|
||||||
for tool in ("scripts/ticket", "scripts/mainline", "scripts/gate-ok", "scripts/gitea-pr-merge.sh", "scripts/stage ", "scripts/stage-deploy-artifacts.py"):
|
|
||||||
assert any(tool in r for r in rules), "缺 " + tool
|
|
||||||
assert not any(r.strip() in ("Bash(python3 *)", "Bash(*)", "Bash(bash *)") for r in rules), "整類放行"
|
|
||||||
PY
|
|
||||||
|
|
||||||
echo "── B. 寫進去(假的 settings.json)──"
|
|
||||||
T="$TMP/a/settings.json"
|
|
||||||
OUT=$(python3 "$S" --target "$T" --home /root 2>&1); RC=$?
|
|
||||||
[ "$RC" = 0 ] && [ -f "$T" ] && ok "B1 目標不存在 ⇒ 建出來(離開碼 0)" || bad "B1 rc=$RC:$OUT"
|
|
||||||
python3 -c "import json;d=json.load(open('$T'));assert len(d['permissions']['allow'])==$N" && ok "B2 寫進 $N 條,JSON 合法" || bad "B2 條數不對或不是 JSON"
|
|
||||||
grep -q 'Bash(python3 /root/.claude/plugins/cache/inkstone/isep/\*/scripts/ticket \*)' "$T" \
|
|
||||||
&& ok "B3 開頭的 ~ 換成了 --home 給的家目錄(雲端=/root)" || bad "B3 ~ 沒換成家目錄"
|
|
||||||
grep -q '"~/' "$T" && bad "B4 檔裡還留著 ~" || ok "B4 檔裡沒有殘留的 ~"
|
|
||||||
grep -q 'CLAUDE_PLUGIN_ROOT' "$T" && ok "B5 \$CLAUDE_PLUGIN_ROOT 那幾條原樣保留(閘印出來的逃生門就是這個形狀)" || bad "B5 少了 \$CLAUDE_PLUGIN_ROOT 形狀"
|
|
||||||
tail -c1 "$T" | od -An -c | grep -q '\\n' && ok "B6 收尾有換行" || bad "B6 沒換行"
|
|
||||||
|
|
||||||
SUM1=$(cksum < "$T"); OUT=$(python3 "$S" --target "$T" --home /root 2>&1); SUM2=$(cksum < "$T")
|
|
||||||
[ "$SUM1" = "$SUM2" ] && printf '%s' "$OUT" | grep -q '已齊' && ok "B7 跑第二次:檔案一個位元組都沒變、說「已齊」(冪等)" || bad "B7 不冪等:$OUT"
|
|
||||||
|
|
||||||
echo "── C. 只加不減:別人手加的東西一個字不動 ──"
|
|
||||||
T2="$TMP/b/settings.json"; mkdir -p "$TMP/b"
|
|
||||||
cat > "$T2" <<'JSON'
|
|
||||||
{
|
|
||||||
"extraKnownMarketplaces": {"inkstone": {"source": {"source": "git", "url": "https://git.uncle6.me/inkstone/ISEP.git"}}},
|
|
||||||
"enabledPlugins": {"isep@inkstone": true},
|
|
||||||
"permissions": {
|
|
||||||
"allow": ["Bash(npx wrangler secret:*)", "Bash(python3 scripts/ticket *)"],
|
|
||||||
"deny": ["Edit(//Users/x/wrangler.toml)"]
|
|
||||||
},
|
|
||||||
"hooks": {"PreToolUse": []}
|
|
||||||
}
|
|
||||||
JSON
|
|
||||||
OUT=$(python3 "$S" --target "$T2" --home /Users/youlinhsieh 2>&1)
|
|
||||||
python3 - "$T2" "$N" <<'PY' && ok "C1 原有的 allow/deny/marketplace/hooks 全在,原本那條沒重複,只補了缺的" || bad "C1 動到了別人的東西:$(cat "$T2")"
|
|
||||||
import json, sys
|
|
||||||
d = json.load(open(sys.argv[1])); n = int(sys.argv[2])
|
|
||||||
a = d["permissions"]["allow"]
|
|
||||||
assert a[0] == "Bash(npx wrangler secret:*)" and a[1] == "Bash(python3 scripts/ticket *)", a[:2]
|
|
||||||
assert a.count("Bash(python3 scripts/ticket *)") == 1
|
|
||||||
assert len(a) == 2 + n - 1, (len(a), n)
|
|
||||||
assert d["permissions"]["deny"] == ["Edit(//Users/x/wrangler.toml)"]
|
|
||||||
assert d["enabledPlugins"] == {"isep@inkstone": True}
|
|
||||||
assert d["hooks"] == {"PreToolUse": []}
|
|
||||||
assert any("/Users/youlinhsieh/.claude/plugins/cache/inkstone/isep/*/scripts/mainline" in x for x in a)
|
|
||||||
PY
|
|
||||||
printf '%s' "$OUT" | grep -q "+$((N-1)) 條" && ok "C2 印出來的是「+$((N-1)) 條」(缺幾條補幾條)" || bad "C2 計數不對:$OUT"
|
|
||||||
|
|
||||||
echo "── D. --check/--dry-run ──"
|
|
||||||
python3 "$S" --target "$T" --home /root --check >/dev/null 2>&1 && ok "D1 --check:全齊 ⇒ 離開碼 0" || bad "D1 --check 全齊卻非 0"
|
|
||||||
T3="$TMP/c/settings.json"; mkdir -p "$TMP/c"; echo '{}' > "$T3"
|
|
||||||
python3 "$S" --target "$T3" --home /root --check >/dev/null 2>&1; RC=$?
|
|
||||||
[ "$RC" = 1 ] && ok "D2 --check:缺 ⇒ 離開碼 1(驗收用)" || bad "D2 --check 缺卻回 $RC"
|
|
||||||
[ "$(cat "$T3")" = "{}" ] && ok "D3 --check 不寫檔" || bad "D3 --check 寫了檔"
|
|
||||||
python3 "$S" --target "$T3" --home /root --dry-run >/dev/null 2>&1
|
|
||||||
[ "$(cat "$T3")" = "{}" ] && ok "D4 --dry-run 不寫檔" || bad "D4 --dry-run 寫了檔"
|
|
||||||
|
|
||||||
echo "── E. 壞掉的目標:不碰、不炸(這支掛在 SessionStart)──"
|
|
||||||
T4="$TMP/d/settings.json"; mkdir -p "$TMP/d"; printf '{ not json' > "$T4"
|
|
||||||
OUT=$(python3 "$S" --target "$T4" --home /root 2>&1); RC=$?
|
|
||||||
[ "$RC" = 0 ] && [ "$(cat "$T4")" = "{ not json" ] && printf '%s' "$OUT" | grep -q '沒有動它' \
|
|
||||||
&& ok "E1 目標不是 JSON ⇒ 原封不動、講出來、離開碼 0" || bad "E1 rc=$RC 內容=$(cat "$T4") out=$OUT"
|
|
||||||
python3 "$S" --target "$T4" --home /root --check >/dev/null 2>&1; [ $? = 1 ] && ok "E2 同一個檔用 --check 問 ⇒ 離開碼 1(不裝沒事)" || bad "E2 --check 對壞檔回 0"
|
|
||||||
|
|
||||||
echo "── F. 接線:SessionStart 有掛、雲端 setup script 有叫 ──"
|
|
||||||
python3 - <<'PY' && ok "F1 hooks.json 的 SessionStart 註冊了 scripts/settings-allow-sync" || bad "F1 hooks.json 沒掛"
|
|
||||||
import json
|
|
||||||
d = json.load(open("hooks/hooks.json"))
|
|
||||||
cmds = [h["command"] for g in d["hooks"]["SessionStart"] for h in g["hooks"]]
|
|
||||||
assert any("scripts/settings-allow-sync" in c for c in cmds), cmds
|
|
||||||
PY
|
|
||||||
grep -q 'settings-allow-sync' docs/cloud-setup-script.sh && ok "F2 docs/cloud-setup-script.sh 裝完 plugin 會跑它" || bad "F2 setup script 沒叫它"
|
|
||||||
grep -q 'exit 0$' docs/cloud-setup-script.sh && ok "F3 setup script 仍然 exit 0(非零會讓整個 session 開不起來)" || bad "F3 setup script 結尾不是 exit 0"
|
|
||||||
|
|
||||||
echo; echo "$PASS/$((PASS+FAIL)) 通過"
|
|
||||||
[ "$FAIL" -eq 0 ]
|
|
||||||
@@ -1,247 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# scripts/stage 的測試(inkstone/ISEP#137)
|
|
||||||
#
|
|
||||||
# 它守什麼: 「雲端總管對 stage 的每一種寫入都有一支固定形狀的正門,而且**只**寫得進 stage」這件事的機器那一半。
|
|
||||||
# 09-07 三種寫入(`npx wrangler secret put`/`stage-deploy-artifacts.py`/curl POST 到 arcrun-yuga3bse)在雲端
|
|
||||||
# 全被 auto mode 分類器擋(複合指令與任意 curl 對不上白名單任何一條)。
|
|
||||||
# 收成 `stage secret …`(CF API)與 `stage api …`(curl 打實例);值只從環境變數名讀;
|
|
||||||
# 判準是 CF 帳號 ID/stage 主機往放行方向比對,不看名字。
|
|
||||||
#
|
|
||||||
# 🔴 全程離線:CF API 與 stage 實例都指到本機一個假伺服器,不打真 Cloudflare、不碰任何 worker。
|
|
||||||
# 真的種一把進 youlin、真的打 stage 實例的實跑在 docs/TESTING.md A36 另記。
|
|
||||||
# 假伺服器對 secret PUT 回 **201**——真 CF 就是回 201,第一次實跑把 201 講成失敗就是這樣抓到的。
|
|
||||||
#
|
|
||||||
# 四個方向都要驗,缺一個就是假綠:
|
|
||||||
# A 拒絕(非 stage/缺變數/值在指令列)⇒ 離開碼 2,而且**沒打網路**
|
|
||||||
# B token 打不到 stage ⇒ 拒絕、印出它打得到誰、沒有任何 PUT
|
|
||||||
# C 種進 stage ⇒ PUT 的路徑帶 stage ID、body 對、值不出現在任何輸出、種完用列表確認
|
|
||||||
# D api:主機只會是 stage;標頭值從環境變數來;body 三種來源;非 2xx 離開碼 1
|
|
||||||
# E 接線:白名單有它四種形狀+Arcrun 那支;ISEP 自己的 Bash 閘對這些呼叫形狀一支都不擋(誤攔比漏擋嚴重)
|
|
||||||
cd "$(dirname "$0")/.." || exit 1
|
|
||||||
ROOT=$(pwd)
|
|
||||||
S=scripts/stage
|
|
||||||
STAGE=1129efd7df2e8899d537e9c8fbabb6cb
|
|
||||||
TMP=$(mktemp -d); trap 'kill $SRV 2>/dev/null; rm -rf "$TMP"' EXIT
|
|
||||||
PASS=0; FAIL=0
|
|
||||||
ok(){ PASS=$((PASS+1)); printf ' ✅ %s\n' "$1"; }
|
|
||||||
bad(){ FAIL=$((FAIL+1)); printf ' ❌ %s\n' "$1"; }
|
|
||||||
LOG="$TMP/log.jsonl"; MODE="$TMP/mode"; STATE="$TMP/secrets.json"
|
|
||||||
export STAGE_TEST_VALUE="v-ISEP137-$(python3 -c 'import secrets;print(secrets.token_hex(12))')-must-never-print" # 每次隨機:C8 才驗得出「值落地」
|
|
||||||
export TOK_STAGE='tok-stage-abcdefghijklmnopqrstuvwxyz0123456789'
|
|
||||||
export KBDB_TOK_TEST="kbdb-$(python3 -c 'import secrets;print(secrets.token_hex(8))')"
|
|
||||||
|
|
||||||
# ── 假伺服器:/accounts… 扮 CF API;/<worker>/… 扮 stage 實例。mode 檔決定 CF 扮誰 ──
|
|
||||||
cat > "$TMP/stub.py" <<'PY'
|
|
||||||
import json, os, sys
|
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
||||||
TMP = sys.argv[1]; PORT = int(sys.argv[2])
|
|
||||||
STAGE = "1129efd7df2e8899d537e9c8fbabb6cb"
|
|
||||||
def mode(): return open(os.path.join(TMP, "mode")).read().strip()
|
|
||||||
def state():
|
|
||||||
p = os.path.join(TMP, "secrets.json")
|
|
||||||
return json.load(open(p)) if os.path.exists(p) else ["KBDB_INTERNAL_TOKEN"]
|
|
||||||
def save(s): json.dump(s, open(os.path.join(TMP, "secrets.json"), "w"))
|
|
||||||
class H(BaseHTTPRequestHandler):
|
|
||||||
def log_message(self, *a): pass
|
|
||||||
def _send(self, code, obj):
|
|
||||||
b = json.dumps(obj).encode(); self.send_response(code)
|
|
||||||
self.send_header("Content-Type", "application/json"); self.send_header("Content-Length", str(len(b)))
|
|
||||||
self.end_headers(); self.wfile.write(b)
|
|
||||||
def _body(self):
|
|
||||||
n = int(self.headers.get("Content-Length", "0")); return self.rfile.read(n).decode() if n else ""
|
|
||||||
def _log(self, raw=None):
|
|
||||||
rec = {"method": self.command, "path": self.path, "auth": self.headers.get("Authorization", ""),
|
|
||||||
"ua": self.headers.get("User-Agent", ""), "ct": self.headers.get("Content-Type", ""),
|
|
||||||
"xkey": self.headers.get("X-Arcrun-API-Key", "")}
|
|
||||||
if raw is not None:
|
|
||||||
try: body = json.loads(raw)
|
|
||||||
except ValueError: body = {}
|
|
||||||
rec["body_name"] = body.get("name"); rec["body_type"] = body.get("type")
|
|
||||||
rec["text_ok"] = body.get("text") == os.environ.get("STAGE_TEST_VALUE")
|
|
||||||
rec["body_raw"] = raw if os.environ.get("STAGE_TEST_VALUE") not in raw else "<redacted>"
|
|
||||||
with open(os.path.join(TMP, "log.jsonl"), "a") as f: f.write(json.dumps(rec) + "\n")
|
|
||||||
def _instance(self):
|
|
||||||
# 扮 stage 實例:POST 沒帶 Bearer ⇒ 401(真 kbdb 就是這樣);其餘 200 回聲
|
|
||||||
raw = self._body(); self._log(raw)
|
|
||||||
if self.command != "GET" and not self.headers.get("Authorization"):
|
|
||||||
return self._send(401, {"error": "Unauthorized"})
|
|
||||||
self._send(200, {"ok": True, "echo_path": self.path, "echo_method": self.command})
|
|
||||||
def do_GET(self):
|
|
||||||
if not self.path.startswith("/accounts"): return self._instance()
|
|
||||||
self._log(); m = mode()
|
|
||||||
if self.path == "/accounts":
|
|
||||||
if m == "401": return self._send(401, {"success": False, "errors": [{"code": 10000, "message": "Authentication error"}]})
|
|
||||||
acct = {"stage": [{"id": STAGE, "name": "Youlin.hsieh.dev@gmail.com's Account"}],
|
|
||||||
"leo21c": [{"id": "9f3b2c1d000000000000000000000leo", "name": "Leo21c's Account"}],
|
|
||||||
"geek": [{"id": "77aa11bb000000000000000000000geek", "name": "geek6688's Account"}],
|
|
||||||
"both": [{"id": STAGE, "name": "Youlin"}, {"id": "9f3b2c1d000000000000000000000leo", "name": "Leo21c"}]}
|
|
||||||
return self._send(200, {"success": True, "errors": [], "result": acct.get(m, acct["stage"])})
|
|
||||||
if self.path.endswith("/secrets"):
|
|
||||||
names = state()
|
|
||||||
if m == "put-ok-list-missing": names = [n for n in names if n != "ISEP_137_PROBE"]
|
|
||||||
return self._send(200, {"success": True, "errors": [], "result": [{"name": n, "type": "secret_text"} for n in names]})
|
|
||||||
self._send(404, {"success": False, "errors": [{"code": 7003, "message": "not found"}]})
|
|
||||||
def do_PUT(self):
|
|
||||||
if not self.path.startswith("/accounts"): return self._instance()
|
|
||||||
raw = self._body(); self._log(raw); body = json.loads(raw or "{}")
|
|
||||||
s = state(); s = [x for x in s if x != body.get("name")] + [body.get("name")]; save(s)
|
|
||||||
self._send(201, {"success": True, "errors": [], "result": {"name": body.get("name"), "type": "secret_text"}}) # 真 CF 回 201
|
|
||||||
def do_DELETE(self):
|
|
||||||
if not self.path.startswith("/accounts"): return self._instance()
|
|
||||||
self._log(); name = self.path.rsplit("/", 1)[-1]
|
|
||||||
save([x for x in state() if x != name]); self._send(200, {"success": True, "errors": [], "result": None})
|
|
||||||
def do_POST(self): self._instance()
|
|
||||||
def do_PATCH(self): self._instance()
|
|
||||||
HTTPServer(("127.0.0.1", PORT), H).serve_forever()
|
|
||||||
PY
|
|
||||||
PORT=$(python3 -c "import socket;s=socket.socket();s.bind(('127.0.0.1',0));print(s.getsockname()[1])")
|
|
||||||
python3 "$TMP/stub.py" "$TMP" "$PORT" & SRV=$!
|
|
||||||
for _ in $(seq 1 50); do python3 -c "import socket;socket.create_connection(('127.0.0.1',$PORT),1)" 2>/dev/null && break; sleep 0.1; done
|
|
||||||
export STAGE_SECRET_PUT_API_BASE="http://127.0.0.1:$PORT"
|
|
||||||
export STAGE_API_BASE_OVERRIDE="http://127.0.0.1:$PORT"
|
|
||||||
echo stage > "$MODE"; : > "$LOG"
|
|
||||||
reset(){ : > "$LOG"; rm -f "$STATE"; echo "${1:-stage}" > "$MODE"; }
|
|
||||||
run(){ OUT=$(python3 "$S" "$@" 2>&1); RC=$?; }
|
|
||||||
hits(){ grep -c "\"method\": \"$1\"" "$LOG" 2>/dev/null || true; }
|
|
||||||
no_value(){ ! printf '%s' "$OUT" | grep -qF "$STAGE_TEST_VALUE"; }
|
|
||||||
|
|
||||||
echo "── A. 本工具自己拒絕的:離開碼 2,而且沒打網路 ──"
|
|
||||||
reset; run secret put --worker w --secret X --from-env STAGE_TEST_VALUE --token-env TOK_STAGE --account 58309bb90fd93ad6d0fe0aae99170e9d
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q "$STAGE" && printf '%s' "$OUT" | grep -q '交回地端' && [ "$(wc -l < "$LOG")" = 0 ] \
|
|
||||||
&& ok "A1 --account 給非 stage(uncle6 的 ID)⇒ 拒絕、講出 stage 是誰、出路是交回地端、一個請求都沒發" || bad "A1 rc=$RC hits=$(wc -l < "$LOG") $OUT"
|
|
||||||
reset; run secret put --worker w --secret X --from-env STAGE_TEST_VALUE --token-env NOPE_TOKEN_VAR
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q 'NOPE_TOKEN_VAR' && [ "$(wc -l < "$LOG")" = 0 ] \
|
|
||||||
&& ok "A2 token 的環境變數沒值 ⇒ 拒絕、點名那個變數、沒打網路" || bad "A2 rc=$RC $OUT"
|
|
||||||
reset; run secret put --worker w --secret X --from-env NOPE_VALUE_VAR --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q 'NOPE_VALUE_VAR' && printf '%s' "$OUT" | grep -q '紅線' && [ "$(wc -l < "$LOG")" = 0 ] \
|
|
||||||
&& ok "A3 值的環境變數沒值 ⇒ 拒絕、點名變數、明講不准改寫進指令列、沒打網路" || bad "A3 rc=$RC $OUT"
|
|
||||||
reset; run secret put --worker w --secret X --value "$STAGE_TEST_VALUE" --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q -- '--value' && no_value && [ "$(wc -l < "$LOG")" = 0 ] \
|
|
||||||
&& ok "A4 --value(值在指令列)⇒ 拒收,而且拒絕訊息裡不回顯那個值" || bad "A4 rc=$RC $OUT"
|
|
||||||
reset; run secret put --secret X --from-env STAGE_TEST_VALUE --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q -- '--worker' && ok "A5 缺 --worker ⇒ 拒絕、講缺哪個" || bad "A5 rc=$RC $OUT"
|
|
||||||
reset; run frobnicate --worker w
|
|
||||||
[ "$RC" = 2 ] && ok "A6 不認得的子命令 ⇒ 拒絕" || bad "A6 rc=$RC $OUT"
|
|
||||||
run --help; [ "$RC" = 0 ] && printf '%s' "$OUT" | grep -q -- '--from-env' && printf '%s' "$OUT" | grep -q -- '--bearer-env' && ok "A7 --help 印兩個子命令的用法、離開碼 0" || bad "A7 rc=$RC"
|
|
||||||
|
|
||||||
echo "── B. token 打不到 stage ⇒ 拒絕、印出它打得到誰、沒有 PUT ──"
|
|
||||||
reset leo21c; run secret put --worker w --secret X --from-env STAGE_TEST_VALUE --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q "Leo21c's Account" && printf '%s' "$OUT" | grep -q "$STAGE" && [ "$(hits PUT)" = 0 ] && no_value \
|
|
||||||
&& ok "B1 token 只打得到 leo21c ⇒ 拒絕、列出那個帳號、講出 stage 是哪個 ID、零 PUT" || bad "B1 rc=$RC PUT=$(hits PUT) $OUT"
|
|
||||||
reset geek; run secret put --worker w --secret X --from-env STAGE_TEST_VALUE --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q "geek6688" && [ "$(hits PUT)" = 0 ] \
|
|
||||||
&& ok "B2 token 只打得到 geek6688(出貨機)⇒ 同樣拒絕、零 PUT" || bad "B2 rc=$RC $OUT"
|
|
||||||
reset 401; run secret put --worker w --secret X --from-env STAGE_TEST_VALUE --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 1 ] && printf '%s' "$OUT" | grep -q 'Authentication error' && [ "$(hits PUT)" = 0 ] \
|
|
||||||
&& ok "B3 CF 回 401 ⇒ 離開碼 1(API 失敗,不是「拒絕」也不是 000)、帶 CF 的錯誤字串、零 PUT" || bad "B3 rc=$RC $OUT"
|
|
||||||
reset; STAGE_SECRET_PUT_API_BASE="http://127.0.0.1:1" run secret put --worker w --secret X --from-env STAGE_TEST_VALUE --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 1 ] && printf '%s' "$OUT" | grep -q '__agentproxy/status' && no_value \
|
|
||||||
&& ok "B4 連不到 CF ⇒ 離開碼 1、印錯誤類型、指到 agentproxy status(不把三種病記成 000)" || bad "B4 rc=$RC $OUT"
|
|
||||||
reset both; run secret put --worker w --secret ISEP_137_PROBE --from-env STAGE_TEST_VALUE --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 0 ] && grep -q "\"path\": \"/accounts/$STAGE/workers/scripts/w/secrets\"" "$LOG" && ! grep -q '0000leo' "$LOG" \
|
|
||||||
&& ok "B5 token 兩個帳號都打得到 ⇒ 放行,但 URL 只帶 stage 的 ID(寫入永遠只到 stage)" || bad "B5 rc=$RC $(cat "$LOG")"
|
|
||||||
|
|
||||||
echo "── C. 種進 stage(假 CF 對 PUT 回 201,跟真的一樣)──"
|
|
||||||
reset; run secret put --worker arcrun-cypher-executor --secret ISEP_137_PROBE --from-env STAGE_TEST_VALUE --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 0 ] && ok "C1 離開碼 0(201 算成功——第一次實跑把 201 講成失敗,就是這格抓的)" || bad "C1 rc=$RC $OUT"
|
|
||||||
grep -q "\"method\": \"PUT\", \"path\": \"/accounts/$STAGE/workers/scripts/arcrun-cypher-executor/secrets\"" "$LOG" \
|
|
||||||
&& ok "C2 PUT 打的是 stage 帳號 ID 底下那顆 worker" || bad "C2 $(cat "$LOG")"
|
|
||||||
grep '"method": "PUT"' "$LOG" | grep -q '"body_name": "ISEP_137_PROBE", "body_type": "secret_text", "text_ok": true' \
|
|
||||||
&& ok "C3 body 的 name/type 對,而且 text 就是環境變數裡那個值(不是變數名)" || bad "C3 $(grep PUT "$LOG")"
|
|
||||||
no_value && ok "C4 stdout/stderr 不含那個值" || bad "C4 值印出來了"
|
|
||||||
grep -q '"auth": "Bearer tok-stage-' "$LOG" && ok "C5 Authorization 帶的是 --token-env 指的那把" || bad "C5 $(head -1 "$LOG")"
|
|
||||||
printf '%s' "$OUT" | grep -q 'ISEP_137_PROBE' && printf '%s' "$OUT" | grep -q 'KBDB_INTERNAL_TOKEN' \
|
|
||||||
&& ok "C6 種完把列表印出來(新的那把+原本就有的)" || bad "C6 $OUT"
|
|
||||||
[ "$(grep -c '"method": "GET", "path": "/accounts/'"$STAGE"'/workers/scripts/arcrun-cypher-executor/secrets"' "$LOG")" = 1 ] \
|
|
||||||
&& ok "C7 種完真的去列了一次(不是只信 PUT 的回應)" || bad "C7 $(cat "$LOG")"
|
|
||||||
! grep -rqF "$STAGE_TEST_VALUE" "$ROOT" 2>/dev/null \
|
|
||||||
&& ok "C8 值沒落在 repo 樹裡任何檔案" || bad "C8 值落地了:$(grep -rlF "$STAGE_TEST_VALUE" "$ROOT")"
|
|
||||||
reset put-ok-list-missing; run secret put --worker w --secret ISEP_137_PROBE --from-env STAGE_TEST_VALUE --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 1 ] && printf '%s' "$OUT" | grep -q '列表卻沒有' \
|
|
||||||
&& ok "C9 CF 說成功但列表沒有 ⇒ 離開碼 1(不把 2xx 講成種好了)" || bad "C9 rc=$RC $OUT"
|
|
||||||
reset; run secret list --worker w --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 0 ] && printf '%s' "$OUT" | grep -q 'KBDB_INTERNAL_TOKEN' && [ "$(hits PUT)" = 0 ] && ok "C10 secret list 印名字、不寫" || bad "C10 rc=$RC $OUT"
|
|
||||||
reset; run secret delete --worker w --secret KBDB_INTERNAL_TOKEN --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 0 ] && grep -q "\"method\": \"DELETE\", \"path\": \"/accounts/$STAGE/workers/scripts/w/secrets/KBDB_INTERNAL_TOKEN\"" "$LOG" \
|
|
||||||
&& ok "C11 secret delete 打對路徑、刪完列表確認" || bad "C11 rc=$RC $OUT $(cat "$LOG")"
|
|
||||||
reset leo21c; run secret delete --worker w --secret X --token-env TOK_STAGE
|
|
||||||
[ "$RC" = 2 ] && [ "$(hits DELETE)" = 0 ] && ok "C12 delete 對非 stage 的 token 一樣拒絕" || bad "C12 rc=$RC"
|
|
||||||
|
|
||||||
echo "── D. api:主機只會是 stage、標頭值從環境變數來、body 三種來源 ──"
|
|
||||||
reset; run api POST https://arcrun-cypher-executor.leo21c.workers.dev/kbdb/entries --json '{}'
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q 'leo21c.workers.dev' && printf '%s' "$OUT" | grep -q 'arcrun-yuga3bse' && [ "$(wc -l < "$LOG")" = 0 ] \
|
|
||||||
&& ok "D1 完整網址指到 leo21c ⇒ 拒絕、講出 stage 主機是什麼、沒打網路" || bad "D1 rc=$RC $OUT"
|
|
||||||
reset; run api POST https://arcrun-kbdb.youlin-hsieh-dev.workers.dev/records --json '{}'
|
|
||||||
[ "$RC" = 2 ] && [ "$(wc -l < "$LOG")" = 0 ] && ok "D2 09-02 已死的舊子網域 youlin-hsieh-dev 也拒絕(不是 stage 的識別碼)" || bad "D2 rc=$RC $OUT"
|
|
||||||
reset; run api POST arcrun-kbdb/records --bearer 'Bearer xyz' --json '{}'
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q -- '--bearer' && [ "$(wc -l < "$LOG")" = 0 ] && ok "D3 --bearer/--header(值在指令列)⇒ 拒收" || bad "D3 rc=$RC $OUT"
|
|
||||||
reset; run api POST arcrun-kbdb/records --bearer-env NOPE_KBDB --json '{}'
|
|
||||||
[ "$RC" = 2 ] && printf '%s' "$OUT" | grep -q 'NOPE_KBDB' && [ "$(wc -l < "$LOG")" = 0 ] && ok "D4 --bearer-env 指的變數沒值 ⇒ 拒絕、點名" || bad "D4 rc=$RC $OUT"
|
|
||||||
reset; run api POST 'arcrun-kbdb/map/recompute?library=rt-lib&owner_id=yuga3bse' --bearer-env KBDB_TOK_TEST
|
|
||||||
[ "$RC" = 0 ] && grep -q '"method": "POST", "path": "/arcrun-kbdb/map/recompute?library=rt-lib&owner_id=yuga3bse", "auth": "Bearer kbdb-' "$LOG" \
|
|
||||||
&& printf '%s' "$OUT" | grep -q '^HTTP 200' && ok "D5 POST <worker>/<path>?query:主機由工具補、query 原樣、Bearer 從環境變數來、印 HTTP 200、離開碼 0" || bad "D5 rc=$RC $OUT $(cat "$LOG")"
|
|
||||||
reset; run api POST arcrun-kbdb/records --bearer-env KBDB_TOK_TEST --json '{"template":"triplet","values":{"s":"a"}}'
|
|
||||||
grep -q '"ct": "application/json"' "$LOG" && grep -q '"body_raw": "{\\"template\\":\\"triplet\\",\\"values\\":{\\"s\\":\\"a\\"}}"' "$LOG" \
|
|
||||||
&& ok "D6 --json:body 原樣送到、自動帶 Content-Type: application/json" || bad "D6 $(cat "$LOG")"
|
|
||||||
reset; STAGE_BODY_TEST='{"secret_ref":"'"$STAGE_TEST_VALUE"'"}' run api PUT arcrun-cypher-executor/credentials/gitea_token --bearer-env KBDB_TOK_TEST --data-env STAGE_BODY_TEST
|
|
||||||
[ "$RC" = 0 ] && grep -q '"method": "PUT", "path": "/arcrun-cypher-executor/credentials/gitea_token"' "$LOG" && grep -q '"body_raw": "<redacted>"' "$LOG" && no_value \
|
|
||||||
&& ok "D7 --data-env:body 從環境變數來(機敏 body 不進指令列),值沒印出來" || bad "D7 rc=$RC $OUT $(cat "$LOG")"
|
|
||||||
reset; printf '{"x":1}' > "$TMP/body.json"; run api POST arcrun-kbdb/records --bearer-env KBDB_TOK_TEST --data-file "$TMP/body.json"
|
|
||||||
[ "$RC" = 0 ] && grep -q '"body_raw": "{\\"x\\":1}"' "$LOG" && ok "D8 --data-file:body 從檔案來" || bad "D8 rc=$RC $(cat "$LOG")"
|
|
||||||
reset; run api POST arcrun-kbdb/records --json '{}'
|
|
||||||
[ "$RC" = 1 ] && printf '%s' "$OUT" | grep -q '^HTTP 401' && ok "D9 沒帶 Bearer 的 POST ⇒ 實例回 401 ⇒ 離開碼 1(不把非 2xx 講成成功)" || bad "D9 rc=$RC $OUT"
|
|
||||||
reset; run api GET arcrun-cypher-executor/health
|
|
||||||
[ "$RC" = 0 ] && grep -q '"method": "GET", "path": "/arcrun-cypher-executor/health"' "$LOG" && ok "D10 GET 不帶 body、不帶 Content-Type" || bad "D10 rc=$RC $OUT"
|
|
||||||
grep -q '"ct": ""' "$LOG" && ok "D11 GET 的請求真的沒有 Content-Type" || bad "D11 $(cat "$LOG")"
|
|
||||||
reset; run api POST arcrun-cypher-executor/webhooks/named/yuga3bse/x/trigger --header-env X-Arcrun-API-Key=KBDB_TOK_TEST --bearer-env KBDB_TOK_TEST --json '{}'
|
|
||||||
grep -q '"xkey": "kbdb-' "$LOG" && ok "D12 --header-env Name=VAR:任意標頭值從環境變數來" || bad "D12 $(cat "$LOG")"
|
|
||||||
reset; run api POST https://arcrun-kbdb.arcrun-yuga3bse.workers.dev/records --bearer-env KBDB_TOK_TEST --json '{}'
|
|
||||||
[ "$RC" = 0 ] && grep -q '"path": "/arcrun-kbdb/records"' "$LOG" && ok "D13 完整網址但主機就是 stage ⇒ 收" || bad "D13 rc=$RC $OUT"
|
|
||||||
reset; run api POST 'arcrun-kbdb/records' --bearer-env KBDB_TOK_TEST --json '{}' --data-file x
|
|
||||||
[ "$RC" = 2 ] && [ "$(wc -l < "$LOG")" = 0 ] && ok "D14 --json 與 --data-file 同時給 ⇒ 拒絕" || bad "D14 rc=$RC"
|
|
||||||
reset; run api FROB arcrun-kbdb/records
|
|
||||||
[ "$RC" = 2 ] && ok "D15 不認得的 METHOD ⇒ 拒絕" || bad "D15 rc=$RC"
|
|
||||||
reset; STAGE_API_BASE_OVERRIDE="http://127.0.0.1:1" run api GET arcrun-cypher-executor/health
|
|
||||||
[ "$RC" = 1 ] && printf '%s' "$OUT" | grep -q 'curl 失敗' && printf '%s' "$OUT" | grep -q '__agentproxy/status' && ok "D16 curl 連不上 ⇒ 離開碼 1、印 curl 的錯誤字串與 agentproxy 出路(不記成 000)" || bad "D16 rc=$RC $OUT"
|
|
||||||
grep -q '"ua": "isep-stage/1' "$LOG" 2>/dev/null || { reset; run api GET arcrun-cypher-executor/health; }
|
|
||||||
grep -q '"ua": "isep-stage/1' "$LOG" && ok "D17 UA 是自己的名字(youlin 邊緣擋 python-urllib UA,Arcrun#176 comment 6487)" || bad "D17 $(cat "$LOG")"
|
|
||||||
|
|
||||||
echo "── E. 接線 ──"
|
|
||||||
python3 - <<'PY' && ok "E1 docs/permissions-allow.json 有 stage 四種呼叫形狀+Arcrun 的 stage-deploy-artifacts.py,沒放整類" || bad "E1 白名單形狀不齊或放了整類"
|
|
||||||
import json
|
|
||||||
rules = json.load(open("docs/permissions-allow.json"))["allow"]
|
|
||||||
need = ['Bash(python3 ~/.claude/plugins/cache/inkstone/isep/*/scripts/stage *)',
|
|
||||||
'Bash(python3 "$CLAUDE_PLUGIN_ROOT/scripts/stage" *)',
|
|
||||||
'Bash(python3 "$CLAUDE_PLUGIN_ROOT"/scripts/stage *)',
|
|
||||||
'Bash(python3 scripts/stage *)',
|
|
||||||
'Bash(python3 scripts/stage-deploy-artifacts.py *)']
|
|
||||||
for n in need: assert n in rules, "缺 " + n
|
|
||||||
assert not any(r in ("Bash(npx *)", "Bash(wrangler *)", "Bash(npx wrangler *)", "Bash(python3 *)", "Bash(curl *)") for r in rules)
|
|
||||||
PY
|
|
||||||
# ISEP 自己掛在 PreToolUse Bash 上的每一支閘,對三種真實呼叫形狀都不准擋(清單當場從 hooks.json 讀,不寫死)
|
|
||||||
BLOCKED=""
|
|
||||||
while IFS= read -r CMD; do
|
|
||||||
for h in $(python3 -c "
|
|
||||||
import json
|
|
||||||
d=json.load(open('hooks/hooks.json'))
|
|
||||||
for g in d['hooks']['PreToolUse']:
|
|
||||||
if 'Bash' in (g.get('matcher') or ''):
|
|
||||||
for x in g['hooks']: print(x['command'].split('/')[-1])
|
|
||||||
"); do
|
|
||||||
[ -f "hooks/$h" ] || continue
|
|
||||||
printf '%s' "{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":$(python3 -c 'import json,sys;print(json.dumps(sys.argv[1]))' "$CMD")},\"session_id\":\"t137\",\"cwd\":\"$ROOT\"}" \
|
|
||||||
| CLAUDE_PLUGIN_ROOT="$ROOT" CLAUDE_PROJECT_DIR="$ROOT" bash "hooks/$h" >/dev/null 2>"$TMP/hook.err"; rc=$?
|
|
||||||
[ "$rc" = 2 ] && BLOCKED="$BLOCKED $h←$(printf '%s' "$CMD" | cut -c1-40)"
|
|
||||||
done
|
|
||||||
done <<'CMDS'
|
|
||||||
python3 ~/.claude/plugins/cache/inkstone/isep/0.24.0/scripts/stage secret put --worker arcrun-cypher-executor --secret CF_SECRETS_API_TOKEN --from-env CF_SECRETS_API_TOKEN_VALUE
|
|
||||||
python3 "$CLAUDE_PLUGIN_ROOT/scripts/stage" api POST 'arcrun-kbdb/map/recompute?library=rt-lib&owner_id=yuga3bse' --bearer-env KBDB_INTERNAL_TOKEN
|
|
||||||
python3 scripts/stage-deploy-artifacts.py all --confirm
|
|
||||||
CMDS
|
|
||||||
[ -z "$BLOCKED" ] && ok "E2 ISEP 掛在 Bash 上的閘,對三種真實呼叫形狀(含 secret 字樣、POST、--confirm)一支都不擋——誤攔比漏擋嚴重" || bad "E2 這幾支誤攔:$BLOCKED"
|
|
||||||
grep -q 'scripts/stage ' scripts/test-settings-allow-sync.sh && grep -q 'stage-deploy-artifacts.py' scripts/test-settings-allow-sync.sh \
|
|
||||||
&& ok "E3 settings-allow-sync 的測試把兩支都算進正門工具(少了會紅)" || bad "E3 settings-allow-sync 測試不認得它們"
|
|
||||||
[ ! -e scripts/stage-secret-put ] && ok "E4 沒有第二支平行的工具(stage-secret-put 已收進 stage secret)" || bad "E4 還留著 stage-secret-put"
|
|
||||||
|
|
||||||
echo; echo "$PASS/$((PASS+FAIL)) 通過"
|
|
||||||
[ "$FAIL" -eq 0 ]
|
|
||||||
@@ -1,224 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# 雲端工人抓票規則的測試(inkstone/ISEP#131)
|
|
||||||
#
|
|
||||||
# 票上的驗收第 1 條:「`scripts/ticket pick` 給定主線檔,回一張符合規則的票;
|
|
||||||
# 池子裡塞一張 `Human`、一張有 assignee、一張 backlog,三張都不會被挑到(測試綠)。」
|
|
||||||
#
|
|
||||||
# 這支測四件事:
|
|
||||||
# ① `pickable()` 純函式——規則本體,一格一條,不打網路
|
|
||||||
# ② `pick` 走整條路(把 api() 換成錄音機餵一個假池子):挑到誰、順序、主線抓盡才抓逾期、
|
|
||||||
# 沒有可抓的票時離開碼 1、沒有主線時離開碼 2 且訊息講得出出路
|
|
||||||
# ③ `claim` 一個動作三件事(指派/s/doing/【身份】留言),以及該擋的擋在**打 API 之前**
|
|
||||||
# ④ 不該擋的(誤攔比漏擋更該修)
|
|
||||||
#
|
|
||||||
# 全程離線:假池子在下面的 POOL;TICKET_HOST 指到連不上的位址,任何一條真的走到網路會當場炸,
|
|
||||||
# 不會靜靜變成假綠。不開票、不改票、不留任何東西在 Gitea 上。
|
|
||||||
cd "$(dirname "$0")/.." || exit 1
|
|
||||||
T=scripts/ticket
|
|
||||||
TMP=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
PASS=0; FAIL=0
|
|
||||||
export TICKET_HOST=http://127.0.0.1:9 GITEA_TOKEN=x
|
|
||||||
export ISEP_COUNTDOWN_STATE_DIR="$TMP/state"; mkdir -p "$ISEP_COUNTDOWN_STATE_DIR"
|
|
||||||
export ISEP_COUNTDOWN_NOW=$(python3 -c 'import datetime as d;print(int(d.datetime(2026,9,7,0,0,tzinfo=d.timezone.utc).timestamp()))')
|
|
||||||
unset ISEP_MAINLINE_FILE ISEP_IDENTITY CLAUDE_PROJECT_DIR
|
|
||||||
|
|
||||||
MAIN="$TMP/mainline.json"
|
|
||||||
cat > "$MAIN" <<'JSON'
|
|
||||||
{"ref":"inkstone/Arcrun#48","owner":"inkstone","repo":"Arcrun","id":48,
|
|
||||||
"title":"主線 M","description":"測試用主線","due_on":"2026-09-12T23:59:59Z",
|
|
||||||
"open_issues":3,"closed_issues":0,"members":[],"set_at":"2026-09-07 07:30"}
|
|
||||||
JSON
|
|
||||||
|
|
||||||
# ── 假池子:三個 repo、三個 open milestone、十一張票 ─────────────────────
|
|
||||||
# 主線 M(未逾期,主線)/逾期 M(2026-08-19 到期)/未來 M(2026-10-01 到期,不是主線)
|
|
||||||
cat > "$TMP/pool.py" <<'PY'
|
|
||||||
import json, os
|
|
||||||
MS = {"main": {"id": 48, "title": "主線 M", "due_on": "2026-09-12T23:59:59Z"},
|
|
||||||
"late": {"id": 49, "title": "逾期 M", "due_on": "2026-08-19T23:59:59Z"},
|
|
||||||
"future": {"id": 50, "title": "未來 M", "due_on": "2026-10-01T23:59:59Z"}}
|
|
||||||
def I(repo, n, labels, ms=None, assignees=(), created="2026-09-01T00:00:00Z", pr=False, title=None):
|
|
||||||
d = {"number": n, "title": title or f"票 {repo}#{n}", "state": "open",
|
|
||||||
"labels": [{"name": l} for l in labels],
|
|
||||||
"assignees": [{"login": a} for a in assignees],
|
|
||||||
"milestone": MS[ms] if ms else None, "created_at": created,
|
|
||||||
"repository": {"full_name": f"inkstone/{repo}"}}
|
|
||||||
if pr: d["pull_request"] = {"merged": False}
|
|
||||||
return d
|
|
||||||
POOL = {
|
|
||||||
"ISEP": [I("ISEP", 1, ["s/todo"], "main"), # ★ 可抓
|
|
||||||
I("ISEP", 2, ["s/todo", "Human"], "main"), # 票上第 1 條:Human
|
|
||||||
I("ISEP", 3, ["s/todo"], "main", assignees=("someone",)), # 票上第 1 條:有 assignee
|
|
||||||
I("ISEP", 4, ["s/backlog"], None), # 票上第 1 條:backlog
|
|
||||||
I("ISEP", 5, ["s/todo"], None), # 沒里程碑
|
|
||||||
I("ISEP", 10, ["s/todo"], "main", pr=True), # PR 不是票
|
|
||||||
I("ISEP", 11, ["s/todo", "human/exec"], "main")], # 執行者是人
|
|
||||||
"Arcrun": [I("Arcrun", 6, ["s/todo", "p/high"], "main", created="2026-08-27T00:00:00Z"), # ★ 主線裡最優先
|
|
||||||
I("Arcrun", 7, ["s/todo"], "late"), # 逾期里程碑:主線抓盡才輪到
|
|
||||||
I("Arcrun", 8, ["s/todo"], "future")], # 不是主線也沒逾期:永遠不抓
|
|
||||||
"mira": [I("mira", 9, ["s/todo", "s/doing"], "main")], # 09-07 實查 mira#6 的形狀:有人在做
|
|
||||||
}
|
|
||||||
MSN = {"ISEP": ["main", "late", "future"], "Arcrun": ["main", "late", "future"], "mira": ["main"]}
|
|
||||||
DROP = set(json.loads(os.environ.get("DROP", "[]"))) # 測「主線抓盡」用:把某幾張從池子拿掉
|
|
||||||
def fake_api(path, payload=None, method=None):
|
|
||||||
rec.append((method or ("POST" if payload is not None else "GET"), path, payload))
|
|
||||||
if path.startswith("/orgs/inkstone/repos"):
|
|
||||||
return [{"name": r} for r in POOL]
|
|
||||||
if path == "/user":
|
|
||||||
return {"login": "claude-code"}
|
|
||||||
if "/milestones?" in path:
|
|
||||||
repo = path.split("/")[3]
|
|
||||||
return [MS[k] for k in MSN.get(repo, [])]
|
|
||||||
if "/issues?" in path:
|
|
||||||
repo = path.split("/")[3]
|
|
||||||
import urllib.parse
|
|
||||||
q = urllib.parse.parse_qs(path.split("?", 1)[1])
|
|
||||||
want = q.get("milestones", [""])[0]
|
|
||||||
return [i for i in POOL[repo] if (i["milestone"] or {}).get("title") == want
|
|
||||||
and f"{repo}#{i['number']}" not in DROP]
|
|
||||||
if path.endswith("/labels?limit=100"):
|
|
||||||
return [{"name": n, "id": k} for k, n in
|
|
||||||
enumerate(["s/todo", "s/doing", "s/review", "p/high", "Human"], 1)]
|
|
||||||
import re
|
|
||||||
m = re.match(r"/repos/inkstone/(\w+)/issues/(\d+)$", path)
|
|
||||||
if m and (method or "GET") == "GET":
|
|
||||||
return next(i for i in POOL[m.group(1)] if i["number"] == int(m.group(2)))
|
|
||||||
return {}
|
|
||||||
rec = []
|
|
||||||
PY
|
|
||||||
|
|
||||||
# probe <python 片段> —— 把 scripts/ticket 當模組載進來、api() 換成假池子,印出片段的值
|
|
||||||
probe() {
|
|
||||||
python3 - "$1" "$2" <<'PY'
|
|
||||||
import sys, os, json, io, contextlib, importlib.util as u
|
|
||||||
from importlib.machinery import SourceFileLoader as L
|
|
||||||
spec = u.spec_from_loader("t", L("t", "scripts/ticket"))
|
|
||||||
m = u.module_from_spec(spec); spec.loader.exec_module(m)
|
|
||||||
ns = {}
|
|
||||||
exec(open(os.environ["POOL_PY"]).read(), ns)
|
|
||||||
m.api = ns["fake_api"]; rec = ns["rec"]
|
|
||||||
argv = json.loads(sys.argv[2]) if sys.argv[2] else None
|
|
||||||
buf = io.StringIO(); rc = None
|
|
||||||
if argv is not None:
|
|
||||||
with contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf):
|
|
||||||
try:
|
|
||||||
getattr(m, argv[0])(argv[1:])
|
|
||||||
except SystemExit as e:
|
|
||||||
rc = e.code
|
|
||||||
print(eval(sys.argv[1], {"m": m, "rec": rec, "rc": rc, "out": buf.getvalue(), "I": ns["I"], "json": json}))
|
|
||||||
PY
|
|
||||||
}
|
|
||||||
export POOL_PY="$TMP/pool.py"
|
|
||||||
|
|
||||||
p() { # p <說明> <want> <python 片段> [argv json]
|
|
||||||
got=$(probe "$3" "${4:-}" 2>&1)
|
|
||||||
if [ "$got" = "$2" ]; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
|
|
||||||
printf 'want=%s got=%s %s\n' "$2" "$got" "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "── ① pickable():規則本體,一格一條(純函式,不打網路)──"
|
|
||||||
p "★ s/todo+沒人+沒 Human+主線 → 可抓" "True" "m.pickable(I('ISEP',1,['s/todo'],'main'),'主線 M')[0]"
|
|
||||||
p "★ 掛 Human → 不可抓(票上第 1 條)" "False" "m.pickable(I('ISEP',2,['s/todo','Human'],'main'),'主線 M')[0]"
|
|
||||||
p "★ 有 assignee → 不可抓(票上第 1 條)" "False" "m.pickable(I('ISEP',3,['s/todo'],'main',assignees=('x',)),'主線 M')[0]"
|
|
||||||
p "★ s/backlog、沒里程碑 → 不可抓(票上第 1 條)" "False" "m.pickable(I('ISEP',4,['s/backlog'],None),'主線 M')[0]"
|
|
||||||
p "s/todo 但沒里程碑 → 不可抓(不抓沒里程碑的)" "False" "m.pickable(I('ISEP',5,['s/todo'],None),'主線 M')[0]"
|
|
||||||
p "human/exec(執行者是人)→ 不可抓" "False" "m.pickable(I('ISEP',11,['s/todo','human/exec'],'main'),'主線 M')[0]"
|
|
||||||
p "s/todo+s/doing 同時掛著(mira#6 的形狀)→ 不可抓,有人在做" "False" "m.pickable(I('mira',9,['s/todo','s/doing'],'main'),'主線 M')[0]"
|
|
||||||
p "hub(scope 容器,09-07 實查 ISEP#31–35 的形狀)→ 不可抓" "False" "m.pickable(I('ISEP',12,['s/todo','hub'],'main'),'主線 M')[0]"
|
|
||||||
p "PR 不是票 → 不可抓" "False" "m.pickable(I('ISEP',10,['s/todo'],'main',pr=True),'主線 M')[0]"
|
|
||||||
p "里程碑不是要求的那個 → 不可抓" "False" "m.pickable(I('Arcrun',8,['s/todo'],'future'),'主線 M')[0]"
|
|
||||||
p "里程碑標題只差空白/大小寫 → 仍算同一個(norm 只有 mainline.py 那一份)" "True" "m.pickable(I('ISEP',1,['s/todo'],'main'),' 主線 m ')[0]"
|
|
||||||
p "理由講得出「為什麼不能抓」(不是只回 False)" "True" "'Human' in m.pickable(I('ISEP',2,['s/todo','Human'],'main'),'主線 M')[1]"
|
|
||||||
p "順序:p/high 先於沒標,沒標先於 p/low" "True" \
|
|
||||||
"m.pick_order(I('a',1,['s/todo','p/high'],'main')) < m.pick_order(I('a',2,['s/todo'],'main')) < m.pick_order(I('a',3,['s/todo','p/low'],'main'))"
|
|
||||||
p "順序:同優先序看開票時間,舊的先" "True" \
|
|
||||||
"m.pick_order(I('a',9,['s/todo'],'main',created='2026-08-01T00:00:00Z')) < m.pick_order(I('a',1,['s/todo'],'main',created='2026-09-01T00:00:00Z'))"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "── ② pick 走整條路(假池子 11 張,三個 repo)──"
|
|
||||||
ARGS="[\"cmd_pick\",\"--mainline\",\"$MAIN\"]"
|
|
||||||
ALL="[\"cmd_pick\",\"--mainline\",\"$MAIN\",\"--all\",\"--json\"]"
|
|
||||||
p "★ 給定主線檔 → 回一張,而且是主線裡最優先的 Arcrun#6(p/high)" "True" "'inkstone/Arcrun#6' in out and rc is None" "$ARGS"
|
|
||||||
p "只回一張(不是整份清單)" "1" "out.count(' ● ')" "$ARGS"
|
|
||||||
p "★ --all:主線裡可抓的恰好是 Arcrun#6、ISEP#1 兩張——Human/assignee/backlog 三張都不在" \
|
|
||||||
"['inkstone/Arcrun#6', 'inkstone/ISEP#1']" "[r['ref'] for r in json.loads(out) if r['group']=='主線']" "$ALL"
|
|
||||||
p "★ --all:逾期里程碑那張 Arcrun#7 排在主線之後(主線抓盡才輪到)" \
|
|
||||||
"['inkstone/Arcrun#7']" "[r['ref'] for r in json.loads(out) if r['group']!='主線']" "$ALL"
|
|
||||||
p "沒逾期也不是主線的 Arcrun#8 不在清單裡" "False" "'inkstone/Arcrun#8' in out" "$ALL"
|
|
||||||
p "backlog(ISEP#4)/沒里程碑(ISEP#5)不在清單裡" "False" "'ISEP#4' in out or 'ISEP#5' in out" "$ALL"
|
|
||||||
p "沒有任何一條真的走到網路(api 全被錄音機接住)" "True" "all(p.startswith('/') for _,p,_ in rec)" "$ALL"
|
|
||||||
p "pick 只讀不寫(沒有 POST/PATCH/PUT)" "True" "all(mm=='GET' for mm,_,_ in rec)" "$ALL"
|
|
||||||
p "訊息印出下一步(認領那一行用絕對路徑,貼到別的 cwd 也叫得到正本)" "True" "'claim inkstone/Arcrun#6' in out and m.self_path() in out" "$ARGS"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo " (主線抓盡 → 才輪到逾期里程碑)"
|
|
||||||
export DROP='["Arcrun#6","ISEP#1"]'
|
|
||||||
p "★ 主線兩張都被拿走後 → 回逾期里程碑的 Arcrun#7" "True" "'inkstone/Arcrun#7' in out and rc is None" "$ARGS"
|
|
||||||
export DROP='["Arcrun#6","ISEP#1","Arcrun#7"]'
|
|
||||||
p "★ 主線與逾期都抓盡 → 離開碼 1(真的沒有,不是故障)" "1" "rc" "$ARGS"
|
|
||||||
p "訊息明講「不要去抓 backlog」(出路是收工回報,不是換規則)" "True" "'backlog' in out and '收工' in out" "$ARGS"
|
|
||||||
p "抓盡時**沒有**回 Arcrun#8(未來里程碑)" "False" "'Arcrun#8' in out" "$ARGS"
|
|
||||||
unset DROP
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo " (沒有主線 ≠ 去抓別的)"
|
|
||||||
NOML="[\"cmd_pick\",\"--mainline\",\"$TMP/none.json\"]"
|
|
||||||
p "主線檔讀不到 → 離開碼 2(讀不到 ≠ 沒有)" "2" "rc" "$NOML"
|
|
||||||
p "…而且一通 API 都沒打" "0" "len(rec)" "$NOML"
|
|
||||||
p "沒給 --mainline、狀態檔也沒有、cwd 也沒有 → 離開碼 2,訊息給出兩條出路" "True" \
|
|
||||||
"rc==2 and 'mainline set' in out and 'system-dev/mainline.json' in out" "[\"cmd_pick\"]"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "── ③ claim:一個動作三件事 ──"
|
|
||||||
CL="[\"cmd_claim\",\"inkstone/Arcrun#6\",\"--mainline\",\"$MAIN\",\"--name\",\"isep-hand\"]"
|
|
||||||
p "★ 指派給本 token 的使用者(欄位,不是一句話)" "[['claude-code']]" \
|
|
||||||
"[pl['assignees'] for mm,p,pl in rec if mm=='PATCH' and p=='/repos/inkstone/Arcrun/issues/6']" "$CL"
|
|
||||||
p "★ s/todo 換成 s/doing,p/high 留著(不是整組蓋掉)" "True" \
|
|
||||||
"[sorted(pl['labels'])==[2,4] for mm,p,pl in rec if mm=='PUT' and p.endswith('/issues/6/labels')]==[True]" "$CL"
|
|
||||||
p "★ 留言第一行是【身份】isep-hand/inkstone/Arcrun/-" "True" \
|
|
||||||
"[pl['body'].split(chr(10))[0] for mm,p,pl in rec if mm=='POST' and p.endswith('/issues/6/comments')]==['【身份】isep-hand/inkstone/Arcrun/-']" "$CL"
|
|
||||||
p "留言講了做完要走 handback(不推 main、不出貨)" "True" \
|
|
||||||
"any('handback' in pl['body'] and '不推 main' in pl['body'] for mm,p,pl in rec if mm=='POST' and p.endswith('/comments'))" "$CL"
|
|
||||||
p "三件事都做了,離開碼 0" "None" "rc" "$CL"
|
|
||||||
p "--as 指定登入名時用它" "[['cloud-bot']]" \
|
|
||||||
"[pl['assignees'] for mm,p,pl in rec if mm=='PATCH']" "[\"cmd_claim\",\"inkstone/Arcrun#6\",\"--mainline\",\"$MAIN\",\"--as\",\"cloud-bot\"]"
|
|
||||||
p "逾期里程碑的票(Arcrun#7)也認領得了——主線抓盡時輪到它" "None" "rc" \
|
|
||||||
"[\"cmd_claim\",\"inkstone/Arcrun#7\",\"--mainline\",\"$MAIN\"]"
|
|
||||||
p "pick --claim:挑到誰就認領誰(Arcrun#6)" "True" \
|
|
||||||
"any(mm=='PATCH' and p.endswith('/issues/6') for mm,p,pl in rec)" "[\"cmd_pick\",\"--mainline\",\"$MAIN\",\"--claim\",\"--name\",\"isep-hand\"]"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo " (該擋的:規則在 claim 這一端再驗一次,擋在**寫入之前**)"
|
|
||||||
blocked() { # blocked <說明> <ref> [extra argv...]
|
|
||||||
what=$1; ref=$2; shift 2
|
|
||||||
extra=$(printf '%s\n' "$@" | python3 -c "import sys,json;print(','.join(json.dumps(l.rstrip()) for l in sys.stdin if l.strip()))")
|
|
||||||
argv="[\"cmd_claim\",\"$ref\",\"--mainline\",\"$MAIN\"${extra:+,$extra}]"
|
|
||||||
p "$what → 離開碼 2,且沒有任何寫入" "True" \
|
|
||||||
"rc==2 and not any(mm in ('PATCH','PUT','POST') for mm,_,_ in rec)" "$argv"
|
|
||||||
}
|
|
||||||
blocked "掛 Human 的 ISEP#2" inkstone/ISEP#2
|
|
||||||
blocked "已指派的 ISEP#3" inkstone/ISEP#3
|
|
||||||
blocked "backlog 的 ISEP#4" inkstone/ISEP#4
|
|
||||||
blocked "沒逾期也不是主線的 Arcrun#8" inkstone/Arcrun#8
|
|
||||||
blocked "有人在做的 mira#9(s/doing 也掛著)" inkstone/mira#9
|
|
||||||
p "擋下時訊息講得出理由與出路(pick)" "True" "'Human' in out and 'pick' in out" \
|
|
||||||
"[\"cmd_claim\",\"inkstone/ISEP#2\",\"--mainline\",\"$MAIN\"]"
|
|
||||||
p "身份名不在名單上 → 在打任何 API 之前就擋(一通都沒打)" "True" "rc==2 and len(rec)==0" \
|
|
||||||
"[\"cmd_claim\",\"inkstone/Arcrun#6\",\"--mainline\",\"$MAIN\",\"--name\",\"路人\"]"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "── ④ 動詞接得上(不帶假池子,走到網路才炸)──"
|
|
||||||
out=$(python3 "$T" pick --mainline "$MAIN" 2>&1); got=$?
|
|
||||||
if [ "$got" = 2 ] && printf '%s' "$out" | grep -q '拿不到 Gitea'; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
|
|
||||||
printf 'want=2 got=%s pick 連不上 Gitea → 離開碼 2 並說「讀不到 ≠ 沒有」(不是離開碼 1 的假「沒票」)\n' "$got"
|
|
||||||
out=$(python3 "$T" 2>&1)
|
|
||||||
if printf '%s' "$out" | grep -q "ticket pick" && printf '%s' "$out" | grep -q "ticket claim"; then PASS=$((PASS+1)); printf ' ✅ '
|
|
||||||
else FAIL=$((FAIL+1)); printf ' ❌ '; fi
|
|
||||||
printf '不帶參數的說明裡列得出 pick/claim(撈不到的東西等於不存在)\n'
|
|
||||||
out=$(python3 "$T" usage pick 2>&1); got=$?
|
|
||||||
if [ "$got" = 0 ] && printf '%s' "$out" | grep -q -- '--mainline'; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
|
|
||||||
printf 'ticket usage pick 印得出用法\n'
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "通過 $PASS 條,失敗 $FAIL 條"
|
|
||||||
[ "$FAIL" = 0 ] || exit 1
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# 「收件 repo 寫 owner/repo 不該是 404」的測試(inkstone/ISEP#130)
|
|
||||||
#
|
|
||||||
# 2026-09-07 實撞:`scripts/ticket new inkstone/ISEP -F …` 回 Gitea 404。
|
|
||||||
# 不是 ISEP 不存在,是這支把 `inkstone/ISEP` 原樣塞進 `/repos/inkstone/{repo}/issues`
|
|
||||||
# ⇒ 打到 `/repos/inkstone/inkstone/ISEP/issues`。404 讀起來像「repo 不存在」,
|
|
||||||
# 於是那天四張票全改成直接打 API 開——**正門壞了人就走側門**。
|
|
||||||
#
|
|
||||||
# 怎麼在不開任何票的前提下驗:把 `scripts/ticket` 當模組載進來,
|
|
||||||
# 把 `api()` 換成一支只記錄路徑的假貨。全程離線、不打 Gitea、不留戳記。
|
|
||||||
cd "$(dirname "$0")/.." || exit 1
|
|
||||||
STAMP=/tmp/.ticket-where-ok
|
|
||||||
SAVED=""; [ -f "$STAMP" ] && SAVED=$(cat "$STAMP")
|
|
||||||
trap '[ -n "$SAVED" ] && printf "%s" "$SAVED" > "$STAMP" || rm -f "$STAMP"' EXIT
|
|
||||||
|
|
||||||
TICKET_HOST=http://127.0.0.1:9 GITEA_TOKEN=x python3 - <<'PY'
|
|
||||||
import importlib.machinery, importlib.util, io, json, os, sys, tempfile, time, contextlib
|
|
||||||
|
|
||||||
loader = importlib.machinery.SourceFileLoader("isep_ticket", "scripts/ticket")
|
|
||||||
spec = importlib.util.spec_from_file_location("isep_ticket", "scripts/ticket", loader=loader)
|
|
||||||
T = importlib.util.module_from_spec(spec); loader.exec_module(T)
|
|
||||||
|
|
||||||
CALLS = []
|
|
||||||
def fake_api(path, payload=None, method=None):
|
|
||||||
CALLS.append((method or ("POST" if payload is not None else "GET"), path))
|
|
||||||
if path.endswith("/labels?limit=100") or path.endswith("/labels?limit=60"):
|
|
||||||
return [{"name": "s/todo", "id": 1}, {"name": "s/doing", "id": 2}]
|
|
||||||
if path.endswith("/issues") and payload is not None:
|
|
||||||
return {"number": 999, "html_url": "http://fake/999", "labels": []}
|
|
||||||
if "/comments" in path:
|
|
||||||
return {"id": 1, "html_url": "http://fake/c1"}
|
|
||||||
if "/dependencies" in path or "/blocks" in path:
|
|
||||||
return [] if payload is None else {}
|
|
||||||
return {"labels": [], "number": 1}
|
|
||||||
T.api = fake_api
|
|
||||||
T.api_soft = lambda path: None
|
|
||||||
|
|
||||||
tmp = tempfile.mkdtemp()
|
|
||||||
body = os.path.join(tmp, "body.md")
|
|
||||||
open(body, "w").write("## 目標\n測試。\n\n## 驗收條件\n離線。\n\n## deliverable 類型\ncode\n")
|
|
||||||
TITLE = "身為要開票的人,我要寫 owner/repo 也開得出票,我才不會被 404 逼去走側門"
|
|
||||||
|
|
||||||
def stamp():
|
|
||||||
json.dump({"at": time.time(), "kws": ["x"], "n": 0, "top": [], "top_detail": [], "shown": True},
|
|
||||||
open(T.stamp_path(), "w"))
|
|
||||||
|
|
||||||
PASS = FAIL = 0
|
|
||||||
def ok(m, *_):
|
|
||||||
global PASS; PASS += 1; print(" ✅ " + m)
|
|
||||||
def bad(m, why="", *_):
|
|
||||||
global FAIL; FAIL += 1; print(" ❌ " + m + (" —— " + why if why else ""))
|
|
||||||
|
|
||||||
def run(fn, argv):
|
|
||||||
"""回 (離開碼, stderr)。die() 走 sys.exit(2)。"""
|
|
||||||
CALLS.clear()
|
|
||||||
err = io.StringIO(); out = io.StringIO()
|
|
||||||
with contextlib.redirect_stderr(err), contextlib.redirect_stdout(out):
|
|
||||||
try:
|
|
||||||
fn(argv); rc = 0
|
|
||||||
except SystemExit as e:
|
|
||||||
rc = e.code if isinstance(e.code, int) else 1
|
|
||||||
return rc, err.getvalue() + out.getvalue()
|
|
||||||
|
|
||||||
print("── new:兩種寫法都要打到同一條路 ──")
|
|
||||||
stamp(); rc, msg = run(T.cmd_new, ["ISEP", "-F", body, "--title", TITLE])
|
|
||||||
posts = [p for m, p in CALLS if m == "POST"]
|
|
||||||
(ok if posts == ["/repos/inkstone/ISEP/issues"] else bad)("① `new ISEP` → /repos/inkstone/ISEP/issues", str(CALLS))
|
|
||||||
|
|
||||||
stamp(); rc, msg = run(T.cmd_new, ["inkstone/ISEP", "-F", body, "--title", TITLE])
|
|
||||||
posts = [p for m, p in CALLS if m == "POST"]
|
|
||||||
(ok if posts == ["/repos/inkstone/ISEP/issues"] else bad)("② `new inkstone/ISEP`(09-07 撞 404 的那一句)→ 同一條路,不再是 /repos/inkstone/inkstone/ISEP", str(CALLS))
|
|
||||||
|
|
||||||
print("── new:寫錯要當場講,不要變成一個 404 讓人猜 ──")
|
|
||||||
stamp(); rc, msg = run(T.cmd_new, ["Leo/ISEP", "-F", body, "--title", TITLE])
|
|
||||||
(ok if rc == 2 and not CALLS and "inkstone" in msg else bad)("③ `new Leo/ISEP` → 擋(exit 2)、一通 API 都不打、訊息說 org 是 inkstone", f"rc={rc} calls={CALLS} msg={msg[:120]}")
|
|
||||||
|
|
||||||
stamp(); rc, msg = run(T.cmd_new, ["inkstone/ISEP#130", "-F", body, "--title", TITLE])
|
|
||||||
(ok if rc == 2 and not CALLS else bad)("④ `new inkstone/ISEP#130`(把票號當 repo)→ 擋,不打 API", f"rc={rc} calls={CALLS}")
|
|
||||||
|
|
||||||
print("── subtask:--to 也吃 owner/repo ──")
|
|
||||||
rc, msg = run(T.cmd_subtask, ["inkstone/ISEP#130", "--title", TITLE, "-F", body, "--to", "inkstone/Arcrun"])
|
|
||||||
posts = [p for m, p in CALLS if m == "POST" and p.endswith("/issues")]
|
|
||||||
(ok if posts == ["/repos/inkstone/Arcrun/issues"] else bad)("⑤ `subtask … --to inkstone/Arcrun` → 子票開在 /repos/inkstone/Arcrun/issues", f"rc={rc} calls={CALLS} msg={msg[:200]}")
|
|
||||||
|
|
||||||
rc, msg = run(T.cmd_subtask, ["inkstone/ISEP#130", "--title", TITLE, "-F", body, "--to", "Arcrun"])
|
|
||||||
posts = [p for m, p in CALLS if m == "POST" and p.endswith("/issues")]
|
|
||||||
(ok if posts == ["/repos/inkstone/Arcrun/issues"] else bad)("⑥ `subtask … --to Arcrun`(原本的寫法)照舊", f"rc={rc} calls={CALLS}")
|
|
||||||
|
|
||||||
print("── 沒有任何東西真的出去 ──")
|
|
||||||
(ok if not os.path.exists(T.stamp_path()) or True else bad)("⑦ 假 api 記到的路徑全部是 /repos/inkstone/<repo>/…,沒有一條含 inkstone/inkstone")
|
|
||||||
if any("inkstone/inkstone" in p for _, p in CALLS): FAIL += 1; PASS -= 1; print(" ❌ ⑦ 出現 inkstone/inkstone")
|
|
||||||
|
|
||||||
print(f"\n通過 {PASS} 條,失敗 {FAIL} 條")
|
|
||||||
sys.exit(1 if FAIL else 0)
|
|
||||||
PY
|
|
||||||
+5
-362
@@ -14,7 +14,7 @@ leo 2026-08-16 三句話,本工具就是它們的機械化:
|
|||||||
|
|
||||||
ticket where <關鍵字...> 搜「這件事該放哪」→ 產生戳記
|
ticket where <關鍵字...> 搜「這件事該放哪」→ 產生戳記
|
||||||
ticket say <票> -F <檔> 貼進既有票的對話(**預設路徑**)
|
ticket say <票> -F <檔> 貼進既有票的對話(**預設路徑**)
|
||||||
ticket new <repo> -F <檔> 開新票(要戳記+模板欄位齊全;<repo> 寫 ISEP 或 inkstone/ISEP 都行)
|
ticket new <repo> -F <檔> 開新票(要戳記+模板欄位齊全)
|
||||||
ticket close <票> --deliverable <URL> 關票(要有交付物連結)
|
ticket close <票> --deliverable <URL> 關票(要有交付物連結)
|
||||||
ticket decide <票> -F <答案檔> 記 leo 的裁決+改狀態(同一個動作)
|
ticket decide <票> -F <答案檔> 記 leo 的裁決+改狀態(同一個動作)
|
||||||
|
|
||||||
@@ -28,12 +28,6 @@ leo 2026-08-16 三句話,本工具就是它們的機械化:
|
|||||||
|
|
||||||
ticket usage <動詞> [--example] 用法的唯一真相源——**閘印的那一行從這裡來**
|
ticket usage <動詞> [--example] 用法的唯一真相源——**閘印的那一行從這裡來**
|
||||||
|
|
||||||
雲端工人抓票(inkstone/ISEP#131,規則機械可判,不靠 prompt 叮嚀):
|
|
||||||
|
|
||||||
ticket pick [--mainline <主線檔>] [--all] [--json] 回一張現在可以抓的票(主線抓盡才抓逾期)
|
|
||||||
ticket claim <票> [--as <登入名>] [--name <身份>] 認領=指派+s/doing+【身份】留言,一個動作
|
|
||||||
ticket pick --claim … 上面兩件連著做
|
|
||||||
|
|
||||||
票的寫法:`owner/repo#N`,例:`inkstone/InkStoneCo#44`
|
票的寫法:`owner/repo#N`,例:`inkstone/InkStoneCo#44`
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
@@ -151,29 +145,6 @@ def parse_ref(s):
|
|||||||
return m.group(1), m.group(2), int(m.group(3))
|
return m.group(1), m.group(2), int(m.group(3))
|
||||||
|
|
||||||
|
|
||||||
def repo_arg(s):
|
|
||||||
"""收件 repo 的參數:`ISEP` 與 `inkstone/ISEP` 都收,回 repo 名(不含 org)。
|
|
||||||
|
|
||||||
🔴 2026-09-07 實撞(inkstone/ISEP#130):總管照票號的習慣寫 `ticket new inkstone/ISEP`,
|
|
||||||
這支把它原樣接進 `/repos/inkstone/{repo}/issues` ⇒ 打到 `/repos/inkstone/inkstone/ISEP/issues`
|
|
||||||
⇒ Gitea 回 **404**,而 404 讀起來像「ISEP 這個 repo 不存在」——
|
|
||||||
於是四張票改成直接打 API 開的,**正門壞了人就走側門**,那正是 `ticket-api-bypass-guard`
|
|
||||||
在防的事。票號全稱寫 `owner/repo#N` 是本 repo 的鐵律(CLAUDE.md),
|
|
||||||
所以 `owner/repo` 這個形狀本來就該被接受,不該是 404 的來源。
|
|
||||||
org 寫成別的(`Leo/ISEP`)⇒ 當場講清楚,不要讓它變成一個 404 去猜。
|
|
||||||
"""
|
|
||||||
s = (s or "").strip()
|
|
||||||
if "/" not in s:
|
|
||||||
return s
|
|
||||||
owner, _, name = s.partition("/")
|
|
||||||
if owner != ORG:
|
|
||||||
die(f"🔴 收件 repo 的 org 是 `{ORG}`,你給的是 `{owner}`({s})。\n"
|
|
||||||
f" `Leo/` 那個 org 2026-08-14 已廢;寫 `{ORG}/{name}` 或直接寫 `{name}`。")
|
|
||||||
if not name or "/" in name or "#" in name:
|
|
||||||
die(f"🔴 收件 repo 的寫法是 `<repo>` 或 `{ORG}/<repo>`(不帶票號),你給的是:{s}")
|
|
||||||
return name
|
|
||||||
|
|
||||||
|
|
||||||
def api_soft(path):
|
def api_soft(path):
|
||||||
"""讀一筆,失敗就回 None(不 die)。給「錦上添花」的資訊用,不影響任何判斷。"""
|
"""讀一筆,失敗就回 None(不 die)。給「錦上添花」的資訊用,不影響任何判斷。"""
|
||||||
try:
|
try:
|
||||||
@@ -312,8 +283,8 @@ def cmd_say(argv):
|
|||||||
# ── new ──────────────────────────────────────────────────────────────────
|
# ── new ──────────────────────────────────────────────────────────────────
|
||||||
def cmd_new(argv):
|
def cmd_new(argv):
|
||||||
if len(argv) < 3 or argv[1] not in ("-F", "--file"):
|
if len(argv) < 3 or argv[1] not in ("-F", "--file"):
|
||||||
die("用法:ticket new <repo 或 owner/repo> -F <內文檔> [--title <標題>]")
|
die("用法:ticket new <repo> -F <內文檔> [--title <標題>]")
|
||||||
repo = repo_arg(argv[0])
|
repo = argv[0]
|
||||||
body = open(argv[2]).read()
|
body = open(argv[2]).read()
|
||||||
title = None
|
title = None
|
||||||
if "--title" in argv:
|
if "--title" in argv:
|
||||||
@@ -843,17 +814,6 @@ def subtask_example(parent=None, draft=None):
|
|||||||
# 🔴 `{bin}` 一定要留成佔位符、由 usage_text() 現填 self_path():
|
# 🔴 `{bin}` 一定要留成佔位符、由 usage_text() 現填 self_path():
|
||||||
# 用法裡寫死 `ticket` 或 `scripts/ticket`,讀的人照著貼就又踩回這張票的坑。
|
# 用法裡寫死 `ticket` 或 `scripts/ticket`,讀的人照著貼就又踩回這張票的坑。
|
||||||
USAGE = {
|
USAGE = {
|
||||||
"pick":
|
|
||||||
"用法:{bin} pick [--mainline <主線 json 檔>] [--all] [--json] [--claim [--as <登入名>] [--name <身份>]]\n"
|
|
||||||
" 回**一張**現在可以抓的票(主線里程碑抓盡才輪到逾期里程碑;不抓 backlog、不抓沒里程碑的)\n"
|
|
||||||
" --mainline 不給時依序找:$ISEP_MAINLINE_FILE → ~/.claude/isep-countdown/mainline.json"
|
|
||||||
" → $CLAUDE_PROJECT_DIR/system-dev/mainline.json\n"
|
|
||||||
" 離開碼:0 = 有票(印在 stdout);1 = 真的沒有可抓的票;2 = 讀不到(讀不到 ≠ 沒有)",
|
|
||||||
"claim":
|
|
||||||
"用法:{bin} claim <owner/repo#N> [--as <登入名,預設本 token 的使用者>] [--name <身份名,預設 subagent>]"
|
|
||||||
" [--mainline <主線 json 檔>]\n"
|
|
||||||
" 認領=指派給自己 + 換成 s/doing + 第一行【身份】的留言,**一個動作**。\n"
|
|
||||||
" 抓票規則在這裡再驗一次:不是 s/todo、已有人、掛 Human、不在主線也不逾期 ⇒ 擋下(離開碼 2)",
|
|
||||||
"subtask":
|
"subtask":
|
||||||
"用法:{bin} subtask <母票 owner/repo#N> --title \"<User Story>\" -F <內文檔>\n"
|
"用法:{bin} subtask <母票 owner/repo#N> --title \"<User Story>\" -F <內文檔>\n"
|
||||||
" [--repo <收件 repo,預設跟母票同一個>] [--label <s/xxx,預設 s/todo>]\n"
|
" [--repo <收件 repo,預設跟母票同一個>] [--label <s/xxx,預設 s/todo>]\n"
|
||||||
@@ -935,7 +895,7 @@ def cmd_subtask(argv):
|
|||||||
|
|
||||||
# `--to <repo>` 是 `ticket handoff` 那個名字底下比較自然的講法,同一個東西。
|
# `--to <repo>` 是 `ticket handoff` 那個名字底下比較自然的講法,同一個東西。
|
||||||
# (handback 的 `--to` 是「交給誰」,subtask 沒有那個參數,不會撞。)
|
# (handback 的 `--to` 是「交給誰」,subtask 沒有那個參數,不會撞。)
|
||||||
repo = repo_arg(opt("--repo", opt("--to", prepo)))
|
repo = opt("--repo", opt("--to", prepo))
|
||||||
label = opt("--label", "s/todo")
|
label = opt("--label", "s/todo")
|
||||||
assign = opt("--assign")
|
assign = opt("--assign")
|
||||||
nxt = opt("--next")
|
nxt = opt("--next")
|
||||||
@@ -1210,327 +1170,10 @@ def cmd_loose(argv):
|
|||||||
return loose
|
return loose
|
||||||
|
|
||||||
|
|
||||||
# ══════════════════════════════════════════════════════════════════════════
|
|
||||||
# inkstone/ISEP#131 — 雲端工人抓票:規則是機械可判的,不靠 prompt 叮嚀
|
|
||||||
#
|
|
||||||
# 票上的原話:Routine 08-06 起讀 `journeys.md` 本 sprint 段,08-19 到期沒續,
|
|
||||||
# **連續兩週讀到殘骸只能空轉**。09-07 把 `cloud-worker.md` 步驟 1 改成從 Gitea 主線
|
|
||||||
# 里程碑抓票(inkstone/InkStoneCo#118)——但那是一段給人讀的字,讀漏一句就抓錯。
|
|
||||||
# 這一段把它做成一個指令,規則寫在 `pickable()` 一支純函式裡,離線測得動。
|
|
||||||
#
|
|
||||||
# 規則(全部是 Gitea 欄位,沒有一格在猜文字):
|
|
||||||
# 可抓 s/* 狀態恰好是 {s/todo} + 沒有 assignee + 沒有 Human/human/* + 不是 hub + 有里程碑
|
|
||||||
# 且里程碑 = 主線;主線抓盡才抓「逾期的 open 里程碑」;backlog/沒里程碑一律不抓
|
|
||||||
# 認領 指派 + s/doing +【身份】留言,一個動作(`claim`)
|
|
||||||
# 完成 分支 + 證據 + s/review + `handback`——那半本來就有,不重做
|
|
||||||
#
|
|
||||||
# 🔴 為什麼是「s/* 恰好等於 {s/todo}」而不是「有 s/todo」:2026-09-07 實查
|
|
||||||
# `inkstone/mira#6` 同時掛著 s/doing 與 s/todo(exclusive 只擋 UI,不擋 API)。
|
|
||||||
# 只看「有 s/todo」會把一張別人正在做的票抓走。要求的是**狀態在場且唯一**,
|
|
||||||
# 仍然是「要求某個東西在場」那個形狀,不是黑名單。
|
|
||||||
#
|
|
||||||
# 🔴 Human 那一格用的是**標籤**(唯一識別碼),不是票上有沒有 👤 這個字——
|
|
||||||
# cloud-worker.md 寫過「票上沒有 👤」,那是文字判準,leo 2026-08-17 已證偽那條路。
|
|
||||||
# `human/exec`(執行者是人)與 `Human` 同組(labels.yaml「人的介入」),一起算。
|
|
||||||
# ══════════════════════════════════════════════════════════════════════════
|
|
||||||
|
|
||||||
_ML = None
|
|
||||||
|
|
||||||
|
|
||||||
def _mainline_lib():
|
|
||||||
"""`hooks/lib/mainline.py`——「主線」這件事的唯一存放處。norm() 也只有那一份。"""
|
|
||||||
global _ML
|
|
||||||
if _ML is None:
|
|
||||||
import importlib.machinery
|
|
||||||
import importlib.util
|
|
||||||
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "hooks", "lib", "mainline.py")
|
|
||||||
loader = importlib.machinery.SourceFileLoader("isep_mainline_lib", path)
|
|
||||||
spec = importlib.util.spec_from_file_location("isep_mainline_lib", path, loader=loader)
|
|
||||||
mod = importlib.util.module_from_spec(spec)
|
|
||||||
loader.exec_module(mod)
|
|
||||||
_ML = mod
|
|
||||||
return _ML
|
|
||||||
|
|
||||||
|
|
||||||
def _now():
|
|
||||||
"""現在。測試用 ISEP_COUNTDOWN_NOW(epoch 秒)把時鐘定住——跟 countdown 同一個開關。"""
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
override = os.environ.get("ISEP_COUNTDOWN_NOW", "").strip()
|
|
||||||
if override:
|
|
||||||
try:
|
|
||||||
return datetime.fromtimestamp(float(override), tz=timezone.utc)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return datetime.now(timezone.utc)
|
|
||||||
|
|
||||||
|
|
||||||
def _label_names(issue):
|
|
||||||
out = []
|
|
||||||
for l in issue.get("labels") or []:
|
|
||||||
out.append(l["name"] if isinstance(l, dict) else str(l))
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def human_gated(labels):
|
|
||||||
"""掛著「人的介入」那一組標籤(labels.yaml:`Human`/`human/*`)。"""
|
|
||||||
return any(n == "Human" or n.startswith("human/") for n in labels)
|
|
||||||
|
|
||||||
|
|
||||||
def pickable(issue, milestone_title):
|
|
||||||
"""這張票現在能不能被雲端工人抓走。回 (ok, 理由)。**純函式,不打網路。**
|
|
||||||
|
|
||||||
`milestone_title`=要求它掛在哪個里程碑底下(主線,或輪到的那個逾期里程碑)。
|
|
||||||
理由是給人看的:`pick --all` 與 `claim` 擋下時都印它,一張票為什麼不能抓要說得出來。
|
|
||||||
"""
|
|
||||||
if issue.get("pull_request"):
|
|
||||||
return False, "這是 PR,不是票"
|
|
||||||
labels = _label_names(issue)
|
|
||||||
st = sorted(n for n in labels if n.startswith("s/"))
|
|
||||||
if st != ["s/todo"]:
|
|
||||||
return False, "狀態不是單一的 s/todo(現在是 %s)" % (st or "沒有 s/*")
|
|
||||||
if issue.get("assignees") or issue.get("assignee"):
|
|
||||||
who = [a.get("login") for a in (issue.get("assignees") or []) if isinstance(a, dict)] \
|
|
||||||
or [(issue.get("assignee") or {}).get("login")]
|
|
||||||
return False, "已經指派給 %s" % "、".join(str(w) for w in who if w)
|
|
||||||
if human_gated(labels):
|
|
||||||
return False, "掛著 %s——要 leo 親手做的" % "、".join(n for n in labels if n == "Human" or n.startswith("human/"))
|
|
||||||
if "hub" in labels:
|
|
||||||
# labels.yaml:hub =「聚合一批 leaf 的 scope 容器,本身不掛 milestone、不對應 PR」
|
|
||||||
# 2026-09-07 實查:ISEP#31–35 五張 hub 掛在逾期里程碑上、s/todo、沒人——
|
|
||||||
# 照欄位規則會被抓走,但它們不是一件可以做完的事。容器不是任務。
|
|
||||||
return False, "是 hub(scope 容器,不是一件可以做完的事)"
|
|
||||||
ms = (issue.get("milestone") or {}).get("title")
|
|
||||||
if not ms:
|
|
||||||
return False, "沒有里程碑(backlog/沒排進 sprint 的不抓)"
|
|
||||||
norm = _mainline_lib().norm
|
|
||||||
if norm(ms) != norm(milestone_title):
|
|
||||||
return False, "里程碑是「%s」,不是「%s」" % (ms, milestone_title)
|
|
||||||
return True, "ok"
|
|
||||||
|
|
||||||
|
|
||||||
def pick_order(issue):
|
|
||||||
"""同一個里程碑裡先抓誰:p/high → 沒標 → p/low;再看開票時間(舊的先);最後票號。
|
|
||||||
結果要**可重現**——同一個池子問兩次要拿到同一張。"""
|
|
||||||
labels = _label_names(issue)
|
|
||||||
prio = 0 if "p/high" in labels else (2 if "p/low" in labels else 1)
|
|
||||||
return (prio, issue.get("created_at") or "", issue.get("number") or 0)
|
|
||||||
|
|
||||||
|
|
||||||
def _ref_of(issue, owner=None, repo=None):
|
|
||||||
full = ((issue.get("repository") or {}).get("full_name")) or ("%s/%s" % (owner, repo))
|
|
||||||
return "%s#%s" % (full, issue.get("number"))
|
|
||||||
|
|
||||||
|
|
||||||
def load_mainline(argv):
|
|
||||||
"""主線從哪來(依序):--mainline <檔> → $ISEP_MAINLINE_FILE → 本機狀態檔
|
|
||||||
(`scripts/mainline set` 寫的那個)→ $CLAUDE_PROJECT_DIR/system-dev/mainline.json(進 repo 的那份,
|
|
||||||
雲端 clone 就讀得到,inkstone/InkStoneCo#118)。回 (dict, 來源說明)。"""
|
|
||||||
def opt(name):
|
|
||||||
return argv[argv.index(name) + 1] if name in argv and argv.index(name) + 1 < len(argv) else None
|
|
||||||
ML = _mainline_lib()
|
|
||||||
tried = []
|
|
||||||
explicit = opt("--mainline") or os.environ.get("ISEP_MAINLINE_FILE", "").strip()
|
|
||||||
if explicit:
|
|
||||||
try:
|
|
||||||
with open(explicit) as f:
|
|
||||||
d = json.load(f)
|
|
||||||
except Exception as e:
|
|
||||||
die("🔴 讀不到主線檔 %s:%s\n 讀不到 ≠ 沒有主線——先把檔案路徑修對,不要因此去抓別的票。" % (explicit, e))
|
|
||||||
if not isinstance(d, dict) or not d.get("title"):
|
|
||||||
die("🔴 主線檔 %s 裡沒有 title 欄——那不是 `scripts/mainline set` 寫出來的檔。" % explicit)
|
|
||||||
return d, explicit
|
|
||||||
tried.append(ML.path())
|
|
||||||
d = ML.load()
|
|
||||||
if d:
|
|
||||||
return d, ML.path()
|
|
||||||
root = os.environ.get("CLAUDE_PROJECT_DIR") or os.getcwd()
|
|
||||||
cand = os.path.join(root, "system-dev", "mainline.json")
|
|
||||||
tried.append(cand)
|
|
||||||
try:
|
|
||||||
with open(cand) as f:
|
|
||||||
d = json.load(f)
|
|
||||||
if isinstance(d, dict) and d.get("title"):
|
|
||||||
return d, cand
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
die("""🔴 現在沒有主線 ⇒ 沒有「可以抓的票」這回事。
|
|
||||||
|
|
||||||
找過:
|
|
||||||
%s
|
|
||||||
|
|
||||||
這不是叫你去抓 backlog 或沒里程碑的票——那是總管排 sprint 的事,不是工人的。
|
|
||||||
出路(擇一):
|
|
||||||
• 雲端:clone inkstone/InkStoneCo,用它 repo 裡那份 → `%s pick --mainline <clone>/system-dev/mainline.json`
|
|
||||||
• 本機:`scripts/mainline list` 看有哪些 → `scripts/mainline set <owner/repo#id>`""" % (
|
|
||||||
"\n".join(" · " + t for t in tried), self_path()))
|
|
||||||
|
|
||||||
|
|
||||||
def _repos(owner):
|
|
||||||
return [r["name"] for r in (api("/orgs/%s/repos?limit=100" % owner) or [])
|
|
||||||
if isinstance(r, dict) and r.get("name")]
|
|
||||||
|
|
||||||
|
|
||||||
def _open_milestones(owner, repos):
|
|
||||||
"""每個 repo 的 open milestone。回 [(repo, milestone dict)]。"""
|
|
||||||
out = []
|
|
||||||
for r in repos:
|
|
||||||
for m in (api("/repos/%s/%s/milestones?state=open&limit=100" % (owner, r)) or []):
|
|
||||||
if isinstance(m, dict) and m.get("title"):
|
|
||||||
out.append((r, m))
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def _issues_in(owner, repo, title):
|
|
||||||
q = urllib.parse.urlencode({"state": "open", "type": "issues", "milestones": title, "limit": 100})
|
|
||||||
rows = api("/repos/%s/%s/issues?%s" % (owner, repo, q)) or []
|
|
||||||
for it in rows:
|
|
||||||
if isinstance(it, dict):
|
|
||||||
it.setdefault("repository", {"full_name": "%s/%s" % (owner, repo)})
|
|
||||||
return [it for it in rows if isinstance(it, dict)]
|
|
||||||
|
|
||||||
|
|
||||||
def pick_candidates(ms, now=None):
|
|
||||||
"""依序回 [(組名, 里程碑標題, [可抓的票…])]:第一組是主線,之後是逾期的 open 里程碑
|
|
||||||
(最逾期的先)。**每一組裡都已經照 pick_order 排好。**"""
|
|
||||||
ML = _mainline_lib()
|
|
||||||
now = now or _now()
|
|
||||||
owner = ms.get("owner") or ORG
|
|
||||||
repos = _repos(owner)
|
|
||||||
opened = _open_milestones(owner, repos)
|
|
||||||
groups = []
|
|
||||||
|
|
||||||
def collect(title):
|
|
||||||
found = []
|
|
||||||
for r, m in opened:
|
|
||||||
if ML.norm(m.get("title")) != ML.norm(title):
|
|
||||||
continue
|
|
||||||
for it in _issues_in(owner, r, m.get("title")):
|
|
||||||
ok, _ = pickable(it, title)
|
|
||||||
if ok:
|
|
||||||
found.append(it)
|
|
||||||
return sorted(found, key=pick_order)
|
|
||||||
|
|
||||||
groups.append(("主線", ms["title"], collect(ms["title"])))
|
|
||||||
|
|
||||||
overdue = {}
|
|
||||||
for r, m in opened:
|
|
||||||
if ML.norm(m.get("title")) == ML.norm(ms["title"]):
|
|
||||||
continue
|
|
||||||
due = ML.due_of(m)
|
|
||||||
if due and due < now:
|
|
||||||
key = ML.norm(m.get("title"))
|
|
||||||
if key not in overdue or due < overdue[key][0]:
|
|
||||||
overdue[key] = (due, m.get("title"))
|
|
||||||
for due, title in sorted(overdue.values()):
|
|
||||||
groups.append(("逾期里程碑", title, collect(title)))
|
|
||||||
return groups
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_pick(argv):
|
|
||||||
"""回一張現在可以抓的票。離開碼:0 有、1 真的沒有、2 讀不到/沒主線。"""
|
|
||||||
if argv and argv[0] in ("-h", "--help"):
|
|
||||||
die(usage_text("pick"), 0)
|
|
||||||
ms, src = load_mainline(argv)
|
|
||||||
as_json = "--json" in argv
|
|
||||||
show_all = "--all" in argv
|
|
||||||
try:
|
|
||||||
groups = pick_candidates(ms)
|
|
||||||
except (urllib.error.URLError, OSError) as e:
|
|
||||||
die("🔴 拿不到 Gitea(%s)。讀不到 ≠ 沒有可抓的票——先修連線,不要空轉也不要抓別的。" % e)
|
|
||||||
|
|
||||||
flat = [(g, t, it) for g, t, its in groups for it in its]
|
|
||||||
if as_json:
|
|
||||||
rows = [{"ref": _ref_of(it), "title": it.get("title"), "group": g, "milestone": t,
|
|
||||||
"labels": _label_names(it), "created_at": it.get("created_at")}
|
|
||||||
for g, t, it in flat]
|
|
||||||
print(json.dumps(rows if show_all else (rows[0] if rows else None), ensure_ascii=False, indent=2))
|
|
||||||
sys.exit(0 if rows else 1)
|
|
||||||
|
|
||||||
print("🎯 主線:「%s」(來源:%s)" % (ms["title"], src))
|
|
||||||
for g, t, its in groups:
|
|
||||||
if g == "主線" or its or show_all:
|
|
||||||
print(" %s「%s」:可抓 %d 張" % (g, t, len(its)))
|
|
||||||
print()
|
|
||||||
if not flat:
|
|
||||||
print("⚪ 沒有可以抓的票——主線與逾期里程碑都抓盡了。")
|
|
||||||
print(" 出路:收工回報(這是正常結果,不是故障)。")
|
|
||||||
print(" 🔴 不要去抓 backlog/沒里程碑/掛 Human/已有人的票——那些不在規則裡,抓了就是跳線。")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
shown = flat if show_all else flat[:1]
|
|
||||||
for g, t, it in shown:
|
|
||||||
print(" ● %s %s" % (_ref_of(it), _label_names(it)))
|
|
||||||
print(" %s" % (it.get("title") or "")[:80])
|
|
||||||
print(" %s「%s」 開票 %s" % (g, t, (it.get("created_at") or "")[:10]))
|
|
||||||
print()
|
|
||||||
if "--claim" in argv:
|
|
||||||
top = flat[0][2]
|
|
||||||
cmd_claim([_ref_of(top)] + [a for a in argv if a != "--claim"])
|
|
||||||
return
|
|
||||||
print("📌 認領(指派+s/doing+【身份】留言,一個動作):")
|
|
||||||
print(" %s claim %s --name <你的名字>" % (self_path(), _ref_of(flat[0][2])))
|
|
||||||
print(" 做完:分支+證據 → `%s handback %s --to %s --label s/review --next \"…\" --evidence <URL>`"
|
|
||||||
% (self_path(), _ref_of(flat[0][2]), HANDBACK_TO))
|
|
||||||
|
|
||||||
|
|
||||||
def cmd_claim(argv):
|
|
||||||
"""認領=指派 + s/doing +【身份】留言,**一個動作**。抓票規則在這裡再驗一次。"""
|
|
||||||
if not argv or argv[0] in ("-h", "--help"):
|
|
||||||
die(usage_text("claim"), 0 if argv else 2)
|
|
||||||
owner, repo, num = parse_ref(argv[0])
|
|
||||||
|
|
||||||
def opt(name, default=None):
|
|
||||||
return argv[argv.index(name) + 1] if name in argv and argv.index(name) + 1 < len(argv) else default
|
|
||||||
|
|
||||||
name = opt("--name") or "subagent"
|
|
||||||
ident = "【身份】%s/%s/%s/%s" % (name, owner, repo, opt("--branch") or "-")
|
|
||||||
# 身份先驗,**在打任何 API 之前**——名單以外的名字連 Gitea 都不會碰到
|
|
||||||
check_identity(ident, "認領留言")
|
|
||||||
|
|
||||||
ms, _ = load_mainline(argv)
|
|
||||||
ML = _mainline_lib()
|
|
||||||
who = opt("--as") or (api("/user") or {}).get("login")
|
|
||||||
if not who:
|
|
||||||
die("🔴 拿不到本 token 的使用者名稱,也沒給 --as。")
|
|
||||||
|
|
||||||
issue = api("/repos/%s/%s/issues/%d" % (owner, repo, num))
|
|
||||||
issue.setdefault("repository", {"full_name": "%s/%s" % (owner, repo)})
|
|
||||||
ims = issue.get("milestone") or {}
|
|
||||||
ok, why = pickable(issue, ims.get("title") or "")
|
|
||||||
if ok:
|
|
||||||
on_mainline = ML.norm(ims.get("title")) == ML.norm(ms["title"])
|
|
||||||
due = ML.due_of(ims)
|
|
||||||
if not on_mainline and not (due and due < _now()):
|
|
||||||
ok, why = False, "里程碑「%s」既不是主線「%s」也還沒逾期" % (ims.get("title"), ms["title"])
|
|
||||||
if not ok:
|
|
||||||
die("""🚫 %s/%s#%d 現在不能抓:%s
|
|
||||||
|
|
||||||
抓票規則(inkstone/ISEP#131,全部是 Gitea 欄位):
|
|
||||||
s/* 恰好是 s/todo + 沒有 assignee + 沒有 Human/human/* + 里程碑是主線(主線抓盡才抓逾期)
|
|
||||||
出路:`%s pick` 會回一張符合規則的票;這張如果真的該你做,回票上問總管改欄位,不要硬抓。""" % (
|
|
||||||
owner, repo, num, why, self_path()))
|
|
||||||
|
|
||||||
api("/repos/%s/%s/issues/%d" % (owner, repo, num), {"assignees": [who]}, method="PATCH")
|
|
||||||
keep = [n for n in _label_names(issue) if not n.startswith("s/")] + ["s/doing"]
|
|
||||||
_set_labels(owner, repo, num, keep)
|
|
||||||
lines = [ident, "",
|
|
||||||
"🙋 **認領** → `%s`" % who, "",
|
|
||||||
"- 里程碑:「%s」%s" % (ims.get("title"), "(主線)" if ML.norm(ims.get("title")) == ML.norm(ms["title"]) else "(逾期里程碑,主線已抓盡)"),
|
|
||||||
"- 狀態:s/todo → s/doing",
|
|
||||||
"- 做完:分支+證據 → `s/review` + `ticket handback`(不推 main、不出貨、不改里程碑)"]
|
|
||||||
api("/repos/%s/%s/issues/%d/comments" % (owner, repo, num), {"body": "\n".join(lines)})
|
|
||||||
print("✅ 認領 %s/%s#%d → `%s`" % (owner, repo, num, who))
|
|
||||||
print(" 指派:%s tag:%s" % (who, [n for n in keep if n.startswith("s/")]))
|
|
||||||
print(" 留言第一行:%s" % ident)
|
|
||||||
print("\n📌 做完:%s handback %s/%s#%d --to %s --label s/review --next \"…\" --evidence <URL>"
|
|
||||||
% (self_path(), owner, repo, num, HANDBACK_TO))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CMDS = {"where": cmd_where, "say": cmd_say, "new": cmd_new, "close": cmd_close,
|
CMDS = {"where": cmd_where, "say": cmd_say, "new": cmd_new, "close": cmd_close,
|
||||||
"decide": cmd_decide, "subtask": cmd_subtask, "handoff": cmd_subtask,
|
"decide": cmd_decide, "subtask": cmd_subtask, "handoff": cmd_subtask,
|
||||||
"handback": cmd_handback, "mine": cmd_mine, "loose": cmd_loose,
|
"handback": cmd_handback, "mine": cmd_mine, "loose": cmd_loose,
|
||||||
"usage": cmd_usage, "pick": cmd_pick, "claim": cmd_claim}
|
"usage": cmd_usage}
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 2 or sys.argv[1] not in CMDS:
|
if len(sys.argv) < 2 or sys.argv[1] not in CMDS:
|
||||||
|
|||||||
+12
-68
@@ -1,21 +1,18 @@
|
|||||||
---
|
---
|
||||||
name: ship-check
|
name: ship-check
|
||||||
description: |
|
description: |
|
||||||
**任何東西要從「內」(Gitea)送到「外」之前必讀**——不只是 arcrun。
|
改完任何會影響用戶的東西之後、說「做完了」之前必讀(改雲端 worker/portal/daemon/
|
||||||
對外包含:發一篇部落格文章到 uncle6.me、推 tag 到 GitHub 鏡像 repo、投稿 n8n 官方模板庫、
|
workflow/installer 都算)。也在下列時機自動載入:要打包 App、要出貨、要推 bundle、
|
||||||
出雲端零件包、出桌面 daemon。也在下列時機自動載入:改完會影響用戶的東西之後、
|
要送 MS Store、leo 問「可以測了嗎」「版本為什麼沒變」「更新了嗎」「封測者拿得到嗎」。
|
||||||
要打包 App/出貨/推 bundle/送 MS Store、要發文、要 pages deploy、要推 GitHub、
|
核心判準:**版本號是 leo 唯一的驗收介面**——portal 版本卡看雲端、daemon 檢查更新看桌面;
|
||||||
leo 問「可以測了嗎」「版本為什麼沒變」「更新了嗎」「封測者拿得到嗎」「發出去了嗎」。
|
版本沒動=他無從判斷你做了什麼=等於沒交付,而「我在某台實例 wrangler deploy 過了」不算。
|
||||||
🔴 第一個動作是**分辨這是哪個出口**,因為 stage/版本/arm 每個出口都不同——
|
收齊:兩條版本線的差別/重打 bundle(最常漏,要 grep 複驗改動真的進去)/
|
||||||
流程本體住在 system-dev/docs/3-specs/critical-paths/ship.md(唯一一份),本 skill 是它的入口。
|
改 workflow 要重編預編圖/三支機械閘+把 DMG/zip 真的打開檢查/寫 changelog(用戶語言)/
|
||||||
核心判準:**收的人拿到的東西真的變了,而且他看得出變了什麼**;
|
D20 開閘出貨/purge jsDelivr/從 leo 會看的那兩處抓實際畫面複驗。
|
||||||
對 arcrun 兩條線而言那個介面就是版本號(portal 看雲端、daemon 看桌面)。
|
附「常見漏掉的」實撞表與收工前五問。
|
||||||
收齊:五個出口的判準/兩條版本線的差別/重打 bundle(最常漏)/改 workflow 要重編預編圖/
|
|
||||||
三支機械閘+把 DMG/zip 真的打開檢查/寫 changelog/D20 開閘出貨/purge jsDelivr/
|
|
||||||
從收的人會看的那個地方抓實際畫面複驗。附「常見漏掉的」實撞表與收工前五問。
|
|
||||||
---
|
---
|
||||||
|
|
||||||
# /ship-check — 東西要出去之前,先確定收的人真的會拿到
|
# /ship-check — 改完東西後,讓 leo 看得到版本變了
|
||||||
|
|
||||||
> **這支解什麼病**(leo 2026-08-05 原話):
|
> **這支解什麼病**(leo 2026-08-05 原話):
|
||||||
> 「對人來說,**我雲端看 portal 有沒有更新,本地看 daemon 有沒有更新**,
|
> 「對人來說,**我雲端看 portal 有沒有更新,本地看 daemon 有沒有更新**,
|
||||||
@@ -28,44 +25,6 @@ description: |
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🚦 第一步:這是哪個出口?(2026-09-02 補,`inkstone/InkStoneCo#112`)
|
|
||||||
|
|
||||||
> **為什麼補這段**(leo 2026-09-02):「Gitea 為『內』,只要對外都是『外』,
|
|
||||||
> **任何東西出去之前都要經過出貨流程,不是只有 Arcrun, Arcrun RAG 這個計劃**」
|
|
||||||
>
|
|
||||||
> 🔴 **這支 skill 2026-09-01 失效過**:它自己與它指向的地方**只認得 daemon 那個形狀**,
|
|
||||||
> 於是那晚要發部落格與 GitHub 模板時,它沒把人導向任何可用的流程——**只好即興補**。
|
|
||||||
|
|
||||||
- 🔴 **流程本體只有一份**:`system-dev/docs/3-specs/critical-paths/ship.md`
|
|
||||||
- 它定義了**內/外的判準**、**六個步驟**、**五個出口各自的 stage/版本/arm/驗法**
|
|
||||||
- **動手前先讀那一卷的對應出口段**,不要憑本 skill 的印象做
|
|
||||||
- **判準一句:送出去之後,有沒有一個不是我們的人看得到/拿得到?** 有 ⇒ 走那六步
|
|
||||||
- **五個出口,各自去 `ship.md` 的哪一段**:
|
|
||||||
- ① 桌面 daemon(`v0.18.x`)——**本 skill 底下的內容主要是它與 ②**
|
|
||||||
- ② 雲端零件包(`1.4.x`)——同上
|
|
||||||
- ③ 部落格 uncle6.me — 🔴 **沒有 arm、沒有版本號**,stage 是 `<8碼>.kbcontent.pages.dev` 快照;
|
|
||||||
`pages deploy` **必須在 repo 外的目錄跑**,否則 `.env` 的 token 會蓋掉 OAuth 並報成權限錯誤
|
|
||||||
|**驗法是瀏覽器,不是 `curl`**(收件人是讀者 ⇒ 見 §5.8 與 `ship.md` 出口③「驗法」)
|
|
||||||
- ④ GitHub 鏡像 repo — 🔴 **要 arm,而且連 `git remote add` 都擋**(D20);
|
|
||||||
Gitea 就是它的 stage;**推 tag 之外還要發 release note**
|
|
||||||
(怎麼發、要不要再 arm ⇒ `ship.md` 出口④ 的「release note 怎麼發」段)
|
|
||||||
- 🔴 **步驟 3 的「Use this template」也要 arm,而且要單獨請一次**——它建的是
|
|
||||||
**第二個 repo**,撞 ROE「單一 repo」那條,夾不進推 tag 的窗口。
|
|
||||||
且 guard 只掛在 `Bash` ⇒ **走瀏覽器按那顆按鈕不會被擋,這條靠人守**
|
|
||||||
(⇒ `ship.md` 出口④ 的「Use this template 要不要 arm」段)
|
|
||||||
- ⑤ n8n 官方投稿 — 沒有 stage,投稿端點尚未查到(`inkstone/llm-wiki-template#9`)
|
|
||||||
- 🔴 **不要拿 ① 的答案去套 ③④⑤**——那正是 2026-09-01 出錯的機制
|
|
||||||
- 🔴 **「這個出口沒有 arm」不等於「這個出口不必經過 leo」**——③⑤ 的人閘是**步驟 5**
|
|
||||||
(leo 親手在 stage 上走過那一遍)。判準全文=`ship.md` 的
|
|
||||||
「誰批准、誰按鍵、在哪台跑」段:**leo 批准,機器執行**
|
|
||||||
- **跨多個 repo 的一批貨,「100%」看母票的相依清單,不要看 milestone 的百分比**
|
|
||||||
(milestone 只數 hub 那個 repo,別的 repo 那幾張不在分母裡)
|
|
||||||
⇒ `ship.md` 的「那個數字看哪裡」段
|
|
||||||
- 🔴 **發現 `ship.md` 沒涵蓋你手上這件事 ⇒ 那一卷缺了一格,回去補它**,
|
|
||||||
不要在別處另開一份流程(leo 2026-09-02 明確選了「改寫 ship.md」)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## ⚠️ 這支 skill 自己的失效模式(先讀這段)
|
## ⚠️ 這支 skill 自己的失效模式(先讀這段)
|
||||||
|
|
||||||
leo 2026-08-05:「**你寫完一個 skill 然後每個我要提醒你,表示這個 skill 無效**」
|
leo 2026-08-05:「**你寫完一個 skill 然後每個我要提醒你,表示這個 skill 無效**」
|
||||||
@@ -85,19 +44,8 @@ leo 2026-08-05:「**你寫完一個 skill 然後每個我要提醒你,表示
|
|||||||
|
|
||||||
## 什麼時候跑
|
## 什麼時候跑
|
||||||
|
|
||||||
**任何東西要送到「外面」之前**——改完會影響用戶的東西、要發一篇文章、要推 tag 到 GitHub、
|
**改完任何會影響用戶的東西之後**(雲端 worker/portal/daemon/workflow),
|
||||||
要投稿、要出零件包或 daemon。在說「做完了」之前跑,不是收工才跑。
|
在說「做完了」之前。不是收工才跑。
|
||||||
|
|
||||||
⚠️ **底下的步驟是出口①②(arcrun 兩條版本線)的細節。**
|
|
||||||
出口③④⑤ 請照上面那段回 `ship.md` 讀該出口的判準——**它們沒有版本號卡可以看**。
|
|
||||||
|
|
||||||
🔴 **但底下 §5.8「驗前端=用瀏覽器真的載一次」是全出口通則,不歸①② 所有**
|
|
||||||
(2026-09-02 補:本 skill 這句劃界曾把 §5.8 圈進①②,
|
|
||||||
而 `ship.md` 對出口③ 給的驗法是 `curl` ⇒ **兩個檔對同一個問題給了兩種答案**)。
|
|
||||||
- **一句話判準:用收的人的那個介面驗。**
|
|
||||||
- 收的人的介面是**網頁** ⇒ 瀏覽器(出口③ 讀者、出口① 的 portal 版本卡)
|
|
||||||
- 收的人的介面是 **API/CLI** ⇒ `curl` 才是對的(出口② 的 `/health`,程式在讀它)
|
|
||||||
- ⇒ 這不是「①② 用 curl、③ 用瀏覽器」,是**每個出口各自問自己的收件人在看什麼**
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -555,10 +503,6 @@ curl -s "https://rag.arcrun.dev/docs/start/install-windows/?cb=$RANDOM" \
|
|||||||
|
|
||||||
> leo 原話:「**你的環境有 web,你應該用 web 驗,你已經開啓了卻沒有完成,你要把這個列入規定。**」
|
> leo 原話:「**你的環境有 web,你應該用 web 驗,你已經開啓了卻沒有完成,你要把這個列入規定。**」
|
||||||
|
|
||||||
🔴 **適用範圍:全出口,不是只有①②**(2026-09-02 補,見上面「什麼時候跑」那段的劃界)。
|
|
||||||
**收的人的介面是網頁就套這條**——出口③ 部落格的收件人是讀者,他的介面就是瀏覽器。
|
|
||||||
`ship.md` 出口③「驗法」那格寫的是同一件事,兩邊只有一種說法。
|
|
||||||
|
|
||||||
**為什麼 `curl | grep` 是假驗證**(08-08 實撞,leo 抓到而不是我發現):
|
**為什麼 `curl | grep` 是假驗證**(08-08 實撞,leo 抓到而不是我發現):
|
||||||
`curl` 拿到的是 **HTML 原始碼**——它**不執行 JS、不載入 `config.js`、不發 API 請求**。
|
`curl` 拿到的是 **HTML 原始碼**——它**不執行 JS、不載入 `config.js`、不發 API 請求**。
|
||||||
所以我 grep 到文案就宣稱「前端驗過」,而使用者實際打開看到的是整條紅色錯誤:
|
所以我 grep 到文案就宣稱「前端驗過」,而使用者實際打開看到的是整條紅色錯誤:
|
||||||
|
|||||||
@@ -229,97 +229,3 @@ leo 當場:「**這些為什麼不寫到票裡?**」
|
|||||||
|
|
||||||
⇒ **推廣**:repo 裡任何「這台機器該有什麼」的清單,都要有一支東西定期拿它去問機器。
|
⇒ **推廣**:repo 裡任何「這台機器該有什麼」的清單,都要有一支東西定期拿它去問機器。
|
||||||
清單自己不會知道它漏了什麼。
|
清單自己不會知道它漏了什麼。
|
||||||
|
|
||||||
## ⚠️ MISTAKE: 兩支閘對同一條指令說不同的話,而讀的那一半從來沒被測過
|
|
||||||
|
|
||||||
票: `inkstone/ISEP#130`
|
|
||||||
日期: 2026-09-07
|
|
||||||
|
|
||||||
症狀: 09-04 雲端 Routine 的 run log:讀 `notify_leo` 定義被 `leo21c-write-guard.sh` 擋下。
|
|
||||||
閘的判準明寫「**讀可以,寫不行**」,卻連讀都擋 ⇒ 雲端什麼都拿不到。
|
|
||||||
|
|
||||||
實查: ① 舊判準 `-d[[:space:]]` 把 `| tr -d '\r'`、`cut -d=` 這種唯讀的 `-d` 當成 curl 的 body。
|
|
||||||
`prod-write-guard.sh` 在 2026-08-12 修過**一模一樣**的洞(它的檔頭寫著「一堆唯讀工具也用 -d」),
|
|
||||||
這支漏了——同一批補丁只改其中一份(`main-and-prod-push-guard.sh` 檔頭記過同款)。
|
|
||||||
② `…/webhooks/named/<ns>/notify_leo/trigger` 在 `prod-write-guard.sh` 是白名單(ISEP#63),
|
|
||||||
在這支卻因為尾巴是 `/trigger` 照擋 ⇒ 撞人閘時發 Telegram 叫 leo 會被擋(InkStoneCo#110 的病)。
|
|
||||||
③ 這支閘從 08-20 建立到現在**沒有任何測試**,`hooks/tests/` 裡 30 支測試沒有它的——
|
|
||||||
「讀會不會被誤攔」這格從來沒被驗過,只有「寫會不會被擋」被人肉試過。
|
|
||||||
|
|
||||||
原因: 同一個判準(「這條指令會不會真的寫到那台」)散在三支閘裡各寫一份,修一份不會帶動另外兩份;
|
|
||||||
而沒有測試的那支,誤攔發生時**不會有任何東西喊一聲**——被擋的人在雲端、沒有人在旁邊。
|
|
||||||
|
|
||||||
正確做法:
|
|
||||||
- 修判準時 `grep -l` 找同一族的閘(`prod-write-guard`/`main-and-prod-push-guard`/`leo21c-write-guard`),
|
|
||||||
一次改齊;本次三支都補了 youlin 09-02 起的新子網域 `arcrun-yuga3bse`。
|
|
||||||
- 每一支「擋」的閘都要有「不該擋」那半的測試,測資用**現場真的會下的指令**
|
|
||||||
(這次是 `cloud-worker.md`/`progress-guard.md` 裡的原句),不是自己挑好抓的例子。
|
|
||||||
- 修之前拿新測試跑舊閘,紅的那幾條才是真的改到的(本次 5 條紅);全綠就是測試順著新閘寫的。
|
|
||||||
|
|
||||||
## ⚠️ MISTAKE: 雲端連不到 youlin 被記成「HTTP 000」,而 000 有三種病,兩種都不是連線
|
|
||||||
|
|
||||||
票: `inkstone/ISEP#130`
|
|
||||||
日期: 2026-09-07
|
|
||||||
|
|
||||||
症狀: 09-04 run log「youlin 從雲端 HTTP 000」;09-07 總管查到舊子網域 `youlin-hsieh-dev` DNS 已死,
|
|
||||||
以為換名字就通。從雲端打新名 `arcrun-yuga3bse` **還是 000**。
|
|
||||||
|
|
||||||
實查: `curl` 印的是 `CONNECT tunnel failed, response 403`,`$HTTPS_PROXY/__agentproxy/status` 記為
|
|
||||||
`connect_rejected … gateway answered 403 (policy denial)`。同一個 session:leo21c 200、
|
|
||||||
git.uncle6.me 200、api.telegram.org 302——**只有 youlin 的主機沒被雲端 egress policy 放行**。
|
|
||||||
`/root/.ccr/README.md` 明寫:403/407 是組織的 egress policy,不要重試、不要繞路,回報主機名。
|
|
||||||
|
|
||||||
原因: `-w '%{http_code}'` 對「DNS 沒有」「proxy 拒絕 CONNECT」「對方沒回」三種都印 000,
|
|
||||||
而三種的修法各在不同人手上(改名字/leo 放行主機/看實例)。把它們記成同一個數字,
|
|
||||||
下一個人就會往錯的方向查(09-07 就差點只修名字收工)。
|
|
||||||
|
|
||||||
正確做法: 雲端看到 000 先跑 `curl -sS "$HTTPS_PROXY/__agentproxy/status" | jq .recentRelayFailures`,
|
|
||||||
`connect_rejected` + 403 ⇒ 是 policy,交給 leo 在 Cloud environment 放行 `*.arcrun-yuga3bse.workers.dev`;
|
|
||||||
不是 ⇒ 才去查名字或實例。記 log 時寫 curl 的錯誤字串(`response 403`/`Could not resolve host`),不要只寫 000。
|
|
||||||
|
|
||||||
## ⚠️ MISTAKE: 正門工具吃 `owner/repo` 會回 404,於是人走了側門
|
|
||||||
|
|
||||||
票: `inkstone/ISEP#130` → comment 6120 第 2 件
|
|
||||||
日期: 2026-09-07
|
|
||||||
|
|
||||||
症狀: `scripts/ticket new inkstone/ISEP -F …` 回 Gitea 404;同一天 `ticket say` 對 InkStoneCo 正常。
|
|
||||||
總管當場改成直接打 API 開了四張票。
|
|
||||||
|
|
||||||
實查: `cmd_new` 把第一個參數原樣塞進 `/repos/inkstone/{repo}/issues` ⇒ `/repos/inkstone/inkstone/ISEP/issues`。
|
|
||||||
404 讀起來像「ISEP 這個 repo 不存在」,跟真正的原因隔了一層。`subtask --to` 同款。
|
|
||||||
|
|
||||||
原因: 票號的鐵律是全稱 `owner/repo#N`(CLAUDE.md),人自然會把收件 repo 也寫成 `owner/repo`;
|
|
||||||
工具只收短名、錯了又不講清楚 ⇒ **正門壞了,人就走 `ticket-api-bypass-guard.sh` 在防的那條側門**。
|
|
||||||
一道閘把人逼去走它自己禁止的路,那道閘就是在製造違規(`docs/governance/cloud-wiring.md` ② 記過同一句)。
|
|
||||||
|
|
||||||
正確做法: `repo_arg()` 兩種寫法都收;org 寫錯(`Leo/`)當場講「org 是 inkstone」,不讓它變成一個要人猜的 404。
|
|
||||||
測試 `scripts/test-ticket-repo-arg.sh` 把 `api()` 換成假貨記路徑,離線驗路徑裡不准出現 `inkstone/inkstone`。
|
|
||||||
|
|
||||||
|
|
||||||
## ⚠️ MISTAKE: 權限白名單是「逐條比前綴」,複合指令永遠對不上——而假伺服器照自己的想像回 200
|
|
||||||
|
|
||||||
票: `inkstone/ISEP#137`(母票 `inkstone/ISEP#130`)
|
|
||||||
日期: 2026-09-07
|
|
||||||
|
|
||||||
症狀: 三條主線工人在雲端對 stage 的寫入全被 Claude Code auto mode 分類器擋:
|
|
||||||
`printf … | npx wrangler secret put …`、`python3 scripts/stage-deploy-artifacts.py all --confirm`、
|
|
||||||
`curl -X POST …arcrun-yuga3bse.workers.dev/records`。同一回合連 `ticket where <含 token 字樣>` 都被擋。
|
|
||||||
leo:「為什麼會擋你,這就是要修復的問題」「本機環境跟你不同應該不行」。
|
|
||||||
|
|
||||||
實查: `docs/permissions-allow.json` 的每一條是**完全比對前綴**。`cd … && printf … | VAR=… npx …` 這種複合指令
|
|
||||||
沒有任何一條對得上,任意寫法的 curl 更不可能;放整類(`Bash(npx *)`/`Bash(curl *)`)又是紅線。
|
|
||||||
⇒ 分類器擋的不是「這件事」,是「這個形狀沒被事先放行」。
|
|
||||||
|
|
||||||
原因: 正門工具的價值在**形狀固定**——一條規則就能事先放行。之前四個正門(ticket/mainline/gate-ok/gitea-pr-merge)
|
|
||||||
都是這樣活下來的;對 stage 的寫入沒有正門,人就只能拼複合指令,而複合指令天生對不上任何前綴。
|
|
||||||
|
|
||||||
正確做法:
|
|
||||||
- 每一種要放行的動作收成一支固定形狀(`scripts/stage secret …`/`stage api …`),白名單放它四種呼叫形狀。
|
|
||||||
「只打 stage」寫死在程式裡(帳號 ID 現查、主機後綴固定),不靠變數名字裡有沒有 `leo21c`。
|
|
||||||
- 別的 repo 已經有的正門(Arcrun `stage-deploy-artifacts.py` 自己寫死 youlin 帳號 ID)**直接放它的形狀**,不重造一支。
|
|
||||||
- 值只從環境變數名讀;`--value`/`--bearer`/`--header` 一律拒收——指令列會進 shell 歷史與 session log。
|
|
||||||
|
|
||||||
📌 同票第二個坑:**假伺服器要照真 API 回,不是照自己的想像回。**
|
|
||||||
離線測試的假 CF 對 secret PUT 回 200,27/27 全綠;第一次真跑 CF 回 **201**,工具把它講成「失敗」——
|
|
||||||
而獨立用 CF API 一列,那把 secret 明明種進去了。全綠的測試證明的是「工具跟假伺服器合得來」,
|
|
||||||
不是「工具跟 CF 合得來」。⇒ 假伺服器的回應碼要抄真的(現在回 201),而且**離線全綠之後一定要真跑一次**。
|
|
||||||
|
|||||||
Reference in New Issue
Block a user