Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 354480901a |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "isep",
|
||||
"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 支腳本,外加治理規範與標籤真相源。本機與雲端裝同一份,沒有子集。",
|
||||
"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)、50 支腳本,外加治理規範與標籤真相源。本機與雲端裝同一份,沒有子集。",
|
||||
"version": "0.22.0",
|
||||
"keywords": [
|
||||
"inkstone",
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
| `agents/` | 7 位 | **工人名單**(`inkstone/ISEP#86`)——派工時指名派給誰,規約見 `docs/governance/worker-roster.md` |
|
||||
| `commands/` | 7 支 | `/wiki-recall` `/wiki-capture` `/cp-write` `/issue-handle` … |
|
||||
| `skills/` | 2 支 | `ship-check`(東西要出去之前)/`deep-recall`(把散落的枝葉還原成一棵樹)。🔴 **這兩支的內容不一定是在這裡寫的**——誰是真相源查 `docs/file-ownership.tsv` |
|
||||
| `scripts/` | 49 支 | `ticket`/`roster`/`isep-nag`/`wiki-compress`/`github-arm.sh` …(頂層檔案,不含 `lib/` 等子目錄) |
|
||||
| `scripts/` | 50 支 | `ticket`/`roster`/`isep-nag`/`wiki-compress`/`github-arm.sh` …(頂層檔案,不含 `lib/` 等子目錄) |
|
||||
|
||||
> 🔴 這五個數字**每次都要在自己的樹上實數**,不准沿用上一版、也不准用加減推
|
||||
> (`system-dev/wiki/mistakes.md`:那是 leo 的驗收介面,多報就是假綠):
|
||||
|
||||
+42
-22
@@ -419,6 +419,47 @@ bash hooks/tests/gitea-arm-check.test.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 條
|
||||
```
|
||||
bash scripts/test-ticket-handoff-writeback.sh
|
||||
@@ -825,28 +866,6 @@ claude -p '請執行 git tag -a v9.9.9 -m test'
|
||||
|
||||
---
|
||||
|
||||
### A27 — 未出貨警察:改了 code 沒出貨要擋,只改 wiki/已出貨/先不出都不擋:13 條
|
||||
```
|
||||
bash scripts/test-unreleased-police.sh
|
||||
```
|
||||
**該看到**:`13/13 通過`。全程在 `mktemp -d` 底下造假 repo 與假 transcript,
|
||||
不碰任何真 repo、不打網路、跑完自己清。
|
||||
|
||||
**它在守什麼**(`inkstone/ISEP#68`,leo 2026-08-27):「每個 repo 只要有改動就要出貨⋯⋯
|
||||
這個 session 有改但要結束沒出貨就抓」。「改過」認的是**這個 session 期間新長出來的 commit**
|
||||
(committer-date 晚於 transcript 第一列的時間戳),「出貨」認的是**有沒有 release tag 收進 HEAD**
|
||||
(`git tag --contains HEAD`)——兩者同一個單位(commit),才數得出「最後 commit 與最新 release 差幾筆」。
|
||||
|
||||
**失敗**:
|
||||
- A 群「該擋」任一放行 ⇒ 假綠:改了 code 卻沒出貨溜過去了
|
||||
- B 群「不該擋」任一被擋 ⇒ **誤攔**(比漏擋嚴重)——特別看「只改 wiki/docs」「已出貨」
|
||||
「有 exempt marker」「release-holds.md 有它」四條,任何一條紅代表閘在懲罰謹慎
|
||||
- C 群紅 ⇒ 訊息教的出路(寫 `.claude/release-holds.md` 一行)**跑不動**,
|
||||
被擋的人只會去找繞過去的方法(`mistakes.md` ISEP#112 的課)
|
||||
- D 群紅 ⇒ 偵測根本不會亮,「全綠」其實是偵測壞了,不是真的乾淨
|
||||
|
||||
---
|
||||
|
||||
## B. 只有 leo 能跑的(雲端)
|
||||
|
||||
機器碰不到 claude.ai 的 Cloud environment 設定,這段一定要你動手。
|
||||
@@ -975,6 +994,7 @@ B2(信標那行)/B3(setup 輸出)/B4(閘的訊息)三個畫面
|
||||
| **A17 未推警察不誤攔雲端分支** | 總管 | ✅ 10/10(2026-08-28,inkstone/ISEP#90) |
|
||||
| **A18 信標會報雲端接線缺陷** | 總管 | ✅ 14/14(2026-08-28,inkstone/ISEP#90) |
|
||||
| **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 張唯讀實跑 |
|
||||
| A7 plugin 裝得起來 | 總管 | ✅ |
|
||||
| **A8 新 session 閘會觸發** | 總管 | 見本版 release note |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 62 支閘,白話盤點表
|
||||
# 61 支閘,白話盤點表
|
||||
|
||||
> 回應 `inkstone/InkStoneCo#40`:「如果加入了,我應該可以白話文看到 hooks 的內容?」
|
||||
> 這份表就是那個「白話文」——不用點開任何 `.sh` 檔,一行看懂一支閘在管什麼。
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
## 一句話結論
|
||||
|
||||
`hooks/` 底下有 **62 個 `.sh` 檔**,`hooks.json` 實際掛上 **85 條註冊**(同一支閘常被多種情境同時掛上);
|
||||
`hooks/` 底下有 **61 個 `.sh` 檔**,`hooks.json` 實際掛上 **84 條註冊**(同一支閘常被多種情境同時掛上);
|
||||
其中 **3 支檔案存在但沒被掛上**(2 支是待人填的空範本、1 支是刻意留著沒開的止血帶,見下面「未生效」表)。
|
||||
下面按「你會在什麼時候撞到它」分組,一支一行。
|
||||
|
||||
> 🔴 **這兩個數字上一版是錯的(2026-08-26 實際數過才發現)**:本頁原本寫「43 個檔、53 條註冊」,
|
||||
> 而當時真實是 **45 個檔、55 條註冊**——中間有兩支閘進來時沒有回頭改這裡。
|
||||
> 現在的寫法是實際數出來的:
|
||||
> `ls hooks/*.sh | wc -l` = 62;`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**。
|
||||
> 本頁 2026-08-27 之前寫的是沒冒號那版——**照著它跑會拿到一個跟本頁不符的數字**。
|
||||
> **一份會偷偷過期的盤點表,跟沒有盤點表差不多**——見本頁最後「怎麼跟實況對帳」那段。
|
||||
@@ -98,11 +98,6 @@
|
||||
> 另外描述欄的「38 支腳本」是把 `kbdb-live-exam/`/`lib/`/`patches/` 三個**目錄**也數進去了;
|
||||
> 用本頁寫死的那道指令(只數檔案)實數是 **39**。
|
||||
|
||||
> 📌 **`inkstone/ISEP#68`(2026-09-03)進來一支**:`unreleased-police.sh`(F 組,Stop)。
|
||||
> 61→**62** 支、84→**85** 條,兩個數字都是**在自己的樹上當場數出來的**(指令同上),
|
||||
> 不是拿上一版加一。它只掛 `Stop` 一個事件(+1 支、+1 條)——刻意不掛 `SubagentStop`:
|
||||
> subagent 交回分支、release 由總管出,在 subagent 收工逼它出貨純屬誤攔。
|
||||
|
||||
---
|
||||
|
||||
## 怎麼讀這張表
|
||||
@@ -231,7 +226,6 @@
|
||||
| `delivery-police.sh` | AI 宣稱「這件事做完了」,卻看不到任何實測證據(畫面截圖、指令輸出、HTTP 狀態碼…)就擋下。 | 🛑 擋 |
|
||||
| `wiki-first-police.sh` | AI 做完事卻沒有把結論寫回 wiki 就想收工,就擋下——下次(或別的 AI)查 wiki 會查不到這次做過什麼。 | 🛑 擋 |
|
||||
| `unpushed-police.sh` | AI 改好的東西還留在本機、沒有真的推送出去給別人用,卻想收工,就擋下——「改對了但沒送到」跟沒改是一樣的。 | 🛑 擋 |
|
||||
| `unreleased-police.sh` | 這個 session 改過的 repo,收工那一刻還沒**出貨**(沒有一個 release tag 收進 HEAD),就擋一次,並點名是哪個 repo、最後 commit 與最新 release 差幾筆。「改過」認的是**這個 session 期間新長出來的 commit**(不是工作區髒、不是 push),跟「出貨」用同一個單位(commit)才數得出差多少。**只在收工問一次,不是每次 commit 都吼**(leo 明說可以累積)。三種不擋:①只改了 wiki/docs(知識就地被讀,不需出版本)②repo 根目錄放了 `.isep-release-exempt`(產物/模板 repo 自己帶理由排除,不是中央手列清單)③在 `.claude/release-holds.md` 寫一行「這次先不出,因為 X」(放行且留痕,出貨後刪掉那行)。只掛 `Stop` 不掛 `SubagentStop`——subagent 交回分支、release 由總管出,在 subagent 收工逼它出貨純屬誤攔。 | 🛑 擋(至多攔一次) |
|
||||
|
||||
> 🔴 **`claim-verify-police.sh` 已於 `inkstone/ISEP#60` 移除**(連同下面原本的 G 組 `subagent-claim-worksheet.sh`)。
|
||||
> 這一對是自造的「待驗單」機制(一張沒有狀態、沒有持有人的 markdown),違反 D58:
|
||||
|
||||
@@ -364,14 +364,6 @@
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/countdown-guard.sh"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"hooks": [
|
||||
{
|
||||
"type": "command",
|
||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/unreleased-police.sh"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"SubagentStop": [
|
||||
|
||||
@@ -1,241 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# unreleased-police.sh — 未出貨警察(Stop hook) inkstone/ISEP#68
|
||||
#
|
||||
# 🔴 本機 LC_ALL 未固定時,把變數(repo 名/數字)串進含全形標點的字串會吃掉字元
|
||||
# (unpushed-police.sh 檔頭第 4 行記過同一課)。固定 locale,別讓報告被環境吃掉。
|
||||
export LC_ALL=C
|
||||
#
|
||||
# ── leo 2026-08-27 的規格(原話就是判準,inkstone/ISEP#68)────────────────
|
||||
# 「每個 repo 只要有改動就要出貨」
|
||||
# 「這個警察很簡單,這個 session 有改但要結束沒出貨就抓,
|
||||
# 你可以久一點再出貨累積幾個 PR,但最後一定要出貨」
|
||||
# 「版本出去之前都只是內部測試」
|
||||
#
|
||||
# 掛點 Stop(session 要結束的那一刻)—— 不是每次 commit,只在收工問一次
|
||||
# 條件 這個 session 改過的 repo
|
||||
# 檢查 有沒有出貨(新的 release)
|
||||
# 寬容 可以累積幾個 PR 再一起出(「先不出」要留痕)
|
||||
# 底線 session 結束前一定要出
|
||||
#
|
||||
# ── 為什麼是 Stop、不是 SubagentStop(誤攔第一防線)────────────────────
|
||||
# leo 規則三點七:subagent 交 deliverable(分支上的 commit),**總管**把它們
|
||||
# 收斂成一個 release。subagent 交回分支、天生不出 release ⇒ 在 SubagentStop
|
||||
# 要它出貨=逼它做一件它不該做的事=純誤攔。所以本閘只掛 Stop。
|
||||
#
|
||||
# ── 四個判準,每一個都寫得出理由(票要求我自己判,不照抄總管)──────────
|
||||
#
|
||||
# ① 「改過」= 這個 session 期間 HEAD 前進了新的 commit(不是「工作區髒」、不是「push」)。
|
||||
# · 出貨(release/tag)的單位是 commit;leo 的「累積幾個 PR」也是累積 commit。
|
||||
# 「改過」要和「出貨」用同一個單位對齊,才數得出「差多少」。
|
||||
# · 「工作區髒」還沒落地,且已被 unpushed-police 管——用它會重疊、又會逼暫存檔出貨(誤攔)。
|
||||
# · 「push」是 D20 開閘的動作、又是 release 的上游,用它當「改過」太晚。
|
||||
# session 起點 = transcript 第一列的時間戳(同 countdown.py 的基準:一段對話=一個 release)。
|
||||
#
|
||||
# ② 「該不該出貨」= 這個 session 的 commit 有沒有動到**知識以外**的檔案。
|
||||
# principles.md:環境(hooks/commands/skills/scripts/plugin)要升版才到得了人手上;
|
||||
# 知識(wiki/docs/_archive)改了就地被讀到,不需要出版本。
|
||||
# ⇒ 只改 wiki/docs 的 commit **不算要出貨的改動**(票驗收 4「只改了 wiki 不該擋」)。
|
||||
# 判準是「有沒有任何一個改到的檔在知識目錄之外」,不是維護一張「哪些算 code」的清單。
|
||||
# 方向:把 docs 誤判成「不用出貨」是漏擋(安全方向);把 wiki 判成「要出貨」是誤攔(要避免)。
|
||||
#
|
||||
# ③ 「哪些 repo 不適用」= repo 根目錄有 `.isep-release-exempt` 這個檔(裡面寫一行理由)。
|
||||
# · 判準是「檔在不在」,不是一張會過期的中央手列清單,也不是名字黑名單。
|
||||
# · **預設納管**:新 repo 進來自動被管(沒人需要記得加),只有產物 repo/模板 repo
|
||||
# 這種真的不出版的才放一個 marker——而且它自己帶著「為什麼不適用」的理由。
|
||||
# (票明說 arcrun-rag-bundles-staging 是產物、system-dev-template 是模板;它們各放一個 marker 即可。)
|
||||
#
|
||||
# ④ 「這次先不出」= $CLAUDE_PROJECT_DIR/.claude/release-holds.md 裡有一行提到這個 repo(+理由)。
|
||||
# · 形狀跟 unpushed-police 的 branch-holds.md 一樣:**要求某個東西在場**(leo 認可的兩種閘形狀之一),
|
||||
# 不是去 transcript 裡撈「先不出因為」這種字(文字層封路已被證偽:8 次誤攔 0 次命中)。
|
||||
# · 「明說先不出」寫進一個檔=同時滿足「放行」與「留痕」(票驗收 5)。
|
||||
# · 出貨了就把那一行刪掉——訊息會這樣講。
|
||||
#
|
||||
# ── 「出貨」怎麼認 ──────────────────────────────────────────────────────
|
||||
# shipped ⟺ `git tag --contains HEAD` 非空(HEAD 這顆已經被某個 release tag 收進去)。
|
||||
# Gitea 的 release 就是 tag;tag 打在哪顆 commit 上是本機答得準的事實,不必打網路。
|
||||
# 沒被收進去 ⇒ 用 `git describe` 找出「最新 release」、數出 HEAD 領先它幾筆——
|
||||
# 那就是「最後 commit 與最新 release 差多少」(票驗收 1 要訊息點得出來)。
|
||||
#
|
||||
# ── fail-open:Stop 閘擋下內部錯誤會鎖死 session,誤攔是本 repo 第一級缺陷 ──
|
||||
# 拿不到 transcript 起點/不是 git repo/git 問不出來 ⇒ 一律放行。
|
||||
#
|
||||
# 迴歸測試:scripts/test-unreleased-police.sh(含「不該擋」與「出路走得通」兩組)
|
||||
|
||||
input="$(cat 2>/dev/null || echo '{}')"
|
||||
|
||||
# ── 防無限迴圈:已被別的 Stop 閘擋出來這一輪 ⇒ 不再擋 ──
|
||||
stop_active="$(printf '%s' "$input" | python3 -c '
|
||||
import sys, json
|
||||
try: print(json.load(sys.stdin).get("stop_hook_active", False))
|
||||
except Exception: print(False)
|
||||
' 2>/dev/null)"
|
||||
[ "$stop_active" = "True" ] && exit 0
|
||||
|
||||
# ── 一次取出 transcript 路徑與 session 起點(epoch)──
|
||||
# 起點的算法跟 hooks/lib/countdown.py transcript_start 同源:transcript 第一列的時間戳。
|
||||
LIBDIR="$(dirname "$0")/lib"
|
||||
read -r START_EPOCH TRANSCRIPT <<EOF2
|
||||
$(printf '%s' "$input" | LIBDIR="$LIBDIR" python3 -c '
|
||||
import sys, json, os
|
||||
sys.path.insert(0, os.environ.get("LIBDIR", ""))
|
||||
start = ""
|
||||
tp = ""
|
||||
try:
|
||||
d = json.load(sys.stdin)
|
||||
tp = d.get("transcript_path") or ""
|
||||
except Exception:
|
||||
d = {}
|
||||
try:
|
||||
from countdown import transcript_start
|
||||
dt = transcript_start(tp)
|
||||
if dt: start = str(int(dt.timestamp()))
|
||||
except Exception:
|
||||
# lib 不在時就地補:讀第一列時間戳
|
||||
try:
|
||||
from datetime import datetime, timezone
|
||||
with open(tp) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line: continue
|
||||
try: row = json.loads(line)
|
||||
except Exception: continue
|
||||
raw = row.get("timestamp")
|
||||
if isinstance(raw, str) and raw.strip():
|
||||
s = raw.strip().replace("Z", "+00:00")
|
||||
try:
|
||||
dt = datetime.fromisoformat(s)
|
||||
if not dt.tzinfo: dt = dt.replace(tzinfo=timezone.utc)
|
||||
start = str(int(dt.timestamp())); break
|
||||
except Exception: pass
|
||||
except Exception: pass
|
||||
print(start or "-", tp or "-")
|
||||
' 2>/dev/null)
|
||||
EOF2
|
||||
|
||||
# 拿不到起點 ⇒ 無從界定「這個 session 改了什麼」⇒ 放行(誤攔比漏擋嚴重)
|
||||
case "$START_EPOCH" in ''|'-'|*[!0-9]*) exit 0 ;; esac
|
||||
|
||||
TOP="${CLAUDE_PROJECT_DIR:-$(cd "$(dirname "$0")/../.." && pwd)}"
|
||||
|
||||
# 掃描對象:頂層 + 已知子 repo(存在才掃),與 unpushed-police 同一份排法。
|
||||
REPOS=""
|
||||
for _body in "$TOP" "$TOP/InkStoneCo"; do
|
||||
[ -d "$_body/.git" ] || [ -f "$_body/.git" ] || continue
|
||||
REPOS="$REPOS $_body $_body/matrix/arcrun $_body/products/arcrun-rag $_body/polaris/mira"
|
||||
done
|
||||
[ -n "$REPOS" ] || REPOS="$TOP"
|
||||
|
||||
HOLDS="$TOP/.claude/release-holds.md"
|
||||
|
||||
problems=""
|
||||
held_note=""
|
||||
exempt_note=""
|
||||
|
||||
for r in $REPOS; do
|
||||
[ -d "$r/.git" ] || [ -f "$r/.git" ] || continue
|
||||
name="${r#$TOP/}"; [ "$name" = "$r" ] && name="$(basename "$r")"
|
||||
[ "$r" = "$TOP" ] && name="(頂層) $(basename "$r")"
|
||||
base="$(basename "$r")"
|
||||
|
||||
# ── ① 這個 session 有沒有新 commit(reachable from HEAD, committer-date >= 起點)──
|
||||
files="$(git -C "$r" log HEAD --since="@$START_EPOCH" --name-only --format= 2>/dev/null \
|
||||
| grep -v '^$' | sort -u)"
|
||||
[ -z "$files" ] && continue # 這個 session 沒動這個 repo → 放行(票驗收 3/4「只讀不寫」)
|
||||
|
||||
# ── ② 有沒有動到「知識以外」的檔(要出貨的改動)──
|
||||
# 知識目錄:路徑含 /wiki/、/docs/、/_archive/,或以它們開頭。
|
||||
nonknow="$(printf '%s\n' "$files" | grep -vE '(^|/)(wiki|docs|_archive)(/|$)' | head -1)"
|
||||
[ -z "$nonknow" ] && continue # 只改了知識(wiki/docs)→ 不需出貨(票驗收 4)
|
||||
|
||||
# ── ③ 這個 repo 是不是 marker 排除(產物/模板)──
|
||||
if [ -f "$r/.isep-release-exempt" ]; then
|
||||
_why="$(head -1 "$r/.isep-release-exempt" 2>/dev/null)"
|
||||
exempt_note="$exempt_note
|
||||
- $name(.isep-release-exempt:${_why:-未寫理由})"
|
||||
continue
|
||||
fi
|
||||
|
||||
# ── 已經出貨了嗎?HEAD 被某個 tag 收進去 ⇒ 出過貨,放行(票驗收 2)──
|
||||
if [ -n "$(git -C "$r" tag --contains HEAD 2>/dev/null | head -1)" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# ── 到這裡:這個 session 動過、要出貨、卻還沒出貨 ──
|
||||
# 「最後 commit 與最新 release 差多少」
|
||||
base_tag="$(git -C "$r" describe --tags --abbrev=0 HEAD 2>/dev/null || true)"
|
||||
if [ -n "$base_tag" ]; then
|
||||
n="$(git -C "$r" rev-list --count "$base_tag"..HEAD 2>/dev/null || echo '?')"
|
||||
detail="最新 release $base_tag ,HEAD 領先它 $n 筆(其中有環境/code 改動未出貨)"
|
||||
else
|
||||
n="$(git -C "$r" rev-list --count HEAD 2>/dev/null || echo '?')"
|
||||
detail="從未出過版(一個 release tag 都沒有),HEAD 共 $n 筆 commit 未出貨"
|
||||
fi
|
||||
short_top="$(printf '%s\n' "$files" | grep -vE '(^|/)(wiki|docs|_archive)(/|$)' | head -3 \
|
||||
| sed 's/^/ · /')"
|
||||
|
||||
# ── ④ 這次先不出(release-holds.md 有提到這個 repo)⇒ 放行 + 留痕 ──
|
||||
if [ -f "$HOLDS" ] && grep -qF "$base" "$HOLDS" 2>/dev/null; then
|
||||
_line="$(grep -F "$base" "$HOLDS" 2>/dev/null | head -1)"
|
||||
held_note="$held_note
|
||||
- $name(先不出,理由在 .claude/release-holds.md):$_line"
|
||||
continue
|
||||
fi
|
||||
|
||||
problems="$problems
|
||||
📦 $name :$detail
|
||||
這個 session 動到、需要出貨的檔(節錄):
|
||||
$short_top"
|
||||
done
|
||||
|
||||
# 沒有任何「改了卻沒出貨」的 repo ⇒ 放行
|
||||
if [ -z "$problems" ]; then
|
||||
# 有 hold/exempt 但沒有真問題時安靜放行——不無事生非(票紅線)
|
||||
exit 0
|
||||
fi
|
||||
|
||||
REPLACE_HOLDS="$HOLDS"
|
||||
|
||||
printf '%s\n' "🚢 未出貨警察:這個 session 改過的 repo,收工前還沒出貨。" >&2
|
||||
# 靜態訊息用 quoted heredoc(mistakes.md:unquoted heredoc 會把反引號當命令執行);
|
||||
# 動態內容用 printf '%s' 分開印,變數與全形標點之間都留空白(避免 locale 吃字元)。
|
||||
cat >&2 <<'EOF'
|
||||
|
||||
【leo 2026-08-27(原話就是判準)】
|
||||
「每個 repo 只要有改動就要出貨」「版本出去之前都只是內部測試」
|
||||
「你可以久一點再出貨累積幾個 PR,但最後一定要出貨」
|
||||
【判準】改對了、commit 了 ≠ 送到人手上。release 出去之前都只是內部測試。
|
||||
EOF
|
||||
|
||||
printf '%s\n' "$problems" >&2
|
||||
|
||||
if [ -n "$held_note" ]; then
|
||||
printf '%s\n' "" >&2
|
||||
printf '%s\n' "⏸️ 這次先不出(已留痕,不擋):$held_note" >&2
|
||||
fi
|
||||
if [ -n "$exempt_note" ]; then
|
||||
printf '%s\n' "" >&2
|
||||
printf '%s\n' "⊘ 排除(.isep-release-exempt):$exempt_note" >&2
|
||||
fi
|
||||
|
||||
cat >&2 <<'EOF'
|
||||
|
||||
━━ 收工前擇一,都走得通 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
1. 該出貨就出貨:升版(改了會被載入的東西=plugin/worker/bundle 就升版)
|
||||
+ 打 release tag。ISEP 自己:bash scripts/check-version-consistency.sh 先對齊,
|
||||
版本三處一致後由總管打 tag。
|
||||
2. 這次先不出(累積、或交回分支由總管出):在下面這個檔寫一行理由——
|
||||
寫完再收工就放行,而且留了痕,總管看得到有東西在路上:
|
||||
EOF
|
||||
|
||||
printf '%s\n' " $REPLACE_HOLDS" >&2
|
||||
printf '%s\n' " 一行格式: <repo 名>: <為什麼這次先不出>" >&2
|
||||
printf '%s\n' " (repo 名就是上面每個 📦 後面那個名字的最後一段,例如 ISEP/mira)" >&2
|
||||
|
||||
cat >&2 <<'EOF'
|
||||
3. 是產物 repo/模板 repo(本來就不出版):在該 repo 根目錄放一個
|
||||
.isep-release-exempt,第一行寫理由。之後這支閘就不再管它。
|
||||
|
||||
🔴 本閘只在收工那一刻問一次,不是每次 commit 都吼(leo 明說可以累積)。
|
||||
出貨之後記得把 release-holds.md 裡對應那一行刪掉,否則下次它會以為你還在累積。
|
||||
EOF
|
||||
exit 2
|
||||
Executable
+224
@@ -0,0 +1,224 @@
|
||||
#!/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,102 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# unreleased-police.sh 的迴歸測試(inkstone/ISEP#68,docs/TESTING.md A27)
|
||||
#
|
||||
# 兩個方向都要有證據(本 repo 心法:誤攔比漏擋嚴重):
|
||||
# A 群「該擋」 —— session 改了 code 卻沒出貨(含「從未出過版」與「領先最新 release N 筆」)
|
||||
# B 群「不該擋」 —— 只讀不寫/只改 wiki/已出貨(tag 收進 HEAD)/排除 marker/這次先不出/stop_hook_active
|
||||
# C 群「出路走得通」—— 照擋下訊息教的「寫 release-holds.md 一行」做,再送一次就放行(ISEP#112 的課)
|
||||
# D 群「鑑別力」 —— 拿掉 marker 同一個 repo 就會擋(證明放行是 marker 造成的,不是偵測壞了)
|
||||
#
|
||||
# 🔴 全程在乾淨的 TMP 底下造假 repo/假 transcript,跑完自己清;不碰任何真 repo、不打網路。
|
||||
set -u
|
||||
HOOK="${1:-$(cd "$(dirname "$0")/.." && pwd)/hooks/unreleased-police.sh}"
|
||||
TMP=$(mktemp -d)
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
# session 起點固定成 2026-01-01T00:00:00Z(transcript 第一列的時間戳)。
|
||||
# 「這個 session 的 commit」=committer-date 晚於這一刻。
|
||||
T0="2026-01-01T00:00:00Z"
|
||||
TR="$TMP/transcript.jsonl"
|
||||
printf '{"timestamp":"%s","type":"user","message":{"content":[{"type":"text","text":"開工"}]}}\n' "$T0" > "$TR"
|
||||
AFTER="2026-06-01T00:00:00Z" # 晚於起點 = 這個 session 改的
|
||||
BEFORE="2025-06-01T00:00:00Z" # 早於起點 = 不是這個 session 改的
|
||||
|
||||
PASS=0; FAIL=0; N=0
|
||||
|
||||
mkrepo() { git init -q "$1"; git -C "$1" config user.email t@t; git -C "$1" config user.name t; }
|
||||
# commit <repo> <date> <相對路徑> <訊息>
|
||||
commit() {
|
||||
mkdir -p "$(dirname "$1/$3")"; echo x >> "$1/$3"; git -C "$1" add -A
|
||||
GIT_AUTHOR_DATE="$2" GIT_COMMITTER_DATE="$2" git -C "$1" commit -qm "$4"
|
||||
}
|
||||
|
||||
# fire <說明> <期望exit> <repo目錄> [extra-json] [--grep <字串>]
|
||||
fire() {
|
||||
desc="$1"; want="$2"; repo="$3"; extra="${4:-}"; needle="${6:-}"
|
||||
N=$((N+1))
|
||||
payload=$(printf '{"session_id":"s%s","transcript_path":"%s"%s}' "$N" "$TR" "$extra")
|
||||
out=$(printf '%s' "$payload" | CLAUDE_PROJECT_DIR="$repo" bash "$HOOK" 2>&1); rc=$?
|
||||
ok=1
|
||||
[ "$rc" = "$want" ] || ok=0
|
||||
if [ -n "$needle" ] && ! printf '%s' "$out" | grep -qF "$needle"; then ok=0; fi
|
||||
if [ "$ok" = 1 ]; then
|
||||
printf ' ✅ %s\n' "$desc"; PASS=$((PASS+1))
|
||||
else
|
||||
printf ' ❌ %s —— 期望 exit=%s,實得 exit=%s' "$desc" "$want" "$rc"
|
||||
[ -n "$needle" ] && printf '(找 "%s")' "$needle"
|
||||
printf '\n'
|
||||
printf '%s\n' "$out" | sed -n '1,10p' | sed 's/^/ /'
|
||||
FAIL=$((FAIL+1))
|
||||
fi
|
||||
}
|
||||
|
||||
echo "── A 群:該擋(改了 code 卻沒出貨)──"
|
||||
mkrepo "$TMP/a1"; commit "$TMP/a1" "$AFTER" hooks/foo.sh "加一支 hook"
|
||||
fire "改了 hook、從未出過版 → 擋,且點名 repo+筆數" 2 "$TMP/a1" "" --grep "從未出過版"
|
||||
|
||||
mkrepo "$TMP/a2"; commit "$TMP/a2" "$BEFORE" hooks/a.sh a; git -C "$TMP/a2" tag v1
|
||||
commit "$TMP/a2" "$AFTER" hooks/b.sh b
|
||||
fire "有舊 release、新 commit 未收進 → 擋,訊息說『領先它 N 筆』" 2 "$TMP/a2" "" --grep "領先它 1 筆"
|
||||
|
||||
mkrepo "$TMP/a3"; commit "$TMP/a3" "$AFTER" scripts/x.sh x; commit "$TMP/a3" "$AFTER" system-dev/wiki/n.md n
|
||||
fire "同一 session 改了 code+wiki → 擋(只要有一個非知識檔)" 2 "$TMP/a3" "" --grep "未出貨"
|
||||
|
||||
echo "── B 群:不該擋 ──"
|
||||
mkrepo "$TMP/b1"; commit "$TMP/b1" "$BEFORE" hooks/foo.sh old
|
||||
fire "這個 session 什麼都沒 commit(只讀不寫)→ 放行" 0 "$TMP/b1"
|
||||
|
||||
mkrepo "$TMP/b2"; commit "$TMP/b2" "$AFTER" system-dev/wiki/note.md "只改 wiki"
|
||||
fire "這個 session 只改了 wiki → 放行" 0 "$TMP/b2"
|
||||
|
||||
mkrepo "$TMP/b2b"; commit "$TMP/b2b" "$AFTER" docs/hooks-inventory.md "只改 docs"
|
||||
fire "這個 session 只改了 docs → 放行" 0 "$TMP/b2b"
|
||||
|
||||
mkrepo "$TMP/b3"; commit "$TMP/b3" "$AFTER" hooks/foo.sh code; git -C "$TMP/b3" tag v9
|
||||
fire "改了 code 而且已出貨(tag 收進 HEAD)→ 放行" 0 "$TMP/b3"
|
||||
|
||||
mkrepo "$TMP/b4"; commit "$TMP/b4" "$AFTER" hooks/foo.sh code
|
||||
printf '產物 repo,管線產出,不出版\n' > "$TMP/b4/.isep-release-exempt"
|
||||
fire "改了 code 但有 .isep-release-exempt marker → 放行" 0 "$TMP/b4"
|
||||
|
||||
mkrepo "$TMP/b5"; commit "$TMP/b5" "$AFTER" hooks/foo.sh code
|
||||
mkdir -p "$TMP/b5/.claude"; printf 'b5: 交回分支,release 由總管出\n' > "$TMP/b5/.claude/release-holds.md"
|
||||
fire "改了 code 沒出貨、但 release-holds.md 有這個 repo(先不出)→ 放行且留痕" 0 "$TMP/b5"
|
||||
|
||||
mkrepo "$TMP/b6"; commit "$TMP/b6" "$AFTER" hooks/foo.sh code
|
||||
fire "已被別的 Stop 閘擋過這一輪(stop_hook_active)→ 放行" 0 "$TMP/b6" ',"stop_hook_active":true'
|
||||
|
||||
echo "── C 群:擋下訊息教的出路,照做真的走得通 ──"
|
||||
mkrepo "$TMP/c1"; commit "$TMP/c1" "$AFTER" hooks/foo.sh code
|
||||
fire "先擋一次" 2 "$TMP/c1" "" --grep "release-holds.md"
|
||||
# 照訊息說的:在 .claude/release-holds.md 寫「<repo 名>: <理由>」
|
||||
mkdir -p "$TMP/c1/.claude"; printf 'c1: 這次累積,下個 session 一起出\n' > "$TMP/c1/.claude/release-holds.md"
|
||||
fire "照訊息寫了 release-holds.md 那一行,再送 → 放行" 0 "$TMP/c1"
|
||||
|
||||
echo "── D 群:鑑別力(放行是 marker/hold 造成的,不是偵測壞了)──"
|
||||
# b4 若拿掉 marker,同一個 repo 就會擋 → 證明偵測本身是會亮的
|
||||
rm -f "$TMP/b4/.isep-release-exempt"
|
||||
fire "把 b4 的 marker 拿掉 → 同一個 repo 就擋(偵測真的會亮)" 2 "$TMP/b4"
|
||||
|
||||
echo
|
||||
echo "$PASS/$N 通過"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
+335
-1
@@ -28,6 +28,12 @@ leo 2026-08-16 三句話,本工具就是它們的機械化:
|
||||
|
||||
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`
|
||||
"""
|
||||
import json
|
||||
@@ -814,6 +820,17 @@ def subtask_example(parent=None, draft=None):
|
||||
# 🔴 `{bin}` 一定要留成佔位符、由 usage_text() 現填 self_path():
|
||||
# 用法裡寫死 `ticket` 或 `scripts/ticket`,讀的人照著貼就又踩回這張票的坑。
|
||||
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":
|
||||
"用法:{bin} subtask <母票 owner/repo#N> --title \"<User Story>\" -F <內文檔>\n"
|
||||
" [--repo <收件 repo,預設跟母票同一個>] [--label <s/xxx,預設 s/todo>]\n"
|
||||
@@ -1170,10 +1187,327 @@ def cmd_loose(argv):
|
||||
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,
|
||||
"decide": cmd_decide, "subtask": cmd_subtask, "handoff": cmd_subtask,
|
||||
"handback": cmd_handback, "mine": cmd_mine, "loose": cmd_loose,
|
||||
"usage": cmd_usage}
|
||||
"usage": cmd_usage, "pick": cmd_pick, "claim": cmd_claim}
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2 or sys.argv[1] not in CMDS:
|
||||
|
||||
Reference in New Issue
Block a user