herdr-orchestra 6.23.0 → 6.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/README.md +15 -0
- package/VERSION +1 -1
- package/agents.default.toml +3 -0
- package/bin/__pycache__/orchcpython-314.pyc +0 -0
- package/bin/orch +806 -61
- package/package.json +1 -1
- package/playbooks/plan.md +49 -6
- package/playbooks/run.md +3 -0
package/bin/orch
CHANGED
|
@@ -932,6 +932,8 @@ def eligible_workers(st, t):
|
|
|
932
932
|
team reaches the tier, the strongest workers the team has, so a run never waits for a model nobody started."""
|
|
933
933
|
if t.get("assign") in st["workers"] and not st["workers"][t["assign"]].get("off"):
|
|
934
934
|
return [t["assign"]]
|
|
935
|
+
if t.get("model"): # `Model:` in plan.md: the developer chose this model, orch never picks another
|
|
936
|
+
return [n for n, w in st["workers"].items() if not w.get("off") and (w.get("model") or "") == t["model"]]
|
|
935
937
|
need = need_rank(t)
|
|
936
938
|
ranks = {n: rank(w.get("tier")) for n, w in st["workers"].items() if not w.get("off")} # `orch bench <w> off`
|
|
937
939
|
if not ranks:
|
|
@@ -1190,7 +1192,8 @@ def is_dirty(path):
|
|
|
1190
1192
|
|
|
1191
1193
|
# ---------------------------------------------------------------- plan parsing
|
|
1192
1194
|
HEAD_RE = re.compile(r"^## \[( |x|X)\]\s*(M\d+)\s*:\s*(.+?)\s*$")
|
|
1193
|
-
|
|
1195
|
+
# a key is words; its last word may also hold digits, dots, dashes (`Check web-app:`, `Workers api2:`)
|
|
1196
|
+
FIELD_RE = re.compile(r"^([A-Z][A-Za-z ]*(?: [A-Za-z0-9][\w.-]*)?):\s*(.*)$")
|
|
1194
1197
|
|
|
1195
1198
|
|
|
1196
1199
|
def parse_plan(text):
|
|
@@ -1243,6 +1246,9 @@ def field(t, key, default=""):
|
|
|
1243
1246
|
return " ".join(vals).strip() if vals else default
|
|
1244
1247
|
|
|
1245
1248
|
|
|
1249
|
+
EXT_DEP_RE = re.compile(r"\b([A-Za-z][\w.-]*):(M\d+)\b")
|
|
1250
|
+
|
|
1251
|
+
|
|
1246
1252
|
def split_ids(s):
|
|
1247
1253
|
if not s or s.lower() in ("none", "-", "n/a"):
|
|
1248
1254
|
return []
|
|
@@ -1343,6 +1349,14 @@ def cmd_sync(args):
|
|
|
1343
1349
|
workers = parse_agents(get("workers"))
|
|
1344
1350
|
if not workers:
|
|
1345
1351
|
errors.append("plan header needs `Workers: claude-1 (claude), codex-1 (codex)`")
|
|
1352
|
+
# a monorepo's sides: `Check frontend: cd web && pnpm test` + `Side: frontend` on a milestone checks only that side
|
|
1353
|
+
sides = {k[len("check "):].strip(): " ".join(v).strip() for k, v in cfg.items()
|
|
1354
|
+
if k.startswith("check ") and k != "check command" and " ".join(v).strip()}
|
|
1355
|
+
workspace = get("workspace") or None # written by `orch sync` in a workspace of several repos
|
|
1356
|
+
ws_repos = workspace_repos(Path(workspace)) if workspace else {}
|
|
1357
|
+
if workspace and not ws_repos:
|
|
1358
|
+
errors.append(f"`Workspace: {workspace}` names a folder with no workspace plan (.orchestrate/workspace.json) — "
|
|
1359
|
+
f"run `orch sync` in that folder")
|
|
1346
1360
|
rev = get("reviewer", "none")
|
|
1347
1361
|
rm = re.match(r"([\w.-]+)\s*\(", rev)
|
|
1348
1362
|
reviewer = None if rev.lower().startswith("none") or not rm else rm.group(1)
|
|
@@ -1392,7 +1406,28 @@ def cmd_sync(args):
|
|
|
1392
1406
|
errors.append(f"duplicate task ids: {sorted(dupes)}")
|
|
1393
1407
|
by_id = {t["id"]: t for t in tasks}
|
|
1394
1408
|
# "Depends on: M1 (uses the API types M1 defines), M2 (needs the table)": reasons in parentheses
|
|
1395
|
-
deps = {t["id"]: split_ids(re.sub(r"\([^)]*\)", "", field(t, "depends on", "none")))
|
|
1409
|
+
deps = {t["id"]: split_ids(EXT_DEP_RE.sub("", re.sub(r"\([^)]*\)", "", field(t, "depends on", "none"))))
|
|
1410
|
+
for t in tasks}
|
|
1411
|
+
# "Depends on: backend:M2 (the endpoint)": a milestone of another repo in the same workspace
|
|
1412
|
+
ext_deps = {}
|
|
1413
|
+
for t in tasks:
|
|
1414
|
+
for repo_, mid in EXT_DEP_RE.findall(re.sub(r"\([^)]*\)", "", field(t, "depends on", "none"))):
|
|
1415
|
+
if repo_.lower() not in ws_repos:
|
|
1416
|
+
errors.append(f"{t['id']} depends on {repo_}:{mid}, but " + (
|
|
1417
|
+
f"the workspace has no repo {repo_!r} (repos: {', '.join(ws_repos)})" if ws_repos else
|
|
1418
|
+
"this run is not part of a workspace of several repos (write the repo:Mn form only there)"))
|
|
1419
|
+
continue
|
|
1420
|
+
ext_deps.setdefault(t["id"], []).append({"repo": repo_.lower(), "path": ws_repos[repo_.lower()],
|
|
1421
|
+
"id": mid})
|
|
1422
|
+
side_of = {}
|
|
1423
|
+
for t in tasks:
|
|
1424
|
+
sd = field(t, "side").split()[0].lower() if field(t, "side") else None
|
|
1425
|
+
if sd and sd not in sides:
|
|
1426
|
+
errors.append(f"{t['id']} has `Side: {sd}`, but the plan has no `Check {sd}:` line"
|
|
1427
|
+
+ (f" (sides: {', '.join(sides)})" if sides else
|
|
1428
|
+
" — add one, e.g. `Check frontend: cd frontend && npm test`"))
|
|
1429
|
+
side_of[t["id"]] = sd if sd in sides else None
|
|
1430
|
+
errors += name_clashes(workers, reviewer, lead[0] if lead else None, workspace)
|
|
1396
1431
|
for t in tasks:
|
|
1397
1432
|
raw = field(t, "depends on", "none")
|
|
1398
1433
|
for d in deps[t["id"]]:
|
|
@@ -1514,6 +1549,20 @@ def cmd_sync(args):
|
|
|
1514
1549
|
and rank(tier_of(reviewer)) < rank(tv)):
|
|
1515
1550
|
warns.append(f"{tid} is {tv}-tier work reviewed by a {tier_of(reviewer)}-tier model ({models[reviewer]}) — "
|
|
1516
1551
|
f"a reviewer weaker than the coder misses design errors")
|
|
1552
|
+
# `Model: gpt-6.2-sol@low` on a milestone: the developer locked it to coders running exactly that model
|
|
1553
|
+
locks = {}
|
|
1554
|
+
for t in tasks:
|
|
1555
|
+
mv = (field(t, "model").split() or [""])[0].strip("`").lower()
|
|
1556
|
+
if not mv or mv in ("any", "auto", "none"):
|
|
1557
|
+
continue
|
|
1558
|
+
locks[t["id"]] = mv
|
|
1559
|
+
why = model_denied(cat, mv)
|
|
1560
|
+
if why:
|
|
1561
|
+
errors.append(f"{t['id']} has `Model: {mv}`, which the model policy does not allow (pattern {why!r}) — "
|
|
1562
|
+
f"pick another model (`orch plan team` lists them)")
|
|
1563
|
+
elif t["enabled"] and not any(models.get(n) == mv for n in workers):
|
|
1564
|
+
errors.append(f"{t['id']} has `Model: {mv}`, but no coder in Workers runs {mv} — "
|
|
1565
|
+
f"`orch plan model {t['id']} {mv}` adds one, or `orch plan model {t['id']} auto` unlocks it")
|
|
1517
1566
|
if lead and models.get(lead[0]) and rank(tier_of(lead[0])) not in (0, 3):
|
|
1518
1567
|
warns.append(f"the lead runs {models[lead[0]]!r} ({tier_of(lead[0])} tier) — planning and coordination are "
|
|
1519
1568
|
f"high-tier work")
|
|
@@ -1665,6 +1714,8 @@ def cmd_sync(args):
|
|
|
1665
1714
|
"budget_s": budget_s,
|
|
1666
1715
|
"estimate_s": feature_est,
|
|
1667
1716
|
"check": get("check command"),
|
|
1717
|
+
"sides": sides,
|
|
1718
|
+
"workspace": workspace,
|
|
1668
1719
|
"setup": get("setup command", "none"),
|
|
1669
1720
|
"reviewer": reviewer,
|
|
1670
1721
|
"reviewer_info": ({"kind": rev_kind, "pane": rev_pane, "detect": detect(rev_kind, rev_pane, "Reviewer"),
|
|
@@ -1728,11 +1779,13 @@ def cmd_sync(args):
|
|
|
1728
1779
|
"files": sorted(files[tid]),
|
|
1729
1780
|
"parallel": field(t, "parallel", "").lower().startswith("allow"),
|
|
1730
1781
|
"tier": tiers[tid], "needs": needs[tid], "model_why": field(t, "model why"), "role": field(t, "role"),
|
|
1782
|
+
"model": locks.get(tid), # locked by the developer: only coders on this model take it
|
|
1731
1783
|
"estimate_s": estimates[tid],
|
|
1732
1784
|
# for the developer (`orch plan show`): the milestone in plain words, and the plan's own reasons
|
|
1733
1785
|
"plain": field(t, "plain"), "why_sep": field(t, "why separate"), "deps_text": field(t, "depends on"),
|
|
1734
1786
|
# hard to undo: always held for `orch approve`, with the coder's proof (None = easy to undo)
|
|
1735
1787
|
"door": "one-way" if tid in doors else None, "door_why": doors.get(tid) or None,
|
|
1788
|
+
"side": side_of.get(tid), "ext_deps": ext_deps.get(tid) or [],
|
|
1736
1789
|
}
|
|
1737
1790
|
if status != st["tasks"][tid]["status"]:
|
|
1738
1791
|
move(st, tid, status, {"skipped": "unticked in plan.md", "needs-answer": "open questions in plan.md"}
|
|
@@ -2314,13 +2367,25 @@ def review_findings(tid, k):
|
|
|
2314
2367
|
return blockers, sugg, known
|
|
2315
2368
|
|
|
2316
2369
|
|
|
2317
|
-
def
|
|
2318
|
-
"""(
|
|
2319
|
-
|
|
2370
|
+
def check_for(st, tid=None):
|
|
2371
|
+
"""The check command for milestone tid: its side's (`Side: frontend` + `Check frontend: ...`), else the plan's."""
|
|
2372
|
+
side = (st.get("tasks", {}).get(tid) or {}).get("side") if tid else None
|
|
2373
|
+
return (st.get("sides") or {}).get(side) or st.get("check") or ""
|
|
2374
|
+
|
|
2375
|
+
|
|
2376
|
+
def full_check(st, tid=None):
|
|
2377
|
+
"""True when tid is checked with the plan's whole check command (not only its side's)."""
|
|
2378
|
+
return check_for(st, tid) == (st.get("check") or "")
|
|
2379
|
+
|
|
2380
|
+
|
|
2381
|
+
def run_check(st, cwd, tid=None):
|
|
2382
|
+
"""(passed, last 60 lines, seconds) for the check command of milestone tid (else the plan's) in cwd."""
|
|
2383
|
+
cmd = check_for(st, tid)
|
|
2384
|
+
if not cmd:
|
|
2320
2385
|
return True, "", 0
|
|
2321
2386
|
t0 = time.time()
|
|
2322
2387
|
try:
|
|
2323
|
-
r = subprocess.run(
|
|
2388
|
+
r = subprocess.run(cmd, shell=True, cwd=cwd, text=True, capture_output=True, timeout=CHECK_TIMEOUT_S)
|
|
2324
2389
|
ok, tail = r.returncode == 0, "\n".join((r.stdout + r.stderr).splitlines()[-60:])
|
|
2325
2390
|
except subprocess.TimeoutExpired:
|
|
2326
2391
|
ok, tail = False, f"check command timed out after {CHECK_TIMEOUT_S // 60} min"
|
|
@@ -2344,9 +2409,10 @@ def tree_of(d):
|
|
|
2344
2409
|
return None
|
|
2345
2410
|
|
|
2346
2411
|
|
|
2347
|
-
def note_green(st, d, ok):
|
|
2348
|
-
"""Remember the tree a passing check ran on in the main folder (a failing one forgets it).
|
|
2349
|
-
|
|
2412
|
+
def note_green(st, d, ok, tid=None):
|
|
2413
|
+
"""Remember the tree a passing check ran on in the main folder (a failing one forgets it). Only the plan's whole
|
|
2414
|
+
check counts: a side's check (`Side:`) covers part of the repo, so `orch finish` must still run the whole one."""
|
|
2415
|
+
if Path(d).resolve() != ROOT.resolve() or (ok and not full_check(st, tid)):
|
|
2350
2416
|
return
|
|
2351
2417
|
st["green_tree"] = tree_of(d) if ok else None
|
|
2352
2418
|
|
|
@@ -2599,7 +2665,43 @@ def cmd_start(args):
|
|
|
2599
2665
|
|
|
2600
2666
|
|
|
2601
2667
|
def deps_met(st, t):
|
|
2602
|
-
return all(st["tasks"][d]["status"] == "merged" for d in t["deps"])
|
|
2668
|
+
return all(st["tasks"][d]["status"] == "merged" for d in t["deps"]) and not ext_waits(t)
|
|
2669
|
+
|
|
2670
|
+
|
|
2671
|
+
def ext_status(e):
|
|
2672
|
+
"""Status of a milestone in another repo of the workspace (`Depends on: backend:M2`), read from that repo's run."""
|
|
2673
|
+
try:
|
|
2674
|
+
return json.loads((Path(e["path"]) / ".orchestrate" / "state.json").read_text())["tasks"][e["id"]]["status"]
|
|
2675
|
+
except (OSError, ValueError, KeyError, TypeError):
|
|
2676
|
+
return "unknown"
|
|
2677
|
+
|
|
2678
|
+
|
|
2679
|
+
def ext_waits(t):
|
|
2680
|
+
"""The milestones in other repos that t still waits for: [(dep, its status)]."""
|
|
2681
|
+
out = []
|
|
2682
|
+
for e in t.get("ext_deps") or []:
|
|
2683
|
+
s_ = ext_status(e)
|
|
2684
|
+
if s_ != "merged":
|
|
2685
|
+
out.append((e, s_))
|
|
2686
|
+
return out
|
|
2687
|
+
|
|
2688
|
+
|
|
2689
|
+
def run_alive(path):
|
|
2690
|
+
"""True while the event manager of the run in path (another repo of the workspace) holds its lease."""
|
|
2691
|
+
p = Path(path) / ".orchestrate" / "driver.lock"
|
|
2692
|
+
if not p.exists():
|
|
2693
|
+
return False
|
|
2694
|
+
with open(p, "a") as f:
|
|
2695
|
+
try:
|
|
2696
|
+
fcntl.flock(f, fcntl.LOCK_SH | fcntl.LOCK_NB)
|
|
2697
|
+
except OSError:
|
|
2698
|
+
return True
|
|
2699
|
+
fcntl.flock(f, fcntl.LOCK_UN)
|
|
2700
|
+
return False
|
|
2701
|
+
|
|
2702
|
+
|
|
2703
|
+
def ext_line(waits):
|
|
2704
|
+
return ", ".join(f"{e['repo']} {e['id']} ({s_})" for e, s_ in waits)
|
|
2603
2705
|
|
|
2604
2706
|
|
|
2605
2707
|
def active_count(st):
|
|
@@ -2631,6 +2733,8 @@ def fix_jobs(st):
|
|
|
2631
2733
|
def cmd_ready(args):
|
|
2632
2734
|
st = load()
|
|
2633
2735
|
cand = [tid for tid in st["order"] if st["tasks"][tid]["status"] == "pending" and deps_met(st, st["tasks"][tid])]
|
|
2736
|
+
ext_wait = [f"WAIT {tid} waits for another repo: {ext_line(ext_waits(st['tasks'][tid]))}" for tid in st["order"]
|
|
2737
|
+
if st["tasks"][tid]["status"] == "pending" and ext_waits(st["tasks"][tid])]
|
|
2634
2738
|
# milestones that share Likely files run one after the other unless one says `Parallel: allow`
|
|
2635
2739
|
busy = {}
|
|
2636
2740
|
for tid, t in st["tasks"].items():
|
|
@@ -2668,7 +2772,7 @@ def cmd_ready(args):
|
|
|
2668
2772
|
print(f"FIX {tid} {st['tasks'][tid]['status']} {st['tasks'][tid]['title']}")
|
|
2669
2773
|
for tid in out:
|
|
2670
2774
|
print(f"READY {tid} {st['tasks'][tid]['title']}")
|
|
2671
|
-
for line in waits:
|
|
2775
|
+
for line in waits + ext_wait:
|
|
2672
2776
|
print(line)
|
|
2673
2777
|
|
|
2674
2778
|
|
|
@@ -2697,14 +2801,8 @@ def cmd_pick(args):
|
|
|
2697
2801
|
need(args, 1, "pick <Mn>")
|
|
2698
2802
|
st = load()
|
|
2699
2803
|
t = task(st, args[0])
|
|
2700
|
-
pref = t["prefer"]
|
|
2701
|
-
names = eligible_workers(st, t)
|
|
2702
|
-
last = t.get("last_worker")
|
|
2703
|
-
nr = need_rank(t)
|
|
2704
2804
|
# the last coder first (its work is in its folder), then the tier asked for before a stronger (dearer) one
|
|
2705
|
-
|
|
2706
|
-
if nr else 0, 0 if pref in ("any", st["workers"][n]["kind"], n) else 1))
|
|
2707
|
-
for n in names:
|
|
2805
|
+
for n in pick_order(st, t):
|
|
2708
2806
|
if worker_free(st, n, st["workers"][n]):
|
|
2709
2807
|
print(n)
|
|
2710
2808
|
return
|
|
@@ -3024,7 +3122,7 @@ def cmd_needs_fix(args):
|
|
|
3024
3122
|
t["job"] = {"file": f"review-fix-{k}.md", "body":
|
|
3025
3123
|
f"# Review findings for {tid}: {t['title']} (round {k})\n\n"
|
|
3026
3124
|
"The reviewer found the problems below. You own the fix: investigate each one and decide how to "
|
|
3027
|
-
f"solve it. Keep every acceptance criterion in {TASK_DIR}/{tid}/task.md, then run `{st
|
|
3125
|
+
f"solve it. Keep every acceptance criterion in {TASK_DIR}/{tid}/task.md, then run `{check_for(st, tid)}`.\n"
|
|
3028
3126
|
"If you think a finding is wrong, explain why in your report instead of changing code for it.\n\n"
|
|
3029
3127
|
+ "\n".join(blockers) + "\n"}
|
|
3030
3128
|
move(st, tid, "needs-fix")
|
|
@@ -3118,7 +3216,7 @@ def cmd_review(args):
|
|
|
3118
3216
|
+ (", the words listed above" if rules["glossary"] else "") +
|
|
3119
3217
|
"? A `rules` finding names the rule it breaks in `rule`. Only written rules count: a matter of taste is at "
|
|
3120
3218
|
"most a suggestion.\n"
|
|
3121
|
-
f"The check command (`{st
|
|
3219
|
+
f"The check command (`{check_for(st, tid)}`) runs on this work by itself: don't report what lint, type checks or "
|
|
3122
3220
|
"tests already catch.\n"
|
|
3123
3221
|
"Do NOT edit any code. Never commit, push or merge: no agent ever pushes to main or merges a PR, even when "
|
|
3124
3222
|
"asked.\n"
|
|
@@ -3402,7 +3500,7 @@ def merge_check_needed(st, tid):
|
|
|
3402
3500
|
run on the same files and can only say the same thing."""
|
|
3403
3501
|
t = st["tasks"][tid]
|
|
3404
3502
|
chk = t.get("chk") or {}
|
|
3405
|
-
if st["isolation"] != "worktree" or not st
|
|
3503
|
+
if st["isolation"] != "worktree" or not check_for(st, tid) or not chk.get("ok") or not chk.get("tree"):
|
|
3406
3504
|
return True
|
|
3407
3505
|
if st.get("branch_check") == "always": # the check depends on more than the files (the folder, the branch)
|
|
3408
3506
|
return True
|
|
@@ -3428,7 +3526,7 @@ def cmd_merge(args):
|
|
|
3428
3526
|
ok, tail = ensure_root_setup(st)
|
|
3429
3527
|
secs = 0
|
|
3430
3528
|
if ok:
|
|
3431
|
-
ok, tail, secs = run_check(st, ROOT)
|
|
3529
|
+
ok, tail, secs = run_check(st, ROOT, tid)
|
|
3432
3530
|
with state_lock():
|
|
3433
3531
|
st2 = load()
|
|
3434
3532
|
t = st2["tasks"][tid]
|
|
@@ -3441,7 +3539,7 @@ def cmd_merge(args):
|
|
|
3441
3539
|
st2["merging"] = None
|
|
3442
3540
|
_integration_failed(st2, tid, tail)
|
|
3443
3541
|
git("commit", "-q", "-m", commit_message(st2, tid), cwd=ROOT)
|
|
3444
|
-
note_green(st2, ROOT, True)
|
|
3542
|
+
note_green(st2, ROOT, True, tid)
|
|
3445
3543
|
fault("after-merge-commit")
|
|
3446
3544
|
git("update-ref", "-d", task_ref(st2, tid), cwd=ROOT, check=False)
|
|
3447
3545
|
_finish(st2, tid)
|
|
@@ -3486,7 +3584,7 @@ def _merge_start(tid):
|
|
|
3486
3584
|
f"Other milestones landed on `{st['branch']}` while you worked, and they conflict with "
|
|
3487
3585
|
f"yours in: {', '.join(files) or 'see git status'}.\n"
|
|
3488
3586
|
f"In this folder run `git merge --no-commit {st['branch']}`, resolve every conflict so BOTH "
|
|
3489
|
-
f"sides keep working (you own the resolution), then run `{st
|
|
3587
|
+
f"sides keep working (you own the resolution), then run `{check_for(st, tid)}`. Do not commit.\n"}
|
|
3490
3588
|
save(st)
|
|
3491
3589
|
who = t["worker"] if holds(st, tid) else "any free coder"
|
|
3492
3590
|
print(f"CONFLICT {tid} files={','.join(files)} -> conflict job queued for {who} (`orch send-job {tid}`)")
|
|
@@ -3504,7 +3602,7 @@ def _merge_start(tid):
|
|
|
3504
3602
|
f"(nothing else landed meanwhile), so the check was not run again")
|
|
3505
3603
|
fault("after-check")
|
|
3506
3604
|
git("commit", "-q", "-m", commit_message(st, tid), cwd=ROOT)
|
|
3507
|
-
note_green(st, ROOT, True)
|
|
3605
|
+
note_green(st, ROOT, True, tid)
|
|
3508
3606
|
fault("after-merge-commit")
|
|
3509
3607
|
git("update-ref", "-d", task_ref(st, tid), cwd=ROOT, check=False)
|
|
3510
3608
|
_finish(st, tid)
|
|
@@ -3546,9 +3644,9 @@ def _integration_failed(st, tid, tail):
|
|
|
3546
3644
|
n = t["fix"]
|
|
3547
3645
|
t["job"] = {"file": f"integration-fix-{n}.md", "body":
|
|
3548
3646
|
f"# {tid} fails the check once merged onto `{st['branch']}` (round {n})\n\n"
|
|
3549
|
-
f"Your milestone passes `{st
|
|
3647
|
+
f"Your milestone passes `{check_for(st, tid)}` on its own, but fails once it is merged with what landed on "
|
|
3550
3648
|
f"`{st['branch']}` since you started. In this folder run `git merge --no-commit {st['branch']}`, find "
|
|
3551
|
-
f"the cause and fix it (you decide how, and keep both sides working), then run `{st
|
|
3649
|
+
f"the cause and fix it (you decide how, and keep both sides working), then run `{check_for(st, tid)}`. "
|
|
3552
3650
|
f"Don't commit, and don't weaken or skip tests.\n\n```\n{tail}\n```\n"}
|
|
3553
3651
|
move(st, tid, "needs-fix", f"fails the check on {st['branch']} once merged (round {n})")
|
|
3554
3652
|
t["wait"] = None
|
|
@@ -3844,7 +3942,7 @@ def cmd_status(args):
|
|
|
3844
3942
|
else ""))
|
|
3845
3943
|
for tid in st["order"]:
|
|
3846
3944
|
t = st["tasks"][tid]
|
|
3847
|
-
print(f" {tid:<4} {t['status']:<15} deps={','.join(t['deps']) or '-':<10} "
|
|
3945
|
+
print(f" {tid:<4} {t['status']:<15} deps={','.join(t['deps'] + [e['repo'] + ':' + e['id'] for e in t.get('ext_deps') or []]) or '-':<10} "
|
|
3848
3946
|
f"worker={t.get('worker') or '-':<10} "
|
|
3849
3947
|
+ (f"tier={t['tier'] if rank(t.get('min_tier')) <= rank(t.get('tier')) else t['min_tier'] + '^'} "
|
|
3850
3948
|
if need_rank(t) else "") + t["title"]
|
|
@@ -3875,6 +3973,10 @@ def cmd_status(args):
|
|
|
3875
3973
|
print(f"ALL_DONE — run `orch finish` to push {st['branch']} and open a PR into {st.get('base')}")
|
|
3876
3974
|
elif lead_on(st) and (undispatched(st) or any(event_open(st, e) for e in st["lead_events"])):
|
|
3877
3975
|
pass
|
|
3976
|
+
elif not any(t["status"] in ACTIVE for t in st["tasks"].values()) and (ext := [
|
|
3977
|
+
f"{k} waits for {ext_line(ext_waits(t))}" for k, t in st["tasks"].items()
|
|
3978
|
+
if t["status"] == "pending" and ext_waits(t)]):
|
|
3979
|
+
print("WAITING FOR ANOTHER REPO — " + "; ".join(ext))
|
|
3878
3980
|
elif not any(t["status"] in ACTIVE for t in st["tasks"].values()) and not any(
|
|
3879
3981
|
t["status"] == "pending" and deps_met(st, t) for t in st["tasks"].values()):
|
|
3880
3982
|
print("STUCK — nothing running and nothing ready; resolve paused/needs-answer/failed tasks with the developer")
|
|
@@ -4302,8 +4404,8 @@ WORKER_RULES = """## Rules for you (the coder)
|
|
|
4302
4404
|
|
|
4303
4405
|
|
|
4304
4406
|
# plan.md lines that are for the lead and orch, not the coder: they stay in plan.md and task.json
|
|
4305
|
-
LEAD_ONLY_FIELDS = {"depends on", "why separate", "prefer", "tier", "needs", "model why", "estimate", "role", "door",
|
|
4306
|
-
"review", "parallel", "plain"}
|
|
4407
|
+
LEAD_ONLY_FIELDS = {"depends on", "why separate", "prefer", "model", "tier", "needs", "model why", "estimate", "role", "door",
|
|
4408
|
+
"review", "parallel", "plain", "side", "repo"}
|
|
4307
4409
|
|
|
4308
4410
|
|
|
4309
4411
|
def coder_section(text, drop_criteria):
|
|
@@ -4378,7 +4480,7 @@ def cmd_write_task(args):
|
|
|
4378
4480
|
if contract["previous_work"]:
|
|
4379
4481
|
parts += ["## Earlier work", f"An earlier attempt ({contract['previous_work']['by'] or 'another coder'}) left "
|
|
4380
4482
|
"work in this folder. Look at it first and continue from it unless it is wrong.", ""]
|
|
4381
|
-
parts += [f"## Check command\n`{st
|
|
4483
|
+
parts += [f"## Check command\n`{check_for(st, tid)}`", "", WORKER_RULES]
|
|
4382
4484
|
out = d / TASK_DIR / tid / "task.md"
|
|
4383
4485
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
4384
4486
|
out.write_text("\n".join(parts))
|
|
@@ -4414,7 +4516,7 @@ def task_contract(st, tid):
|
|
|
4414
4516
|
"files_allowed": t.get("files") or [], "scope": st.get("scope", "warn"),
|
|
4415
4517
|
"tier": t.get("tier"), "needs": t.get("needs") or [], "role": t.get("role") or None,
|
|
4416
4518
|
"interfaces": items("interfaces"), "constraints": items("constraints"), "out_of_scope": items("out of scope"),
|
|
4417
|
-
"depends_on": deps, "check": st
|
|
4519
|
+
"depends_on": deps, "check": check_for(st, tid), "attempt": t.get("attempt", 0) + 1, "lost_attempts": t.get("lost", 0),
|
|
4418
4520
|
"previous_work": {"by": t.get("last_worker")} if work_ref(st, tid) else None,
|
|
4419
4521
|
"result_format": RESULT_FORMAT,
|
|
4420
4522
|
}
|
|
@@ -4492,6 +4594,14 @@ def cmd_dispatch(args):
|
|
|
4492
4594
|
die("--tier must be small, medium or high")
|
|
4493
4595
|
for tid in args:
|
|
4494
4596
|
t = task(st, tid)
|
|
4597
|
+
lock = t.get("model")
|
|
4598
|
+
if lock and opts.get("--to") and (st["workers"][opts["--to"]].get("model") or "") != lock:
|
|
4599
|
+
die(f"{tid} is locked to {lock} by the developer, and {opts['--to']} runs "
|
|
4600
|
+
f"{st['workers'][opts['--to']].get('model') or 'another model'}. Only the developer changes the "
|
|
4601
|
+
f"lock: when they ask, `orch plan model {tid} <model>`")
|
|
4602
|
+
if lock and opts.get("--tier"):
|
|
4603
|
+
die(f"{tid} is locked to {lock} by the developer, so --tier does not apply. Only the developer "
|
|
4604
|
+
f"changes the lock: when they ask, `orch plan model {tid} <model>`")
|
|
4495
4605
|
if t["status"] not in ("pending", "paused", "failed"):
|
|
4496
4606
|
die(f"{tid} is {t['status']} — only pending, paused or failed milestones can be dispatched"
|
|
4497
4607
|
+ (" (answer its open questions in plan.md, then `orch sync`)" if t["status"] == "needs-answer" else ""))
|
|
@@ -4856,12 +4966,237 @@ def plan_steps(st, tids):
|
|
|
4856
4966
|
return [[t for t in tids if level[t] == n] for n in range(1, max(level.values(), default=0) + 1)]
|
|
4857
4967
|
|
|
4858
4968
|
|
|
4969
|
+
PLAN_USAGE = ("usage: orch plan show | orch plan team | orch plan model <Mn|reviewer> <model>[@<thinking>] "
|
|
4970
|
+
"(or `<model> <thinking>`; `auto` unlocks a milestone)")
|
|
4971
|
+
|
|
4972
|
+
|
|
4973
|
+
def pick_order(st, t):
|
|
4974
|
+
"""The coders that may take t, in the order `orch pick` tries them (free or not): its last coder, then the
|
|
4975
|
+
closest tier, then its Prefer."""
|
|
4976
|
+
pref, last, nr = t.get("prefer") or "any", t.get("last_worker"), need_rank(t)
|
|
4977
|
+
names = eligible_workers(st, t)
|
|
4978
|
+
names.sort(key=lambda n: (0 if n == last else 1, (rank(st["workers"][n].get("tier")) or nr) - nr
|
|
4979
|
+
if nr else 0, 0 if pref in ("any", st["workers"][n]["kind"], n) else 1))
|
|
4980
|
+
return names
|
|
4981
|
+
|
|
4982
|
+
|
|
4983
|
+
def model_choices(kind):
|
|
4984
|
+
"""(models, thinking levels) a developer can pick for an agent of `kind`: the models the tool itself lists
|
|
4985
|
+
(`codex debug models`) when orch asked it, else the catalog's. The policy's denied models never show."""
|
|
4986
|
+
cat = models_catalog() or {}
|
|
4987
|
+
reg = (registry(required=False) or {}).get(kind) or {}
|
|
4988
|
+
models = []
|
|
4989
|
+
cfg = (cat.get("discover") or {}).get(kind) or {}
|
|
4990
|
+
if (cat.get("found") or {}).get(kind) and cfg.get("cmd"):
|
|
4991
|
+
rows = _tool_models(kind, cfg["cmd"]) or []
|
|
4992
|
+
models = [m["slug"].lower() for m in rows if m.get("visibility") != "hide" and not m.get("upgrade")
|
|
4993
|
+
and not LEGACY_RE.search(m.get("description") or "")]
|
|
4994
|
+
if not models:
|
|
4995
|
+
models = [split_effort(mid)[0] for mid, m in (cat.get("models") or {}).items() if kind in (m.get("kinds") or [])]
|
|
4996
|
+
models = [m for m in dict.fromkeys(models) if not model_denied(cat, m)]
|
|
4997
|
+
efforts = [str(e).lower() for e in reg.get("efforts") or []] if reg.get("effort_flag") else []
|
|
4998
|
+
return models, efforts
|
|
4999
|
+
|
|
5000
|
+
|
|
5001
|
+
def _thinking(mid):
|
|
5002
|
+
base, eff = split_effort(mid or "")
|
|
5003
|
+
return (base or "?"), (eff or "default")
|
|
5004
|
+
|
|
5005
|
+
|
|
5006
|
+
def cmd_plan_team(st):
|
|
5007
|
+
"""orch plan team -> one row per milestone and one for the reviewer: which coder builds it, on which model and
|
|
5008
|
+
thinking level, and whether the developer locked it. Then what can be picked instead."""
|
|
5009
|
+
if run_mode(st) == "subagent":
|
|
5010
|
+
print("SUBAGENT MODE: the subagents run on the models in your orch config (`/orch-mode` in Pi sets them), "
|
|
5011
|
+
"not on a team of panels, so there is no team table to change here.")
|
|
5012
|
+
return
|
|
5013
|
+
tids = [t for t in st["order"] if st["tasks"][t]["status"] != "skipped"]
|
|
5014
|
+
rows = []
|
|
5015
|
+
for tid in tids:
|
|
5016
|
+
t = st["tasks"][tid]
|
|
5017
|
+
who = pick_order(st, t)
|
|
5018
|
+
mid = t.get("model") or (st["workers"][who[0]].get("model") if who else None)
|
|
5019
|
+
base, eff = _thinking(mid) if mid else ("?", "?")
|
|
5020
|
+
how = ("locked by you" if t.get("model") else
|
|
5021
|
+
f"by level ({t['tier']})" if t.get("tier") else "first free coder")
|
|
5022
|
+
rows.append((tid, t["title"], " or ".join(who) if who else "NOBODY", base, eff, how))
|
|
5023
|
+
if st.get("reviewer"):
|
|
5024
|
+
ri = st.get("reviewer_info") or {}
|
|
5025
|
+
base, eff = _thinking(ri.get("model")) if ri.get("model") else ("?", "?")
|
|
5026
|
+
rows.append(("Reviewer", "checks the reviewed steps", st["reviewer"], base, eff,
|
|
5027
|
+
"" if ri.get("model") else "model not written in the plan"))
|
|
5028
|
+
head = ("Step", "What", "Coder", "Model", "Thinking", "Chosen")
|
|
5029
|
+
cut = lambda x: x if len(x) <= 30 else x[:29] + "…"
|
|
5030
|
+
rows = [tuple(cut(str(c)) for c in r) for r in rows]
|
|
5031
|
+
wid = [max(len(r[i]) for r in rows + [head]) for i in range(len(head))]
|
|
5032
|
+
fmt = lambda r: " ".join(c.ljust(wid[i]) for i, c in enumerate(r)).rstrip()
|
|
5033
|
+
print(f"TEAM for {st.get('title') or st['branch']}: who builds each step, on which model and thinking level")
|
|
5034
|
+
print(fmt(head))
|
|
5035
|
+
for r in rows:
|
|
5036
|
+
print(fmt(r))
|
|
5037
|
+
if any(r[2] == "NOBODY" for r in rows):
|
|
5038
|
+
print("WARN a step has no coder on its model: `orch plan model <Mn> <model>` adds one")
|
|
5039
|
+
kinds = list(dict.fromkeys([w["kind"] for w in st["workers"].values()]
|
|
5040
|
+
+ [(st.get("reviewer_info") or {}).get("kind")]))
|
|
5041
|
+
for kind in [k for k in kinds if k]:
|
|
5042
|
+
models, efforts = model_choices(kind)
|
|
5043
|
+
if models:
|
|
5044
|
+
print(f"You can pick ({kind}): models {', '.join(models)}"
|
|
5045
|
+
+ (f" · thinking {', '.join(efforts)}" if efforts else " · no thinking setting"))
|
|
5046
|
+
deny = (models_catalog() or {}).get("policy", {}).get("deny") or []
|
|
5047
|
+
if deny:
|
|
5048
|
+
print(f"Never allowed: {', '.join(deny)}")
|
|
5049
|
+
print("Change one: orch plan model <Mn|reviewer> <model>@<thinking> (`auto` gives a step back to its level)")
|
|
5050
|
+
|
|
5051
|
+
|
|
5052
|
+
def _plan_section(lines, tid):
|
|
5053
|
+
i0 = next(i for i, ln in enumerate(lines) if (m := HEAD_RE.match(ln)) and m.group(2) == tid)
|
|
5054
|
+
i1 = next((i for i in range(i0 + 1, len(lines)) if lines[i].startswith("## ")), len(lines))
|
|
5055
|
+
return i0, i1
|
|
5056
|
+
|
|
5057
|
+
|
|
5058
|
+
def cmd_plan_model(args):
|
|
5059
|
+
"""orch plan model <Mn|reviewer> <model>[@<thinking>] -> the developer's choice, written into plan.md: `Model:`
|
|
5060
|
+
on the milestone (a lock: only coders on that model take it, orch never moves it to another model), or the
|
|
5061
|
+
model on the Reviewer line. When no coder runs that model, a new coder joins Workers; `orch team up` opens its
|
|
5062
|
+
panel. `auto` takes a milestone's lock off again. Then `orch sync`."""
|
|
5063
|
+
if len(args) == 3 and "@" not in args[1] and re.fullmatch(r"[A-Za-z]+", args[2]):
|
|
5064
|
+
args = [args[0], f"{args[1]}@{args[2]}"] # `M3 gpt-6.2-sol low` -> `M3 gpt-6.2-sol@low`
|
|
5065
|
+
if len(args) != 2:
|
|
5066
|
+
die(PLAN_USAGE)
|
|
5067
|
+
target, mid = args[0], args[1].strip("`").lower()
|
|
5068
|
+
is_rev = target.lower() == "reviewer"
|
|
5069
|
+
if not is_rev and not re.fullmatch(r"M\d+", target):
|
|
5070
|
+
die(PLAN_USAGE)
|
|
5071
|
+
plan = ORCH / "plan.md"
|
|
5072
|
+
if not plan.exists():
|
|
5073
|
+
die("missing .orchestrate/plan.md — write the plan first")
|
|
5074
|
+
text = plan.read_text()
|
|
5075
|
+
cfg, tasks = parse_plan(text)
|
|
5076
|
+
get = lambda k: " ".join(cfg.get(k, [])).strip()
|
|
5077
|
+
if get("repos"):
|
|
5078
|
+
die("this is a workspace of several repos: run `orch plan model` inside the repo the milestone belongs to")
|
|
5079
|
+
if not is_rev and target not in {t["id"] for t in tasks}:
|
|
5080
|
+
die(f"{target} is not in plan.md")
|
|
5081
|
+
workers_s, rev_s, lead_s = get("workers"), get("reviewer"), get("lead")
|
|
5082
|
+
workers, models = parse_agents(workers_s), parse_models(workers_s)
|
|
5083
|
+
rname = None
|
|
5084
|
+
if rev_s and not rev_s.lower().startswith("none"):
|
|
5085
|
+
rm = re.match(r"([\w.-]+)\s*\(", rev_s)
|
|
5086
|
+
rname = rm.group(1) if rm else None
|
|
5087
|
+
lines = text.split("\n")
|
|
5088
|
+
old_st = json.loads(STATE.read_text()) if STATE.exists() else {}
|
|
5089
|
+
cat = models_catalog()
|
|
5090
|
+
reg = registry(required=False) or {}
|
|
5091
|
+
notes = []
|
|
5092
|
+
if run_mode(old_st) == "subagent":
|
|
5093
|
+
die("this plan is in subagent mode: its subagents run on the models in your orch config, not on panels "
|
|
5094
|
+
"(`/orch-mode` in Pi sets them)")
|
|
5095
|
+
old_lock = None if is_rev else (field(next(t for t in tasks if t["id"] == target), "model").split() or [""])[0].lower()
|
|
5096
|
+
still = {(field(t, "model").split() or [""])[0].lower() for t in tasks if t["id"] != target}
|
|
5097
|
+
if old_lock and old_lock != mid and old_lock not in still:
|
|
5098
|
+
left = [n for n, m in models.items() if m == old_lock]
|
|
5099
|
+
if left:
|
|
5100
|
+
notes.append(f"NOTE {', '.join(left)} ({old_lock}) stays in the team and may take other steps of its "
|
|
5101
|
+
f"level; take it out of Workers in plan.md if you don't want its panel")
|
|
5102
|
+
if mid in ("auto", "any", "none"):
|
|
5103
|
+
if is_rev:
|
|
5104
|
+
die("the reviewer always runs a model: name one (`orch plan team` lists them)")
|
|
5105
|
+
i0, i1 = _plan_section(lines, target)
|
|
5106
|
+
lines = lines[:i0] + [ln for ln in lines[i0:i1] if not re.match(r"Model:\s", ln)] + lines[i1:]
|
|
5107
|
+
plan.write_text("\n".join(lines))
|
|
5108
|
+
print(f"UNLOCKED {target}: it goes to a coder of its level again")
|
|
5109
|
+
for n in notes:
|
|
5110
|
+
print(n)
|
|
5111
|
+
cmd_sync([])
|
|
5112
|
+
return
|
|
5113
|
+
why = model_denied(cat, mid)
|
|
5114
|
+
if why:
|
|
5115
|
+
die(f"{mid} is not allowed by the model policy (pattern {why!r}) — `orch plan team` lists what you can pick")
|
|
5116
|
+
base, eff = split_effort(mid)
|
|
5117
|
+
team_kinds = list(dict.fromkeys(k for k, _ in workers.values()))
|
|
5118
|
+
if is_rev:
|
|
5119
|
+
if not rname:
|
|
5120
|
+
die("the plan has no reviewer (`Reviewer: none`)")
|
|
5121
|
+
kind = parse_agents(rev_s)[rname][0]
|
|
5122
|
+
else:
|
|
5123
|
+
same = [workers[n][0] for n, m in models.items() if m and split_effort(m)[0] == base and n in workers]
|
|
5124
|
+
in_cat = [k for x, m in ((cat or {}).get("models") or {}).items() if split_effort(x)[0] == base
|
|
5125
|
+
for k in m.get("kinds") or []]
|
|
5126
|
+
lead_kind = next(iter(parse_agents(lead_s).values()), (None,))[0]
|
|
5127
|
+
kind = next((k for k in same + [k for k in in_cat if k in team_kinds] + [lead_kind] + team_kinds if k), None)
|
|
5128
|
+
if not kind:
|
|
5129
|
+
die("the plan has no Workers to add a coder to")
|
|
5130
|
+
v = reg.get(kind) or {}
|
|
5131
|
+
if eff and reg and not v.get("effort_flag"):
|
|
5132
|
+
die(f"{kind} has no thinking setting orch can start it with: name the model without @{eff}")
|
|
5133
|
+
efforts = [str(e).lower() for e in v.get("efforts") or []]
|
|
5134
|
+
if eff and efforts and eff not in efforts:
|
|
5135
|
+
die(f"{kind} has no thinking level {eff!r}: pick one of {', '.join(efforts)}")
|
|
5136
|
+
choices, _ = model_choices(kind)
|
|
5137
|
+
if choices and base not in choices:
|
|
5138
|
+
notes.append(f"NOTE {base} is not in the list {kind} gives ({', '.join(choices)}): check the name")
|
|
5139
|
+
if cat and model_tier(cat, mid) is None:
|
|
5140
|
+
notes.append(f"NOTE {mid} has no level (small / medium / high) in the catalog: fine for your choice, "
|
|
5141
|
+
f"orch only can't compare it with the others")
|
|
5142
|
+
hend = next((i for i, ln in enumerate(lines) if ln.startswith("## ")), len(lines))
|
|
5143
|
+
if is_rev:
|
|
5144
|
+
i = next(i for i in range(hend) if lines[i].startswith("Reviewer:"))
|
|
5145
|
+
pane = parse_agents(rev_s)[rname][1]
|
|
5146
|
+
lines[i] = f"Reviewer: {rname} ({kind}: {mid}" + (f" @pane:{pane}" if pane else "") + ")"
|
|
5147
|
+
plan.write_text("\n".join(lines))
|
|
5148
|
+
print(f"REVIEWER {rname} now runs {base} on {eff or 'its default'} thinking")
|
|
5149
|
+
oldm = parse_models(rev_s).get(rname)
|
|
5150
|
+
if oldm != mid and herdr_state(rname) is not None:
|
|
5151
|
+
notes.append(f"NOTE {rname}'s panel is open on {oldm or 'another model'}: quit the agent in that panel "
|
|
5152
|
+
f"(or close it), then `orch team up` opens it again on {mid}")
|
|
5153
|
+
else:
|
|
5154
|
+
who = [n for n, m in models.items() if m == mid and n in workers]
|
|
5155
|
+
if not who:
|
|
5156
|
+
same_kind = [n for n, (k, _) in workers.items() if k == kind]
|
|
5157
|
+
pm = re.match(r"(.*?)(\d+)$", same_kind[0]) if same_kind else None
|
|
5158
|
+
prefix = pm.group(1) if pm else f"{kind}-"
|
|
5159
|
+
taken = set(workers) | ({rname} if rname else set()) | set(parse_agents(lead_s))
|
|
5160
|
+
nums = [int(m.group(1)) for n in taken if (m := re.fullmatch(re.escape(prefix) + r"(\d+)", n))]
|
|
5161
|
+
new = f"{prefix}{max(nums, default=0) + 1}"
|
|
5162
|
+
i = next(i for i in range(hend) if lines[i].startswith("Workers:"))
|
|
5163
|
+
lines[i] = lines[i].rstrip().rstrip(",") + f", {new} ({kind}: {mid})"
|
|
5164
|
+
who = [new]
|
|
5165
|
+
started = any((w or {}).get("dir") for w in (old_st.get("workers") or {}).values())
|
|
5166
|
+
notes.append(f"NEW coder {new} ({kind}: {mid}) joins the team for {target}: "
|
|
5167
|
+
+ ("run `orch start` (it makes its folder), then `orch team up` opens its panel"
|
|
5168
|
+
if started else "`orch team up` opens its panel when the run starts (on go)"))
|
|
5169
|
+
i0, i1 = _plan_section(lines, target)
|
|
5170
|
+
sec = [ln for ln in lines[i0 + 1:i1] if not re.match(r"Model:\s", ln)]
|
|
5171
|
+
at = next((k + 1 for k, ln in enumerate(sec) if ln.startswith("Tier:")), 0)
|
|
5172
|
+
sec.insert(at, f"Model: {mid}")
|
|
5173
|
+
lines = lines[:i0 + 1] + sec + lines[i1:]
|
|
5174
|
+
plan.write_text("\n".join(lines))
|
|
5175
|
+
print(f"LOCKED {target} to {base} on {eff or 'its default'} thinking: only {' or '.join(who)} takes it, "
|
|
5176
|
+
f"and orch never moves it to another model (to change it: `orch plan model {target} <model>`)")
|
|
5177
|
+
ot = (old_st.get("tasks") or {}).get(target) or {}
|
|
5178
|
+
if ot.get("status") in ACTIVE:
|
|
5179
|
+
notes.append(f"NOTE {target} is being worked on by {ot.get('worker')} now: your choice counts from its "
|
|
5180
|
+
f"next start. To move it now: `orch set {target} paused`, then `orch dispatch {target}`")
|
|
5181
|
+
elif ot.get("status") == "merged":
|
|
5182
|
+
notes.append(f"NOTE {target} has already landed: for a change to it on this model, "
|
|
5183
|
+
f"`orch fix {target} \"<the change>\" --to {who[0]}`")
|
|
5184
|
+
for n in notes:
|
|
5185
|
+
print(n)
|
|
5186
|
+
cmd_sync([])
|
|
5187
|
+
|
|
5188
|
+
|
|
4859
5189
|
def cmd_plan(args):
|
|
4860
5190
|
"""orch plan show -> the plan for a person: one short card per milestone in plain words (from each milestone's
|
|
4861
5191
|
`Plain:` line), what it waits for and why, who builds it on which model, how long it should take, and which
|
|
4862
|
-
milestones run together. plan.md keeps every detail; this is the part a developer reads.
|
|
5192
|
+
milestones run together. plan.md keeps every detail; this is the part a developer reads.
|
|
5193
|
+
orch plan team -> the model table; orch plan model -> the developer's choice of model for a step or the reviewer."""
|
|
5194
|
+
if args[:1] == ["team"]:
|
|
5195
|
+
return cmd_plan_team(load())
|
|
5196
|
+
if args[:1] == ["model"]:
|
|
5197
|
+
return cmd_plan_model(args[1:])
|
|
4863
5198
|
if args[:1] != ["show"]:
|
|
4864
|
-
die(
|
|
5199
|
+
die(PLAN_USAGE)
|
|
4865
5200
|
st = load()
|
|
4866
5201
|
tids = [t for t in st["order"] if st["tasks"][t]["status"] != "skipped"]
|
|
4867
5202
|
print(f"PLAN in plain words: {st.get('title') or st['branch']} — {len(tids)} milestone(s) on {st['branch']}"
|
|
@@ -4888,7 +5223,9 @@ def cmd_plan(args):
|
|
|
4888
5223
|
w = st["workers"][n]
|
|
4889
5224
|
who.append(f"{n} ({w['model']})" if w.get("model") else n)
|
|
4890
5225
|
bits = [f"Built by: {' or '.join(who) if who else 'the next free coder'}"]
|
|
4891
|
-
if t.get("
|
|
5226
|
+
if t.get("model"):
|
|
5227
|
+
bits.append(f"locked by you to {t['model']}")
|
|
5228
|
+
elif t.get("tier"):
|
|
4892
5229
|
bits.append(f"{t['tier']} model")
|
|
4893
5230
|
if t.get("estimate_s"):
|
|
4894
5231
|
bits.append(f"about {_short_dur(t['estimate_s'])}")
|
|
@@ -4996,6 +5333,10 @@ def cmd_escalate(args):
|
|
|
4996
5333
|
tid, reason = args[0], " ".join(args[1:])
|
|
4997
5334
|
st = load()
|
|
4998
5335
|
t = task(st, tid)
|
|
5336
|
+
if t.get("model"):
|
|
5337
|
+
print(f"NO_ESCALATION {tid} (the developer locked it to {t['model']}: only they change that, "
|
|
5338
|
+
f"with `orch plan model {tid} <model>`)")
|
|
5339
|
+
sys.exit(3)
|
|
4999
5340
|
cur = rank(st["workers"].get(t.get("worker") or t.get("last_worker") or "", {}).get("tier"))
|
|
5000
5341
|
above = sorted({rank(w.get("tier")) for w in st["workers"].values()} - set(range(0, max(cur, need_rank(t)) + 1)))
|
|
5001
5342
|
if t.get("escalated") or not cur or not above:
|
|
@@ -5274,8 +5615,8 @@ def _autopilot(args):
|
|
|
5274
5615
|
save(s_)
|
|
5275
5616
|
|
|
5276
5617
|
def check(cwd, tid=None, where="worktree"):
|
|
5277
|
-
ok, tail, secs = run_check(
|
|
5278
|
-
patch_state(lambda s_: note_green(s_, cwd, ok))
|
|
5618
|
+
ok, tail, secs = run_check(load(), cwd, tid)
|
|
5619
|
+
patch_state(lambda s_: note_green(s_, cwd, ok, tid))
|
|
5279
5620
|
if tid:
|
|
5280
5621
|
patch_state(lambda s_: s_["tasks"][tid].setdefault("checks", []).append(
|
|
5281
5622
|
{"where": where, "ok": ok, "secs": secs, "ts": now()}))
|
|
@@ -5531,7 +5872,7 @@ def _autopilot(args):
|
|
|
5531
5872
|
s_ = load()
|
|
5532
5873
|
t_ = s_["tasks"][tid]
|
|
5533
5874
|
k = t_["attempt"]
|
|
5534
|
-
if not s_
|
|
5875
|
+
if not check_for(s_, tid):
|
|
5535
5876
|
check_done(tid, k, d, None, 0, "", 0)
|
|
5536
5877
|
return True
|
|
5537
5878
|
if check_slots() <= 0:
|
|
@@ -5541,7 +5882,7 @@ def _autopilot(args):
|
|
|
5541
5882
|
end_wait(tid, "check slot")
|
|
5542
5883
|
tree0 = tree_of(d)
|
|
5543
5884
|
patch_state(lambda s2: s2["tasks"][tid].update(checking={"since": now(), "where": "worktree"}))
|
|
5544
|
-
bg_start(f"check-{tid}-{k}", tid, "check", s_
|
|
5885
|
+
bg_start(f"check-{tid}-{k}", tid, "check", check_for(s_, tid), d, True,
|
|
5545
5886
|
lambda code, out, secs: check_done(tid, k, d, tree0, code, out, secs), CHECK_TIMEOUT_S)
|
|
5546
5887
|
return True
|
|
5547
5888
|
|
|
@@ -5553,20 +5894,20 @@ def _autopilot(args):
|
|
|
5553
5894
|
def upd(s2):
|
|
5554
5895
|
t2 = s2["tasks"][tid]
|
|
5555
5896
|
t2.pop("checking", None)
|
|
5556
|
-
if s2
|
|
5897
|
+
if check_for(s2, tid):
|
|
5557
5898
|
t2.setdefault("checks", []).append({"where": "worktree", "ok": ok, "secs": secs, "ts": now()})
|
|
5558
5899
|
# the tree is kept only when the check left the files as it found them: then a branch that gets exactly
|
|
5559
5900
|
# these files needs no second check (merge_check_needed)
|
|
5560
5901
|
t2["chk"] = {"attempt": k, "ok": ok, "tail": tail, "tree": tree if tree and tree == tree0 else None,
|
|
5561
5902
|
"used": False}
|
|
5562
|
-
note_green(s2, d, ok)
|
|
5903
|
+
note_green(s2, d, ok, tid)
|
|
5563
5904
|
patch_state(upd)
|
|
5564
|
-
if s_check := load()
|
|
5905
|
+
if s_check := check_for(load(), tid):
|
|
5565
5906
|
say(f"{tid} check {'passed' if ok else 'FAILED'} in {_fmt_secs(secs)} ({s_check})")
|
|
5566
5907
|
|
|
5567
5908
|
def early_review_ok(tid, t):
|
|
5568
5909
|
s_ = load()
|
|
5569
|
-
return (s_.get("early_review", True) and bool(s_
|
|
5910
|
+
return (s_.get("early_review", True) and bool(check_for(s_, tid)) and bool(s_.get("reviewer"))
|
|
5570
5911
|
and t["review"] and not t.get("review_ok") and not t.get("pre_conflict") and holds(s_, tid))
|
|
5571
5912
|
|
|
5572
5913
|
def check_fix(tid, tail, blockers=()):
|
|
@@ -5579,7 +5920,7 @@ def _autopilot(args):
|
|
|
5579
5920
|
say(f"{tid} checks failed -> fix round {n}" + (f" (with the reviewer's {len(blockers)} blocker(s))"
|
|
5580
5921
|
if blockers else ""))
|
|
5581
5922
|
write_and_send(tid, f"fix-{n}.md",
|
|
5582
|
-
f"# Checks failing for {tid} (round {n})\n\nThe check command `{st
|
|
5923
|
+
f"# Checks failing for {tid} (round {n})\n\nThe check command `{check_for(st, tid)}` "
|
|
5583
5924
|
f"failed. Diagnose the cause and fix it; you decide how. Don't change unrelated "
|
|
5584
5925
|
f"code, and don't weaken or skip tests to make them pass.\n\n"
|
|
5585
5926
|
f"```\n{tail}\n```\n"
|
|
@@ -5775,7 +6116,7 @@ def _autopilot(args):
|
|
|
5775
6116
|
f"# {tid} changed files outside its scope (round {n})\n\n"
|
|
5776
6117
|
f"This milestone may change only: {', '.join(allowed)}. It also changed: "
|
|
5777
6118
|
f"{', '.join(new)}.\nUndo those changes, or, if the task truly can't be done without them, "
|
|
5778
|
-
f"leave them and explain why in your report. Then run `{st
|
|
6119
|
+
f"leave them and explain why in your report. Then run `{check_for(st, tid)}`.\n"),
|
|
5779
6120
|
f"still outside its scope after {MAX_FIX} fix rounds: {', '.join(new)}")
|
|
5780
6121
|
return False
|
|
5781
6122
|
if new:
|
|
@@ -5798,7 +6139,7 @@ def _autopilot(args):
|
|
|
5798
6139
|
+ "\n".join(f"- {c['id']}: {c.get('evidence', '')}" for c in unmet)
|
|
5799
6140
|
+ (f"\n\nAlready deferred by the developer (leave them; keep them `met: false`): "
|
|
5800
6141
|
f"{', '.join(skipped)}." if skipped else "")
|
|
5801
|
-
+ f"\n\nFinish them (you decide how), run `{st
|
|
6142
|
+
+ f"\n\nFinish them (you decide how), run `{check_for(st, tid)}`, and write a new result.\n"
|
|
5802
6143
|
"If one truly can't be met in this repo (for example an outside API or service it needs does not "
|
|
5803
6144
|
"exist), don't try again: set status `question`, say which criterion and why, and offer to "
|
|
5804
6145
|
"build the rest and defer that one. The developer decides.\n"),
|
|
@@ -6112,6 +6453,8 @@ def _autopilot(args):
|
|
|
6112
6453
|
last_tick = time.time()
|
|
6113
6454
|
slept = sleep_meter()
|
|
6114
6455
|
waiting_since = None # set while nothing runs and the run waits for the lead or the developer
|
|
6456
|
+
ext_told = None # what was last said about waiting for another repo of the workspace
|
|
6457
|
+
ext_since = time.time()
|
|
6115
6458
|
seen = {"procs": time.time(), "check": 0.0, "present": None, "told": False}
|
|
6116
6459
|
|
|
6117
6460
|
def watch_herdr():
|
|
@@ -6312,6 +6655,23 @@ def _autopilot(args):
|
|
|
6312
6655
|
run("poll", str(int(min(30, max(1, POLL_STEP_S * 3)))), ok=(0, 10))
|
|
6313
6656
|
continue
|
|
6314
6657
|
waiting_since = None
|
|
6658
|
+
# a workspace of several repos: a milestone here waits for one in another repo (its own run lands it)
|
|
6659
|
+
ext = {k: ext_waits(v) for k, v in tasks.items() if v["status"] == "pending" and v.get("ext_deps")
|
|
6660
|
+
and all(tasks[d]["status"] == "merged" for d in v["deps"])}
|
|
6661
|
+
ext = {k: w for k, w in ext.items() if w and not any(s_ in ("failed", "skipped") for _, s_ in w)}
|
|
6662
|
+
if not active and not ready and ext:
|
|
6663
|
+
line = "; ".join(f"{k} waits for {ext_line(w)}" for k, w in ext.items())
|
|
6664
|
+
if line != ext_told:
|
|
6665
|
+
say(f"waiting for another repo: {line}", True)
|
|
6666
|
+
ext_told, ext_since = line, time.time()
|
|
6667
|
+
idle = sorted({e["repo"] for w in ext.values() for e, _ in w if not run_alive(e["path"])})
|
|
6668
|
+
if idle and time.time() - ext_since > LEAD_IDLE_MAX_S:
|
|
6669
|
+
say(f"STOPPED — still waiting for another repo after {LEAD_IDLE_MAX_S // 60} min, and the event manager "
|
|
6670
|
+
f"of {', '.join(idle)} is not running: {line}. Everything is kept: start it there (`orch autopilot` "
|
|
6671
|
+
f"in the workspace starts every repo's)", True)
|
|
6672
|
+
sys.exit(3)
|
|
6673
|
+
run("poll", str(int(min(30, max(1, POLL_STEP_S * 3)))), ok=(0, 10))
|
|
6674
|
+
continue
|
|
6315
6675
|
if not active and not ready:
|
|
6316
6676
|
bg_reap() # a background merge that just ended (held, failed) says so before we stop
|
|
6317
6677
|
waiting = [f" {k} {v['status']}: {v.get('reason') or ''}" for k, v in tasks.items()
|
|
@@ -6795,8 +7155,15 @@ def cmd_team(args):
|
|
|
6795
7155
|
orch team up [--dry-run] -> open a herdr pane for every agent in the plan that herdr cannot find."""
|
|
6796
7156
|
if args and args[0] == "up":
|
|
6797
7157
|
return team_up(args[1:])
|
|
6798
|
-
usage = "usage: orch team <kind> [--coders N] [--models a,b] [--no-reviewer]
|
|
6799
|
-
|
|
7158
|
+
usage = ("usage: orch team <kind> [--coders N] [--models a,b] [--no-reviewer] [--prefix <name>] | "
|
|
7159
|
+
"orch team up [--dry-run]")
|
|
7160
|
+
rest, coders, models, reviewer, prefix = list(args), None, None, True, None
|
|
7161
|
+
if "--prefix" in rest:
|
|
7162
|
+
i = rest.index("--prefix")
|
|
7163
|
+
prefix = rest[i + 1] if len(rest) > i + 1 else die(usage)
|
|
7164
|
+
del rest[i:i + 2]
|
|
7165
|
+
if not re.fullmatch(r"[A-Za-z0-9][\w.-]*", prefix):
|
|
7166
|
+
die("--prefix takes a plain name, e.g. --prefix frontend")
|
|
6800
7167
|
if "--no-reviewer" in rest:
|
|
6801
7168
|
rest.remove("--no-reviewer")
|
|
6802
7169
|
reviewer = False
|
|
@@ -6832,17 +7199,23 @@ def cmd_team(args):
|
|
|
6832
7199
|
top = cands[-1][0] if cands else None
|
|
6833
7200
|
no_flag = not v.get("model_flag")
|
|
6834
7201
|
fmt = lambda name, m: f"{name} ({kind}: {m})" if m and not no_flag else f"{name} ({kind})"
|
|
6835
|
-
|
|
7202
|
+
if prefix is None: # another run is going on this machine: names it doesn't use
|
|
7203
|
+
prefix, busy_in = team_prefix([f"{kind}-{i + 1}" for i in range(len(picked))] + ["reviewer", "lead"])
|
|
7204
|
+
if prefix:
|
|
7205
|
+
print(f"NOTE: another run ({busy_in}) is going and uses these names, so this team's names start with "
|
|
7206
|
+
f"{prefix}- (herdr finds agents by name; `--prefix <name>` picks another)")
|
|
7207
|
+
pre = f"{prefix}-" if prefix else ""
|
|
7208
|
+
workers = [fmt(f"{pre}{kind}-{i + 1}", m) for i, m in enumerate(picked)]
|
|
6836
7209
|
tier = {mid: t for mid, t in cands}
|
|
6837
7210
|
print(f"TEAM from {kind}: {len(workers)} coder(s)" + (", 1 reviewer" if reviewer and "reviewer" in roles else ""))
|
|
6838
7211
|
for i, m in enumerate(picked):
|
|
6839
|
-
print(f" {kind + '-' + str(i + 1):<12} {m or 'its default model'}" + (f" ({tier[m]} tier)" if m in tier else ""))
|
|
7212
|
+
print(f" {pre + kind + '-' + str(i + 1):<12} {m or 'its default model'}" + (f" ({tier[m]} tier)" if m in tier else ""))
|
|
6840
7213
|
if reviewer and "reviewer" in roles:
|
|
6841
|
-
print(f" {'reviewer':<12} {top or 'its default model'}" + (f" ({tier[top]} tier)" if top in tier else ""))
|
|
7214
|
+
print(f" {pre + 'reviewer':<12} {top or 'its default model'}" + (f" ({tier[top]} tier)" if top in tier else ""))
|
|
6842
7215
|
print("\nPlan header lines:")
|
|
6843
|
-
print(f"Lead: lead ({kind}: <the model your own pane runs>)")
|
|
7216
|
+
print(f"Lead: {pre}lead ({kind}: <the model your own pane runs>)")
|
|
6844
7217
|
print("Workers: " + ", ".join(workers))
|
|
6845
|
-
print("Reviewer: " + (fmt("reviewer", top) if reviewer and "reviewer" in roles else "none"))
|
|
7218
|
+
print("Reviewer: " + (fmt(f"{pre}reviewer", top) if reviewer and "reviewer" in roles else "none"))
|
|
6846
7219
|
if not cands and not models:
|
|
6847
7220
|
print(f"\nNOTE: the model catalog has no allowed model for {kind}, so every pane starts on its default model "
|
|
6848
7221
|
f"(add models in {user_models_file()} to get tiers)")
|
|
@@ -6852,7 +7225,7 @@ def cmd_team(args):
|
|
|
6852
7225
|
print(f"\nNOTE: the strongest allowed {kind} model is {top} ({tier.get(top)} tier): high-tier milestones go to "
|
|
6853
7226
|
f"it, and `orch sync` will say so")
|
|
6854
7227
|
if top and v.get("model_flag") and "lead" in roles:
|
|
6855
|
-
print(f"\nYour own lead pane on the strongest level (start it like this, then write `Lead: lead ({kind}: {top})`):"
|
|
7228
|
+
print(f"\nYour own lead pane on the strongest level (start it like this, then write `Lead: {pre}lead ({kind}: {top})`):"
|
|
6856
7229
|
f"\n {launch_cmd(kind, v, top, strict=False, role='lead')}")
|
|
6857
7230
|
print(f"\nCheck these are models your {kind} really reaches (`--models a,b` to choose others).")
|
|
6858
7231
|
print("\nThese panes don't exist yet. After `orch sync` and `orch start`, `orch team up` opens each one in its "
|
|
@@ -8003,8 +8376,9 @@ USAGE = """usage: orch <command> [args]
|
|
|
8003
8376
|
lead run --section <EVENT|ALL_DONE|rules> one part of the run playbook (orch events prints these for you)
|
|
8004
8377
|
lead check preflight: is this agent in a Herdr pane / can it reach herdr?
|
|
8005
8378
|
lead whoami show the lead's own herdr pane and name it as the plan's `Lead:` (default `lead`)
|
|
8006
|
-
team <kind> [--coders N] [--models a,b] [--no-reviewer]
|
|
8379
|
+
team <kind> [--coders N] [--models a,b] [--no-reviewer] [--prefix <name>]
|
|
8007
8380
|
the plan's team built from one installed tool: coders + reviewer on its catalog models
|
|
8381
|
+
(named after the repo, e.g. app-codex-1, while another run is going on this machine)
|
|
8008
8382
|
team up [--dry-run] [--mode panes|subagent]
|
|
8009
8383
|
open a herdr pane for every agent in the plan herdr can't find, in its folder, and name it
|
|
8010
8384
|
(subagent mode: no panes; sets up the Pi coder/reviewer subagents instead)
|
|
@@ -8025,6 +8399,9 @@ USAGE = """usage: orch <command> [args]
|
|
|
8025
8399
|
manual the manual tests: what to try by hand, numbered, from the summary's Manual verification
|
|
8026
8400
|
checklist (`orch finish` prints them too, and the lead posts them in its chat)
|
|
8027
8401
|
plan show the plan for a person: each milestone in plain words, who builds it, how long, the order
|
|
8402
|
+
plan team who builds each milestone and reviews, on which model and thinking level, and what you can pick
|
|
8403
|
+
plan model <Mn|reviewer> <model>@<thinking> the developer's choice: locks a milestone to that model (a coder
|
|
8404
|
+
on it joins the team when none runs it) or sets the reviewer's; `auto` unlocks a milestone
|
|
8028
8405
|
events [--peek] (lead) what you were woken for; reading acknowledges it
|
|
8029
8406
|
dispatch <Mn>... [--to <worker>] [--tier <tier>] (lead) start or restart milestones; starts the event manager
|
|
8030
8407
|
check [Mn] run the plan's check command in the main folder: CHECK PASS, or CHECK FAIL (exit 1)
|
|
@@ -8041,7 +8418,9 @@ USAGE = """usage: orch <command> [args]
|
|
|
8041
8418
|
guard [status|--print] install the pre-push guard: no agent ever pushes to main/master/the default branch
|
|
8042
8419
|
(orch start installs it too); status: report it and whether GitHub protects main
|
|
8043
8420
|
doctor [kind...] check installed agents against the real tool: version, launch flags, skills, herdr
|
|
8044
|
-
sync parse .orchestrate/plan.md -> state.json (validates deps, cycles, overlaps)
|
|
8421
|
+
sync parse .orchestrate/plan.md -> state.json (validates deps, cycles, overlaps). In a workspace
|
|
8422
|
+
(plan header `Repos: frontend, backend`): writes and syncs each repo's own plan; then
|
|
8423
|
+
milestone commands go to that milestone's repo, the others run in every repo
|
|
8045
8424
|
start create/switch to the feature branch (plan `Branch:`); create worker worktrees (worktree mode)
|
|
8046
8425
|
status [--json] table of workers + tasks; prints ALL_DONE or STUCK when relevant. --json: the run summary
|
|
8047
8426
|
both views read (milestones with their plain description, agents, counts, time, cost)
|
|
@@ -8977,6 +9356,71 @@ def update_notice(network=True):
|
|
|
8977
9356
|
pass
|
|
8978
9357
|
|
|
8979
9358
|
|
|
9359
|
+
def workspace_repos(ws):
|
|
9360
|
+
"""{name: absolute path} of the repos in a workspace (its .orchestrate/workspace.json, written by `orch sync`)."""
|
|
9361
|
+
try:
|
|
9362
|
+
d = json.loads((Path(ws) / ".orchestrate" / "workspace.json").read_text())
|
|
9363
|
+
return {str(k).lower(): str(v) for k, v in (d.get("repos") or {}).items()}
|
|
9364
|
+
except (OSError, ValueError, AttributeError):
|
|
9365
|
+
return {}
|
|
9366
|
+
|
|
9367
|
+
|
|
9368
|
+
def run_names(root):
|
|
9369
|
+
"""(workers + reviewer, lead name, workspace) of the run in root, from its state; None when it can't be read."""
|
|
9370
|
+
try:
|
|
9371
|
+
st = json.loads((Path(root) / ".orchestrate" / "state.json").read_text())
|
|
9372
|
+
except (OSError, ValueError):
|
|
9373
|
+
return None
|
|
9374
|
+
names = set(st.get("workers") or {}) | ({st["reviewer"]} if st.get("reviewer") else set())
|
|
9375
|
+
return names, (st.get("lead") or {}).get("name"), st.get("workspace")
|
|
9376
|
+
|
|
9377
|
+
|
|
9378
|
+
def name_clashes(workers, reviewer, lead, workspace):
|
|
9379
|
+
"""Errors for agent names another run on this machine uses right now: herdr finds agents by name, so two runs
|
|
9380
|
+
with a `codex-1` each would send work to the same pane. A shared lead is fine inside one workspace."""
|
|
9381
|
+
if os.environ.get("ORCH_NAME_CHECK", "1") == "0":
|
|
9382
|
+
return []
|
|
9383
|
+
mine = set(workers) | ({reviewer} if reviewer else set()) | ({lead} if lead else set())
|
|
9384
|
+
errs = []
|
|
9385
|
+
here = ROOT.resolve() if ROOT else None
|
|
9386
|
+
for root in active_runs():
|
|
9387
|
+
if here and Path(root).resolve() == here:
|
|
9388
|
+
continue
|
|
9389
|
+
got = run_names(root)
|
|
9390
|
+
if not got:
|
|
9391
|
+
continue
|
|
9392
|
+
theirs, their_lead, their_ws = got
|
|
9393
|
+
if their_lead and not (workspace and their_ws == workspace and their_lead == lead):
|
|
9394
|
+
theirs = theirs | {their_lead}
|
|
9395
|
+
clash = sorted(mine & theirs)
|
|
9396
|
+
if clash:
|
|
9397
|
+
errs.append(f"{', '.join(clash)}: {'this name is' if len(clash) == 1 else 'these names are'} already used "
|
|
9398
|
+
f"by the run in {root}, which is going now. herdr finds agents by name, so both runs would "
|
|
9399
|
+
f"send work to the same pane. Rename {'it' if len(clash) == 1 else 'them'} in this plan, e.g. "
|
|
9400
|
+
f"`{(ROOT.name if ROOT else 'app')}-{clash[0]}` (`orch team <kind>` picks such names by "
|
|
9401
|
+
f"itself while another run is going)")
|
|
9402
|
+
return errs
|
|
9403
|
+
|
|
9404
|
+
|
|
9405
|
+
def team_prefix(names):
|
|
9406
|
+
"""(prefix, the other run's folder) when a run going on this machine uses one of names, else (None, None).
|
|
9407
|
+
The prefix is this repo's folder name."""
|
|
9408
|
+
try:
|
|
9409
|
+
r = subprocess.run(["git", "rev-parse", "--show-toplevel"], text=True, capture_output=True, timeout=10)
|
|
9410
|
+
here = Path(r.stdout.strip()) if r.returncode == 0 and r.stdout.strip() else Path.cwd()
|
|
9411
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
9412
|
+
here = Path.cwd()
|
|
9413
|
+
if os.environ.get("ORCH_NAME_CHECK", "1") == "0":
|
|
9414
|
+
return None, None
|
|
9415
|
+
for root in active_runs():
|
|
9416
|
+
if Path(root).resolve() == here.resolve():
|
|
9417
|
+
continue
|
|
9418
|
+
got = run_names(root)
|
|
9419
|
+
if got and (got[0] | ({got[1]} if got[1] else set())) & set(names):
|
|
9420
|
+
return re.sub(r"[^\w.-]", "-", here.name) or "run", root
|
|
9421
|
+
return None, None
|
|
9422
|
+
|
|
9423
|
+
|
|
8980
9424
|
def active_runs():
|
|
8981
9425
|
"""Repos whose event manager is running on this machine right now (each manager signs in under active/)."""
|
|
8982
9426
|
live = []
|
|
@@ -9610,6 +10054,302 @@ SUBAGENT_PLAN_NOTE = """SUBAGENT MODE (Pi, one window). This replaces every herd
|
|
|
9610
10054
|
"""
|
|
9611
10055
|
|
|
9612
10056
|
|
|
10057
|
+
# ---------------------------------------------------------------- a workspace of several repos (frontend + backend)
|
|
10058
|
+
# A folder (a git repo or not) whose .orchestrate/plan.md has `Repos: frontend, backend` is a workspace. Every
|
|
10059
|
+
# milestone names its repo (`Repo: backend`). `orch sync` there writes one normal plan per repo (in that repo's own
|
|
10060
|
+
# .orchestrate/), so each repo is an ordinary run: its own worktrees (`<repo>-wt/<coder>`), its own feature branch,
|
|
10061
|
+
# its own check, its own PR. One lead drives all of them from the workspace folder; orch sends each command to the
|
|
10062
|
+
# repo its milestone belongs to, or to every repo. A milestone may wait for one of another repo: `backend:M2`.
|
|
10063
|
+
WS_GENERATED = "<!-- written by `orch sync` from the workspace plan {plan}: edit that file, not this one -->"
|
|
10064
|
+
WS_PER_REPO = ("check ", "setup ", "workers ", "reviewer ")
|
|
10065
|
+
|
|
10066
|
+
|
|
10067
|
+
def ws_plan_repos(ws, cfg):
|
|
10068
|
+
"""{name: absolute path} from the header `Repos: frontend, backend` (or `Repos: web=apps/web, api=../api`)."""
|
|
10069
|
+
out = {}
|
|
10070
|
+
for item in re.split(r"[,\s]+", " ".join(cfg.get("repos", []))):
|
|
10071
|
+
if not item:
|
|
10072
|
+
continue
|
|
10073
|
+
name, _, rel = item.partition("=")
|
|
10074
|
+
rel = rel or name
|
|
10075
|
+
out[(name if _ else Path(rel).name).lower()] = str((Path(ws) / rel).resolve())
|
|
10076
|
+
return out
|
|
10077
|
+
|
|
10078
|
+
|
|
10079
|
+
def _git_top(d):
|
|
10080
|
+
try:
|
|
10081
|
+
r = subprocess.run(["git", "rev-parse", "--path-format=absolute", "--git-common-dir"], cwd=str(d), text=True,
|
|
10082
|
+
capture_output=True, timeout=10)
|
|
10083
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
10084
|
+
return None
|
|
10085
|
+
return Path(r.stdout.strip()).parent.resolve() if r.returncode == 0 and r.stdout.strip() else None
|
|
10086
|
+
|
|
10087
|
+
|
|
10088
|
+
def find_workspace(start):
|
|
10089
|
+
"""The workspace folder start is in (its .orchestrate/plan.md has `Repos:`), unless start is inside one of its
|
|
10090
|
+
repos or their coder folders: commands there belong to that repo's own run. None when there is no workspace."""
|
|
10091
|
+
p = Path(start).resolve()
|
|
10092
|
+
for d in [p, *p.parents]:
|
|
10093
|
+
plan = d / ".orchestrate" / "plan.md"
|
|
10094
|
+
if not plan.is_file():
|
|
10095
|
+
continue
|
|
10096
|
+
try:
|
|
10097
|
+
cfg, _ = parse_plan(plan.read_text())
|
|
10098
|
+
except OSError:
|
|
10099
|
+
return None
|
|
10100
|
+
if not cfg.get("repos"):
|
|
10101
|
+
return None # the nearest plan is an ordinary run's
|
|
10102
|
+
repos = [Path(r).resolve() for r in ws_plan_repos(d, cfg).values()]
|
|
10103
|
+
top = _git_top(p)
|
|
10104
|
+
if top and top in repos:
|
|
10105
|
+
return None
|
|
10106
|
+
if any(p == r or r in p.parents for r in repos):
|
|
10107
|
+
return None
|
|
10108
|
+
return d
|
|
10109
|
+
return None
|
|
10110
|
+
|
|
10111
|
+
|
|
10112
|
+
def _fields(lines):
|
|
10113
|
+
"""Header lines -> [(key or None, [lines])]: a `Key: value` line with its continuation lines, or another line."""
|
|
10114
|
+
out = []
|
|
10115
|
+
for line in lines:
|
|
10116
|
+
fm = FIELD_RE.match(line.strip())
|
|
10117
|
+
if fm and not line.startswith((" ", "\t", "-")):
|
|
10118
|
+
out.append((fm.group(1).strip().lower(), [line]))
|
|
10119
|
+
elif out and out[-1][0] and line.strip() and line.startswith((" ", "\t", "-")):
|
|
10120
|
+
out[-1][1].append(line)
|
|
10121
|
+
else:
|
|
10122
|
+
out.append((None, [line]))
|
|
10123
|
+
return out
|
|
10124
|
+
|
|
10125
|
+
|
|
10126
|
+
def _prefix_agents(value, repo):
|
|
10127
|
+
"""`claude-1 (claude: sonnet), codex-1 (codex)` -> `frontend-claude-1 (claude: sonnet), frontend-codex-1 (codex)`."""
|
|
10128
|
+
return re.sub(r"([\w.-]+)(\s*\()", lambda m: (m.group(1) if m.group(1).lower().startswith(repo + "-")
|
|
10129
|
+
else f"{repo}-{m.group(1)}") + m.group(2), value)
|
|
10130
|
+
|
|
10131
|
+
|
|
10132
|
+
def ws_repo_plan(ws, text, repo, task_repo, all_repos):
|
|
10133
|
+
"""The plan for one repo of the workspace: the shared header, that repo's check, setup, coders and reviewer, its
|
|
10134
|
+
milestones (a dependency on another repo's milestone written `backend:M2`) and every other section."""
|
|
10135
|
+
lines = text.splitlines()
|
|
10136
|
+
first = next((i for i, l in enumerate(lines) if l.startswith("## ")), len(lines))
|
|
10137
|
+
head = _fields(lines[:first])
|
|
10138
|
+
get = {k: " ".join(x.split(":", 1)[1].strip() if j == 0 else x.strip() for j, x in enumerate(ls)).strip()
|
|
10139
|
+
for k, ls in head if k}
|
|
10140
|
+
out = [WS_GENERATED.format(plan=Path(ws) / ".orchestrate" / "plan.md")]
|
|
10141
|
+
for k, ls in head:
|
|
10142
|
+
if k and (k in ("repos", "workers", "reviewer", "check command", "setup command", "workspace")
|
|
10143
|
+
or (k.startswith(WS_PER_REPO) and k.split(" ", 1)[1] in all_repos)
|
|
10144
|
+
or k.startswith(("workers ", "reviewer "))):
|
|
10145
|
+
continue
|
|
10146
|
+
out += ls
|
|
10147
|
+
while out and not out[-1].strip():
|
|
10148
|
+
out.pop()
|
|
10149
|
+
out.append(f"Workspace: {ws}")
|
|
10150
|
+
chk = get.get(f"check {repo}") or get.get("check command")
|
|
10151
|
+
if chk:
|
|
10152
|
+
out.append(f"Check command: {chk}")
|
|
10153
|
+
out.append(f"Setup command: {get.get(f'setup {repo}') or get.get('setup command') or 'none'}")
|
|
10154
|
+
out.append(f"Workers: {get.get(f'workers {repo}') or _prefix_agents(get.get('workers', ''), repo)}")
|
|
10155
|
+
rev = get.get(f"reviewer {repo}") or get.get("reviewer") or "none"
|
|
10156
|
+
out.append(f"Reviewer: {rev if rev.lower().startswith('none') or get.get(f'reviewer {repo}') else _prefix_agents(rev, repo)}")
|
|
10157
|
+
out.append("")
|
|
10158
|
+
sec, keep = [], True
|
|
10159
|
+
|
|
10160
|
+
def flush():
|
|
10161
|
+
if keep:
|
|
10162
|
+
out.extend(sec)
|
|
10163
|
+
for line in lines[first:]:
|
|
10164
|
+
if line.startswith("## "):
|
|
10165
|
+
flush()
|
|
10166
|
+
sec = [line]
|
|
10167
|
+
m = HEAD_RE.match(line)
|
|
10168
|
+
keep = not m or task_repo.get(m.group(2)) == repo
|
|
10169
|
+
continue
|
|
10170
|
+
sec.append(line)
|
|
10171
|
+
flush()
|
|
10172
|
+
# a dependency on a milestone of another repo: `M2` -> `backend:M2` (only inside `Depends on:`)
|
|
10173
|
+
res, in_dep = [], False
|
|
10174
|
+
for line in out:
|
|
10175
|
+
fm = FIELD_RE.match(line.strip())
|
|
10176
|
+
if fm and not line.startswith((" ", "\t", "-")):
|
|
10177
|
+
in_dep = fm.group(1).strip().lower() == "depends on"
|
|
10178
|
+
elif line.startswith("## "):
|
|
10179
|
+
in_dep = False
|
|
10180
|
+
if in_dep:
|
|
10181
|
+
line = re.sub(r"(?<![\w:])(M\d+)\b", lambda m: m.group(1) if task_repo.get(m.group(1), repo) == repo
|
|
10182
|
+
else f"{task_repo[m.group(1)]}:{m.group(1)}", line)
|
|
10183
|
+
res.append(line)
|
|
10184
|
+
return "\n".join(res).rstrip() + "\n"
|
|
10185
|
+
|
|
10186
|
+
|
|
10187
|
+
def ws_runs(ws):
|
|
10188
|
+
"""[(name, path)] of the repos that have a run of this workspace (their plan says `Workspace: <ws>`)."""
|
|
10189
|
+
out = []
|
|
10190
|
+
for name, path in workspace_repos(ws).items():
|
|
10191
|
+
plan = Path(path) / ".orchestrate" / "plan.md"
|
|
10192
|
+
try:
|
|
10193
|
+
if f"Workspace: {ws}" in plan.read_text():
|
|
10194
|
+
out.append((name, path))
|
|
10195
|
+
except OSError:
|
|
10196
|
+
pass
|
|
10197
|
+
return out
|
|
10198
|
+
|
|
10199
|
+
|
|
10200
|
+
def ws_sync(ws):
|
|
10201
|
+
plan = Path(ws) / ".orchestrate" / "plan.md"
|
|
10202
|
+
text = plan.read_text()
|
|
10203
|
+
cfg, tasks = parse_plan(text)
|
|
10204
|
+
repos = ws_plan_repos(ws, cfg)
|
|
10205
|
+
errors = []
|
|
10206
|
+
for name, path in repos.items():
|
|
10207
|
+
if _git_top(path) != Path(path).resolve():
|
|
10208
|
+
errors.append(f"repo {name}: {path} is not the top folder of a git repo")
|
|
10209
|
+
task_repo = {}
|
|
10210
|
+
for t in tasks:
|
|
10211
|
+
r = field(t, "repo").split()[0].lower() if field(t, "repo") else None
|
|
10212
|
+
if not r:
|
|
10213
|
+
if t["enabled"]:
|
|
10214
|
+
errors.append(f"{t['id']} needs `Repo: <one of {', '.join(repos)}>`: in a workspace every milestone "
|
|
10215
|
+
f"belongs to one repo")
|
|
10216
|
+
continue
|
|
10217
|
+
if r not in repos:
|
|
10218
|
+
errors.append(f"{t['id']} has `Repo: {r}`, but `Repos:` names only {', '.join(repos)}")
|
|
10219
|
+
continue
|
|
10220
|
+
task_repo[t["id"]] = r
|
|
10221
|
+
ids = [t["id"] for t in tasks]
|
|
10222
|
+
for d in sorted({i for i in ids if ids.count(i) > 1}):
|
|
10223
|
+
errors.append(f"duplicate task id {d}: milestone ids are counted across the whole workspace")
|
|
10224
|
+
deps = {t["id"]: split_ids(re.sub(r"\([^)]*\)", "", field(t, "depends on", "none"))) for t in tasks}
|
|
10225
|
+
color = {}
|
|
10226
|
+
|
|
10227
|
+
def dfs(n, stack):
|
|
10228
|
+
color[n] = 1
|
|
10229
|
+
for d in deps.get(n, []):
|
|
10230
|
+
if d not in deps:
|
|
10231
|
+
errors.append(f"{n} depends on unknown task {d}")
|
|
10232
|
+
elif color.get(d) == 1:
|
|
10233
|
+
errors.append("dependency cycle across repos: " + " -> ".join(stack + [n, d]))
|
|
10234
|
+
elif not color.get(d):
|
|
10235
|
+
dfs(d, stack + [n])
|
|
10236
|
+
color[n] = 2
|
|
10237
|
+
for n in deps:
|
|
10238
|
+
if not color.get(n):
|
|
10239
|
+
dfs(n, [])
|
|
10240
|
+
used = sorted(set(task_repo.values()), key=list(repos).index)
|
|
10241
|
+
for name in used:
|
|
10242
|
+
p = Path(repos[name]) / ".orchestrate" / "plan.md"
|
|
10243
|
+
if p.exists() and f"Workspace: {ws}" not in p.read_text():
|
|
10244
|
+
try:
|
|
10245
|
+
ost = json.loads((p.parent / "state.json").read_text())
|
|
10246
|
+
left = [k for k, v in ost.get("tasks", {}).items() if v.get("status") not in ("merged", "skipped")]
|
|
10247
|
+
except (OSError, ValueError):
|
|
10248
|
+
left = []
|
|
10249
|
+
if left:
|
|
10250
|
+
errors.append(f"repo {name} has its own run going ({', '.join(left[:4])} not landed): finish it there "
|
|
10251
|
+
f"first (`orch status` in {repos[name]})")
|
|
10252
|
+
if errors:
|
|
10253
|
+
for e in errors:
|
|
10254
|
+
print("ERROR:", e)
|
|
10255
|
+
sys.exit(1)
|
|
10256
|
+
(Path(ws) / ".orchestrate" / "workspace.json").write_text(json.dumps(
|
|
10257
|
+
{"repos": repos, "tasks": task_repo, "plan": str(plan)}, indent=1) + "\n")
|
|
10258
|
+
for name in repos:
|
|
10259
|
+
if name not in used:
|
|
10260
|
+
print(f"WARN: repo {name} has no milestone in this plan, so it gets no run")
|
|
10261
|
+
code = 0
|
|
10262
|
+
for name in used:
|
|
10263
|
+
d = Path(repos[name]) / ".orchestrate"
|
|
10264
|
+
d.mkdir(exist_ok=True)
|
|
10265
|
+
p = d / "plan.md"
|
|
10266
|
+
if p.exists() and f"Workspace: {ws}" not in p.read_text():
|
|
10267
|
+
shutil.copyfile(p, d / "plan.before-workspace.md")
|
|
10268
|
+
print(f"SAVED {name}'s own old plan as {d / 'plan.before-workspace.md'}")
|
|
10269
|
+
p.write_text(ws_repo_plan(str(ws), text, name, task_repo, list(repos)))
|
|
10270
|
+
print(f"== {name} ({repos[name]}): " + ", ".join(k for k, v in task_repo.items() if v == name))
|
|
10271
|
+
sys.stdout.flush()
|
|
10272
|
+
r = subprocess.run([sys.executable, os.path.abspath(__file__), "sync"], cwd=repos[name])
|
|
10273
|
+
code = max(code, r.returncode)
|
|
10274
|
+
sys.exit(code)
|
|
10275
|
+
|
|
10276
|
+
|
|
10277
|
+
WS_TASK_FREE = {"autopilot", "events", "status", "start", "finish", "resume", "stop", "team", "report", "story",
|
|
10278
|
+
"manual", "doctor", "cleanup", "ready", "guard", "plan", "mode", "check"}
|
|
10279
|
+
|
|
10280
|
+
|
|
10281
|
+
def workspace_main(ws, cmd, args):
|
|
10282
|
+
"""Carry out one orch command in a workspace: in the repo its milestone belongs to, or in every repo."""
|
|
10283
|
+
me = [sys.executable, os.path.abspath(__file__)]
|
|
10284
|
+
if cmd == "sync":
|
|
10285
|
+
ws_sync(ws)
|
|
10286
|
+
runs = ws_runs(ws)
|
|
10287
|
+
if not runs:
|
|
10288
|
+
die(f"{ws} is a workspace of several repos (its plan has `Repos:`), and no repo has a run of it yet — "
|
|
10289
|
+
f"run `orch sync` here")
|
|
10290
|
+
info = json.loads((Path(ws) / ".orchestrate" / "workspace.json").read_text())
|
|
10291
|
+
repo_of = info.get("tasks") or {}
|
|
10292
|
+
paths = dict(runs)
|
|
10293
|
+
|
|
10294
|
+
def one(name, a, header=True):
|
|
10295
|
+
if header:
|
|
10296
|
+
print(f"== {name} ({paths[name]})")
|
|
10297
|
+
sys.stdout.flush()
|
|
10298
|
+
return subprocess.run(me + [cmd, *a], cwd=paths[name]).returncode
|
|
10299
|
+
if cmd in ("view", "board"):
|
|
10300
|
+
die(f"`orch {cmd}` shows one repo's run: run it inside one of the repos ({', '.join(paths.values())})")
|
|
10301
|
+
if cmd == "sub":
|
|
10302
|
+
die("subagent mode works in one folder, one milestone at a time: a workspace of several repos runs in panes "
|
|
10303
|
+
f"mode. For subagent mode, plan and run inside one repo ({', '.join(paths.values())})")
|
|
10304
|
+
mids = [a for a in args if re.fullmatch(r"M\d+", a)]
|
|
10305
|
+
if mids:
|
|
10306
|
+
unknown = [m for m in mids if m not in repo_of]
|
|
10307
|
+
if unknown:
|
|
10308
|
+
die(f"{', '.join(unknown)}: no such milestone in the workspace plan (`orch status` lists them)")
|
|
10309
|
+
groups = {}
|
|
10310
|
+
for m in mids:
|
|
10311
|
+
groups.setdefault(repo_of[m], []).append(m)
|
|
10312
|
+
code = 0
|
|
10313
|
+
for name, ms in groups.items():
|
|
10314
|
+
a = [x for x in args if not re.fullmatch(r"M\d+", x) or x in ms]
|
|
10315
|
+
code = max(code, one(name, a, header=len(groups) > 1))
|
|
10316
|
+
sys.exit(code)
|
|
10317
|
+
if cmd == "bench" and args:
|
|
10318
|
+
for name, path in runs:
|
|
10319
|
+
got = run_names(path)
|
|
10320
|
+
if got and args[0] in got[0]:
|
|
10321
|
+
sys.exit(one(name, args, header=False))
|
|
10322
|
+
die(f"no repo of the workspace has a coder named {args[0]}")
|
|
10323
|
+
if cmd == "autopilot": # one event manager per repo, side by side
|
|
10324
|
+
procs = []
|
|
10325
|
+
for name, path in runs:
|
|
10326
|
+
print(f"== {name}: event manager started ({path})")
|
|
10327
|
+
sys.stdout.flush()
|
|
10328
|
+
procs.append(subprocess.Popen(me + [cmd, *args], cwd=path))
|
|
10329
|
+
sys.exit(max(p.wait() for p in procs))
|
|
10330
|
+
code = 0
|
|
10331
|
+
for name, _ in runs:
|
|
10332
|
+
code = max(code, one(name, args))
|
|
10333
|
+
if cmd == "events":
|
|
10334
|
+
left = {}
|
|
10335
|
+
for name, path in runs:
|
|
10336
|
+
try:
|
|
10337
|
+
st = json.loads((Path(path) / ".orchestrate" / "state.json").read_text())
|
|
10338
|
+
left[name] = [k for k, v in st["tasks"].items() if v["status"] not in ("merged", "skipped")]
|
|
10339
|
+
except (OSError, ValueError, KeyError):
|
|
10340
|
+
left[name] = ["?"]
|
|
10341
|
+
done = [n for n, l in left.items() if not l]
|
|
10342
|
+
if done and len(done) < len(left):
|
|
10343
|
+
print(f"\nWORKSPACE: {', '.join(done)} has landed every milestone; still going: "
|
|
10344
|
+
+ ", ".join(f"{n} ({', '.join(l)})" for n, l in left.items() if l)
|
|
10345
|
+
+ ". An ALL_DONE above is for that repo only: write the summaries when every repo is done.")
|
|
10346
|
+
elif done:
|
|
10347
|
+
print(f"\nWORKSPACE: every repo has landed all its milestones. Each repo gets its own PR: finish the "
|
|
10348
|
+
f"summary in each repo's .orchestrate/summary.md ({', '.join(paths.values())}), then `orch finish` "
|
|
10349
|
+
f"here runs it in every repo.")
|
|
10350
|
+
sys.exit(code)
|
|
10351
|
+
|
|
10352
|
+
|
|
9613
10353
|
def subagent_ready_or_die(st):
|
|
9614
10354
|
if run_mode(st) != "subagent":
|
|
9615
10355
|
die("this run is in panes mode — `orch sub` is for subagent mode (`orch mode subagent`); "
|
|
@@ -9627,20 +10367,22 @@ def cmd_check(args):
|
|
|
9627
10367
|
st = load()
|
|
9628
10368
|
if args:
|
|
9629
10369
|
task(st, args[0])
|
|
9630
|
-
if
|
|
10370
|
+
tid = args[0] if args else None
|
|
10371
|
+
cmd = check_for(st, tid)
|
|
10372
|
+
if not cmd:
|
|
9631
10373
|
print("CHECK NONE: the plan has no `Check command`")
|
|
9632
10374
|
return
|
|
9633
|
-
ok, tail, secs = run_check(st, ROOT)
|
|
10375
|
+
ok, tail, secs = run_check(st, ROOT, tid)
|
|
9634
10376
|
if not driver_alive():
|
|
9635
10377
|
with state_lock():
|
|
9636
10378
|
st = load()
|
|
9637
|
-
note_green(st, ROOT, ok)
|
|
10379
|
+
note_green(st, ROOT, ok, tid) # `orch finish` reuses a pass on exactly these files
|
|
9638
10380
|
save(st)
|
|
9639
10381
|
label = f" {args[0]}" if args else ""
|
|
9640
10382
|
if ok:
|
|
9641
|
-
print(f"CHECK PASS{label} ({secs}s): {
|
|
10383
|
+
print(f"CHECK PASS{label} ({secs}s): {cmd}")
|
|
9642
10384
|
return
|
|
9643
|
-
print(f"CHECK FAIL{label} ({secs}s): {
|
|
10385
|
+
print(f"CHECK FAIL{label} ({secs}s): {cmd}\n" + "\n".join(tail.splitlines()[-30:]))
|
|
9644
10386
|
sys.exit(1)
|
|
9645
10387
|
|
|
9646
10388
|
|
|
@@ -9846,6 +10588,9 @@ if __name__ == "__main__":
|
|
|
9846
10588
|
if len(sys.argv) < 2 or sys.argv[1] not in COMMANDS:
|
|
9847
10589
|
print(USAGE)
|
|
9848
10590
|
sys.exit(0 if len(sys.argv) < 2 or sys.argv[1] in ("--help", "-h", "help") else 2)
|
|
10591
|
+
_ws = find_workspace(Path.cwd())
|
|
10592
|
+
if _ws is not None: # a workspace of several repos: each repo is its own run
|
|
10593
|
+
workspace_main(_ws, sys.argv[1], sys.argv[2:])
|
|
9849
10594
|
ROOT = main_root()
|
|
9850
10595
|
ORCH = ROOT / ".orchestrate"
|
|
9851
10596
|
ORCH.mkdir(exist_ok=True)
|