Compare commits

...

6 Commits

Author SHA1 Message Date
Leo 147fdb1482 release: v0.30.8——雲端環境變數清單有版本(v6),產物放桌面
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 19:44:47 +08:00
Leo ef11871ba4 雲端環境變數清單有版本了:docs/cloud-env-versions.tsv 記每版 key,產生器印版本與差異、改清單沒升版就拒絕,產物預設放桌面(v6:+ARCRUN_NS_UNCLE6/GITHUB_MIRROR_TOKEN/GITHUB_ACCOUNT_NAME)
leo 2026-09-18:「你這裡記錄每版的 credential 的 key,但 value 自動產生,我就貼上去,你要有版本,因為這件事做了很多次,但你都沒記錄版本」
v1–v5 由 git 歷史還原(f855d82、ca9ea99、7aef943、cb310e9、dd86fef)。test-make-cloud-env.sh 13/13(新增 V1 檔頭版本、V2 不一致拒絕)。
(inkstone/ISEP#158、inkstone/InkStoneCo#98 c7739)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 19:44:40 +08:00
Leo 7b5a6450df release: v0.30.7——雲端工人會分診、會組里程碑,組了就照里程碑做(inkstone/ISEP#159)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 18:46:13 +08:00
Leo 2bbcda2ac3 雲端工人會分診、會組里程碑,組了就照里程碑做(inkstone/ISEP#159)
leo 09-18:「它看到票時要能夠組成 milestone 提出版本,所以不只是看票,還要組票。」
雲端只會撿(ISEP#130),沒有任何機制分診或組里程碑;open 302 張裡 74 張沒 s/*、257 張沒掛里程碑。

- ticket triage:沒 s/* 的票 → s/backlog/s/triage/s/pending+票上一則說明(--why 必填),一個動作;
  --dup-of:說明+close/duplicate+關+在留下的那張留一則指回來(留下的那張若是 leo 的就不寫)
- ticket compose:把已分診的票組成 InkStoneCo 里程碑(開工規約 1–7 條):既有載體+前置相依、
  s/backlog → s/todo、名字不准是版本號、期限 1–60 天、不開新票;先全部讀過才寫,理由一次列齊
- 不碰:Human/human/*、指派給別人(含 Leo)——判準是標籤與 assignee 登入名
- pick --pool:還沒到期的 InkStoneCo 里程碑的前置排在散票之前;可做的都抓盡時回待分診的票,
  每列帶 next;queue-drain-guard 照 next 印(待分診是 triage,不是 claim)
- 全局票池只有一個讀法 pool_issues(),接口留給 ISEP#154(global_index 寫卡驗完後只換這一個函式)
- InkStoneCo 掛在 open 里程碑的票=載體(容器):不進票池、不算待分診

假設(寫在這裡等總管 review):
- 分診只收「沒有 s/*」的票;s/triage 仍是總管/leo 的判斷,工人只能把拿不準的丟進 s/triage
- 載體撈不到時,工人用 ticket where+ticket new 補一張 InkStoneCo User Story 當載體(開工規約第 2 條的「真缺口」)
- 期限上限 60 天(9999 與過去日期都擋)

實測:test-ticket-triage 80/80、test-ticket-pick 84/84、queue-drain-guard 28/28;
真 Gitea 代跑一趟:分診 4 張、建 InkStoneCo milestone 68(載體 InkStoneCo#136,前置 ISEP#47、arcrun-rag#199),
pick --pool 第一組即為它的前置;一次違規三格的 compose 真的零寫入擋下。
待總管定版。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 18:43:07 +08:00
Leo 51c668f9c8 release: v0.30.6——雲端工人從 open 票池持續領票,可抓 0 張時講出池子去哪了(inkstone/ISEP#130)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 14:02:07 +08:00
Leo 06fb2c59c8 雲端工人從 open 票池持續領票,可抓 0 張時講出池子去哪了(inkstone/ISEP#130 c7801)
根因:pick 只看主線成員與逾期里程碑;org 299 張 open 裡 254 張沒掛里程碑,
舊規則實跑可抓 0 張,09-18 六趟 run 都印「正常結果,不是故障」收工。

- 第三層:主線與逾期都抓盡、且是接票的環境(--pool 或 ISEP_DRAIN=1),
  再看整個 open 票池裡 s/* 恰好是 s/todo 或 s/backlog 的票(不限里程碑)。
  Human/human/*、指派給別人(含 Leo)、hub、PR、s/triage、沒有 s/* 一格不放寬。
- 本機沒設 ISEP_DRAIN 時不讀票池:總管跑過 handback 不會被佇列閘叫去抓票池(避免誤攔)。
- claim 同規則;可抓 0 張時列池子大小與每種不能抓的理由各幾張,不再說成正常。
- 分頁讀到空頁才停(伺服器每頁上限可能小於 50)。

假設(寫在這裡等總管 review):s/backlog 算「決定要做」可抓;沒有 s/* 的 72 張算未驗傷不抓、只計數。
實測:真 Gitea 改前可抓 0/改後 --pool 可抓 101;test-ticket-pick 80/80。
待總管定版。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 13:58:56 +08:00
12 changed files with 1147 additions and 57 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "isep",
"description": "InkStone Environment Plugin —— leo 的 Claude Code 環境唯一真相源:62 支機械閘(88 條註冊,白話盤點見 docs/hooks-inventory.md)、7 支 slash command、2 支 skill、8 位有名字的工人(agents/,見 docs/governance/worker-roster.md)、65 支腳本,外加治理規範與標籤真相源。本機與雲端裝同一份,沒有子集。",
"version": "0.30.5",
"version": "0.30.8",
"keywords": [
"inkstone",
"guardrails",
+63 -3
View File
@@ -429,12 +429,12 @@ bash hooks/tests/gitea-arm-check.test.sh .
- ①③⑤⑥ 任一紅 ⇒ 收手收得太晚,暫存區已經開始長東西(磁碟風險回來了)
- ② 紅 ⇒ 訊息沒給出走得通的那一行(本票整張票在講的就是這件事)
- ⑧⑨⑩ 任一紅 ⇒ **誤攔/複製錯**:正常用法被弄壞,或複本裡混進了 `hooks/` 以外的東西
### A31 — 雲端工人抓票的規則是機械可判的:53
### A31 — 雲端工人抓票的規則是機械可判的:84
```
bash scripts/test-ticket-pick.sh
```
**該看到**`通過 53 條,失敗 0 條`。**全程離線**:假池子(3 個 repo、3 個 open milestone、
12 張票、1 條相依邊)餵給換掉的 `api()`,時鐘走 `ISEP_COUNTDOWN_NOW``TICKET_HOST` 指到連不上的位址
**該看到**`通過 84 條,失敗 0 條`。**全程離線**:假池子(5 個 repo、3 個 open milestone、
52 張票、1 條相依邊`big` 那個 repo 的假伺服器每頁只給 30 張,驗分頁)餵給換掉的 `api()`,時鐘走 `ISEP_COUNTDOWN_NOW``TICKET_HOST` 指到連不上的位址
——任何一條真的走到網路會當場炸,不會靜靜變成假綠。**不開票、不改票、不留任何東西在 Gitea 上。**
**它在守什麼**`inkstone/ISEP#131`):Routine 08-06 起讀 `journeys.md` 本 sprint 段,
@@ -447,6 +447,9 @@ Gitea 主線里程碑抓票(`inkstone/InkStoneCo#118`),但那是一段給
「在主線上」=hub 里程碑裡、或被主線成員當相依(跨 repo 邊,inkstone/ISEP#133);
別 repo 裡同名的里程碑**不算**主線。主線抓盡才抓「逾期的 open 里程碑」(一個里程碑物件一組);
backlog/沒里程碑且沒有邊的一律不抓
⇒ 帶 --pool 或環境 ISEP_DRAIN=1(接票的環境):兩層都抓盡後再看整個 open 票池,
s/* 恰好是 s/todo 或 s/backlog 就可抓(不限里程碑),其他格一格不放寬(inkstone/ISEP#130
可抓 0 張時列出池子大小與每種「不能抓的理由」各幾張,不再印「正常、不是故障」
認領 claim 指派 + s/doing + 第一行【身份】的留言,一個動作
完成 handback --label s/review(本來就有的那半,不重做)
```
@@ -464,6 +467,14 @@ Gitea 主線里程碑抓票(`inkstone/InkStoneCo#118`),但那是一段給
- ③「該擋」六條任一紅 ⇒ 規則只長在 `pick` 這端,手動 `claim` 一張 Human 的票照樣過
- ③「身份名不在名單上 → 一通都沒打」紅 ⇒ 名單以外的名字碰到了 Gitea
- ④ 第一條紅 ⇒ 連不上 Gitea 時回了離開碼 1,雲端會把「斷線」當「沒票」收工
- ⑤「主線與逾期都抓盡、帶 --pool → 回 mira#25」紅 ⇒ 又回到 09-18 的形狀:幾百張 open 票,工人說沒事做
- ⑤「--all 票池恰好是這幾張」紅 ⇒ 要嘛放寬了不該碰的(Human/指派 Leotriage/沒 s/*/hub),要嘛漏了該抓的
- ⑤「ISEP_DRAIN=1 --pool」紅 ⇒ 雲端工人照 `cloud-worker.md``ticket pick`、佇列閘自己跑的 pick,都看不到票池
- ②「沒帶 --pool → 票池一通都沒讀」紅 ⇒ **誤攔**:本機總管跑過 `handback` 後每次收工都會被佇列閘點名去抓票池
- ⑤「可抓 0 張時列理由表、不說正常」紅 ⇒ 「0 張」又被說成正常收工(c7797)
- ⑤「分頁」紅 ⇒ 伺服器每頁上限比 50 小時,第二頁之後的票看不到
- ⑤「票池抓盡、還有沒 s/* 的票 → 回待分診那張,下一步是 triage」紅 ⇒ 沒驗傷的票又沉默地消失在「可抓 0 張」後面(`inkstone/ISEP#159`A43 測分診本身)
- ⑤「pick --claim 遇到待分診 → 不認領」紅 ⇒ 會對一張還沒決定要不要做的票寫 s/doing
📌 **真實 Gitea 唯讀實跑**2026-09-07isep-hand,不改任何票):
`ticket pick --mainline InkStoneCo/system-dev/mainline.json --all` 在主線
@@ -474,6 +485,55 @@ Gitea 主線里程碑抓票(`inkstone/InkStoneCo#118`),但那是一段給
assignee`claude-code`、標籤 `s/todo → s/doing`、留言 6325 第一行【身份】——
之後再 `pick` 就不再回 #131(票上驗收第 2 條的 log 在票的留言裡)。
### A43 — 雲端工人會分診、會組里程碑,而且碰不到 leo 的票:80 條
```
bash scripts/test-ticket-triage.sh
bash hooks/tests/queue-drain-guard.test.sh # 28 條:待分診那一列,閘印 triage 不印 claim
```
**該看到**`通過 80 條,失敗 0 條``通過 28 條,失敗 0 條`。**全程離線**(形狀同 A31:假池子 3 個 repo、
3 個 open 里程碑、1 張載體帶 3 條相依;時鐘定在 2026-09-18`TICKET_HOST` 連不上)。
**它在守什麼**`inkstone/ISEP#159`):leo 09-18「我有快 500 個票⋯⋯它看到票時要能夠組成 milestone 提出版本,
所以不只是看票,還要組票」。當天實量 open 302 張、沒 s/* 的 74 張、沒掛里程碑的 257 張;雲端只會撿(A31),不會組。
哪張跟哪張重複、哪幾張該一起出版——是**讀票的人的判斷**;這一支守的是判斷寫回 Gitea 的那一步:
```
triage 沒有 s/* 的票 → s/backlogs/triages/pending 票上一則說明(--why 必填),一個動作
--dup-of <票> → 說明+close/duplicate+關+在留下的那張留一則指回來
compose --title --goal --due --carrier inkstone/InkStoneCo#N <前置…>
建在 InkStoneCo、掛在既有載體、前置掛成相依、s/backlog → s/todo,不開任何新票
先全部讀過才寫第一筆;驗不過一次列出全部理由
pick --pool 時:還沒到期的 InkStoneCo 里程碑的前置 → 排在散票之前(組了就照里程碑做)
可做的都抓盡 → 回一張待分診的(row 帶 next=triage 那一行,佇列閘照它印)
不碰 掛 Humanhuman/*、指派給別人(含 Leo)——判準是標籤與 assignee 登入名,不看文字
```
**失敗**
- ①「掛 Human/指派 Leo → 不碰」任一紅,或 ②③ 裡「驗收 3」那幾條紅 ⇒ **會寫 leo 的票**(驗收 3 破了)
- ②「重複的對象是 Leo 的票 → 不在它上面寫字」紅 ⇒ 關重複票時順手在 leo 的票上留言
- ②「寫入恰好是 [留言, 改標籤]」紅 ⇒ 改了欄位卻沒留說明(驗收 1:每張被動過的票都說得出分到哪、為什麼)
- ②「--to s/todo 擋」紅 ⇒ 沒排進里程碑的票被標成「已排進里程碑」
- ③「好幾格不對時一次列齊」紅 ⇒ 改一格撞一次——閘在懲罰人
- ③「名字是版本號/沒期限/9999/過去」任一紅 ⇒ 開工規約第 5、6 條破了
- ③「載體不在 InkStoneCo」紅 ⇒ 開工規約第 7 條破了(在子 repo 建里程碑)
- ③「前置已是別的里程碑載體的前置」/「載體是別一輪的前置」紅 ⇒ 一張票同時排進兩輪
- ③「不開任何新票」紅 ⇒ 開工規約第 2 條破了
- ④「里程碑那一組排在票池之前」紅 ⇒ 組了里程碑,工人還是照開票時間撿散票
- ④「沒帶 --pool → 不看、不回待分診」紅 ⇒ **誤攔**:本機總管收工時被佇列閘叫去分診
- ④「載體票本身不當成可做的票」紅 ⇒ 工人會去「做」一張容器票
📌 **真實 Gitea 實跑**2026-09-18isep-hand 用本分支代跑一趟,署名 `[isep-hand]`):
- 分診前 `triage --list`:待分診 72 張 → 分診 4 張後 67 張(總數同時受別條線影響;我動的 4 張讀回皆對)
- `Arcrun#188` → 與 `Arcrun#143` 重複:`close/duplicate`、已關,#143 上有指回來的留言
- `Arcrun#131``s/triage`(與 #143 同一件事,兩張留哪張交總管)
- `ISEP#47``arcrun-rag#199``s/backlog`,各有一則說明
- 組里程碑:`ticket where` 撈不到能載這一輪的 InkStoneCo User Story ⇒ 補一張載體 `InkStoneCo#136`
`compose` 建出 InkStoneCo milestone 68「金鑰不再出現在任何畫面與 log 裡」(期限 09-25):
載體掛上、`ISEP#47``arcrun-rag#199` 成為相依並 `s/backlog → s/todo`、三張各一則說明
- `pick --pool --all`(主線 #65):第一組就是這個里程碑的兩張前置,之後票池 101 張、待分診 67 張
- 真的擋:`compose --carrier InkStoneCo#134 ISEP#47 Arcrun#143` → 離開碼 2、一筆都沒寫,三個理由一次列出
#134 已是主線載體 #55 的前置/#47 已排進 milestone 68#143 還沒分診)
### A19 — 下游做完時頂層跟著關:49 條
```
bash scripts/test-ticket-handoff-writeback.sh
+10
View File
@@ -0,0 +1,10 @@
# 雲端環境(claude.ai Cloud environment)變數清單的版本紀錄——**只記名字,不記值**。
# leo 2026-09-18:「你這裡記錄每版的 credential 的 key,但 value 自動產生,我就貼上去,你要有版本,因為這件事做了很多次,但你都沒記錄版本」
# 產生器 scripts/make-cloud-env.sh 讀本檔最後一版的號碼印在產物檔頭,並列出與前一版的差異。
# 欄位:版本<TAB>日期<TAB>key(逗號分隔,順序=NEEDED<TAB>為什麼變
v1 2026-08-20 GITEA_TOKEN_CLAUDE_CODE 首版:雲端 bootstrap 與 plugin 安裝(f855d82
v2 2026-09-01 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE 雲端拿得到 youlin 的 CF tokenISEP#115 c5526ca9ea99
v3 2026-09-01 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE,CLOUDFLARE_ACCOUNT_ID_YOULIN,YOULIN_MCP_OWNER_SECRETS,STAGE_USERNAME_YOULIN,STAGE_PASSWORD_YOULIN,CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE,CLOUDFLARE_ACCOUNT_ID_GEEK6688 leo「youlin 和 geek6688 都全給」(ISEP#115 c554155427aef943
v4 2026-09-01 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE,CLOUDFLARE_ACCOUNT_ID_YOULIN,YOULIN_MCP_OWNER_SECRETS,STAGE_USERNAME_YOULIN,STAGE_PASSWORD_YOULIN,CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE,CLOUDFLARE_ACCOUNT_ID_GEEK6688,UNCLE6_CF_API_KEY 出貨三站實際部署到 uncle6ISEP#115 c5577cb310e9
v5 2026-09-01 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE,CLOUDFLARE_ACCOUNT_ID_YOULIN,YOULIN_MCP_OWNER_SECRETS,STAGE_USERNAME_YOULIN,STAGE_PASSWORD_YOULIN,CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE,CLOUDFLARE_ACCOUNT_ID_GEEK6688,UNCLE6_CF_API_KEY,ARCRUN_NS_YOULIN 出貨線實例座標(Arcrun#195dd86fefv0.21.0
v6 2026-09-18 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE,CLOUDFLARE_ACCOUNT_ID_YOULIN,YOULIN_MCP_OWNER_SECRETS,STAGE_USERNAME_YOULIN,STAGE_PASSWORD_YOULIN,CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE,CLOUDFLARE_ACCOUNT_ID_GEEK6688,UNCLE6_CF_API_KEY,ARCRUN_NS_YOULIN,ARCRUN_NS_UNCLE6,GITHUB_MIRROR_TOKEN,GITHUB_ACCOUNT_NAME 雲端要能出 stageproduncle6 namespaceGitHub 鏡像兩把(InkStoneCo#98 c7739ISEP#158
1 # 雲端環境(claude.ai Cloud environment)變數清單的版本紀錄——**只記名字,不記值**。
2 # leo 2026-09-18:「你這裡記錄每版的 credential 的 key,但 value 自動產生,我就貼上去,你要有版本,因為這件事做了很多次,但你都沒記錄版本」
3 # 產生器 scripts/make-cloud-env.sh 讀本檔最後一版的號碼印在產物檔頭,並列出與前一版的差異。
4 # 欄位:版本<TAB>日期<TAB>key(逗號分隔,順序=NEEDED)<TAB>為什麼變
5 v1 2026-08-20 GITEA_TOKEN_CLAUDE_CODE 首版:雲端 bootstrap 與 plugin 安裝(f855d82)
6 v2 2026-09-01 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE 雲端拿得到 youlin 的 CF token(ISEP#115 c5526,ca9ea99)
7 v3 2026-09-01 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE,CLOUDFLARE_ACCOUNT_ID_YOULIN,YOULIN_MCP_OWNER_SECRETS,STAGE_USERNAME_YOULIN,STAGE_PASSWORD_YOULIN,CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE,CLOUDFLARE_ACCOUNT_ID_GEEK6688 leo「youlin 和 geek6688 都全給」(ISEP#115 c5541/5542,7aef943)
8 v4 2026-09-01 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE,CLOUDFLARE_ACCOUNT_ID_YOULIN,YOULIN_MCP_OWNER_SECRETS,STAGE_USERNAME_YOULIN,STAGE_PASSWORD_YOULIN,CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE,CLOUDFLARE_ACCOUNT_ID_GEEK6688,UNCLE6_CF_API_KEY 出貨三站實際部署到 uncle6(ISEP#115 c5577,cb310e9)
9 v5 2026-09-01 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE,CLOUDFLARE_ACCOUNT_ID_YOULIN,YOULIN_MCP_OWNER_SECRETS,STAGE_USERNAME_YOULIN,STAGE_PASSWORD_YOULIN,CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE,CLOUDFLARE_ACCOUNT_ID_GEEK6688,UNCLE6_CF_API_KEY,ARCRUN_NS_YOULIN 出貨線實例座標(Arcrun#195,dd86fef/v0.21.0)
10 v6 2026-09-18 GITEA_TOKEN_CLAUDE_CODE,CLOUDFLARE_API_TOKEN_YOULIN_CC_USE,CLOUDFLARE_ACCOUNT_ID_YOULIN,YOULIN_MCP_OWNER_SECRETS,STAGE_USERNAME_YOULIN,STAGE_PASSWORD_YOULIN,CLOUDFLARE_API_TOKEN_CC_SHIPPING_CORE,CLOUDFLARE_ACCOUNT_ID_GEEK6688,UNCLE6_CF_API_KEY,ARCRUN_NS_YOULIN,ARCRUN_NS_UNCLE6,GITHUB_MIRROR_TOKEN,GITHUB_ACCOUNT_NAME 雲端要能出 stage/prod:uncle6 namespace+GitHub 鏡像兩把(InkStoneCo#98 c7739;ISEP#158)
+23
View File
@@ -206,6 +206,29 @@ $ curl … https://git.uncle6.me/api/v1/version → 200
其餘(讀票、認領、留言、handback、寫 code、跑測試、開 PR、對 leo21c 唯讀查詢、發 Telegram、**種 secret/直推成品/POST 到 stage 實例**——走 `scripts/stage` 與 Arcrun 的 `stage-deploy-artifacts.py`)雲端全做。
📌 這份清單的家是 `inkstone/InkStoneCo` 的 `cloud-worker.md`(票上驗收第 4 條),ISEP 只放草稿;併進去由總管做。
## 雲端工人不只撿票,還要分診、組里程碑(inkstone/ISEP#159,給 `cloud-worker.md` 的草稿)
leo 09-18:「它看到票時要能夠組成 milestone 提出版本,所以不只是看票,還要組票。」
ISEP 這一半是 `scripts/ticket` 的 `triage``compose` 兩個動詞,與 `pick --pool` 多的兩層(見 `docs/TESTING.md` A43)。
`cloud-worker.md` 現在寫著「🚫 不開里程碑、不改里程碑⋯⋯」——那一條要換成下面這段(**併進 InkStoneCo 由總管做**):
```
1. 分診:`ticket triage --list`(找重複用 `--all`)。每張沒 s/* 的票讀過之後擇一:
ticket triage <票> --to s/backlog --why "…" 決定要做
ticket triage <票> --to s/triage --why "…" 要總管/leo 判斷(方向、品味、要不要做)
ticket triage <票> --to s/pending --why "…" 在等外部
ticket triage <票> --dup-of <留下的那張> --why "…" 重複(關新的、留舊的)
都帶 `--name <ISEP 工人名> --sign cloud-worker`。掛 Human/指派 Leo 的票工具會擋,不必自己判。
2. 組里程碑:已分診、彼此相關、做完能出一個可測版本的幾張 ⇒
ticket compose --title "<這一輪要讓什麼變成真的>" --goal "…" --due <160 天內>
--carrier inkstone/InkStoneCo#N <前置票…> --name … --sign cloud-worker
載體=既有的 InkStoneCo User Story`ticket where` 撈不到能載這一輪的 ⇒ 先 `ticket new InkStoneCo` 補一張 US 當載體
(開工規約第 2 條:撈不到才是真缺口)。一張票同時只排一輪,工具會擋。
3. 取票:`ticket pick`ISEP_DRAIN=1 ⇒ 自帶 --pool)。組好的里程碑的前置排在散票之前;
可做的都抓盡時它回一張待分診的,下一步就是它印的那行 triage。
收工條件不變:`ticket pick` 回離開碼 1。
```
## 這張票沒動、也不會動的東西
- 沒有動 `youlinhsieh/inkstoneco`GitHub 薄殼 repo)——這個新機制**完全不需要
+9 -1
View File
@@ -11,6 +11,14 @@
其中 **3 支檔案存在但沒被掛上**(2 支是待人填的空範本、1 支是刻意留著沒開的止血帶,見下面「未生效」表)。
下面按「你會在什麼時候撞到它」分組,一支一行。
> 📌 **`inkstone/ISEP#159`2026-09-18,待總管定版)+0 支、+0 條、腳本 65→66**:沒加閘。`scripts/ticket` 多兩個動詞
> `triage`(沒 s/* 的票給狀態+留說明,或當重複關掉並指回去)與 `compose`(把已分診的票組成 InkStoneCo 里程碑:載體+前置,
> 先全部驗過才寫);`pick --pool` 多兩層(還沒到期的 InkStoneCo 里程碑的前置、最後是待分診的票),每一列帶 `next`。
> `queue-drain-guard.sh` 改判準不加閘:照 pick 那一列的 `next` 印下一步(待分診的票下一步是 triage,不是 claim)。
> `scripts/` 1`test-ticket-triage.sh`。
> **62 支、88 條、66 支腳本是在這棵樹上當場數出來的**`ls hooks/*.sh | wc -l`62、
> `grep -c '"command":' hooks/hooks.json`88、`ls -p scripts | grep -v / | wc -l`66)。
> 📌 **`inkstone/ISEP#153`2026-09-13,待總管定版)+0 支、+1 條**`baton-handback-guard.sh` 多掛一條 `Stop`。
> 背景派工時 `PostToolUse:Agent` 在工人**剛出發**就觸發,舊版當場念「收工了但棒子沒交回來」(09-13 對 ISEP#150、arcrun-rag#14 各一次,工人其實還要跑 17 分鐘)。
> 現在送出那一刻看到 launch ack 就不查;工人交件(主對話收到 `<task-notification>` completed)時由 Stop 那半用 `tool-use-id` 對回原派工單再查,同一條線只點名一次。
@@ -284,7 +292,7 @@
| `delivery-police.sh` | AI 宣稱「這件事做完了」,卻看不到任何實測證據(畫面截圖、指令輸出、HTTP 狀態碼…)就擋下。 | 🛑 擋 |
| `wiki-first-police.sh` | AI 做完事卻沒有把結論寫回 wiki 就想收工,就擋下——下次(或別的 AI)查 wiki 會查不到這次做過什麼。 | 🛑 擋 |
| `unpushed-police.sh` | AI 改好的東西還留在本機、沒有真的推送出去給別人用,卻想收工,就擋下——「改對了但沒送到」跟沒改是一樣的。 | 🛑 擋 |
| `queue-drain-guard.sh` | **在接票的 session(跑過 `ticket pickclaimhandback`,或環境設了 `ISEP_DRAIN=1`),池子裡還有現在就能抓的票,就不准收工**——它自己跑一次 `ticket pick`,有票就把票號和認領指令交回去。這是 ISEP 唯一一支看「佇列」而不是看「這回合寫了什麼」的收工閘(`inkstone/ISEP#33`:雲端三趟 run 都是做完一件、還有票就停)。做不了的票要把理由寫回票、改欄位,pick 就不再回它。跟 leo 聊天的 session 不會被咬;同一張連續指名 3 次、讀不到佇列 3 次、或一個 session 擋滿 40 次就放行並留痕,不會鎖死。 | 🛑 擋(有上限) |
| `queue-drain-guard.sh` | **在接票的 session(跑過 `ticket pickclaimhandback`,或環境設了 `ISEP_DRAIN=1`),池子裡還有現在就能抓的票,就不准收工**——它自己跑一次 `ticket pick`,有票就把票號和認領指令交回去。「池子」多大看環境:設了 `ISEP_DRAIN=1`(雲端工人)時 pick 會看到整個 open 票池的 `s/todo``s/backlog`;本機沒設時只看主線與逾期里程碑,所以總管跑過 `handback` 也不會被叫去抓票池(`inkstone/ISEP#130`)。雲端環境下可做的都抓盡、還有沒 s/* 的票時,pick 回一張待分診的,本閘照那一列印 `ticket triage …` 而不是 claim`inkstone/ISEP#159`)。這是 ISEP 唯一一支看「佇列」而不是看「這回合寫了什麼」的收工閘(`inkstone/ISEP#33`:雲端三趟 run 都是做完一件、還有票就停)。做不了的票要把理由寫回票、改欄位,pick 就不再回它。跟 leo 聊天的 session 不會被咬;同一張連續指名 3 次、讀不到佇列 3 次、或一個 session 擋滿 40 次就放行並留痕,不會鎖死。 | 🛑 擋(有上限) |
| `baton-handback-guard.sh` | **背景派出去的工人交件時**(主對話收到完工通知),檢查那張工單票有沒有把棒子交回來(指派/標籤/下一步三格),缺就擋一次要 AI 補。工人還在跑的時候一聲都不出(`inkstone/ISEP#153`)。同一條線只點名一次;補完三格就不再出現。前景派工的那一半在下面 H 組。 | 🛑 擋(每條線至多一次) |
> 🔴 **`claim-verify-police.sh` 已於 `inkstone/ISEP#60` 移除**(連同下面原本的 G 組 `subagent-claim-worksheet.sh`)。
+9 -3
View File
@@ -33,6 +33,9 @@
# 不用 $CLAUDE_PROJECT_DIR:雲端沒有它,21 支閘的 log 因此靜默寫進 /.claude/hooks/ISEP#130 c6873)。
# 狀態與 log 一律寫 ${ISEP_DRAIN_STATE_DIR:-${TMPDIR:-/tmp}},那裡在哪台都寫得進去。
#
# 「池子」多大由 pick 決定:環境 ISEP_DRAIN=1 時 pick 會往下看到整個 open 票池(inkstone/ISEP#130);
# 本機沒設時只看主線與逾期——總管跑過 handback 不會因此被叫去抓票池。
#
# 迴歸測試:hooks/tests/queue-drain-guard.test.sh
set -u
@@ -138,6 +141,7 @@ miss = 0
try:
row = json.loads(out)
ref, title = row.get("ref"), (row.get("title") or "")[:80]
nxt = (row.get("next") or "").replace("\t", " ").replace("\n", " ")
except Exception:
save("ALLOW:unparsable")
if not ref:
@@ -149,19 +153,21 @@ if same > MAX_SAME:
if blocks >= MAX_BLOCKS:
save("ALLOW:max-blocks")
blocks += 1
save("BLOCK:%s\t%s\t%d" % (ref, title, same))
save("BLOCK:%s\t%s\t%d\t%s" % (ref, title, same, nxt))
' 2>/dev/null) || VERDICT="ALLOW:crash"
case "$VERDICT" in
BLOCK:*)
body="${VERDICT#BLOCK:}"
REF=$(printf '%s' "$body" | cut -f1); TITLE=$(printf '%s' "$body" | cut -f2); N=$(printf '%s' "$body" | cut -f3)
REF=$(printf '%s' "$body" | cut -f1); TITLE=$(printf '%s' "$body" | cut -f2); N=$(printf '%s' "$body" | cut -f3); NEXT=$(printf '%s' "$body" | cut -f4)
# pick 的每一列自帶下一步(inkstone/ISEP#159):待分診的票下一步是 triage 不是 claim——照它印,不自己猜
[ -z "$NEXT" ] && NEXT="python3 \"$PLUGIN_ROOT/scripts/ticket\" claim $REF --name <你的名字>"
note "⛔ 擋下" "池子還有 $REF(第 $N 次指名)"
cat >&2 <<MSG
🔁 佇列警察:**這個 session 在接票,而池子裡還有一張現在就能抓的票——還不是收工的時候。**
下一張:$REF $TITLE
認領:python3 "$PLUGIN_ROOT/scripts/ticket" claim $REF --name <你的名字>
下一步:$NEXT
leo 2026-09-13:「任務完成自己去拿下一個任務,幫我消化任務」。
回報寫在票上就好,**不必在這裡寫收工摘要**——摘要等 pick 抓盡再寫一次。
+5
View File
@@ -61,6 +61,11 @@ run "★ stop_hook_active=true 仍擋(別的閘擋過一次就讓路,正是
ISEP_DRAIN=1 run "ISEP_DRAIN=1:還沒跑過任何 ticket 指令也擋" 2 s4 chat.jsonl
check "log 寫在狀態目錄(不靠 CLAUDE_PROJECT_DIR" "grep -q '擋下' '$TMP/state-s4/queue-drain-guard.log'"
stub 0 '{"ref":"inkstone/mira#21","title":"沒人看過的票","group":"待分診","next":"python3 /x/scripts/ticket triage inkstone/mira#21 --to <s/backlog|s/triage|s/pending> --why \"<一句理由>\""}'
run "★ 可做的都抓盡、還有待分診的票 → 擋(ISEP#159:沒驗傷的票不會自己消失)" 2 s9 worker.jsonl
check "訊息照 pick 那一列的 next 印 triage,不印 claim(待分診的票認領不了)" \
"grep -q 'triage inkstone/mira#21' '$TMP/stderr' && ! grep -q 'claim inkstone/mira#21' '$TMP/stderr'"
echo
echo "── ② 不該擋 ──"
stub 0 "$TICKET"
+35 -7
View File
@@ -5,7 +5,7 @@
# 誤觸時怎麼關: 這支不擋任何東西。不想產生就別跑;產物在版控外,刪掉即可。
#
# 用法:bash scripts/make-cloud-env.sh
# 產物:~/.claude/cloud-env/<日期>.txt(權限 600**不在任何 repo 裡**
# 產物:~/Desktop/cloud-env-<版本>-<日期>.txt(權限 600**不在任何 repo 裡**;版本紀錄 docs/cloud-env-versions.tsv
# 本腳本只寫「變數名字」,值在執行當下才從既有 .env 讀出來寫進產物 —— 值不進版控、不進對話。
set -euo pipefail
@@ -44,6 +44,14 @@ NEEDED=(
# 只有 namespace 是機敏 ⇒ 走環境變數。原本只住在 ~/.arcrun/config.yaml 的 api_key
# 那個檔在家目錄、不隨 clone 走 ⇒ 雲端永遠拿不到。
ARCRUN_NS_YOULIN # youlin 實例的 namespaceX-Arcrun-API-Key
ARCRUN_NS_UNCLE6 # uncle6 實例的 namespace:出貨第 1、19、20 站派給 uncle6 工作流(inkstone/InkStoneCo#98 → comment 7739
# ── prod 出貨把產物推上 GitHub 鏡像(第 14、21、22 站)──
# 🔴 名字進清單 ≠ 雲端可以自由寫 GitHub`github-contact-guard.sh` 照樣擋,
# 寫入仍要 D20 開閘(保險檔落在哪由 inkstone/ISEP#157 處理)。
# 進清單是因為「拿不到這兩個名字」會讓 prod 那半在雲端**連開閘之後都走不下去**。
GITHUB_MIRROR_TOKEN # GitHub 鏡像 repo 的寫入 token(走標頭,不進網址)
GITHUB_ACCOUNT_NAME # 上面那把的帳號名(組鏡像 repo 路徑用,不是機密)
)
#
# 🔴 這份清單的邊界——加一把之前先問「這把打得到哪個實例」,不是「這把方便嗎」
@@ -91,13 +99,30 @@ lookup() { # $1=變數名 → 印出值(找不到就空)
return 1
}
# 預設丟 ~/.claude/cloud-env(權限 700)。要放別的地方= OUT_DIR=~/Desktop bash scripts/make-cloud-env.sh
OUT_DIR="${OUT_DIR:-$HOME/.claude/cloud-env}"
# ── 版本(leo 2026-09-18:「你要有版本,因為這件事做了很多次,但你都沒記錄版本」)──
# 真相源=docs/cloud-env-versions.tsv(只記 key,不記值)。最後一列=現行版。
# 🔴 NEEDED 跟最後一列的 key 不一致 ⇒ 拒絕產生:改了清單就必須在 tsv 加一版。
VERSIONS="$(cd "$(dirname "$0")/.." && pwd)/docs/cloud-env-versions.tsv"
[ -f "$VERSIONS" ] || { echo "🔴 找不到 $VERSIONS" >&2; exit 1; }
CUR_LINE=$(grep -v '^#' "$VERSIONS" | grep -v '^[[:space:]]*$' | tail -1)
PREV_LINE=$(grep -v '^#' "$VERSIONS" | grep -v '^[[:space:]]*$' | tail -2 | head -1)
VER=$(printf '%s' "$CUR_LINE" | cut -f1); VER_DATE=$(printf '%s' "$CUR_LINE" | cut -f2)
VER_KEYS=$(printf '%s' "$CUR_LINE" | cut -f3); VER_WHY=$(printf '%s' "$CUR_LINE" | cut -f4)
PREV_VER=$(printf '%s' "$PREV_LINE" | cut -f1); PREV_KEYS=$(printf '%s' "$PREV_LINE" | cut -f3)
NEEDED_JOINED=$(IFS=,; printf '%s' "${NEEDED[*]}")
if [ "$NEEDED_JOINED" != "$VER_KEYS" ]; then
echo "🔴 NEEDED 與 $VERSIONS 最後一版($VER)的 key 不一致——改了清單就要在 tsv 加一列新版本再跑。" >&2
echo " NEEDED$NEEDED_JOINED" >&2
echo " $VER $VER_KEYS" >&2
exit 2
fi
ADDED=$(comm -13 <(tr , '\n' <<<"$PREV_KEYS" | sort) <(tr , '\n' <<<"$VER_KEYS" | sort) | paste -sd, -)
REMOVED=$(comm -23 <(tr , '\n' <<<"$PREV_KEYS" | sort) <(tr , '\n' <<<"$VER_KEYS" | sort) | paste -sd, -)
# 預設丟桌面(leo 2026-09-18 指定)。要放別的地方= OUT_DIR=<目錄> bash scripts/make-cloud-env.sh
OUT_DIR="${OUT_DIR:-$HOME/Desktop}"
mkdir -p "$OUT_DIR"
# 只在「這個目錄是我們自己造的預設位置」時才收緊權限——
# OUT_DIR 可被覆寫,不該對使用者指定的既有目錄(例如 ~/Desktop)動權限。
[ "$OUT_DIR" = "$HOME/.claude/cloud-env" ] && chmod 700 "$OUT_DIR"
OUT="$OUT_DIR/$(date +%Y%m%d-%H%M%S).txt"
OUT="$OUT_DIR/cloud-env-${VER}-$(date +%Y%m%d-%H%M).txt"
SETUP="$(cd "$(dirname "$0")/.." && pwd)/docs/cloud-setup-script.sh"
[ -f "$SETUP" ] || { echo "🔴 找不到 $SETUP" >&2; exit 1; }
@@ -105,6 +130,8 @@ SETUP="$(cd "$(dirname "$0")/.." && pwd)/docs/cloud-setup-script.sh"
MISSING=()
{
echo "claude.ai → Cloud environments → 你的環境。下面兩塊各自貼進對應欄位。"
echo "版本:${VER}${VER_DATE})——${VER_WHY}"
echo "${PREV_VER} 多:${ADDED:-(無)}|少:${REMOVED:-(無)}"
echo "產生時間:$(date '+%Y-%m-%d %H:%M')"
echo
echo "════════ ① Environment variables(一行一個,名字與值分開填)════════"
@@ -123,5 +150,6 @@ MISSING=()
chmod 600 "$OUT"
echo "✅ 產生完成:$OUT"
echo " 版本:${VER}(比 ${PREV_VER} 多:${ADDED:-}|少:${REMOVED:-}"
echo " 變數 ${#NEEDED[@]} 個|找不到值的 ${#MISSING[@]}${MISSING[*]:-}"
echo " 🔴 這個檔含金鑰真身:貼完就刪(rm '$OUT'),它刻意不在任何 repo 裡。"
+8
View File
@@ -59,6 +59,14 @@ chk 0 "$miss" "A3 每個名字都帶著值出現在 ① 區塊"
printf '%s\n' "$OUT_LINE" | grep -q "找不到值的 0 個" \
&& ok "A4 收尾那行說「找不到值的 0 個」" || bad "A4 收尾計數不對:$OUT_LINE"
# 版本(leo 2026-09-18):產物檔頭帶現行版本號;清單改了沒升版要拒絕
grep -q "^版本:v[0-9]" "$F" && ok "V1 產物檔頭寫著版本號" || bad "V1 產物檔頭沒有版本號"
VT="$(cd "$(dirname "$S")/.." && pwd)/docs/cloud-env-versions.tsv"; VB="$VT.bak-test"
cp "$VT" "$VB"; printf 'v999\t2099-01-01\tNOPE_ONLY\t測試用\n' >> "$VT"
INKSTONE_ROOT="$FAKE" OUT_DIR="$OUTD" bash "$S" >/dev/null 2>&1; rc=$?
mv "$VB" "$VT"
chk 2 "$rc" "V2 清單與最後一版 key 不一致時拒絕產生(離開碼 2)"
# 缺值時不准假綠:拿掉第一個,它要變成 <🔴 …> 且計數變 1
grep -v "^${NEEDED[0]}=" "$FAKE/.env" > "$FAKE/.env.tmp" && mv "$FAKE/.env.tmp" "$FAKE/.env"
OUT2=$(INKSTONE_ROOT="$FAKE" OUT_DIR="$OUTD" bash "$S" 2>&1)
+82 -6
View File
@@ -21,7 +21,7 @@ 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
unset ISEP_MAINLINE_FILE ISEP_IDENTITY CLAUDE_PROJECT_DIR ISEP_DRAIN ISEP_WORKER_LOGIN
MAIN="$TMP/mainline.json"
cat > "$MAIN" <<'JSON'
@@ -57,9 +57,21 @@ POOL = {
"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 的形狀:有人在做
"mira": [I("mira", 9, ["s/todo", "s/doing"], "main"), # 09-07 實查 mira#6 的形狀:有人在做
# ── 票池那一層才看得到的(inkstone/ISEP#130):都沒有里程碑 ──
I("mira", 20, ["s/triage"], None), # 還沒決定要不要做:不抓
I("mira", 21, [], None), # 沒有 s/*(還沒驗傷):不抓,但要被點名
I("mira", 22, ["s/todo"], None, assignees=("Leo",)), # 指派 Leo:不抓
I("mira", 23, ["s/backlog", "Human"], None), # Human:不抓
I("mira", 24, ["s/review"], None), # 等總管:不抓
I("mira", 25, ["s/backlog", "p/high"], None, created="2026-09-05T00:00:00Z"), # ★ 票池裡最優先
I("mira", 26, ["s/todo", "hub"], None), # hub:容器不是任務
I("mira", 27, ["Human"], None)], # 沒 s/* 但掛 Human:不抓、也不分診(ISEP#159
# 分頁:伺服器每頁上限 30(比 pick 要的 50 小)——只看「不滿一頁」就停的寫法會漏掉第 31 張之後的
"big": [I("big", n, [], None) for n in range(1, 31)] + [I("big", 31, ["s/backlog"], None)],
}
MSN = {"ISEP": ["main", "late", "future"], "Arcrun": ["main", "late", "future"], "mira": ["main"]}
SERVER_PAGE_MAX = 30
# 相依邊(inkstone/ISEP#133):主線錨在 Arcrun#48Arcrun#6 把 ISEP#1 當相依 ⇒ ISEP#1 在主線上;
# ISEP#13 掛在 ISEP 的同名里程碑但沒有任何邊 ⇒ 不在主線上。mira#9 同理(同名、沒邊)。
DEPS = {"Arcrun#6": ["ISEP#1"]}
@@ -84,9 +96,13 @@ def fake_api(path, payload=None, method=None):
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]
rows = [i for i in POOL[repo] if f"{repo}#{i['number']}" not in DROP]
if "milestones" in q:
want = q["milestones"][0]
return [i for i in rows if (i["milestone"] or {}).get("title") == want]
# 不帶里程碑=整個 repo 的 open 票(票池那一層),照 Gitea 的分頁
page = int(q.get("page", ["1"])[0]); per = min(int(q.get("limit", ["50"])[0]), SERVER_PAGE_MAX)
return rows[(page - 1) * per: page * per]
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)]
@@ -182,7 +198,10 @@ 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 "沒帶 --pool 時訊息明講「這一趟沒有看票池」並給出 --pool 這條路(ISEP#130:不再說成正常收工)" "True" \
"'沒有看票池' in out and '--pool' in out and '不是故障' not in out" "$ARGS"
p "沒帶 --pool、主線與逾期都抓盡 → 票池一通都沒讀(本機總管不會因此被點名去抓票池)" "False" \
"any('page=' in p for _,p,_ in rec)" "$ARGS"
p "抓盡時**沒有**回 Arcrun#8(未來里程碑)" "False" "'Arcrun#8' in out" "$ARGS"
unset DROP
@@ -236,6 +255,63 @@ p "擋下時訊息講得出理由與出路(pick" "True" "'Human' in out and
p "身份名不在名單上 → 在打任何 API 之前就擋(一通都沒打)" "True" "rc==2 and len(rec)==0" \
"[\"cmd_claim\",\"inkstone/Arcrun#6\",\"--mainline\",\"$MAIN\",\"--name\",\"路人\"]"
echo
echo "── ⑤ 票池那一層(inkstone/ISEP#130 c7801:幾百張 open 票,工人卻回「沒事做」)──"
POOLA="[\"cmd_pick\",\"--mainline\",\"$MAIN\",\"--pool\"]"
POOLALL="[\"cmd_pick\",\"--mainline\",\"$MAIN\",\"--pool\",\"--all\",\"--json\"]"
p "pickables/backlog 在票池那一層可抓" "True" "m.pickable(I('ISEP',4,['s/backlog'],None),None,None,m.POOL_STATUSES)[0]"
p "pickables/triage 在票池那一層仍不可抓(要不要做還沒決定)" "False" "m.pickable(I('x',1,['s/triage'],None),None,None,m.POOL_STATUSES)[0]"
p "pickable:沒有 s/* 仍不可抓,理由講得出「沒有 s/*」" "True" "'沒有 s/*' in m.pickable(I('x',1,[],None),None,None,m.POOL_STATUSES)[1]"
p "pickable:票池裡的 backlog 掛 Human → 不可抓(不該碰的一格都沒放寬)" "False" "m.pickable(I('x',1,['s/backlog','Human'],None),None,None,m.POOL_STATUSES)[0]"
p "pickable:票池裡指派給 Leo → 不可抓" "False" "m.pickable(I('x',1,['s/todo'],None,assignees=('Leo',)),None,'claude-code',m.POOL_STATUSES)[0]"
p "順序:同優先序 s/todo 先於 s/backlog" "True" \
"m.pick_order(I('a',9,['s/todo'],None)) < m.pick_order(I('a',1,['s/backlog'],None))"
p "主線有票時帶 --pool 也照樣先回主線的 Arcrun#6,票池一通都沒讀(能省就省)" "True" \
"'inkstone/Arcrun#6' in out and not any('page=' in p for _,p,_ in rec)" "$POOLA"
export DROP='["Arcrun#6","ISEP#1","Arcrun#7"]'
p "★ 主線與逾期都抓盡、帶 --pool → 回票池裡最優先的 mira#25p/high 的 backlog" "True" \
"'inkstone/mira#25' in out and rc is None" "$POOLA"
p "★ --all:票池可抓的恰好是這幾張,照 p/high → s/todo → s/backlog 排(Human/指派 Leotriage/沒 s/*reviews/doinghubPR 都不在)" \
"['inkstone/mira#25', 'inkstone/ISEP#5', 'inkstone/Arcrun#8', 'inkstone/ISEP#13', 'inkstone/ISEP#4', 'inkstone/big#31']" \
"[r['ref'] for r in json.loads(out) if r['group']=='票池']" "$POOLALL"
p "★ 分頁:伺服器每頁只給 30 張時,第 31 張(big#31)照樣讀得到" "True" "'inkstone/big#31' in out" "$POOLALL"
p "票池那一層也只讀不寫" "True" "all(mm=='GET' for mm,_,_ in rec)" "$POOLALL"
export ISEP_DRAIN=1
p "★ 環境 ISEP_DRAIN=1(雲端工人的環境)= 帶 --pool,指令不必改" "True" \
"'inkstone/mira#25' in out and rc==0" "[\"cmd_pick\",\"--mainline\",\"$MAIN\",\"--json\"]"
unset ISEP_DRAIN
unset DROP
export DROP='["Arcrun#6","ISEP#1","Arcrun#7","mira#25","Arcrun#8","ISEP#13","ISEP#5","ISEP#4","big#31"]'
p "★ 票池抓盡、但還有沒 s/* 的票 → 回一張待分診的(同一天開的,票號序第一的 big#1),下一步是 triage 不是 claimISEP#159" "True" \
"rc is None and 'inkstone/big#1' in out and ' triage inkstone/big#1 ' in out and 'claim inkstone/big#1' not in out" "$POOLA"
p "--json:待分診那一列帶 group=待分診 與貼了就能跑的 next(佇列閘照它印)" "True" \
"(lambda r: r['group']=='待分診' and ' triage ' in r['next'])(json.loads(out))" \
"[\"cmd_pick\",\"--mainline\",\"$MAIN\",\"--pool\",\"--json\"]"
p "待分診那一層不回掛 Human 的 mira#27(沒 s/* 也不碰)" "False" "'mira#27' in out" "$POOLALL"
p "pick --claim 遇到待分診的票 → 不認領(沒有任何寫入)" "True" \
"not any(mm in ('PATCH','PUT','POST') for mm,_,_ in rec)" \
"[\"cmd_pick\",\"--mainline\",\"$MAIN\",\"--pool\",\"--claim\"]"
export DROP='["Arcrun#6","ISEP#1","Arcrun#7","mira#25","Arcrun#8","ISEP#13","ISEP#5","ISEP#4","big#31","mira#21"'"$(python3 -c 'print("".join(",\"big#%d\"" % n for n in range(1,31)))')"']'
p "★ 票池與待分診都抓盡 → 離開碼 1" "1" "rc" "$POOLA"
p "★ 可抓 0 張時列出池子大小與「不能抓的理由」各幾張(沒 s/* 又掛 Human 的被點名),而且不說成「正常/不是故障」" "True" \
"'open 票池' in out and '沒有 s/*' in out and '不是故障' not in out and '正常' not in out" "$POOLA"
p "--json 抓盡時同一張理由表寫到 stderr(stdout 仍是 null,佇列閘照舊解析得動)" "True" \
"out.startswith('null') and '不能抓' not in out.split(chr(10))[0] and '沒有 s/*' in out" \
"[\"cmd_pick\",\"--mainline\",\"$MAIN\",\"--pool\",\"--json\"]"
unset DROP
echo
echo " (認領票池裡的票)"
CLP="[\"cmd_claim\",\"inkstone/ISEP#4\",\"--mainline\",\"$MAIN\",\"--name\",\"isep-hand\",\"--pool\"]"
p "★ --pool 認領 backlog 的 ISEP#4 → 過,s/backlog 換成 s/doing" "True" \
"rc is None and [sorted(pl['labels']) for mm,p,pl in rec if mm=='PUT' and p.endswith('/issues/4/labels')]==[[2]]" "$CLP"
p "認領留言寫明是從 open 票池抓的、狀態從 s/backlog 變 s/doing" "True" \
"any('open 票池' in pl['body'] and 's/backlog → s/doing' in pl['body'] for mm,p,pl in rec if mm=='POST' and p.endswith('/comments'))" "$CLP"
blocked "--pool 也擋掛 Human 的 mira#23" inkstone/mira#23 --pool
blocked "--pool 也擋指派 Leo 的 mira#22" inkstone/mira#22 --pool
blocked "--pool 也擋 s/triage 的 mira#20" inkstone/mira#20 --pool
blocked "--pool 也擋沒有 s/* 的 mira#21" inkstone/mira#21 --pool
echo
echo "── ④ 動詞接得上(不帶假池子,走到網路才炸)──"
out=$(python3 "$T" pick --mainline "$MAIN" 2>&1); got=$?
+300
View File
@@ -0,0 +1,300 @@
#!/bin/bash
# 雲端工人「分診+組里程碑」的測試(inkstone/ISEP#159
#
# 票上的驗收:
# 1. 沒狀態的票數下降,每張被動過的票上都有一則說明(分到哪、為什麼;重複的指向哪張)
# 2. 提出新里程碑:載體票在 InkStoneCo、執行票掛成前置、名字不是版本號、有期限、deliverable=版本
# 3. 不碰 Human、不碰指派給 Leo 的票
# 4. 組了之後照里程碑往下做(pick --pool 先回它的前置票)
#
# 全程離線:api() 換成錄音機餵假池子;TICKET_HOST 指到連不上的位址,漏接一條會當場炸,不會假綠。
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 ISEP_MEMBER_BACKOFF=0
export ISEP_COUNTDOWN_STATE_DIR="$TMP/state"; mkdir -p "$ISEP_COUNTDOWN_STATE_DIR"
# 時鐘定在 2026-09-18 00:00 UTC
export ISEP_COUNTDOWN_NOW=$(python3 -c 'import datetime as d;print(int(d.datetime(2026,9,18,0,0,tzinfo=d.timezone.utc).timestamp()))')
unset ISEP_MAINLINE_FILE ISEP_IDENTITY CLAUDE_PROJECT_DIR ISEP_DRAIN
export ISEP_WORKER_LOGIN=claude-code # 抓票者自己是誰(真跑時問 /user;離線測試不打網路)
MAIN="$TMP/mainline.json"
cat > "$MAIN" <<'JSON'
{"ref":"inkstone/InkStoneCo#65","owner":"inkstone","repo":"InkStoneCo","id":65,
"title":"主線 M","due_on":"2026-09-25T23:59:59Z","members":[]}
JSON
cat > "$TMP/pool.py" <<'PY'
import json, os, re, urllib.parse
MS = {"main": {"id": 65, "title": "主線 M", "due_on": "2026-09-25T23:59:59Z", "state": "open"},
"mine": {"id": 70, "title": "組好的 M", "due_on": "2026-09-30T23:59:59Z", "state": "open"},
"sub": {"id": 9, "title": "子 repo 的舊里程碑", "due_on": "2026-10-30T23:59:59Z", "state": "open"}}
def I(repo, n, labels, ms=None, assignees=(), created="2026-09-01T00:00:00Z", pr=False, state="open", title=None):
d = {"number": n, "title": title or f"票 {repo}#{n}", "state": state,
"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 = {
"InkStoneCo": [I("InkStoneCo", 55, [], None, title="身為一天只看兩眼的人…"), # ★ 載體候選:沒里程碑、沒人
I("InkStoneCo", 132, ["Human", "s/pending"], "main", assignees=("Leo",)), # 主線載體(Leo 的)
I("InkStoneCo", 80, ["s/backlog"], "mine"), # 組好的 M 的載體(有 s/* 也不是任務)
I("InkStoneCo", 81, ["Human"], None), # 掛 Human 的載體候選
I("InkStoneCo", 82, [], "main"),
I("InkStoneCo", 83, [], None, assignees=("Leo",)), # 指派 Leo 的載體候選
I("InkStoneCo", 84, ["s/backlog"], None)], # 已是「組好的 M」載體的前置——不能再當載體 # 已掛在主線里程碑的載體候選
"ISEP": [I("ISEP", 1, [], None, created="2026-08-01T00:00:00Z"), # ★ 待分診(最舊)
I("ISEP", 2, [], None), # 待分診
I("ISEP", 3, ["Human"], None), # 沒 s/*、掛 Human:不碰
I("ISEP", 4, [], None, assignees=("Leo",)), # 沒 s/*、指派 Leo:不碰
I("ISEP", 5, ["s/backlog", "type/bug"], None), # ★ 已分診:可組進里程碑
I("ISEP", 6, ["s/triage"], None), # 還沒決定:不可組
I("ISEP", 7, ["s/backlog"], None), # 已是組好的 M 的前置
I("ISEP", 8, ["s/backlog"], "sub"), # 掛著子 repo 里程碑
I("ISEP", 9, [], None, pr=True), # PR
I("ISEP", 10, [], None, assignees=("claude-code",))], # 只指派給自己:可分診
"Arcrun": [I("Arcrun", 20, ["s/todo"], None), # ★ 已分診:可組進里程碑
I("Arcrun", 21, ["s/todo"], None), # 組好的 M 的前置(pick 用)
I("Arcrun", 22, ["s/backlog", "Human"], None), # Human 前置:不碰
I("Arcrun", 23, ["s/backlog"], None, assignees=("Leo",))], # 指派 Leo 的前置:不碰 # Human 前置:不碰
}
MSN = {"InkStoneCo": ["main", "mine"], "ISEP": ["sub"]}
DEPS = {"InkStoneCo#80": ["ISEP#7", "Arcrun#21", "InkStoneCo#84"]}
def _by_ref(ref):
repo, n = ref.split("#")
return next(i for i in POOL[repo] if i["number"] == int(n))
BLOCKS = {}
for _p, _cs in DEPS.items():
for _c in _cs:
BLOCKS.setdefault(_c, []).append(_p)
LABELS = ["s/triage", "s/backlog", "s/todo", "s/doing", "s/review", "s/pending", "close/duplicate",
"Human", "type/bug", "p/high"]
DROP = set(json.loads(os.environ.get("DROP", "[]")))
rec = []
def fake_api(path, payload=None, method=None):
verb = method or ("POST" if payload is not None else "GET")
rec.append((verb, path, payload))
if path.startswith("/orgs/inkstone/repos"):
return [{"name": r} for r in POOL]
if path == "/user":
return {"login": "claude-code"}
if path.endswith("/labels?limit=100"):
return [{"name": n, "id": k} for k, n in enumerate(LABELS, 1)]
if "/milestones" in path:
repo = path.split("/")[3]
if verb == "POST":
return {"id": 71, "title": payload["title"]}
return [MS[k] for k in MSN.get(repo, [])]
if "/issues?" in path:
repo = path.split("/")[3]
q = urllib.parse.parse_qs(path.split("?", 1)[1])
rows = [i for i in POOL[repo] if f"{repo}#{i['number']}" not in DROP]
if "milestones" in q:
want = q["milestones"][0]
return [i for i in rows if (i["milestone"] or {}).get("title") == want]
rows = [i for i in rows if i["state"] == "open"]
page = int(q.get("page", ["1"])[0]); per = int(q.get("limit", ["50"])[0])
return rows[(page - 1) * per: page * per]
m = re.match(r"/repos/inkstone/([\w-]+)/issues/(\d+)/(dependencies|blocks)(\?.*)?$", path)
if m:
if verb == "POST":
return {}
table = DEPS if m.group(3) == "dependencies" else BLOCKS
return [_by_ref(r) for r in table.get(f"{m.group(1)}#{m.group(2)}", [])]
m = re.match(r"/repos/inkstone/([\w-]+)/issues/(\d+)$", path)
if m and verb == "GET":
return _by_ref(f"{m.group(1)}#{m.group(2)}")
return {}
PY
export POOL_PY="$TMP/pool.py"
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
W = [(mm, p, pl) for mm, p, pl in rec if mm in ("POST", "PATCH", "PUT", "DELETE")]
print(eval(sys.argv[1], {"m": m, "rec": rec, "W": W, "rc": rc, "out": buf.getvalue(), "I": ns["I"], "json": json}))
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"
}
j() { python3 -c 'import json,sys;print(json.dumps(sys.argv[1:],ensure_ascii=False))' "$@"; }
echo "── ① 規則本體(純函式)──"
p "沒 s/*、沒人、沒 Human → 待分診" "True" "m.triageable(I('ISEP',1,[]),'claude-code')[0]"
p "★ 掛 Human → 不碰(驗收 3)" "False" "m.triageable(I('ISEP',3,['Human']),'claude-code')[0]"
p "human/exec 同組 → 不碰" "False" "m.triageable(I('ISEP',3,['human/exec']),'claude-code')[0]"
p "★ 指派給 Leo → 不碰(驗收 3)" "False" "m.triageable(I('ISEP',4,[],assignees=('Leo',)),'claude-code')[0]"
p "只指派給自己 → 可分診" "True" "m.triageable(I('ISEP',10,[],assignees=('claude-code',)),'claude-code')[0]"
p "不知道自己是誰、票有指派 → 不碰(不猜)" "False" "m.triageable(I('ISEP',10,[],assignees=('claude-code',)),None)[0]"
p "已經有 s/*(連 s/triage 也算)→ 不是待分診" "False" "m.triageable(I('ISEP',6,['s/triage']),'claude-code')[0]"
p "PR → 不是票" "False" "m.triageable(I('ISEP',9,[],pr=True),'claude-code')[0]"
p "已關 → 不碰" "False" "m.triageable(I('ISEP',1,[],state='closed'),'claude-code')[0]"
p "InkStoneCo 裡掛在 open 里程碑的票(載體)→ 不是待分診(它是容器)" "False" "m.triageable(I('InkStoneCo',82,[],'main'),'claude-code')[0]"
p "別的 repo 掛著里程碑、沒 s/* → 照樣待分診(載體只認 InkStoneCo)" "True" "m.triageable(I('ISEP',8,[],'sub'),'claude-code')[0]"
p "名字以版本號開頭(1.4.52 雲端零件包)→ 算版本號名字" "True" "m._version_like('1.4.52 雲端零件包')"
p "v 開頭也算" "True" "m._version_like('v0.30 什麼')"
p "名字裡提到版本但不是開頭(封測不再斷,含 1.4 修正)→ 不算(誤攔比漏擋嚴重)" "False" "m._version_like('封測不再斷,含 1.4 修正')"
echo
echo "── ② triage:一個動作=說明+欄位(驗收 1)──"
TR=$(j cmd_triage inkstone/ISEP#1 --to s/backlog --why "還在用、要修" --name isep-hand)
p "★ 先留說明、再改標籤:寫入恰好是 [留言, 改標籤]" "[('POST', '/repos/inkstone/ISEP/issues/1/comments'), ('PUT', '/repos/inkstone/ISEP/issues/1/labels')]" \
"[(mm,p) for mm,p,_ in W]" "$TR"
p "★ 說明第一行是【身份】,內文講得出分到哪、為什麼" "True" \
"(lambda b: b.split(chr(10))[0]=='【身份】isep-handinkstone/ISEP-' and 's/backlog' in b and '還在用、要修' in b)(W[0][2]['body'])" "$TR"
p "標籤換成 s/backlogid 2" "[2]" "W[1][2]['labels']" "$TR"
p "離開碼 0" "None" "rc" "$TR"
TD=$(j cmd_triage inkstone/ISEP#2 --dup-of inkstone/ISEP#5 --why "同一件事" --name isep-hand)
p "★ 重複:留說明→標 close/duplicate→關→在留下的那張留一則指回來" \
"[('POST', '/repos/inkstone/ISEP/issues/2/comments'), ('PUT', '/repos/inkstone/ISEP/issues/2/labels'), ('PATCH', '/repos/inkstone/ISEP/issues/2'), ('POST', '/repos/inkstone/ISEP/issues/5/comments')]" \
"[(mm,p) for mm,p,_ in W]" "$TD"
p "★ 重複那則說明指向留下的那張(驗收 1:重複的指向哪張)" "True" "'inkstone/ISEP#5' in W[0][2]['body']" "$TD"
p "關的是 state=closed、標的是 close/duplicateid 7" "True" "W[2][2]=={'state':'closed'} and W[1][2]['labels']==[7]" "$TD"
TDL=$(j cmd_triage inkstone/ISEP#2 --dup-of inkstone/InkStoneCo#132 --why "同一件事")
p "★ 重複的對象是 Leo 的票 → 這張照關,但**不在 Leo 的票上寫任何字**(驗收 3)" "True" \
"rc is None and not any('/InkStoneCo/' in p for _,p,_ in W) and '沒在' in out" "$TDL"
p "只指派給自己的 ISEP#10 → 分診得了" "None" "rc" "$(j cmd_triage inkstone/ISEP#10 --to s/triage --why 要總管看)"
echo
echo " (該擋的:擋下時一筆都沒寫)"
nb() { # nb <說明> <argv json> [要在訊息裡看到的字]
p "$1 → 離開碼 2、零寫入${3:+、訊息有「$3}" "True" "rc==2 and not W${3:+ and '$3' in out}" "$2"
}
nb "★ 掛 Human 的 ISEP#3(驗收 3" "$(j cmd_triage inkstone/ISEP#3 --to s/backlog --why x)" "掛著 Human"
nb "★ 指派給 Leo 的 ISEP#4(驗收 3" "$(j cmd_triage inkstone/ISEP#4 --to s/backlog --why x)" "指派給 Leo"
nb "已分診過的 ISEP#6" "$(j cmd_triage inkstone/ISEP#6 --to s/backlog --why x)" "已經分診過"
nb "PR" "$(j cmd_triage inkstone/ISEP#9 --to s/backlog --why x)"
p "triage --sign cloud-worker ⇒ 說明內文署 [cloud-worker]" "True" "'[cloud-worker]' in W[0][2]['body']" \
"$(j cmd_triage inkstone/ISEP#1 --to s/backlog --why x --sign cloud-worker)"
nb "沒寫 --why(說明是驗收 1 的本體)" "$(j cmd_triage inkstone/ISEP#1 --to s/backlog)" "--why"
nb "--to s/todo(要經 compose 排進里程碑才給)" "$(j cmd_triage inkstone/ISEP#1 --to s/todo --why x)" "compose"
nb "--to 與 --dup-of 都給" "$(j cmd_triage inkstone/ISEP#1 --to s/backlog --dup-of inkstone/ISEP#5 --why x)"
nb "--dup-of 指到自己" "$(j cmd_triage inkstone/ISEP#1 --dup-of inkstone/ISEP#1 --why x)"
p "參數錯(沒 --why)→ 一通 API 都沒打" "0" "len(rec)" "$(j cmd_triage inkstone/ISEP#1 --to s/backlog)"
p "身份名不在名單上 → 一通 API 都沒打" "True" "rc==2 and len(rec)==0" "$(j cmd_triage inkstone/ISEP#1 --to s/backlog --why x --name 路人)"
echo
echo " (--list:工人拿什麼來判斷)"
p "★ --list 列出待分診的票(InkStoneCo 還沒分診的也算),不列 Human/Leo/已分診/PR" \
"['inkstone/ISEP#1', 'inkstone/ISEP#10', 'inkstone/ISEP#2', 'inkstone/InkStoneCo#55']" \
"[r['ref'] for r in json.loads(out)]" "$(j cmd_triage --list --json)"
p "--list --all 連已分診的 open 票也列(找重複要看全部),並標出哪些可分診" "True" \
"(lambda rows: len(rows)>10 and {r['ref'] for r in rows if r['triageable']}=={'inkstone/ISEP#1','inkstone/ISEP#2','inkstone/ISEP#10','inkstone/InkStoneCo#55'})(json.loads(out))" \
"$(j cmd_triage --list --all --json)"
p "--list 文字版講得出「不碰」的有幾張,並給出下一步那一行" "True" \
"'不碰' in out and ' triage inkstone/ISEP#1 ' in out" "$(j cmd_triage --list)"
p "--list 只讀不寫" "True" "not W" "$(j cmd_triage --list)"
echo
echo "── ③ compose:組里程碑(驗收 2)──"
CP=$(j cmd_compose --title "雲端自己把票池消化成版本" --goal "leo 不必一張張叫它做" --due 2026-10-01 \
--carrier inkstone/InkStoneCo#55 inkstone/ISEP#5 inkstone/Arcrun#20 --name isep-hand)
p "★ 里程碑建在 inkstone/InkStoneCo(開工規約第 7 條)" "True" \
"[p for mm,p,_ in W if mm=='POST' and p.endswith('/milestones')]==['/repos/inkstone/InkStoneCo/milestones']" "$CP"
p "★ 有期限(23:59:59Z),不是 9999" "2026-10-01T23:59:59Z" \
"[pl['due_on'] for mm,p,pl in W if p.endswith('/milestones')][0]" "$CP"
p "★ 描述寫明這一輪要讓什麼變成真的、deliverable=總管驗過的新版本、載體與前置" "True" \
"(lambda d: '這一輪要讓什麼變成真的:leo 不必' in d and 'deliverable' in d and '新版本' in d and 'inkstone/InkStoneCo#55' in d and 'inkstone/ISEP#5' in d)([pl['description'] for mm,p,pl in W if p.endswith('/milestones')][0])" "$CP"
p "★ 載體票掛上新里程碑(id 71" "True" \
"('PATCH','/repos/inkstone/InkStoneCo/issues/55',{'milestone':71}) in W" "$CP"
p "★ 兩張執行票都掛成載體票的前置(/dependencies" "True" \
"[pl for mm,p,pl in W if mm=='POST' and p=='/repos/inkstone/InkStoneCo/issues/55/dependencies']==[{'owner':'inkstone','repo':'ISEP','index':5},{'owner':'inkstone','repo':'Arcrun','index':20}]" "$CP"
p "★ s/backlog → s/todo(已排進里程碑,等人領票),type/bug 留著" "[3, 9]" \
"sorted([pl['labels'] for mm,p,pl in W if mm=='PUT' and p=='/repos/inkstone/ISEP/issues/5/labels'][0])" "$CP"
p "本來就 s/todo 的 Arcrun#20 不重貼標籤" "False" "any(p.endswith('/Arcrun/issues/20/labels') for _,p,_ in W)" "$CP"
p "每張前置與載體都留了一則說明(第一行【身份】)" "True" \
"sorted(p for mm,p,pl in W if mm=='POST' and p.endswith('/comments') and pl['body'].startswith('【身份】'))==['/repos/inkstone/Arcrun/issues/20/comments','/repos/inkstone/ISEP/issues/5/comments','/repos/inkstone/InkStoneCo/issues/55/comments']" "$CP"
p "★ 不開任何新票(開工規約第 2 條)" "False" \
"any(mm=='POST' and p.endswith('/issues') for mm,p,_ in W)" "$CP"
p "離開碼 0,印出里程碑網址" "True" "rc is None and '/inkstone/InkStoneCo/milestone/71' in out" "$CP"
CPS=$(j cmd_compose --title "雲端自己把票池消化成版本" --goal g --due 2026-10-01 --carrier inkstone/InkStoneCo#55 inkstone/ISEP#5 --sign cloud-worker)
p "--sign cloud-worker ⇒ 每則留言內文都署 [cloud-worker]--sign 的值不會被當成前置票" "True" \
"rc is None and all('[cloud-worker]' in pl['body'] for mm,p,pl in W if p.endswith('/comments')) and not any('cloud-worker' in str(pl) for mm,p,pl in W if p.endswith('/dependencies'))" "$CPS"
p "沒給 --sign ⇒ 不署一個寫死的名字(誰跑的就署誰)" "False" \
"any('[cloud-worker]' in pl['body'] for mm,p,pl in W if p.endswith('/comments'))" "$CP"
echo
echo " (該擋的:先全部驗過才寫——擋下時一筆都沒寫,而且理由一次列齊)"
cb() { # cb <說明> <要在訊息裡看到的字> <argv...>
what=$1; want=$2; shift 2
p "$what → 離開碼 2、零寫入、訊息有「$want" "True" "rc==2 and not W and '$want' in out" "$(j cmd_compose "$@")"
}
OK=(--goal g --due 2026-10-01 --carrier inkstone/InkStoneCo#55)
cb "★ 名字是版本號(開工規約第 5 條)" "版本號" --title "1.4.52 雲端零件包" "${OK[@]}" inkstone/ISEP#5
cb "沒名字" "--title" "${OK[@]}" inkstone/ISEP#5
cb "★ 沒期限(開工規約第 6 條)" "--due" --title 好名字 --goal g --carrier inkstone/InkStoneCo#55 inkstone/ISEP#5
cb "期限 9999" "天內" --title 好名字 --goal g --due 9999-01-01 --carrier inkstone/InkStoneCo#55 inkstone/ISEP#5
cb "期限在過去" "天內" --title 好名字 --goal g --due 2026-09-01 --carrier inkstone/InkStoneCo#55 inkstone/ISEP#5
cb "載體不在 InkStoneCo(不准在子 repo 建里程碑)" "InkStoneCo" --title 好名字 --goal g --due 2026-10-01 --carrier inkstone/ISEP#1 inkstone/ISEP#5
cb "沒有前置" "前置" --title 好名字 "${OK[@]}"
cb "★ 載體掛 Human(驗收 3" "載體 inkstone/InkStoneCo#81:掛著 Human" --title 好名字 --goal g --due 2026-10-01 --carrier inkstone/InkStoneCo#81 inkstone/ISEP#5
cb "★ 載體指派給 Leo(驗收 3" "載體 inkstone/InkStoneCo#83:指派給 Leo" --title 好名字 --goal g --due 2026-10-01 --carrier inkstone/InkStoneCo#83 inkstone/ISEP#5
cb "載體本身是別的 open 里程碑載體的前置(那一輪還在跑)" "那一輪還在跑" --title 好名字 --goal g --due 2026-10-01 --carrier inkstone/InkStoneCo#84 inkstone/ISEP#5
cb "載體已在別的 open 里程碑" "已經掛在里程碑" --title 好名字 --goal g --due 2026-10-01 --carrier inkstone/InkStoneCo#82 inkstone/ISEP#5
cb "同名 open 里程碑已在" "同名" --title "組好的 M" "${OK[@]}" inkstone/ISEP#5
cb "★ 前置掛 Human(驗收 3" "前置 inkstone/Arcrun#22:掛著 Human" --title 好名字 "${OK[@]}" inkstone/Arcrun#22
cb "★ 前置指派給 Leo(驗收 3" "前置 inkstone/Arcrun#23:指派給 Leo" --title 好名字 "${OK[@]}" inkstone/Arcrun#23
cb "前置還沒分診(沒 s/*" "還沒分診" --title 好名字 "${OK[@]}" inkstone/ISEP#1
cb "前置是 s/triage(要不要做還沒決定)" "還沒分診" --title 好名字 "${OK[@]}" inkstone/ISEP#6
cb "前置已經是別的里程碑載體的前置(一張票同時只排一輪)" "只排一輪" --title 好名字 "${OK[@]}" inkstone/ISEP#7
cb "前置掛著子 repo 的里程碑" "已經掛在里程碑" --title 好名字 "${OK[@]}" inkstone/ISEP#8
p "★ 好幾格不對時一次列齊(Human 前置+沒分診前置,兩個理由都在)" "True" \
"rc==2 and not W and 'Arcrun#22:掛著 Human' in out and 'ISEP#1 還沒分診' in out" \
"$(j cmd_compose --title 好名字 "${OK[@]}" inkstone/Arcrun#22 inkstone/ISEP#1)"
p "參數層的錯(版本號名字)在打任何 API 之前就擋" "0" "len(rec)" \
"$(j cmd_compose --title 1.2.3 "${OK[@]}" inkstone/ISEP#5)"
echo
echo "── ④ 組了之後照里程碑往下做(驗收:再照里程碑往下做)──"
POOLA=$(j cmd_pick --mainline "$MAIN" --pool --all --json)
p "★ --pool:還沒到期的 InkStoneCo 里程碑「組好的 M」一組,成員是載體的前置(ISEP#7 的 s/backlog 不抓,Arcrun#21 s/todo 可抓)" \
"['inkstone/Arcrun#21']" "[r['ref'] for r in json.loads(out) if r['group']=='里程碑']" "$POOLA"
p "★ 載體票本身(InkStoneCo#80s/backlog)不當成可做的票——里程碑那組與票池那組都沒有它" "False" \
"any(r['ref']=='inkstone/InkStoneCo#80' for r in json.loads(out))" "$POOLA"
p "里程碑那一組排在票池之前(先照里程碑做,再撿散票)" "True" \
"(lambda g: g.index('里程碑') < g.index('票池'))([r['group'] for r in json.loads(out)])" "$POOLA"
p "★ 待分診那一組最舊的先(ISEP#1 08-01 開),不含 HumanLeo" \
"['inkstone/ISEP#1', 'inkstone/ISEP#10', 'inkstone/ISEP#2', 'inkstone/InkStoneCo#55']" \
"[r['ref'] for r in json.loads(out) if r['group']=='待分診']" "$POOLA"
p "每一列都帶下一步(里程碑那一列是 claim、待分診那一列是 triage" "True" \
"all((' triage ' in r['next']) == (r['group']=='待分診') for r in json.loads(out))" "$POOLA"
p "沒帶 --pool(本機總管)→ 不看還沒到期的里程碑、也不回待分診(誤攔比漏擋嚴重)" "True" \
"rc==1 and '里程碑「組好的' not in out and '待分診' not in out" "$(j cmd_pick --mainline "$MAIN")"
p "pick 只讀不寫" "True" "not W" "$POOLA"
echo
echo "── ⑤ 動詞接得上 ──"
out=$(python3 "$T" usage triage 2>&1); got=$?
if [ "$got" = 0 ] && printf '%s' "$out" | grep -q -- '--dup-of'; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
printf 'ticket usage triage 印得出用法\n'
out=$(python3 "$T" usage compose 2>&1); got=$?
if [ "$got" = 0 ] && printf '%s' "$out" | grep -q -- '--carrier'; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
printf 'ticket usage compose 印得出用法\n'
out=$(python3 "$T" triage inkstone/ISEP#1 --to s/backlog --why x 2>&1); got=$?
if [ "$got" != 0 ] && ! printf '%s' "$out" | grep -q '✅'; then PASS=$((PASS+1)); printf ' ✅ '; else FAIL=$((FAIL+1)); printf ' ❌ '; fi
printf 'triage 連不上 Gitea → 非零離開、不印成功(got=%s\n' "$got"
echo
echo "通過 $PASS 條,失敗 $FAIL"
[ "$FAIL" = 0 ] || exit 1
+602 -36
View File
@@ -30,10 +30,19 @@ leo 2026-08-16 三句話,本工具就是它們的機械化:
雲端工人抓票(inkstone/ISEP#131,規則機械可判,不靠 prompt 叮嚀):
ticket pick [--mainline <主線檔>] [--all] [--json] 回一張現在可以抓的票(主線抓盡才抓逾期)
ticket pick [--mainline <主線檔>] [--all] [--json] [--pool]
回一張現在可以抓的票(主線 → 逾期里程碑 → --pool 時 open 票池)
ticket claim <票> [--as <登入名>] [--name <身份>] 認領=指派+s/doing+【身份】留言,一個動作
ticket pick --claim … 上面兩件連著做
雲端工人分診+組里程碑(inkstone/ISEP#159:不只撿票,還要組票):
ticket triage --list [--all] [--json] 還沒有 s/* 的票(--all 連已分診的一起列,找重複用)
ticket triage <票> --to <s/backlog|s/triage|s/pending> --why <一句> 給狀態+票上一則說明,一個動作
ticket triage <票> --dup-of <留下的票> --why <一句> 重複:說明+close/duplicate+關+指回去
ticket compose --title … --goal … --due YYYY-MM-DD --carrier inkstone/InkStoneCo#N <前置…>
組一個 InkStoneCo 里程碑(先全部驗過才寫,不開新票)
票的寫法:`owner/repo#N`,例:`inkstone/InkStoneCo#44`
"""
import json
@@ -894,17 +903,36 @@ def subtask_example(parent=None, draft=None):
# 用法裡寫死 `ticket` 或 `scripts/ticket`,讀的人照著貼就又踩回這張票的坑。
USAGE = {
"pick":
"用法:{bin} pick [--mainline <主線 json 檔>] [--all] [--json] [--claim [--as <登入名>] [--name <身份>]]\n"
" 回**一張**現在可以抓的票主線抓盡才輪到逾期里程碑;不抓 backlog)。主線的成員=hub 里程碑裡的票+\n"
"用法:{bin} pick [--mainline <主線 json 檔>] [--all] [--json] [--pool] [--claim [--as <登入名>] [--name <身份>]]\n"
" 回**一張**現在可以抓的票:主線 → 主線抓盡才輪到逾期里程碑 → 帶 --pool(或環境 ISEP_DRAIN=1)時\n"
" 再輪到整個 open 票池的 s/todos/backlog(不限里程碑;Human、指派給別人、hub 照樣不抓,inkstone/ISEP#130)。\n"
" 可抓 0 張時列出池子裡每種「不能抓的理由」各幾張。主線的成員=hub 里程碑裡的票+\n"
" hub 票+它們的相依(跨 repo)——別 repo 的同名里程碑不算主線(inkstone/ISEP#133\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"
" [--mainline <主線 json 檔>] [--pool]\n"
" 認領=指派給自己 + 換成 s/doing + 第一行【身份】的留言,**一個動作**。\n"
" 抓票規則在這裡再驗一次:不是 s/todo、已有人、掛 Human、不在主線也不逾期 ⇒ 擋下(離開碼 2)",
" 抓票規則在這裡再驗一次:不是 s/todo、已有人、掛 Human、不在主線也不逾期 ⇒ 擋下(離開碼 2)\n"
" 帶 --pool(或 ISEP_DRAIN=1)時 open 票池裡的 s/todos/backlog 也認領得了",
"triage":
"用法:{bin} triage --list [--json] [--all]\n"
" {bin} triage <owner/repo#N> --to <s/backlog|s/triage|s/pending> --why \"<一句理由>\" [--name <身份>] [--sign <署名>]\n"
" {bin} triage <owner/repo#N> --dup-of <owner/repo#M> --why \"<一句理由>\" [--name <身份>] [--sign <署名>]\n"
" 分診**還沒有 s/* 的票**inkstone/ISEP#159):給它一個狀態+在票上留一則說明,一個動作;\n"
" 重複的關掉並指向留下的那張(close/duplicate,留下的那張也留一則指回來)。\n"
" --list 列出現在待分診的票;--all 連已分診的 open 票一起列(找重複用)。\n"
" 掛 Humanhuman/*、指派給別人(含 Leo)的票一律不碰;s/todo 要經 compose 排進里程碑才給。",
"compose":
"用法:{bin} compose --title \"<這一輪要讓什麼變成真的>\" --goal \"<一段話>\" --due YYYY-MM-DD\n"
" --carrier inkstone/InkStoneCo#N <前置票 owner/repo#M ...> [--name <身份>] [--sign <署名,例 cloud-worker>]\n"
" 把已分診的票組成一個里程碑(inkstone/ISEP#159CLAUDE.md 開工規約 17 條):\n"
" 里程碑建在 inkstone/InkStoneCo、掛在既有的載體票上;前置票掛成載體票的相依,s/backlog → s/todo\n"
" deliverable=一個總管在 stage 驗過的新版本(版本號由總管定)。**不開任何新票。**\n"
" 先全部驗過才寫:名字像版本號、期限不在 1–60 天內、同名里程碑已在、載體或前置掛 Human/指派別人、\n"
" 前置還沒分診或已在別的 open 里程碑裡 ⇒ 一次列出全部理由,一筆都不寫(離開碼 2)。",
"subtask":
"用法:{bin} subtask <母票 owner/repo#N> --title \"<User Story>\" -F <內文檔>\n"
" [--repo <收件 repo,預設跟母票同一個>] [--label <s/xxx,預設 s/todo>]\n"
@@ -1270,7 +1298,12 @@ def cmd_loose(argv):
#
# 規則(全部是 Gitea 欄位,沒有一格在猜文字):
# 可抓 s/* 狀態恰好是 {s/todo} 沒有 assignee 沒有 Humanhuman/* 不是 hub 有里程碑
# 且里程碑 = 主線;主線抓盡才抓「逾期的 open 里程碑」backlog/沒里程碑一律不抓
# 且里程碑 = 主線;主線抓盡才抓「逾期的 open 里程碑」
# ⇒ 兩層都抓盡、且是接票的環境(--pool/ISEP_DRAIN=1)⇒ 第三層:整個 open 票池裡
# s/* 恰好是 s/todo 或 s/backlog 的(不限里程碑),其他格一格不放寬(inkstone/ISEP#130 c7801
# 🔴 2026-09-18 實量:org 299 張 open、254 張沒掛里程碑;舊規則只看主線成員與逾期里程碑,
# 實跑可抓 0 張 ⇒ 09-18 六趟 run 全部「可接 0 張、正常收工」。加上票池這一層,同一刻可抓 101 張。
# 主線/逾期是**先抓誰**,不是**只抓誰**。
# 認領 指派 + s/doing +【身份】留言,一個動作(`claim`)
# 完成 分支 證據 s/review `handback`——那半本來就有,不重做
#
@@ -1326,7 +1359,25 @@ def human_gated(labels):
return any(n == "Human" or n.startswith("human/") for n in labels)
def pickable(issue, milestone_title, me=None):
# 票池那一層接受的狀態(inkstone/ISEP#130 c7801):labels.yaml 裡「決定要做、沒人在做」的只有這兩個。
# s/todo 已排進 milestone,等人領票
# s/backlog 驗過了、確定要做,但還沒排進任何 sprint
# 其他狀態都有人或有事在管:s/triage=還沒決定要不要做(總管/leo 的事)、s/doing=有人在做、
# s/reviews/stage=等總管或 leo、s/pending=在等外部。**沒有 s/* 的票**=還沒被驗傷,一樣不抓,
# 但會被點名計數(見 pool_candidates),不再沉默地消失在「可抓 0 張」後面。
MAINLINE_STATUSES = ("s/todo",)
POOL_STATUSES = ("s/todo", "s/backlog")
def pool_mode(argv=()):
"""要不要往下看到整個 open 票池。`--pool` 或環境 `ISEP_DRAIN=1`(雲端工人的環境本來就設它)。
為什麼不是預設全開:`queue-drain-guard` 在本機只要總管跑過 `ticket handback` 就會問 pick——
票池永遠有票,總管每次收工都會被點名去抓票,那是誤攔。接票的環境自己宣告,不靠猜。"""
return "--pool" in argv or os.environ.get("ISEP_DRAIN") == "1"
def pickable(issue, milestone_title, me=None, statuses=MAINLINE_STATUSES):
"""這張票現在能不能被雲端工人抓走。回 (ok, 理由)。**純函式,不打網路。**
`milestone_title`=要求它掛在哪個里程碑底下(主線,或輪到的那個逾期里程碑)。
@@ -1336,14 +1387,15 @@ def pickable(issue, milestone_title, me=None):
指派 `claude-code` ⇒ 舊規則說「已經指派給 claude-code」⇒ **工人把自己當成別人**,
09-11 那趟 runArcrun#86 c6917)就是用這條理由判定「主線沒有可抓的票」然後收工。
`s/todo` 的意思本來就是「沒人在做」;有人在做的形狀是 `s/doing`,那格照擋。
`statuses`=接受哪些 s/*(主線/逾期只收 s/todo;票池另收 s/backlog,見 POOL_STATUSES)。
理由是給人看的:`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 len(st) != 1 or st[0] not in statuses:
return False, "狀態不是單一的 %s(現在是 %s" % ("".join(statuses), 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")]
@@ -1371,11 +1423,12 @@ def pickable(issue, milestone_title, me=None):
def pick_order(issue):
"""同一個里程碑裡先抓誰:p/high → 沒標 → p/low再看開票時間(舊的先);最後票號。
結果要**可重現**——同一個池子問兩次要拿到同一張。"""
"""同一裡先抓誰:p/high → 沒標 → p/low同優先序 s/todo 先於 s/backlog(排進 sprint 的先);
再看開票時間(舊的先);最後票號。結果要**可重現**——同一個池子問兩次要拿到同一張。"""
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)
status = 1 if "s/backlog" in labels else 0
return (prio, status, issue.get("created_at") or "", issue.get("number") or 0)
def _ref_of(issue, owner=None, repo=None):
@@ -1463,13 +1516,109 @@ def _fetch_issue(ref):
return it
def _open_issues(owner, repo):
"""一個 repo 的全部 open 票(分頁讀完;Gitea 每頁上限 50,只讀一頁會漏)。"""
out, page = [], 1
while page <= 40:
q = urllib.parse.urlencode({"state": "open", "type": "issues", "limit": 50, "page": page})
rows = [it for it in (api("/repos/%s/%s/issues?%s" % (owner, repo, q)) or []) if isinstance(it, dict)]
for it in rows:
it.setdefault("repository", {"full_name": "%s/%s" % (owner, repo)})
if not rows: # 讀到空頁才停:伺服器的每頁上限可能比 50 小,看「不滿一頁」會提早收手
break
out += rows
page += 1
return out
def pool_issues(owner):
"""整個 org 的 open 票(不含 PR)——**全局票池的唯一讀法**,pick 的票池層與 triage 共用這一份。
🔌 接口留給 inkstone/ISEP#154:全局票池是 Arcrun 工作流 `global_index`tickets 庫),
寫卡驗完之前先用這裡直打 Gitea。要換成讀 #154 那份時**只換這一個函式**——
呼叫端拿到的形狀不變(Gitea issue dict,帶 `repository.full_name`),不另寫第三套撈法。"""
out = []
for r in _repos(owner):
out += [it for it in _open_issues(owner, r) if not it.get("pull_request")]
return out
def pool_candidates(owner, me, seen=(), issues=None):
"""第三層:整個 org 的 open 票池(inkstone/ISEP#130 c7801)。回 (可抓的票…, 池子大小, {不能抓的理由: 張數})。
leo 09-18:「我看到 Gitea 有 446 張票,要它自己領工作就是持續消化工作,它說沒事做?」
⇒ 主線與逾期里程碑只是**先抓誰**,不是**只抓誰**。它們抓盡之後,池子裡「決定要做、沒人在做」的票
POOL_STATUSES)照樣可抓。不該碰的一格都沒放寬:Human/human/*、指派給別人(含 Leo)、hub、PR。
「要 Mac/要 prod」沒有欄位可判——那是工人讀票後走 cloud-worker.md「做不了的票」:寫回票+改欄位,
pick 下一輪就不再回它(改的是 s/*,不是猜文字)。
`seen`=前兩層已經列過的票號,不重複。理由表一併回傳:**可抓 0 張時要說得出池子去哪了**。"""
found, why_count, total = [], {}, 0
for it in (pool_issues(owner) if issues is None else issues):
if it.get("pull_request"):
continue
total += 1
ref = _ref_of(it)
if ref in seen:
continue
if _is_carrier(it):
# 開工規約第 7 條:InkStoneCo 里程碑裡的票是載體(容器),做的是它的前置(inkstone/ISEP#159
why = "是里程碑「%s」的載體票(容器,做的是它的前置)" % it["milestone"].get("title")
why_count[why] = why_count.get(why, 0) + 1
continue
ok, why = pickable(it, None, me, POOL_STATUSES)
if ok:
found.append(it)
else:
why_count[why] = why_count.get(why, 0) + 1
return sorted(found, key=pick_order), total, why_count
def _me():
"""抓票者自己是誰:只指派給自己的 s/todo 票算可抓(inkstone/ISEP#33,見 pickable
問不到(舊 token、測試替身沒有 /user)⇒ None ⇒ 照舊規則,不因為這一格讓 pick 整個死掉"""
return os.environ.get("ISEP_WORKER_LOGIN") or ((api_soft("/user") or {}).get("login"))
def mainline_members(ms):
"""主線的成員(inkstone/ISEP#133):hub 里程碑裡的票+hub 票+它們的相依(跨 repo)。
判準在 `hooks/lib/mainline.py::collect_members`,這裡只是把本檔的 `api` 遞進去。"""
return _mainline_lib().collect_members(api, ms)
def pick_candidates(ms, now=None):
# 里程碑一律住在這個 repo(CLAUDE.md 開工規約第 7 條,leo 2026-09-13):
# 裡面只放載體票,別 repo 的執行票是載體票的**前置**/dependencies)。
CARRIER_REPO = "InkStoneCo"
def carrier_members(owner, m):
"""InkStoneCo 里程碑的**執行票**=載體票沿相依收下去的票,不含載體票本身(載體是容器不是任務)。
判準同主線(`hooks/lib/mainline.py::collect_members`inkstone/ISEP#133),不另寫一份。"""
refs, info = _mainline_lib().collect_members(
api, {"owner": owner, "repo": CARRIER_REPO, "id": m.get("id"), "title": m.get("title")})
roots = set(info.get("milestone") or [])
return [r for r in refs if r not in roots]
def _milestone_group(owner, r, m, me):
"""一個里程碑底下現在可抓的票。InkStoneCo 的里程碑看相依邊;別的 repo 照舊看票上的里程碑欄。"""
found = []
if r == CARRIER_REPO:
for ref in carrier_members(owner, m):
it = _fetch_issue(ref)
if it and (it.get("state") or "open") == "open" and pickable(it, None, me)[0]:
found.append(it)
return sorted(found, key=pick_order)
for it in _issues_in(owner, r, m.get("title")):
if str((it.get("milestone") or {}).get("id")) != str(m.get("id")):
continue
ok, _ = pickable(it, m.get("title"), me)
if ok:
found.append(it)
return sorted(found, key=pick_order)
def pick_candidates(ms, now=None, pool=False):
"""依序回 [(組名, 里程碑標題, [可抓的票…])]:第一組是主線,之後是逾期的 open 里程碑
(最逾期的先)。**每一組裡都已經照 pick_order 排好。**
@@ -1481,9 +1630,7 @@ def pick_candidates(ms, now=None):
owner = ms.get("owner") or ORG
anchor = "%s/%s#%s" % (ms.get("owner"), ms.get("repo"), ms.get("id"))
# 抓票者自己是誰:只指派給自己的 s/todo 票算可抓(inkstone/ISEP#33,見 pickable
# 問不到(舊 token、測試替身沒有 /user)⇒ me=None ⇒ 照舊規則,不因為這一格讓 pick 整個死掉
me = os.environ.get("ISEP_WORKER_LOGIN") or ((api_soft("/user") or {}).get("login"))
me = _me()
refs, info = mainline_members(ms)
found = []
@@ -1497,23 +1644,26 @@ def pick_candidates(ms, now=None):
groups = [("主線", ms["title"], sorted(found, key=pick_order))]
repos = _repos(owner)
overdue = []
overdue, upcoming = [], []
for r, m in _open_milestones(owner, repos):
if "%s/%s#%s" % (owner, r, m.get("id")) == anchor:
continue
due = ML.due_of(m)
if due and due < now:
overdue.append((due, r, m))
elif r == CARRIER_REPO:
upcoming.append((due, r, m))
for due, r, m in sorted(overdue, key=lambda x: x[0]):
found = []
for it in _issues_in(owner, r, m.get("title")):
if str((it.get("milestone") or {}).get("id")) != str(m.get("id")):
continue
ok, _ = pickable(it, m.get("title"), me)
if ok:
found.append(it)
groups.append(("逾期里程碑", "%s%s/%s#%s" % (m.get("title"), owner, r, m.get("id")),
sorted(found, key=pick_order)))
_milestone_group(owner, r, m, me)))
if pool:
# 第三層(inkstone/ISEP#159):還沒到期的 InkStoneCo 里程碑——雲端工人自己組的里程碑就在這裡,
# 「組了之後照里程碑往下做」靠這一層:它的前置票先於票池裡散的票。期限近的先。
# 只在接票的環境(--poolISEP_DRAIN=1)看:本機總管收工時不會因此被點名。
far = now.replace(year=now.year + 100)
for due, r, m in sorted(upcoming, key=lambda x: x[0] or far):
groups.append(("里程碑", "%s%s/%s#%s" % (m.get("title"), owner, r, m.get("id")),
_milestone_group(owner, r, m, me)))
return groups
@@ -1524,28 +1674,42 @@ def cmd_pick(argv):
ms, src = load_mainline(argv)
as_json = "--json" in argv
show_all = "--all" in argv
pool = pool_mode(argv)
pool_total, pool_why = None, {}
try:
groups = pick_candidates(ms)
groups = pick_candidates(ms, pool=pool)
# 票池那一層只在前面都抓盡(或要看全部)時才讀——它要翻整個 org,能省就省
if pool and (show_all or not any(its for _, _, its in groups)):
seen = {_ref_of(it) for _, _, its in groups for it in its}
me = _me()
issues = pool_issues(ms.get("owner") or ORG)
found, pool_total, pool_why = pool_candidates(ms.get("owner") or ORG, me, seen, issues)
groups.append(("票池", "open 票池(%s,不限里程碑)" % "".join(POOL_STATUSES), found))
# 最後一層(inkstone/ISEP#159):沒有可做的票時,還沒驗傷的票就是下一件事——
# 回一張待分診的票,下一步是 `triage` 不是 `claim`(佇列閘照 row 的 next 印)。
if show_all or not found:
groups.append(("待分診", "還沒有 s/* 的 open 票", triage_candidates(issues, me)))
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")}
"labels": _label_names(it), "created_at": it.get("created_at"),
"next": _next_cmd(g, _ref_of(it))}
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))
if not rows:
_explain_empty(pool, pool_total, pool_why, sys.stderr)
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)))
if g in ("主線", "票池", "待分診") or its or show_all:
print(" %s「%s」:%s %d 張" % (g, t, "待分診" if g == "待分診" else "可抓", len(its)))
print()
if not flat:
print("⚪ 沒有可以抓的票——主線與逾期里程碑都抓盡了。")
print(" 出路:收工回報(這是正常結果,不是故障)。")
print(" 🔴 不要去抓 backlog/沒里程碑/掛 Human/已有人的票——那些不在規則裡,抓了就是跳線。")
_explain_empty(pool, pool_total, pool_why, sys.stdout)
sys.exit(1)
shown = flat if show_all else flat[:1]
@@ -1554,16 +1718,46 @@ def cmd_pick(argv):
print(" %s" % (it.get("title") or "")[:80])
print(" %s「%s」 開票 %s" % (g, t, (it.get("created_at") or "")[:10]))
print()
if flat[0][0] == "待分診":
# 分診不是認領:沒有人要「做」這張票,要的是決定它去哪
print("📌 可做的票都抓盡了,下一件事是分診(還沒驗傷的票不會自己消失):")
print(" " + _next_cmd("待分診", _ref_of(flat[0][2])))
print(" 找重複:%s triage --list --all  組里程碑:%s usage compose" % (self_path(), self_path()))
return
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 claim %s --name <你的名字>%s" % (self_path(), _ref_of(flat[0][2]),
" --pool" if flat[0][0] == "票池" and "--pool" in argv else ""))
print(" 做完:分支+證據 → `%s handback %s --to %s --label s/review --next \"…\" --evidence <URL>`"
% (self_path(), _ref_of(flat[0][2]), HANDBACK_TO))
def _next_cmd(group, ref):
"""這一列的下一步,**貼了就能跑的那一行**(佇列閘照這一格印,不自己猜)。"""
if group == "待分診":
return ("%s triage %s --to <s/backlog|s/triage|s/pending> --why \"<一句理由>\""
" (重複的:--dup-of <owner/repo#M>" % (self_path(), ref))
return "%s claim %s --name <你的名字>" % (self_path(), ref)
def _explain_empty(pool, total, why, out):
"""可抓 0 張時講清楚池子去哪了。**不准說成「正常、不是故障」**inkstone/ISEP#130 c7797
09-18 六趟 run 都把「可抓 0 張」寫成正常收工,而池子裡有幾百張 open 票)。"""
w = lambda line="": print(line, file=out)
if not pool:
w("⚪ 主線與逾期里程碑可抓 0 張——**這一趟沒有看票池**,所以這不代表沒事做。")
w(" 要看整個 open 票池:加 `--pool`(雲端工人的環境設了 ISEP_DRAIN=1 就自動看)。")
return
w("⚪ 可抓 0 張:主線、逾期里程碑、open 票池(%d 張)都沒有一張符合抓票規則。" % (total or 0))
w(" 這不是「沒事做」,是池子裡的票全都卡在下面這些格子——把這張表原樣放進收工摘要/載體票,交總管分診:")
for k, n in sorted(why.items(), key=lambda kv: (-kv[1], kv[0]))[:12]:
w(" %4d 張 %s" % (n, k))
w(" 🔴 不要自己改欄位去湊一張可抓的票(把 s/triage 改 s/todo、摘 Human、改指派)——那是總管/leo 的判斷。")
def cmd_claim(argv):
"""認領=指派 s/doing +【身份】留言,**一個動作**。抓票規則在這裡再驗一次。"""
if not argv or argv[0] in ("-h", "--help"):
@@ -1596,21 +1790,31 @@ def cmd_claim(argv):
if not (due and due < _now()):
ok, why = False, "里程碑「%s」既不是主線「%s」也還沒逾期(別 repo 的同名里程碑不算主線)" % (
ims.get("title"), ms["title"])
tier = "(主線)" if on_mainline else "(逾期里程碑,主線已抓盡)"
if not ok and pool_mode(argv):
# 第三層:open 票池(inkstone/ISEP#130)。規則同 pick 那一層,一格不放寬 Human/指派/hub。
pok, pwhy = pickable(issue, None, who, POOL_STATUSES)
if pok:
ok, tier = True, "open 票池,主線與逾期里程碑已抓盡)"
else:
why = pwhy
if not ok:
die("""🚫 %s/%s#%d 現在不能抓:%s
抓票規則(inkstone/ISEP#131,全部是 Gitea 欄位):
s/* 恰好是 s/todo 沒有 assignee 沒有 Humanhuman/* + 在主線上(hub 里程碑或相依;主線抓盡才抓逾期)
帶 --pool(或環境 ISEP_DRAIN=1)時另收 open 票池裡的 s/todos/backloginkstone/ISEP#130),其他格照舊
出路:`%s pick` 會回一張符合規則的票;這張如果真的該你做,回票上問總管改欄位,不要硬抓。""" % (
owner, repo, num, why, self_path()))
api("/repos/%s/%s/issues/%d" % (owner, repo, num), {"assignees": [who]}, method="PATCH")
before = sorted(n for n in _label_names(issue) if n.startswith("s/"))
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") or "(無,靠相依在主線上)", "(主線)" if on_mainline else "逾期里程碑,主線已抓盡)"),
"- 狀態:s/todo → s/doing",
"- 里程碑:「%s」%s" % (ims.get("title") or ("(無,靠相依在主線上)" if on_mainline else "無)"), tier),
"- 狀態:%s → s/doing" % "、".join(before),
"- 做完:分支+證據 → `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))
@@ -1621,10 +1825,372 @@ def cmd_claim(argv):
# ══════════════════════════════════════════════════════════════════════════
# inkstone/ISEP#159 — 分診+組里程碑:雲端工人不只「撿」,還要「組」
#
# leo 2026-09-18:「它看到票時要能夠組成 milestone 提出版本,所以不只是看票,還要組票。」
# 「我需要幫忙的 AI,而不是我要一直服務它的 AI。」
# 09-18 實量 inkstone orgopen 302 張,沒有 s/* 的 74 張、沒掛里程碑的 257 張。
#
# 哪張跟哪張重複、哪幾張該組成一輪——那是**判斷**,留給讀票的人(雲端工人);
# 這裡只管判斷寫回 Gitea 的那一步,讓它**一個動作、有說明、碰不到不該碰的**:
# · 判準全是欄位與唯一識別碼(s/* 標籤、assignee 登入名、票號、里程碑 id),沒有一格在猜文字
# · 不該碰的=掛 Human/human/*、指派給別人(含 Leo)——讀可以,一個字都不寫
# · compose 先全部驗過才寫第一筆;驗不過一次列出全部理由(改一格撞一次=閘在懲罰人)
# ══════════════════════════════════════════════════════════════════════════
TRIAGE_TO = ("s/backlog", "s/triage", "s/pending")
COMPOSE_MEMBER_STATUSES = ("s/backlog", "s/todo", "s/doing", "s/review", "s/stage", "s/pending")
COMPOSE_MAX_DAYS = 60
def hands_off(issue, me):
"""這張票能不能寫(留言/改標籤/關)。回 None=可以,否則回理由。**純函式。**"""
if not isinstance(issue, dict) or not issue.get("number"):
return "讀不到這張票"
if issue.get("pull_request"):
return "這是 PR,不是票"
if (issue.get("state") or "open") != "open":
return "已經關了"
labels = _label_names(issue)
if human_gated(labels):
return "掛著 %s——要 leo 親手做的,不碰" % "、".join(
n for n in labels if n == "Human" or n.startswith("human/"))
who = [a.get("login") for a in (issue.get("assignees") or []) if isinstance(a, dict)]
if not who and isinstance(issue.get("assignee"), dict):
who = [issue["assignee"].get("login")]
others = [w for w in who if w and w != me]
if others or (who and not me):
return "指派給 %s——棒子在別人手上,不碰" % "、".join(str(w) for w in who if w)
return None
def _status_of(issue):
return sorted(n for n in _label_names(issue) if n.startswith("s/"))
def triageable(issue, me):
"""待分診=還沒有任何 s/*,而且碰得了。回 (ok, 理由)。**純函式。**"""
why = hands_off(issue, me)
if why:
return False, why
st = _status_of(issue)
if st:
return False, "已經分診過(%s" % "、".join(st)
if _is_carrier(issue):
return False, "是里程碑「%s」的載體票(容器,狀態跟著它的前置走)" % issue["milestone"].get("title")
return True, "ok"
def _is_carrier(issue):
"""InkStoneCo 裡掛在 open 里程碑上的票=載體(開工規約第 7 條)。只看欄位:repo 與里程碑狀態。"""
full = ((issue.get("repository") or {}).get("full_name")) or ""
ims = issue.get("milestone") or {}
return full == "%s/%s" % (ORG, CARRIER_REPO) and bool(ims) and (ims.get("state") or "open") == "open"
def triage_candidates(issues, me):
"""票池裡現在待分診的票,舊的先(放最久的最該有人看一眼)。"""
found = [it for it in issues if triageable(it, me)[0]]
return sorted(found, key=lambda it: (it.get("created_at") or "", _ref_of(it)))
def _opt(argv, name, default=None):
return argv[argv.index(name) + 1] if name in argv and argv.index(name) + 1 < len(argv) else default
def _positional(argv, flags_with_value):
out, skip = [], False
for a in argv:
if skip:
skip = False
continue
if a in flags_with_value:
skip = True
continue
if a.startswith("--"):
continue
out.append(a)
return out
def _fetch(owner, repo, num):
it = api("/repos/%s/%s/issues/%d" % (owner, repo, num))
if isinstance(it, dict):
it.setdefault("repository", {"full_name": "%s/%s" % (owner, repo)})
return it
def _sign(argv):
"""`--sign cloud-worker` ⇒ 留言內文署名 `[cloud-worker]`。身份欄(--name)只收名單上的名字,
雲端工人不在名單上(cloud-worker.md 步驟 1),署名就寫在內文——誰跑的就署誰,不寫死。"""
v = (_opt(argv, "--sign") or "").strip()
return "[%s]" % v if v else ""
def _ident_line(name, owner, repo):
return "【身份】%s%s/%s-" % (name, owner, repo)
# ── triage ───────────────────────────────────────────────────────────────
def cmd_triage(argv):
"""分診一張還沒有 s/* 的票:給狀態+留說明(或當重複關掉並指向留下的那張),一個動作。"""
if not argv or argv[0] in ("-h", "--help"):
die(usage_text("triage"), 0 if argv else 2)
if argv[0] == "--list":
return _triage_list(argv[1:])
ref = argv[0]
owner, repo, num = parse_ref(ref)
to, dup, why = _opt(argv, "--to"), _opt(argv, "--dup-of"), (_opt(argv, "--why") or "").strip()
name = _opt(argv, "--name") or "subagent"
# ── 離線就能判的先判,一通 API 都不打 ──
problems = []
if bool(to) == bool(dup):
problems.append("--to 與 --dup-of 恰好給一個(分到哪個狀態,或跟哪張重複)")
if to and to not in TRIAGE_TO:
extra = ("——s/todo 的意思是「已排進里程碑」,走 `ticket compose` 排進去才給" if to == "s/todo" else "")
problems.append("--to 只收 %s,你給的是 %s%s" % ("".join(TRIAGE_TO), to, extra))
if not why:
problems.append("--why 要寫一句理由——票上那則說明就是它(驗收:每張被動過的票上都說得出分到哪、為什麼)")
dparts = None
if dup:
dparts = parse_ref(dup)
if dparts == (owner, repo, num):
problems.append("--dup-of 指到自己")
if problems:
die("🚫 triage %s 還沒送出,參數要補:\n%s\n\n%s" % (
ref, "\n".join(" · " + p for p in problems), usage_text("triage")))
ident = _ident_line(name, owner, repo)
check_identity(ident, "分診留言")
me = _me()
issue = _fetch(owner, repo, num)
ok, reason = triageable(issue, me)
if not ok:
die("🚫 %s 不分診:%s\n 出路:`%s triage --list` 列得出現在待分診的票;"
"已經有 s/* 的票要改狀態,走 `ticket handback``ticket decide`。" % (ref, reason, self_path()))
before_labels = _label_names(issue)
new_status = "close/duplicate" if dup else to
ids = _labels_of(owner, repo)
if new_status not in ids:
die("🚫 %s/%s 沒有標籤 %s(標籤的唯一真相源是 ISEP labels.yaml,改那裡再跑 gitea-labels-sync"
% (owner, repo, new_status))
target, target_note = None, None
if dup:
target = _fetch(*dparts)
if not isinstance(target, dict) or not target.get("number"):
die("🚫 --dup-of %s 讀不到" % dup)
if target.get("pull_request"):
die("🚫 --dup-of %s 是 PR,不是票" % dup)
if (target.get("state") or "open") != "open":
die("🚫 --dup-of %s 已經關了——跟一張關掉的票「重複」不代表這件事做完了。\n"
" 出路:這張給 --to s/triage 並在 --why 寫「疑似與 %s 重複、那張已關」,交總管看。" % (dup, dup))
target_note = hands_off(target, me)
# ── 寫:說明先落地,再改欄位(改到一半炸掉時,票上至少說得出發生了什麼)──
dref = "%s/%s#%d" % dparts if dparts else None
lines = [ident, "",
"🗂️ **分診**inkstone/ISEP#159%s" % _sign(argv), ""]
if dup:
lines += ["- 與 %s 重複 → 關掉這張,後續在那張" % dref,
"- 為什麼:%s" % why]
else:
lines += ["- 狀態:(沒有 s/*)→ `%s`" % to,
"- 為什麼:%s" % why]
api("/repos/%s/%s/issues/%d/comments" % (owner, repo, num), {"body": "\n".join(lines)})
keep = [n for n in before_labels if not n.startswith("s/")] + [new_status]
api("/repos/%s/%s/issues/%d/labels" % (owner, repo, num), {"labels": [ids[n] for n in keep]}, method="PUT")
if dup:
api("/repos/%s/%s/issues/%d" % (owner, repo, num), {"state": "closed"}, method="PATCH")
if target_note is None:
to_ident = _ident_line(name, dparts[0], dparts[1])
api("/repos/%s/%s/issues/%d/comments" % dparts,
{"body": "\n".join([to_ident, "", "🗂️ %s 與這張重複,已關掉併到這裡(%s%s" % (ref, why, _sign(argv))])})
print("✅ 分診 %s → %s" % (ref, ("重複,併入 %s(已關)" % dref) if dup else to))
print(" 票上留了說明:%s" % why)
if dup and target_note:
print(" ⚪ 沒在 %s 留指回來的留言:%s" % (dref, target_note))
def _triage_list(argv):
owner = ORG
me = _me()
issues = pool_issues(owner)
pending = triage_candidates(issues, me)
show = issues if "--all" in argv else pending
if "--json" in argv:
rows = [{"ref": _ref_of(it), "title": it.get("title"), "status": _status_of(it),
"milestone": (it.get("milestone") or {}).get("title"),
"triageable": triageable(it, me)[0], "created_at": it.get("created_at")}
for it in sorted(show, key=lambda it: _ref_of(it))]
print(json.dumps(rows, ensure_ascii=False, indent=2))
return
untouched = sum(1 for it in issues if not _status_of(it) and not triageable(it, me)[0])
print("🗂️ open 票池 %d 張;待分診 %d 張(另有 %d 張沒 s/* 但掛 Human/指派給別人,不碰)"
% (len(issues), len(pending), untouched))
for it in sorted(show, key=lambda it: _ref_of(it)):
st = "、".join(_status_of(it)) or "(沒有 s/*"
print(" %-28s %-12s %s" % (_ref_of(it), st, (it.get("title") or "")[:70]))
if pending:
print("\n📌 %s" % _next_cmd("待分診", _ref_of(pending[0])))
# ── compose ──────────────────────────────────────────────────────────────
def _version_like(title):
"""名字就是版本號(`1.4.52 雲端零件包`)——開工規約第 5 條:版本號是 deliverable,不是名字。"""
return bool(re.match(r"^\s*[vV]?\d+(\.\d+)+", title or ""))
def cmd_compose(argv):
"""把已分診的票組成一個 InkStoneCo 里程碑(載體票+前置),先全部驗過才寫。"""
if not argv or argv[0] in ("-h", "--help"):
die(usage_text("compose"), 0 if argv else 2)
from datetime import datetime, timedelta, timezone
title = (_opt(argv, "--title") or "").strip()
goal = (_opt(argv, "--goal") or "").strip()
due_s = (_opt(argv, "--due") or "").strip()
carrier_s = _opt(argv, "--carrier")
name = _opt(argv, "--name") or "subagent"
members_s = _positional(argv, ("--title", "--goal", "--due", "--carrier", "--name", "--sign"))
problems = []
if not title:
problems.append("--title 要寫:名字回答「這一輪要讓什麼變成真的」(開工規約第 5 條)")
elif _version_like(title):
problems.append("--title「%s」以版本號開頭——版本號是 deliverable 不是名字(開工規約第 5 條,leo 2026-08-24" % title)
if not goal:
problems.append("--goal 要寫一段話:這一輪做完,用戶那邊什麼會變成真的")
due = None
now = _now()
try:
due = datetime.strptime(due_s, "%Y-%m-%d").replace(hour=23, minute=59, second=59, tzinfo=timezone.utc)
except ValueError:
problems.append("--due 要是 YYYY-MM-DD(開工規約第 6 條:期限一律要填),你給的是「%s」" % due_s)
if due and not (now < due <= now + timedelta(days=COMPOSE_MAX_DAYS + 1)):
problems.append("--due %s 不在今天之後 %d 天內——過去的期限等於已逾期,太遠的期限是「沒有期限」穿了期限的衣服"
% (due_s, COMPOSE_MAX_DAYS))
carrier = None
if not carrier_s:
problems.append("--carrier 要給一張 inkstone/InkStoneCo 的既有票當載體(開工規約第 7 條;不開新票)")
else:
carrier = parse_ref(carrier_s)
if carrier[:2] != (ORG, CARRIER_REPO):
problems.append("--carrier %s 不在 %s/%s——里程碑一律建在 InkStoneCo,載體票也在那裡" % (carrier_s, ORG, CARRIER_REPO))
members = []
for m in members_s:
r = parse_ref(m)
if r == carrier:
problems.append("%s 是載體票本身,不用再列成前置" % m)
elif r not in members:
members.append(r)
if not members:
problems.append("至少列一張前置票(別 repo 的執行票)——沒有前置的里程碑交不出版本")
if problems:
die("🚫 compose 還沒送出(一筆都沒寫):\n%s\n\n%s" % (
"\n".join(" · " + p for p in problems), usage_text("compose")))
ident = _ident_line(name, ORG, CARRIER_REPO)
check_identity(ident, "組里程碑留言")
# ── 線上驗:全部讀過一次,理由收齊才決定寫不寫 ──
me = _me()
ML = _mainline_lib()
cref = "%s/%s#%d" % carrier
citem = _fetch(*carrier)
why = hands_off(citem, me)
if why:
problems.append("載體 %s%s" % (cref, why))
elif citem.get("milestone") and (citem["milestone"].get("state") or "open") == "open":
problems.append("載體 %s 已經掛在里程碑「%s」——一張載體只載一輪" % (cref, citem["milestone"].get("title")))
else:
for b in _blocks(*carrier):
bm = (b or {}).get("milestone") or {}
if (b or {}).get("state", "open") == "open" and bm and (bm.get("state") or "open") == "open":
problems.append("載體 %s 已經是 %s(里程碑「%s」)的前置——它那一輪還在跑,不能再載另一輪"
% (cref, ML.issue_ref(b) or "?", bm.get("title")))
break
existing = api("/repos/%s/%s/milestones?state=open&limit=100" % (ORG, CARRIER_REPO)) or []
for m in existing:
if isinstance(m, dict) and ML.norm(m.get("title")) == ML.norm(title):
problems.append("InkStoneCo 已經有 open 里程碑「%s」(id %s)——同名不再建一個" % (m.get("title"), m.get("id")))
rows = []
for mo, mr, mn in members:
mref = "%s/%s#%d" % (mo, mr, mn)
it = _fetch(mo, mr, mn)
why = hands_off(it, me)
if why:
problems.append("前置 %s%s" % (mref, why))
continue
st = _status_of(it)
if len(st) != 1 or st[0] not in COMPOSE_MEMBER_STATUSES:
problems.append("前置 %s 還沒分診(現在 %s)——先 `ticket triage` 決定要不要做" % (mref, st or "沒有 s/*"))
continue
ims = it.get("milestone") or {}
if ims and (ims.get("state") or "open") == "open":
problems.append("前置 %s 已經掛在里程碑「%s」" % (mref, ims.get("title")))
continue
for b in _blocks(mo, mr, mn):
bm = (b or {}).get("milestone") or {}
if (b or {}).get("state", "open") == "open" and bm and (bm.get("state") or "open") == "open":
problems.append("前置 %s 已經是 %s(里程碑「%s」)的前置——一張票同時只排一輪"
% (mref, ML.issue_ref(b) or "?", bm.get("title")))
break
else:
rows.append(((mo, mr, mn), mref, it, st[0]))
if problems:
die("🚫 compose 驗不過(一筆都沒寫):\n%s\n\n"
"出路:把上面每一格換掉(換一張載體、拿掉那張前置、先 triage),再送一次。"
"掛 Human/指派給 Leo 的票不會被組進來——那是 leo 的。" % "\n".join(" · " + p for p in problems))
# ── 寫 ──
member_refs = [r for _, r, _, _ in rows]
desc = "\n".join([
"這一輪要讓什麼變成真的:%s" % goal,
"deliverable=一個總管在 stage 驗過的新版本(版本號由總管定);前置全部關閉=100%=才出版本。",
"載體票:%s;前置:%s" % (cref, "、".join(member_refs)),
"組票:%s %sinkstone/ISEP#159CLAUDE.md 開工規約 17 條)" % (_sign(argv) or name, now.strftime("%Y-%m-%d")),
])
ms = api("/repos/%s/%s/milestones" % (ORG, CARRIER_REPO),
{"title": title, "description": desc, "due_on": due.strftime("%Y-%m-%dT%H:%M:%SZ")})
mid = (ms or {}).get("id")
if not mid:
die("🔴 建里程碑沒拿到 id(Gitea 回:%s)——後面一筆都沒寫" % str(ms)[:200])
url = "%s/%s/%s/milestone/%s" % (HOST, ORG, CARRIER_REPO, mid)
print("✅ 里程碑「%s」(%s/%s milestone %s,期限 %s" % (title, ORG, CARRIER_REPO, mid, due_s))
api("/repos/%s/%s/issues/%d" % carrier, {"milestone": mid}, method="PATCH")
print(" 載體 %s 掛上里程碑" % cref)
for (mo, mr, mn), mref, it, st in rows:
add_dependency(carrier, (mo, mr, mn))
moved = ""
if st == "s/backlog":
ids = _labels_of(mo, mr)
keep = [n for n in _label_names(it) if not n.startswith("s/")] + ["s/todo"]
if all(n in ids for n in keep):
api("/repos/%s/%s/issues/%d/labels" % (mo, mr, mn), {"labels": [ids[n] for n in keep]}, method="PUT")
moved = "s/backlog → s/todo"
api("/repos/%s/%s/issues/%d/comments" % (mo, mr, mn),
{"body": "\n".join([_ident_line(name, mo, mr), "",
"🧩 排進里程碑「%s」(載體 %s,期限 %s%s %s" % (title, cref, due_s, moved, _sign(argv)),
url])})
print(" 前置 %s%s" % (mref, moved))
api("/repos/%s/%s/issues/%d/comments" % carrier,
{"body": "\n".join([ident, "", "🧩 **組里程碑**inkstone/ISEP#159%s" % _sign(argv), "",
"- 里程碑:「%s」→ %s" % (title, url),
"- 期限:%s" % due_s,
"- 這一輪要讓什麼變成真的:%s" % goal,
"- 前置(全部關閉=100%%=才出版本):%s" % "、".join(member_refs),
"- deliverable:一個總管在 stage 驗過的新版本(版本號由總管定)"])})
print(" %s" % url)
print("\n📌 接下來照里程碑做:`%s pick --pool` 會先回這個里程碑的前置票(還沒到期的里程碑排在散票之前)" % self_path())
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, "pick": cmd_pick, "claim": cmd_claim}
"usage": cmd_usage, "pick": cmd_pick, "claim": cmd_claim,
"triage": cmd_triage, "compose": cmd_compose}
if __name__ == "__main__":
if len(sys.argv) < 2 or sys.argv[1] not in CMDS: