65 lines
2.4 KiB
Python
Executable File
65 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""列出可執行的議題。輸入:open.json agents.json tabs.json"""
|
|
import json, re, sys
|
|
|
|
open_issues = json.load(open(sys.argv[1]))
|
|
agents = json.load(open(sys.argv[2]))
|
|
tabs = json.load(open(sys.argv[3]))
|
|
|
|
def find(o, k):
|
|
if isinstance(o, dict):
|
|
if k in o: return o[k]
|
|
for v in o.values():
|
|
r = find(v, k)
|
|
if r is not None: return r
|
|
elif isinstance(o, list):
|
|
for v in o:
|
|
r = find(v, k)
|
|
if r is not None: return r
|
|
|
|
def labels(i): return [l.strip() for l in (i.get("labels") or "").split() if l.strip()] if isinstance(i.get("labels"), str) else [l["name"] for l in i.get("labels") or []]
|
|
|
|
open_idx = {i["index"] for i in open_issues}
|
|
by_idx = {i["index"]: i for i in open_issues}
|
|
|
|
# Herdr 裡活著的 agent:名稱 issue-N,或掛在標籤 #N 的 tab 上
|
|
running = set()
|
|
for a in find(agents, "agents") or []:
|
|
m = re.fullmatch(r"issue-(\d+)", str(a.get("name") or ""))
|
|
if m: running.add(m.group(1))
|
|
agent_tabs = {a.get("tab_id") for a in find(agents, "agents") or []}
|
|
for t in find(tabs, "tabs") or []:
|
|
m = re.fullmatch(r"#(\d+)", str(t.get("label") or ""))
|
|
if m and t.get("tab_id") in agent_tabs: running.add(m.group(1))
|
|
|
|
def blockers(i):
|
|
m = re.search(r"Blocked by:\s*([^\n]*)", i.get("body") or "")
|
|
return re.findall(r"#(\d+)", m.group(1)) if m else []
|
|
|
|
def spec(i):
|
|
return next((l for l in labels(i) if l.startswith("規格/#") or l.startswith("總覽/#")), "")
|
|
|
|
runnable, blocked, stale = [], [], []
|
|
for i in sorted(open_issues, key=lambda x: int(x["index"])):
|
|
ls = labels(i)
|
|
if "ready-for-agent" not in ls: continue
|
|
if "類型/規格" in ls or "類型/總覽" in ls: continue
|
|
n = i["index"]
|
|
if n in running: continue
|
|
if "in-progress" in ls:
|
|
stale.append(n); continue
|
|
open_blockers = [b for b in blockers(i) if b in open_idx]
|
|
if open_blockers:
|
|
blocked.append((n, open_blockers)); continue
|
|
runnable.append((n, spec(i), i["title"]))
|
|
|
|
print(f"可執行({len(runnable)}):編號\t規格\t標題")
|
|
for n, s, t in runnable:
|
|
print(f"#{n}\t{s}\t{t}")
|
|
print()
|
|
print("Herdr 執行中:" + (" ".join(f"#{n}" for n in sorted(running, key=int)) or "無"))
|
|
if stale:
|
|
print("掛 in-progress 但沒有 agent(需處理,重跑 start 會接續):" + " ".join(f"#{n}" for n in stale))
|
|
if blocked:
|
|
print("被阻擋:" + " ".join(f"#{n}←{','.join('#'+b for b in bs)}" for n, bs in blocked))
|