herdr-orchestra 6.30.0 → 6.32.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 +39 -0
- package/README.md +1 -0
- package/VERSION +1 -1
- package/bin/__pycache__/orchcpython-314.pyc +0 -0
- package/bin/orch +587 -57
- package/package.json +1 -1
- package/view/herdr-plugin/herdr-plugin.toml +3 -1
- package/view/index.html +77 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes. Versions follow [semantic versioning](https://semver.org).
|
|
4
4
|
|
|
5
|
+
## [6.32.0] - 2026-11-28
|
|
6
|
+
|
|
7
|
+
The board key (`prefix+a`) opens the board again. Since 6.22.0 the popup flashed open and closed at once.
|
|
8
|
+
|
|
9
|
+
Example: you press `prefix+a` in a pane of your repo. The popup showed for a moment and was gone. Now the board opens and stays until you press `q`.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- **The board popup found no `board.sh`.** The plugin told herdr to run `sh board.sh`. Herdr starts a popup in the folder given with `--cwd` (your repo, since 6.22.0) and resolves only a first word containing a `/` against the plugin folder (herdr 0.9.5, `plugin_command.rs`). So `sh` looked for `board.sh` in your repo, printed "cannot open board.sh" and ended, and herdr closed the popup at once. The 6.30.0 guard lives in `board.sh`, so it never ran. The command is now `sh -c 'exec sh "$HERDR_PLUGIN_ROOT/board.sh"'`; herdr sets `HERDR_PLUGIN_ROOT` to the plugin folder for every plugin pane.
|
|
13
|
+
- A new test starts the popup the way herdr does (the manifest's command, in the repo folder, herdr's resolution rules and variables). Before this fix it fails with "cannot open board.sh"; with it, the board stays open until `q`.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Corrected note from 6.30.0: herdr stores the real folder behind a plugin link (it resolves the `current` link to the version folder). The link follows updates because every install and `orch update` re-links it (`orch view plugin refresh`), not because of the `current` path itself.
|
|
17
|
+
|
|
18
|
+
### After updating
|
|
19
|
+
Nothing to do: `orch update` re-links the plugin. If `prefix+a` still flashes, run `orch view plugin unlink` and then `orch view plugin link`.
|
|
20
|
+
|
|
21
|
+
## [6.31.0] - 2026-11-28
|
|
22
|
+
|
|
23
|
+
See what each milestone changed, like GitLens shows it: the files by folder with `+/-` counts and A/M/D marks, and each file's diff. In the board popup and in the browser view.
|
|
24
|
+
|
|
25
|
+
Example: M2 "Goals API" is being built by agy-3. On the board (`prefix+a`), press `f`: you see `app/api/goals/route.ts +177 −0 A`, `lib/app-navigation.ts +5 −1 M`, `lib/hooks/use-goals.ts +229 −0 U` (new, not added to git yet) and so on, updating every 2 seconds while agy-3 works. Press Enter on a file for its coloured diff, q to go back. In `orch view`, click M2 and the same list is in its card; click a file for its diff.
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
- **Board: changed files and diffs.** `↑`/`↓` now pick a milestone as well as an agent. `f` (or `Enter` on a milestone) opens its changed files; `Enter` on a file opens its diff (`↑`/`↓`, `space`, `u` scroll); `←`/`→` switch milestone; `q` goes back one screen, and closes the board only from the main screen.
|
|
29
|
+
- **Browser view: changed files and diffs.** The card of the milestone you click lists its changed files; a file opens its diff in a panel (Esc closes). New read-only routes `/api/changes?m=Mn` and `/api/diff?m=Mn&f=<path>` (in docs/contracts.md); they keep the page's host and `--lan` token checks.
|
|
30
|
+
- **`orch changes [Mn [file]] [--json]`**: the same in any terminal, for you or the lead.
|
|
31
|
+
- What is shown: a milestone being built shows the coder's folder against where its work started, unsaved and new files included (and against the branch it merges in while resolving a conflict); work waiting for review or a fix shows what was handed in; a landed milestone shows its commit on the feature branch; a milestone not started says "no changes yet". In a shared folder (subagent mode, `Isolation: shared`) it is the main folder's unsaved files.
|
|
32
|
+
- orch now saves the commit each milestone lands as (`landed` in state.json). Runs from older versions are found by the commit's `Milestone: Mn` line.
|
|
33
|
+
|
|
34
|
+
### Safe by design
|
|
35
|
+
- It only reads git: `GIT_OPTIONAL_LOCKS=0` (git does not even refresh its index), no external diff tools, a 15 second limit per git call, at most 500 files and 4000 diff lines. A test checks that the coder's files, its git index and the repo's git objects are exactly the same after the board, `orch changes` and a diff were used on its folder.
|
|
36
|
+
- A diff can only show a file the milestone changed: no other file can be read through the board or the page.
|
|
37
|
+
- Escape codes inside a file (or a file name) are never sent to the terminal.
|
|
38
|
+
- An error while reading changes stays on screen with "[q] back" and is saved in `board-error.log`, like the 6.30.0 board errors; the popup never closes by itself.
|
|
39
|
+
- The popup still starts in the pane's repo (6.22.0) and runs from the `current` install (6.30.0); nothing about how it opens changed. A workspace of several repos works per repo, as the board always did.
|
|
40
|
+
|
|
41
|
+
### Not yet tried
|
|
42
|
+
- On real herdr: tested with the simulated herdr and in a real terminal (pty) with real git repos and worktrees, including the popup keys above, and the page in a real browser (Chromium). Not yet seen with real coders working.
|
|
43
|
+
|
|
5
44
|
## [6.30.0] - 2026-11-27
|
|
6
45
|
|
|
7
46
|
The board key (`prefix+a`) now always runs the board popup of the version you have installed, and the popup never vanishes without saying why.
|
package/README.md
CHANGED
|
@@ -339,6 +339,7 @@ Three views show a run while it goes; none of them changes it.
|
|
|
339
339
|
|
|
340
340
|
- **`orch view`** opens the run as a live picture in your browser: the run ring, a milestone graph (arrows = "needs this first", red = needs you) with a one-line description under each milestone, the agents, the details of the milestone you click (with the exact `orch answer` command), time and cost against the estimate, a replay slider, and an optional browser alert when something needs you. `orch view --lan` also opens it to your phone on the same Wi-Fi, behind a secret link. `orch status` and the lead's "needs you" lines print its link while it runs.
|
|
341
341
|
- **`orch board`** draws the same run as text for a Herdr pane; `orch view plugin link` adds a small Herdr plugin that opens it as a popup (Herdr 0.7.4+).
|
|
342
|
+
- **What each milestone changed**: press `f` on the board, or click a milestone in `orch view`, for its changed files by folder with `+/-` counts (live while the coder works, unsaved files included), and a file for its diff. `orch changes M2` prints the same. Read-only.
|
|
342
343
|
- **Herdr's sidebar** names each agent by what it does (`codex-1 · M2 building`), set by the event manager on a separate thread, display only (Herdr 0.6.3+; `ORCH_SIDEBAR=0` turns it off). `orch view herdr-config` prints extra sidebar rows.
|
|
343
344
|
|
|
344
345
|
`orch status --json` prints the run summary all three read (see [docs/contracts.md](docs/contracts.md)). More: [Watch a run](https://herdr-orchestra.vercel.app/docs/watching/).
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
6.
|
|
1
|
+
6.32.0
|
|
Binary file
|
package/bin/orch
CHANGED
|
@@ -173,7 +173,7 @@ def state_lock():
|
|
|
173
173
|
# usable while autopilot drives: reads, and the lead's requests (the event manager carries them out)
|
|
174
174
|
LEASE_FREE = {"status", "ready", "pick", "report", "approve", "autopilot", "events", "dispatch", "answer", "defer",
|
|
175
175
|
"fix", "team", "resume", "bench", "stop", "doctor", "plan", "story", "check", "free", "manual", "view",
|
|
176
|
-
"board"}
|
|
176
|
+
"board", "changes"}
|
|
177
177
|
_LEASE = None
|
|
178
178
|
|
|
179
179
|
|
|
@@ -3485,6 +3485,7 @@ def cmd_commit(args):
|
|
|
3485
3485
|
def _finish(st, tid):
|
|
3486
3486
|
t = st["tasks"][tid]
|
|
3487
3487
|
move(st, tid, "merged", "")
|
|
3488
|
+
note_landed(st, tid) # the commit it landed as, for `orch changes` / the board / `orch view`
|
|
3488
3489
|
t["wait"] = None
|
|
3489
3490
|
if (st.get("merging") or {}).get("tid") == tid:
|
|
3490
3491
|
st["merging"] = None
|
|
@@ -7834,6 +7835,23 @@ def serve_view(port, lan, token, opened):
|
|
|
7834
7835
|
return self._send(200, page.read_text(), "text/html; charset=utf-8")
|
|
7835
7836
|
if u.path == "/api/state":
|
|
7836
7837
|
return self._send(200, json.dumps(view_model()), "application/json")
|
|
7838
|
+
if u.path in ("/api/changes", "/api/diff"): # read-only git; a file must be one the milestone changed
|
|
7839
|
+
try:
|
|
7840
|
+
st = _board_state()
|
|
7841
|
+
tid = q.get("m", [""])[0]
|
|
7842
|
+
if tid not in st.get("tasks", {}):
|
|
7843
|
+
return self._send(404, json.dumps({"error": f"no milestone {tid!r} in this run"}),
|
|
7844
|
+
"application/json")
|
|
7845
|
+
if u.path == "/api/changes":
|
|
7846
|
+
return self._send(200, json.dumps(milestone_changes(st, tid)), "application/json")
|
|
7847
|
+
path = q.get("f", [""])[0]
|
|
7848
|
+
lines, err = file_diff(st, tid, path)
|
|
7849
|
+
cut = len(lines) > CHANGES_MAX_DIFF
|
|
7850
|
+
return self._send(200, json.dumps({"id": tid, "path": path, "lines": lines[:CHANGES_MAX_DIFF],
|
|
7851
|
+
"cut": cut, "total": len(lines), "error": err}),
|
|
7852
|
+
"application/json")
|
|
7853
|
+
except Exception as e: # noqa: BLE001 - the page shows it; the server keeps serving
|
|
7854
|
+
return self._send(500, json.dumps({"error": f"{type(e).__name__}: {e}"}), "application/json")
|
|
7837
7855
|
if u.path == "/api/history":
|
|
7838
7856
|
return self._send(200, json.dumps({"events": view_events()}), "application/json")
|
|
7839
7857
|
if u.path == "/api/stream":
|
|
@@ -7938,9 +7956,9 @@ description = "orch run board"
|
|
|
7938
7956
|
|
|
7939
7957
|
|
|
7940
7958
|
def board_plugin_dir():
|
|
7941
|
-
"""The board plugin folder to give herdr
|
|
7942
|
-
|
|
7943
|
-
|
|
7959
|
+
"""The board plugin folder to give herdr: `current/view/herdr-plugin` for an install, the checkout's folder for a
|
|
7960
|
+
checkout. Herdr stores the real folder behind a link (it resolves `current` to the version folder), so a link
|
|
7961
|
+
follows updates only because every install re-links it (`orch view plugin refresh`, run by install.sh)."""
|
|
7944
7962
|
cur = share_dir() / "current" / "view" / "herdr-plugin"
|
|
7945
7963
|
try:
|
|
7946
7964
|
installed = Path(__file__).resolve().parent.parent.parent == share_dir().resolve()
|
|
@@ -8259,6 +8277,274 @@ _GROUP_ICON = {"landed": "✔", "building": "●", "checking": "●", "review":
|
|
|
8259
8277
|
"waiting": "○", "skipped": "-"}
|
|
8260
8278
|
|
|
8261
8279
|
|
|
8280
|
+
# ---- what each milestone changed: `orch changes`, the board's changed-files screen and `orch view`. Only reads git:
|
|
8281
|
+
# never the index, never a ref, never a file (GIT_OPTIONAL_LOCKS=0 stops even git's own index refresh), so looking
|
|
8282
|
+
# can't disturb a coder or a merge. Every git call has a time limit, so a huge repo can't freeze the board.
|
|
8283
|
+
CHANGES_MAX_FILES = 500 # files listed per milestone; the rest are counted
|
|
8284
|
+
CHANGES_MAX_DIFF = 4000 # lines of one file's diff
|
|
8285
|
+
CHANGES_MAX_READ = 2_000_000 # bytes read of a new file nobody added to git yet (to count its lines)
|
|
8286
|
+
EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
|
8287
|
+
|
|
8288
|
+
|
|
8289
|
+
def _rgit(d, *args, timeout=15):
|
|
8290
|
+
"""Read-only git in folder d: bytes out, None when it fails or takes too long."""
|
|
8291
|
+
env = dict(os.environ, GIT_OPTIONAL_LOCKS="0", GIT_PAGER="cat", LC_ALL="C", GIT_TERMINAL_PROMPT="0")
|
|
8292
|
+
try:
|
|
8293
|
+
r = subprocess.run(["git", "-c", "core.quotepath=off", "-c", "color.ui=never", *args], cwd=str(d), env=env,
|
|
8294
|
+
capture_output=True, timeout=timeout)
|
|
8295
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
8296
|
+
return None
|
|
8297
|
+
return r.stdout if r.returncode == 0 else None
|
|
8298
|
+
|
|
8299
|
+
|
|
8300
|
+
def _rsha(d, ref):
|
|
8301
|
+
out = _rgit(d, "rev-parse", "-q", "--verify", ref + "^{commit}")
|
|
8302
|
+
return out.decode().strip() if out else None
|
|
8303
|
+
|
|
8304
|
+
|
|
8305
|
+
def landed_commit(st, tid):
|
|
8306
|
+
"""The commit Mn landed as on the feature branch: recorded when it merged, else (runs from before 6.31) found by
|
|
8307
|
+
its `Milestone: Mn` line among the branch's own commits. None when it landed with no changes."""
|
|
8308
|
+
t = st["tasks"].get(tid) or {}
|
|
8309
|
+
if t.get("landed") and _rsha(ROOT, t["landed"]):
|
|
8310
|
+
return _rsha(ROOT, t["landed"])
|
|
8311
|
+
br = st.get("branch")
|
|
8312
|
+
if not br or not _rsha(ROOT, br):
|
|
8313
|
+
return None
|
|
8314
|
+
rng = [f"{st['base']}..{br}"] if st.get("base") and _rsha(ROOT, st["base"]) else [br, "-n", "200"]
|
|
8315
|
+
out = _rgit(ROOT, "log", "--format=%H", "-E", f"--grep=^Milestone: {re.escape(tid)}$", *rng)
|
|
8316
|
+
shas = out.decode().split() if out else []
|
|
8317
|
+
return shas[0] if shas else None
|
|
8318
|
+
|
|
8319
|
+
|
|
8320
|
+
def note_landed(st, tid):
|
|
8321
|
+
"""Remember the commit Mn just landed as (the main folder's HEAD, when that is Mn's commit)."""
|
|
8322
|
+
head = _rsha(ROOT, "HEAD")
|
|
8323
|
+
body = _rgit(ROOT, "log", "-1", "--format=%B", "HEAD") if head else None
|
|
8324
|
+
if body and re.search(rf"(?m)^Milestone: {re.escape(tid)}$", body.decode(errors="replace")):
|
|
8325
|
+
st["tasks"][tid]["landed"] = head
|
|
8326
|
+
|
|
8327
|
+
|
|
8328
|
+
def changes_source(st, tid):
|
|
8329
|
+
"""Where Mn's changes are right now, in one of four shapes:
|
|
8330
|
+
live a coder works on it: its folder (unsaved files included) against where its work started
|
|
8331
|
+
saved work kept between steps (waiting for review, a fix, a merge): the hidden ref against where it started
|
|
8332
|
+
landed merged: the one commit it landed as on the feature branch
|
|
8333
|
+
none nothing to show yet, with why"""
|
|
8334
|
+
t = st["tasks"].get(tid)
|
|
8335
|
+
if t is None:
|
|
8336
|
+
return {"kind": "none", "why": f"no milestone {tid} in this run"}
|
|
8337
|
+
status = t.get("status", "pending")
|
|
8338
|
+
if status == "skipped":
|
|
8339
|
+
return {"kind": "none", "why": "skipped: it changes nothing"}
|
|
8340
|
+
if status == "merged":
|
|
8341
|
+
sha = landed_commit(st, tid)
|
|
8342
|
+
if not sha:
|
|
8343
|
+
return {"kind": "none", "why": "landed, with no file changes (or its commit is no longer on the branch)"}
|
|
8344
|
+
parent = _rsha(ROOT, sha + "^") or EMPTY_TREE
|
|
8345
|
+
return {"kind": "landed", "pairs": [(parent, sha)], "dir": str(ROOT), "commit": sha}
|
|
8346
|
+
shared = st.get("isolation") == "shared"
|
|
8347
|
+
d = t.get("dir") or (str(ROOT) if shared else None)
|
|
8348
|
+
owns = holds(st, tid) or (shared and status in ACTIVE and st.get("tree_task") in (None, tid))
|
|
8349
|
+
if owns and d and Path(d).is_dir():
|
|
8350
|
+
if shared:
|
|
8351
|
+
base = _rsha(d, "HEAD")
|
|
8352
|
+
else:
|
|
8353
|
+
base = (_rsha(d, "MERGE_HEAD") # resolving a conflict: against the branch it merges in
|
|
8354
|
+
or (_rgit(d, "merge-base", "HEAD", st["branch"]) or b"").decode().strip() or _rsha(d, "HEAD"))
|
|
8355
|
+
if base:
|
|
8356
|
+
others = [x for x, o in st["tasks"].items() if x != tid and o.get("status") in ACTIVE
|
|
8357
|
+
and o.get("dir") == d] if shared else []
|
|
8358
|
+
return {"kind": "live", "dir": d, "base": base, "worker": t.get("worker"),
|
|
8359
|
+
"shared_with": others}
|
|
8360
|
+
ref = work_ref(st, tid)
|
|
8361
|
+
if ref:
|
|
8362
|
+
sha = _rsha(ROOT, ref)
|
|
8363
|
+
if sha and shared and _rsha(ROOT, sha + "^2"): # a stash: files git knew, plus the new ones (3rd parent)
|
|
8364
|
+
pairs = [(_rsha(ROOT, sha + "^1"), sha)]
|
|
8365
|
+
if _rsha(ROOT, sha + "^3"):
|
|
8366
|
+
pairs.append((EMPTY_TREE, _rsha(ROOT, sha + "^3")))
|
|
8367
|
+
return {"kind": "saved", "pairs": pairs, "dir": str(ROOT)}
|
|
8368
|
+
if sha:
|
|
8369
|
+
mb = (_rgit(ROOT, "merge-base", st["branch"], sha) or b"").decode().strip() or _rsha(ROOT, sha + "^")
|
|
8370
|
+
return {"kind": "saved", "pairs": [(mb or EMPTY_TREE, sha)], "dir": str(ROOT)}
|
|
8371
|
+
if status == "pending":
|
|
8372
|
+
return {"kind": "none", "why": "not started yet: no changes yet"}
|
|
8373
|
+
return {"kind": "none", "why": "no changes yet"}
|
|
8374
|
+
|
|
8375
|
+
|
|
8376
|
+
def _parse_numstat(raw):
|
|
8377
|
+
"""`git diff --numstat -z -M` -> [(path, old_path|None, add|None, del|None)] (None counts: a binary file)."""
|
|
8378
|
+
out, parts, i = [], raw.decode(errors="replace").split("\0"), 0
|
|
8379
|
+
while i < len(parts):
|
|
8380
|
+
rec = parts[i]
|
|
8381
|
+
i += 1
|
|
8382
|
+
if not rec:
|
|
8383
|
+
continue
|
|
8384
|
+
f = rec.split("\t", 2)
|
|
8385
|
+
if len(f) < 3:
|
|
8386
|
+
continue
|
|
8387
|
+
a, dl, path = f
|
|
8388
|
+
old = None
|
|
8389
|
+
if path == "" and i + 1 < len(parts): # a rename: the old and the new name follow
|
|
8390
|
+
old, path = parts[i], parts[i + 1]
|
|
8391
|
+
i += 2
|
|
8392
|
+
out.append((path, old, None if a == "-" else int(a), None if dl == "-" else int(dl)))
|
|
8393
|
+
return out
|
|
8394
|
+
|
|
8395
|
+
|
|
8396
|
+
def _parse_status(raw):
|
|
8397
|
+
"""`git diff --name-status -z -M` -> {path: letter} (A added, M changed, D deleted, R renamed, T type)."""
|
|
8398
|
+
out, parts, i = {}, raw.decode(errors="replace").split("\0"), 0
|
|
8399
|
+
while i < len(parts):
|
|
8400
|
+
s = parts[i]
|
|
8401
|
+
i += 1
|
|
8402
|
+
if not s:
|
|
8403
|
+
continue
|
|
8404
|
+
if s[0] in "RC" and i + 1 < len(parts):
|
|
8405
|
+
out[parts[i + 1]] = s[0]
|
|
8406
|
+
i += 2
|
|
8407
|
+
elif i < len(parts):
|
|
8408
|
+
out[parts[i]] = s[0]
|
|
8409
|
+
i += 1
|
|
8410
|
+
return out
|
|
8411
|
+
|
|
8412
|
+
|
|
8413
|
+
def _skip_path(p):
|
|
8414
|
+
return p.startswith((TASK_DIR + "/", ".orchestrate/")) or p in (TASK_DIR, ".orchestrate")
|
|
8415
|
+
|
|
8416
|
+
|
|
8417
|
+
def _new_file_lines(path):
|
|
8418
|
+
"""(lines, binary) of a file git does not know yet, reading at most CHANGES_MAX_READ bytes."""
|
|
8419
|
+
try:
|
|
8420
|
+
with open(path, "rb") as fh:
|
|
8421
|
+
b = fh.read(CHANGES_MAX_READ)
|
|
8422
|
+
except OSError:
|
|
8423
|
+
return 0, False
|
|
8424
|
+
if b"\0" in b[:8000]:
|
|
8425
|
+
return None, True
|
|
8426
|
+
return b.count(b"\n") + (1 if b and not b.endswith(b"\n") else 0), False
|
|
8427
|
+
|
|
8428
|
+
|
|
8429
|
+
def milestone_files(src):
|
|
8430
|
+
"""The files a changes_source() changed: (files, error). Each file: {path, old, status, add, del, untracked}."""
|
|
8431
|
+
files, seen = [], set()
|
|
8432
|
+
if src["kind"] == "none":
|
|
8433
|
+
return [], None
|
|
8434
|
+
if src["kind"] == "live":
|
|
8435
|
+
d, base = src["dir"], src["base"]
|
|
8436
|
+
pairs = [((base,), d)]
|
|
8437
|
+
else:
|
|
8438
|
+
d = src["dir"]
|
|
8439
|
+
pairs = [((a, b), d) for a, b in src["pairs"]]
|
|
8440
|
+
for revs, where in pairs:
|
|
8441
|
+
ns = _rgit(where, "diff", "--no-ext-diff", "--no-textconv", "-M", "-z", "--numstat", *revs, "--")
|
|
8442
|
+
st_ = _rgit(where, "diff", "--no-ext-diff", "--no-textconv", "-M", "-z", "--name-status", *revs, "--")
|
|
8443
|
+
if ns is None or st_ is None:
|
|
8444
|
+
return files, f"git could not compare {' and '.join(r[:12] for r in revs)} in {where}"
|
|
8445
|
+
letters = _parse_status(st_)
|
|
8446
|
+
for path, old, a, dl in _parse_numstat(ns):
|
|
8447
|
+
if _skip_path(path) or path in seen:
|
|
8448
|
+
continue
|
|
8449
|
+
seen.add(path)
|
|
8450
|
+
files.append({"path": path, "old": old, "status": letters.get(path, "M"), "add": a, "del": dl,
|
|
8451
|
+
"untracked": False})
|
|
8452
|
+
if src["kind"] == "live":
|
|
8453
|
+
raw = _rgit(src["dir"], "ls-files", "-z", "--others", "--exclude-standard")
|
|
8454
|
+
for path in (raw or b"").decode(errors="replace").split("\0"):
|
|
8455
|
+
if not path or _skip_path(path) or path in seen:
|
|
8456
|
+
continue
|
|
8457
|
+
seen.add(path)
|
|
8458
|
+
n, binary = _new_file_lines(os.path.join(src["dir"], path)) if len(files) < CHANGES_MAX_FILES else (0, False)
|
|
8459
|
+
files.append({"path": path, "old": None, "status": "A", "add": n, "del": None if binary else 0,
|
|
8460
|
+
"untracked": True})
|
|
8461
|
+
files.sort(key=lambda f: (os.path.dirname(f["path"]), os.path.basename(f["path"])))
|
|
8462
|
+
return files, None
|
|
8463
|
+
|
|
8464
|
+
|
|
8465
|
+
def milestone_changes(st, tid):
|
|
8466
|
+
"""Mn's changed files as one dict (the shape `orch changes --json` and `orch view` use)."""
|
|
8467
|
+
t = st["tasks"].get(tid) or {}
|
|
8468
|
+
src = changes_source(st, tid)
|
|
8469
|
+
files, err = milestone_files(src)
|
|
8470
|
+
more = max(0, len(files) - CHANGES_MAX_FILES)
|
|
8471
|
+
shown = files[:CHANGES_MAX_FILES]
|
|
8472
|
+
words = {"live": "live: what the coder has changed so far, unsaved files included",
|
|
8473
|
+
"saved": "saved work, not landed yet",
|
|
8474
|
+
"landed": "landed: what it added to the feature branch",
|
|
8475
|
+
"none": src.get("why", "no changes yet")}
|
|
8476
|
+
note = words[src["kind"]]
|
|
8477
|
+
if src.get("shared_with"):
|
|
8478
|
+
note += f" (the folder is shared with {', '.join(src['shared_with'])}: their unsaved files show here too)"
|
|
8479
|
+
return {"id": tid, "title": t.get("title", tid), "status": t.get("status", "pending"),
|
|
8480
|
+
"group": VIEW_GROUPS.get(t.get("status"), "waiting"), "kind": src["kind"], "note": note,
|
|
8481
|
+
"worker": t.get("worker") if src["kind"] == "live" else None,
|
|
8482
|
+
"dir": src.get("dir"), "commit": src.get("commit"), "error": err,
|
|
8483
|
+
"files": shown, "more": more,
|
|
8484
|
+
"totals": {"files": len(files), "add": sum(f["add"] or 0 for f in files),
|
|
8485
|
+
"del": sum(f["del"] or 0 for f in files)}}
|
|
8486
|
+
|
|
8487
|
+
|
|
8488
|
+
def file_diff(st, tid, path):
|
|
8489
|
+
"""The diff of one file Mn changed: (lines, error). The path must be one of Mn's changed files, so nothing else
|
|
8490
|
+
(another folder, a file outside the repo) can be read through it."""
|
|
8491
|
+
src = changes_source(st, tid)
|
|
8492
|
+
files, err = milestone_files(src)
|
|
8493
|
+
f = next((x for x in files if x["path"] == path), None)
|
|
8494
|
+
if f is None:
|
|
8495
|
+
return [], err or f"{path} is not one of {tid}'s changed files (any more)"
|
|
8496
|
+
paths = [path] + ([f["old"]] if f.get("old") else [])
|
|
8497
|
+
if f["untracked"]:
|
|
8498
|
+
full = os.path.join(src["dir"], path)
|
|
8499
|
+
n, binary = _new_file_lines(full)
|
|
8500
|
+
head = [f"new file {path} (not added to git yet)"]
|
|
8501
|
+
if binary:
|
|
8502
|
+
return head + ["Binary file: not shown."], None
|
|
8503
|
+
try:
|
|
8504
|
+
with open(full, "rb") as fh:
|
|
8505
|
+
text = fh.read(CHANGES_MAX_READ).decode(errors="replace")
|
|
8506
|
+
except OSError as e:
|
|
8507
|
+
return head, f"could not read {path}: {e}"
|
|
8508
|
+
body = ["+" + ln for ln in text.splitlines()]
|
|
8509
|
+
return head + [f"@@ -0,0 +1,{n} @@"] + body, None
|
|
8510
|
+
if src["kind"] == "live":
|
|
8511
|
+
out = _rgit(src["dir"], "diff", "--no-ext-diff", "--no-textconv", "-M", src["base"], "--", *paths)
|
|
8512
|
+
else:
|
|
8513
|
+
out = None
|
|
8514
|
+
for a, b in src["pairs"]:
|
|
8515
|
+
got = _rgit(src["dir"], "diff", "--no-ext-diff", "--no-textconv", "-M", a, b, "--", *paths)
|
|
8516
|
+
if got:
|
|
8517
|
+
out = got
|
|
8518
|
+
break
|
|
8519
|
+
if out is None:
|
|
8520
|
+
return [], f"git could not show the diff of {path}"
|
|
8521
|
+
lines = out.decode(errors="replace").splitlines()
|
|
8522
|
+
return lines or [f"{path}: no line changes (mode or name only)"], None
|
|
8523
|
+
|
|
8524
|
+
|
|
8525
|
+
def changes_tree_lines(ch, width=100, color=True, sel=None):
|
|
8526
|
+
"""The changed files as a folder tree with +/- counts and A/M/D marks; returns (lines, row of each file)."""
|
|
8527
|
+
def c(k, s):
|
|
8528
|
+
return f"\x1b[{_C[k]}m{s}\x1b[0m" if color and k else s
|
|
8529
|
+
out, rows, last_dir = [], [], None
|
|
8530
|
+
num_w = 16
|
|
8531
|
+
for i, f in enumerate(ch["files"]):
|
|
8532
|
+
d = os.path.dirname(f["path"])
|
|
8533
|
+
if d != last_dir:
|
|
8534
|
+
out.append(c("d", (d + "/") if d else "./"))
|
|
8535
|
+
last_dir = d
|
|
8536
|
+
name = os.path.basename(f["path"]) + (f" ← {f['old']}" if f.get("old") else "")
|
|
8537
|
+
plain = "binary" if f["add"] is None else f"+{f['add']} −{f['del'] or 0}"
|
|
8538
|
+
nums = c("d", "binary") if f["add"] is None else c("g", f"+{f['add']}") + " " + c("r", f"−{f['del'] or 0}")
|
|
8539
|
+
mark = "U" if f["untracked"] else f["status"] # U: new, not added to git yet (as VS Code marks it)
|
|
8540
|
+
room = max(10, min(64, width - num_w - 8))
|
|
8541
|
+
name = name if len(name) <= room else "…" + name[-(room - 1):]
|
|
8542
|
+
out.append(("› " if sel == i else " ") + " " + name.ljust(room) + " " * max(1, num_w - len(plain)) + nums
|
|
8543
|
+
+ " " + c({"A": "g", "D": "r"}.get(f["status"], "a"), mark))
|
|
8544
|
+
rows.append(len(out) - 1)
|
|
8545
|
+
return out, rows
|
|
8546
|
+
|
|
8547
|
+
|
|
8262
8548
|
def _fmt_min(s):
|
|
8263
8549
|
if s is None:
|
|
8264
8550
|
return "?"
|
|
@@ -8290,11 +8576,8 @@ def render_board(vm, width=100, color=True, sel=None, note=""):
|
|
|
8290
8576
|
out += notes
|
|
8291
8577
|
out += ["", c("d", "MILESTONES")]
|
|
8292
8578
|
ms = {m["id"]: m for m in vm["milestones"]}
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
for d in m["deps"][:1]:
|
|
8296
|
-
kids.setdefault(d, []).append(m["id"])
|
|
8297
|
-
shown = set()
|
|
8579
|
+
rows = board_rows(vm)
|
|
8580
|
+
picked = rows[sel] if sel is not None and sel < len(rows) else None
|
|
8298
8581
|
name_w = max(18, min(34, width - 52))
|
|
8299
8582
|
|
|
8300
8583
|
def line(m, pre, sub):
|
|
@@ -8307,34 +8590,22 @@ def render_board(vm, width=100, color=True, sel=None, note=""):
|
|
|
8307
8590
|
word = "waits for " + ",".join(d for d in m["deps"] if ms.get(d, {}).get("group") != "landed") \
|
|
8308
8591
|
if any(ms.get(d, {}).get("group") != "landed" for d in m["deps"]) else "ready"
|
|
8309
8592
|
head = cut(f"{pre}{_GROUP_ICON[g]} {m['id']} {m['title']}", name_w + 8)
|
|
8310
|
-
out.append(
|
|
8593
|
+
out.append(("›" if picked == ("m", m["id"]) else " ")
|
|
8594
|
+
+ head.ljust(name_w + 9).replace(_GROUP_ICON[g], c(_GROUP_C[g], _GROUP_ICON[g]), 1)
|
|
8311
8595
|
+ c(_GROUP_C[g], word.ljust(16) if g != "needs_you" else "NEEDS YOU".ljust(16))
|
|
8312
8596
|
+ c("d", f"{who} {extra}".rstrip()))
|
|
8313
8597
|
if m["desc"] and m["desc"] != m["title"]:
|
|
8314
|
-
out.append(sub + c("d", cut(m["desc"], width - len(sub) -
|
|
8598
|
+
out.append(" " + sub + c("d", cut(m["desc"], width - len(sub) - 2)))
|
|
8315
8599
|
if m["group"] == "needs_you" and (m.get("question") or m.get("reason")):
|
|
8316
|
-
out.append(sub + c("r", cut(f"\"{m.get('question') or m.get('reason')}\"", width - len(sub) -
|
|
8600
|
+
out.append(" " + sub + c("r", cut(f"\"{m.get('question') or m.get('reason')}\"", width - len(sub) - 2)))
|
|
8317
8601
|
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
return
|
|
8321
|
-
shown.add(tid)
|
|
8322
|
-
conn = "" if depth == 0 else ("└─ " if last else "├─ ")
|
|
8323
|
-
cont = prefix + ("" if depth == 0 else (" " if last else "│ "))
|
|
8324
|
-
line(ms[tid], prefix + conn, cont + " ")
|
|
8325
|
-
ch = [k for k in kids.get(tid, []) if k not in shown]
|
|
8326
|
-
for i, k in enumerate(ch):
|
|
8327
|
-
walk(k, cont, i == len(ch) - 1, depth + 1)
|
|
8328
|
-
for m in vm["milestones"]:
|
|
8329
|
-
if not any(d in ms for d in m["deps"][:1]):
|
|
8330
|
-
walk(m["id"], "", True, 0)
|
|
8331
|
-
for m in vm["milestones"]:
|
|
8332
|
-
walk(m["id"], "", True, 0)
|
|
8602
|
+
for tid, pre, sub in board_tree(vm):
|
|
8603
|
+
line(ms[tid], pre, sub)
|
|
8333
8604
|
out += ["", c("d", "AGENTS")]
|
|
8334
8605
|
for i, a in enumerate(vm["agents"]):
|
|
8335
8606
|
busy = a.get("task") or a["role"] == "lead"
|
|
8336
8607
|
col = "a" if a["role"] == "lead" else ("p" if a["role"] == "reviewer" else "b") if a.get("task") else "d"
|
|
8337
|
-
mark = "›" if
|
|
8608
|
+
mark = "›" if picked == ("a", i) else " "
|
|
8338
8609
|
out.append(f"{mark}{c(col, '◆' if a['role'] == 'lead' else '●' if busy else '○')} "
|
|
8339
8610
|
f"{a['name']:<12} {str(a.get('kind') or ''):<8} {str(a.get('tier') or ''):<7} "
|
|
8340
8611
|
+ c(col if busy else "d", (f"{a['task']} · " if a.get("task") else "") + a["state"]))
|
|
@@ -8345,26 +8616,223 @@ def render_board(vm, width=100, color=True, sel=None, note=""):
|
|
|
8345
8616
|
+ (c("d", f" {cut(e.get('why') or '', 50)}") if e.get("why") else ""))
|
|
8346
8617
|
if note:
|
|
8347
8618
|
out += ["", c("a", note)]
|
|
8348
|
-
out += ["", c("d", "[↑↓] pick
|
|
8619
|
+
out += ["", c("d", "[↑↓] pick [enter] a milestone's changed files / jump to an agent [f] changed files "
|
|
8620
|
+
"[w] web view [q] close")]
|
|
8349
8621
|
return out
|
|
8350
8622
|
|
|
8351
8623
|
|
|
8352
|
-
def
|
|
8353
|
-
"""
|
|
8354
|
-
|
|
8624
|
+
def board_tree(vm):
|
|
8625
|
+
"""The milestones in the board's order, as a tree under each one's first dependency: [(id, prefix, sub-prefix)]."""
|
|
8626
|
+
ms = {m["id"]: m for m in vm.get("milestones", [])}
|
|
8627
|
+
kids, shown, rows = {}, set(), []
|
|
8628
|
+
for m in vm.get("milestones", []):
|
|
8629
|
+
for d in m["deps"][:1]:
|
|
8630
|
+
kids.setdefault(d, []).append(m["id"])
|
|
8631
|
+
|
|
8632
|
+
def walk(tid, prefix, last, depth):
|
|
8633
|
+
if tid in shown:
|
|
8634
|
+
return
|
|
8635
|
+
shown.add(tid)
|
|
8636
|
+
conn = "" if depth == 0 else ("└─ " if last else "├─ ")
|
|
8637
|
+
cont = prefix + ("" if depth == 0 else (" " if last else "│ "))
|
|
8638
|
+
rows.append((tid, prefix + conn, cont + " "))
|
|
8639
|
+
ch = [k for k in kids.get(tid, []) if k not in shown]
|
|
8640
|
+
for i, k in enumerate(ch):
|
|
8641
|
+
walk(k, cont, i == len(ch) - 1, depth + 1)
|
|
8642
|
+
for m in vm.get("milestones", []):
|
|
8643
|
+
if not any(d in ms for d in m["deps"][:1]):
|
|
8644
|
+
walk(m["id"], "", True, 0)
|
|
8645
|
+
for m in vm.get("milestones", []):
|
|
8646
|
+
walk(m["id"], "", True, 0)
|
|
8647
|
+
return rows
|
|
8648
|
+
|
|
8649
|
+
|
|
8650
|
+
def board_rows(vm):
|
|
8651
|
+
"""What [↑↓] moves through on the board: every milestone (board order), then every agent."""
|
|
8652
|
+
return [("m", tid) for tid, _, _ in board_tree(vm)] + [("a", i) for i in range(len(vm.get("agents", [])))]
|
|
8653
|
+
|
|
8654
|
+
|
|
8655
|
+
def board_default_milestone(vm, row=None):
|
|
8656
|
+
"""The milestone [f] opens: the picked one, the picked agent's, else one being built, one that needs you, the
|
|
8657
|
+
last landed, or the first."""
|
|
8658
|
+
if row and row[0] == "m":
|
|
8659
|
+
return row[1]
|
|
8660
|
+
if row and row[0] == "a":
|
|
8661
|
+
a = vm["agents"][row[1]]
|
|
8662
|
+
if a.get("task"):
|
|
8663
|
+
return a["task"]
|
|
8664
|
+
ms = vm.get("milestones", [])
|
|
8665
|
+
for groups in (("building", "checking", "review", "landing"), ("needs_you",)):
|
|
8666
|
+
m = next((m for m in ms if m["group"] in groups), None)
|
|
8667
|
+
if m:
|
|
8668
|
+
return m["id"]
|
|
8669
|
+
landed = [m for m in ms if m["group"] == "landed"]
|
|
8670
|
+
return (landed[-1] if landed else ms[0])["id"] if ms else None
|
|
8671
|
+
|
|
8672
|
+
|
|
8673
|
+
def board_error_lines(e, what="this run", back="[q] close"):
|
|
8674
|
+
"""What the live board shows when drawing failed, instead of ending (herdr would close the popup and the error
|
|
8675
|
+
with it). The full traceback is saved for a bug report; the board tries again when the run changes."""
|
|
8355
8676
|
import traceback
|
|
8356
8677
|
tb = traceback.format_exc()
|
|
8357
8678
|
saved = share_dir() / "board-error.log"
|
|
8358
8679
|
with contextlib.suppress(OSError):
|
|
8359
8680
|
share_dir().mkdir(parents=True, exist_ok=True)
|
|
8360
8681
|
saved.write_text(f"{time.strftime('%Y-%m-%d %H:%M:%S')} orch {installed_version()} in {ROOT}\n{tb}")
|
|
8361
|
-
return ["orch board", "", f"The board could not draw
|
|
8682
|
+
return ["orch board", "", f"The board could not draw {what}: {type(e).__name__}: {e}",
|
|
8362
8683
|
f"The full error is saved in {saved}: please send it with a bug report.",
|
|
8363
|
-
"It tries again when the run changes.
|
|
8684
|
+
f"It tries again when the run changes. {back}"]
|
|
8685
|
+
|
|
8686
|
+
|
|
8687
|
+
_CTRL = re.compile(r"[\x00-\x08\x0b-\x1f\x7f-\x9f]")
|
|
8688
|
+
|
|
8689
|
+
|
|
8690
|
+
def _safe(s, width=None):
|
|
8691
|
+
"""A file name or diff line made safe to print: no escape codes from the file reach the terminal."""
|
|
8692
|
+
s = _CTRL.sub("·", str(s).expandtabs(4))
|
|
8693
|
+
return s if width is None or len(s) <= width else s[:max(0, width - 1)] + "…"
|
|
8694
|
+
|
|
8695
|
+
|
|
8696
|
+
def _board_state():
|
|
8697
|
+
return migrate(json.loads(STATE.read_text()))
|
|
8698
|
+
|
|
8699
|
+
|
|
8700
|
+
def render_changes(ch, width=100, height=40, color=True, sel=0, top=0):
|
|
8701
|
+
"""The board's changed-files screen for one milestone. Returns (lines, top): top keeps the picked file in view."""
|
|
8702
|
+
def c(k, s):
|
|
8703
|
+
return f"\x1b[{_C[k]}m{s}\x1b[0m" if color and k else s
|
|
8704
|
+
g = ch["group"]
|
|
8705
|
+
head = [c("a", "orch board · changed files") + c("d", f" {time.strftime('%H:%M')}"
|
|
8706
|
+
+ (" · live" if ch["kind"] == "live" else "")),
|
|
8707
|
+
c(_GROUP_C.get(g, "d"), f"{_GROUP_ICON.get(g, '○')} ") + c("B", _safe(f"{ch['id']} {ch['title']}", width - 30))
|
|
8708
|
+
+ c("d", f" {VIEW_WORDS.get(ch['status'], ch['status'])}" + (f" · {ch['worker']}" if ch.get("worker") else "")),
|
|
8709
|
+
c("d", _safe(ch["note"], width))]
|
|
8710
|
+
tot = ch["totals"]
|
|
8711
|
+
if ch["files"]:
|
|
8712
|
+
head.append(c("B", f"{tot['files']} file{'s' if tot['files'] != 1 else ''} ") + c("g", f"+{tot['add']}")
|
|
8713
|
+
+ " " + c("r", f"−{tot['del']}"))
|
|
8714
|
+
if ch.get("error"):
|
|
8715
|
+
head.append(c("r", _safe(ch["error"], width)))
|
|
8716
|
+
foot = ["", c("d", "A added · M changed · D deleted · R renamed · U new, not added to git yet"),
|
|
8717
|
+
c("d", "[↑↓] pick file [enter] its diff [←→] other milestone [q] back")]
|
|
8718
|
+
if not ch["files"]:
|
|
8719
|
+
return head + ["", "No changed files to show." if ch["kind"] != "none" else "Nothing to show yet."] + foot, 0
|
|
8720
|
+
body, rows = changes_tree_lines({**ch, "files": [{**f, "path": _safe(f["path"]), "old": f["old"] and _safe(f["old"])}
|
|
8721
|
+
for f in ch["files"]]}, width, color, sel)
|
|
8722
|
+
if ch.get("more"):
|
|
8723
|
+
body.append(c("d", f"… and {ch['more']} more files (`orch changes {ch['id']}` lists them all)"))
|
|
8724
|
+
room = max(3, height - len(head) - len(foot) - 1)
|
|
8725
|
+
r = rows[min(sel, len(rows) - 1)]
|
|
8726
|
+
if r < top:
|
|
8727
|
+
top = max(0, r - 1) # keep the file's folder line in view too
|
|
8728
|
+
elif r >= top + room:
|
|
8729
|
+
top = r - room + 1
|
|
8730
|
+
top = max(0, min(top, max(0, len(body) - room)))
|
|
8731
|
+
shown = body[top:top + room]
|
|
8732
|
+
if top > 0:
|
|
8733
|
+
shown[0] = c("d", f" ↑ {top} more")
|
|
8734
|
+
if top + room < len(body):
|
|
8735
|
+
shown[-1] = c("d", f" ↓ {len(body) - top - room + 1} more")
|
|
8736
|
+
return head + [""] + shown + foot, top
|
|
8737
|
+
|
|
8738
|
+
|
|
8739
|
+
def render_diff(ch, f, lines, width=100, height=40, color=True, top=0, err=None):
|
|
8740
|
+
"""The board's diff screen for one file: coloured, cut to the width, scrolled to top. Returns (lines, top)."""
|
|
8741
|
+
def c(k, s):
|
|
8742
|
+
return f"\x1b[{_C[k]}m{s}\x1b[0m" if color and k else s
|
|
8743
|
+
nums = "binary" if f["add"] is None else f"+{f['add']} −{f['del'] or 0}"
|
|
8744
|
+
head = [c("a", "orch board · diff") + c("d", f" {ch['id']} {_safe(ch['title'], 40)}"
|
|
8745
|
+
+ (" · live" if ch["kind"] == "live" else "")),
|
|
8746
|
+
c("B", _safe(f["path"], width - len(nums) - 6)) + " " + c("d", f"{nums} {f['status']}")]
|
|
8747
|
+
if err:
|
|
8748
|
+
head.append(c("r", _safe(err, width)))
|
|
8749
|
+
foot = ["", c("d", "[↑↓] scroll [space] page down [u] page up [q] back to the files")]
|
|
8750
|
+
room = max(3, height - len(head) - len(foot) - 1)
|
|
8751
|
+
body = lines[:CHANGES_MAX_DIFF]
|
|
8752
|
+
if len(lines) > CHANGES_MAX_DIFF:
|
|
8753
|
+
body.append(f"… cut at {CHANGES_MAX_DIFF} lines: see the rest with `orch changes {ch['id']} {f['path']}`")
|
|
8754
|
+
top = max(0, min(top, max(0, len(body) - room)))
|
|
8755
|
+
|
|
8756
|
+
def paint(ln):
|
|
8757
|
+
t = _safe(ln, width - 1)
|
|
8758
|
+
if ln.startswith(("+++", "---", "diff --git", "index ", "new file", "deleted file", "similarity", "rename ")):
|
|
8759
|
+
return c("d", t)
|
|
8760
|
+
return c("g", t) if ln.startswith("+") else c("r", t) if ln.startswith("-") else \
|
|
8761
|
+
c("t", t) if ln.startswith("@@") else t
|
|
8762
|
+
shown = [paint(ln) for ln in body[top:top + room]]
|
|
8763
|
+
if top + room < len(body):
|
|
8764
|
+
shown.append(c("d", f" ↓ {len(body) - top - room} more lines ({top + 1}-{top + room} of {len(body)})"))
|
|
8765
|
+
return head + [""] + shown + foot, top
|
|
8766
|
+
|
|
8767
|
+
|
|
8768
|
+
def _board_key(fd, select):
|
|
8769
|
+
ch = os.read(fd, 8).decode(errors="ignore")
|
|
8770
|
+
if ch == "\x1b" and select.select([sys.stdin], [], [], 0.05)[0]:
|
|
8771
|
+
ch += os.read(fd, 8).decode(errors="ignore") # the rest of an escape sequence, not the Esc key
|
|
8772
|
+
return {"\x1bOA": "\x1b[A", "\x1bOB": "\x1b[B", "\x1bOC": "\x1b[C", "\x1bOD": "\x1b[D"}.get(ch, ch)
|
|
8773
|
+
|
|
8774
|
+
|
|
8775
|
+
UP, DOWN, RIGHT, LEFT, PGDN, PGUP = "\x1b[A", "\x1b[B", "\x1b[C", "\x1b[D", "\x1b[6~", "\x1b[5~"
|
|
8776
|
+
|
|
8777
|
+
|
|
8778
|
+
def cmd_changes(args):
|
|
8779
|
+
"""orch changes [Mn [file]] [--json] [--no-color] -> what each milestone changed (read-only git)."""
|
|
8780
|
+
as_json = "--json" in args
|
|
8781
|
+
color = "--no-color" not in args and sys.stdout.isatty() and not os.environ.get("NO_COLOR")
|
|
8782
|
+
rest = [a for a in args if a not in ("--json", "--no-color")]
|
|
8783
|
+
st = load()
|
|
8784
|
+
width = shutil.get_terminal_size((100, 40)).columns
|
|
8785
|
+
if not rest:
|
|
8786
|
+
allc = [milestone_changes(st, tid) for tid in st["order"]]
|
|
8787
|
+
if as_json:
|
|
8788
|
+
print(json.dumps({"milestones": allc}, indent=1))
|
|
8789
|
+
return
|
|
8790
|
+
for ch in allc:
|
|
8791
|
+
tot = ch["totals"]
|
|
8792
|
+
print(f"{ch['id']:<4} {_safe(ch['title'], 34):<34} " + (
|
|
8793
|
+
f"{tot['files']:>3} file{'s' if tot['files'] != 1 else ''} +{tot['add']} −{tot['del']} ({ch['kind']})"
|
|
8794
|
+
if ch["files"] else ch["note"]))
|
|
8795
|
+
print("\n`orch changes Mn` lists a milestone's files, `orch changes Mn <file>` shows one file's diff")
|
|
8796
|
+
return
|
|
8797
|
+
tid = rest[0]
|
|
8798
|
+
if tid not in st["tasks"]:
|
|
8799
|
+
die(f"no milestone {tid} in this run (`orch status` lists them)")
|
|
8800
|
+
if len(rest) > 1:
|
|
8801
|
+
lines, err = file_diff(st, tid, rest[1])
|
|
8802
|
+
if as_json:
|
|
8803
|
+
print(json.dumps({"id": tid, "path": rest[1], "lines": lines, "error": err}, indent=1))
|
|
8804
|
+
else:
|
|
8805
|
+
for ln in lines:
|
|
8806
|
+
t = _safe(ln)
|
|
8807
|
+
print(t if not color else f"\x1b[32m{t}\x1b[0m" if ln.startswith("+") and not ln.startswith("+++")
|
|
8808
|
+
else f"\x1b[31m{t}\x1b[0m" if ln.startswith("-") and not ln.startswith("---")
|
|
8809
|
+
else f"\x1b[36m{t}\x1b[0m" if ln.startswith("@@") else t)
|
|
8810
|
+
if err:
|
|
8811
|
+
die(err)
|
|
8812
|
+
return
|
|
8813
|
+
ch = milestone_changes(st, tid)
|
|
8814
|
+
if as_json:
|
|
8815
|
+
print(json.dumps(ch, indent=1))
|
|
8816
|
+
return
|
|
8817
|
+
tot = ch["totals"]
|
|
8818
|
+
print(_safe(f"{tid} {ch['title']} · {VIEW_WORDS.get(ch['status'], ch['status'])}"
|
|
8819
|
+
+ (f" · {ch['worker']}" if ch.get("worker") else "")))
|
|
8820
|
+
print(_safe(ch["note"]))
|
|
8821
|
+
if ch["files"]:
|
|
8822
|
+
print(f"{tot['files']} file{'s' if tot['files'] != 1 else ''} +{tot['add']} −{tot['del']}\n")
|
|
8823
|
+
body, _ = changes_tree_lines({**ch, "files": [{**f, "path": _safe(f["path"]),
|
|
8824
|
+
"old": f["old"] and _safe(f["old"])} for f in ch["files"]]},
|
|
8825
|
+
width, color)
|
|
8826
|
+
print("\n".join(body))
|
|
8827
|
+
if ch["more"]:
|
|
8828
|
+
print(f"… and {ch['more']} more files")
|
|
8829
|
+
if ch.get("error"):
|
|
8830
|
+
die(ch["error"])
|
|
8364
8831
|
|
|
8365
8832
|
|
|
8366
8833
|
def cmd_board(args):
|
|
8367
|
-
"""orch board [--once] [--no-color] -> the run as text, redrawn when it changes (for a herdr pane or popup).
|
|
8834
|
+
"""orch board [--once] [--no-color] -> the run as text, redrawn when it changes (for a herdr pane or popup).
|
|
8835
|
+
[f] or [enter] on a milestone opens its changed files, [enter] on a file its diff; q goes back one screen."""
|
|
8368
8836
|
# live needs a keyboard and a screen: with stdin or stdout not a terminal, draw once (termios would fail)
|
|
8369
8837
|
once = "--once" in args or not (sys.stdout.isatty() and sys.stdin.isatty())
|
|
8370
8838
|
color = "--no-color" not in args and sys.stdout.isatty() and not os.environ.get("NO_COLOR")
|
|
@@ -8376,49 +8844,108 @@ def cmd_board(args):
|
|
|
8376
8844
|
import tty
|
|
8377
8845
|
fd = sys.stdin.fileno()
|
|
8378
8846
|
old = termios.tcgetattr(fd)
|
|
8379
|
-
sel, note, last,
|
|
8847
|
+
sel, note, last, fetched = None, "", None, 0.0
|
|
8380
8848
|
opened, closed_by = time.time(), "an interrupt"
|
|
8849
|
+
screen, vm, need, redraw = "run", {}, True, True # need: read the run (and git) again; redraw: draw again
|
|
8850
|
+
mid, ch, fsel, ftop = None, None, 0, 0 # the changed-files screen: milestone, its changes, picked file, scroll
|
|
8851
|
+
dfile, dlines, derr, dtop = None, [], None, 0 # the diff screen
|
|
8381
8852
|
try:
|
|
8382
8853
|
tty.setcbreak(fd)
|
|
8383
8854
|
sys.stdout.write("\x1b[?1049h\x1b[?25l")
|
|
8384
8855
|
while True:
|
|
8385
8856
|
k = _view_snapshot_key()
|
|
8386
|
-
|
|
8387
|
-
|
|
8857
|
+
live = screen != "run" and ch is not None and ch["kind"] == "live"
|
|
8858
|
+
if k != last or time.time() - fetched > (2 if live else 30): # a coder's unsaved files: look every 2s
|
|
8859
|
+
last, need = k, True
|
|
8860
|
+
if need or redraw:
|
|
8388
8861
|
size = shutil.get_terminal_size((100, 40))
|
|
8389
8862
|
try:
|
|
8390
|
-
|
|
8391
|
-
|
|
8863
|
+
if need:
|
|
8864
|
+
fetched = time.time()
|
|
8865
|
+
vm = view_model()
|
|
8866
|
+
if screen != "run":
|
|
8867
|
+
st = _board_state()
|
|
8868
|
+
ch = milestone_changes(st, mid)
|
|
8869
|
+
if screen == "diff":
|
|
8870
|
+
dlines, derr = file_diff(st, mid, dfile["path"])
|
|
8871
|
+
need = redraw = False
|
|
8872
|
+
if screen == "run":
|
|
8873
|
+
lines = render_board(vm, size.columns, color, sel, note)
|
|
8874
|
+
elif screen == "files":
|
|
8875
|
+
fsel = min(fsel, max(0, len(ch["files"]) - 1))
|
|
8876
|
+
lines, ftop = render_changes(ch, size.columns, size.lines, color, fsel, ftop)
|
|
8877
|
+
else:
|
|
8878
|
+
f = next((x for x in ch["files"] if x["path"] == dfile["path"]), dfile)
|
|
8879
|
+
lines, dtop = render_diff(ch, f, dlines, size.columns, size.lines, color, dtop, derr)
|
|
8392
8880
|
except Exception as e: # noqa: BLE001 - a popup closes when its program ends: show it, keep going
|
|
8393
|
-
|
|
8394
|
-
lines = board_error_lines(e
|
|
8881
|
+
need = redraw = False
|
|
8882
|
+
lines = board_error_lines(e, "this run" if screen == "run" else f"{mid}'s changes",
|
|
8883
|
+
"[q] close" if screen == "run" else "[q] back")
|
|
8395
8884
|
sys.stdout.write("\x1b[H\x1b[2J" + "\n".join(lines[:size.lines]))
|
|
8396
8885
|
sys.stdout.flush()
|
|
8397
8886
|
r, _, _ = select.select([sys.stdin], [], [], 0.5)
|
|
8398
8887
|
if not r:
|
|
8399
8888
|
continue
|
|
8400
|
-
|
|
8401
|
-
if ch == "\x1b" and select.select([sys.stdin], [], [], 0.05)[0]:
|
|
8402
|
-
ch += os.read(fd, 8).decode(errors="ignore") # the rest of an escape sequence, not the Esc key
|
|
8889
|
+
key = _board_key(fd, select)
|
|
8403
8890
|
if time.time() - opened < 0.5:
|
|
8404
8891
|
continue # what a terminal sends as a pane opens (focus or size replies) is not a key press
|
|
8405
|
-
|
|
8406
|
-
if
|
|
8407
|
-
|
|
8892
|
+
size = shutil.get_terminal_size((100, 40))
|
|
8893
|
+
if screen == "diff":
|
|
8894
|
+
page = max(3, size.lines - 8)
|
|
8895
|
+
if key in ("q", "Q", "\x1b", LEFT, "h"):
|
|
8896
|
+
screen, need = "files", True
|
|
8897
|
+
elif key in (UP, "k"):
|
|
8898
|
+
dtop = max(0, dtop - 1)
|
|
8899
|
+
elif key in (DOWN, "j"):
|
|
8900
|
+
dtop += 1
|
|
8901
|
+
elif key in (" ", PGDN):
|
|
8902
|
+
dtop += page
|
|
8903
|
+
elif key in ("u", "U", PGUP):
|
|
8904
|
+
dtop = max(0, dtop - page)
|
|
8905
|
+
elif key == "g":
|
|
8906
|
+
dtop = 0
|
|
8907
|
+
redraw = True
|
|
8908
|
+
continue
|
|
8909
|
+
if screen == "files":
|
|
8910
|
+
ids = [m["id"] for m in vm.get("milestones", [])]
|
|
8911
|
+
n = len(ch["files"]) if ch else 0
|
|
8912
|
+
if key in ("q", "Q", "\x1b"):
|
|
8913
|
+
screen, ch, need = "run", None, True
|
|
8914
|
+
elif key in (UP, "k") and n:
|
|
8915
|
+
fsel = max(0, fsel - 1)
|
|
8916
|
+
elif key in (DOWN, "j") and n:
|
|
8917
|
+
fsel = min(n - 1, fsel + 1)
|
|
8918
|
+
elif key in (RIGHT, LEFT, "l", "h", "]", "[") and mid in ids:
|
|
8919
|
+
step = 1 if key in (RIGHT, "l", "]") else -1
|
|
8920
|
+
mid, fsel, ftop, need = ids[(ids.index(mid) + step) % len(ids)], 0, 0, True
|
|
8921
|
+
elif key in ("\r", "\n") and n:
|
|
8922
|
+
dfile, dtop, screen, need = ch["files"][fsel], 0, "diff", True
|
|
8923
|
+
redraw = True
|
|
8924
|
+
continue
|
|
8925
|
+
rows = board_rows(vm)
|
|
8926
|
+
n = len(rows)
|
|
8927
|
+
if key in ("q", "Q", "\x1b"):
|
|
8928
|
+
closed_by = repr(key)
|
|
8408
8929
|
break
|
|
8409
|
-
if
|
|
8930
|
+
if key in (UP, "k"):
|
|
8410
8931
|
sel = (n - 1 if sel is None else max(0, sel - 1)) if n else None
|
|
8411
|
-
elif
|
|
8932
|
+
elif key in (DOWN, "j"):
|
|
8412
8933
|
sel = (0 if sel is None else min(n - 1, sel + 1)) if n else None
|
|
8413
|
-
elif
|
|
8414
|
-
|
|
8934
|
+
elif key in ("f", "F") or (key in ("\r", "\n") and sel is not None and n and rows[sel][0] == "m"):
|
|
8935
|
+
mid = board_default_milestone(vm, rows[sel] if sel is not None and sel < n else None)
|
|
8936
|
+
if mid:
|
|
8937
|
+
screen, ch, fsel, ftop, need = "files", None, 0, 0, True
|
|
8938
|
+
else:
|
|
8939
|
+
note = "no milestones in this run yet"
|
|
8940
|
+
elif key in ("\r", "\n") and sel is not None and n:
|
|
8941
|
+
a = vm["agents"][rows[sel][1]]
|
|
8415
8942
|
r2 = subprocess.run([HERDR, "agent", "focus", a["name"]], text=True, capture_output=True)
|
|
8416
8943
|
note = f"jumped to {a['name']}" if r2.returncode == 0 else f"herdr could not focus {a['name']}"
|
|
8417
|
-
elif
|
|
8944
|
+
elif key in ("w", "W"):
|
|
8418
8945
|
r2 = subprocess.run([sys.executable, os.path.abspath(__file__), "view", "--bg"], text=True,
|
|
8419
8946
|
capture_output=True, cwd=ROOT)
|
|
8420
8947
|
note = (r2.stdout.strip().splitlines() or ["orch view: could not start"])[0]
|
|
8421
|
-
|
|
8948
|
+
redraw = True
|
|
8422
8949
|
except KeyboardInterrupt:
|
|
8423
8950
|
pass
|
|
8424
8951
|
finally:
|
|
@@ -8444,11 +8971,11 @@ COMMANDS = {
|
|
|
8444
8971
|
"report": cmd_report, "events": cmd_events, "dispatch": cmd_dispatch, "answer": cmd_answer, "defer": cmd_defer,
|
|
8445
8972
|
"escalate": cmd_escalate, "fix": cmd_fix, "plan": cmd_plan, "story": cmd_story, "manual": cmd_manual, "team": cmd_team, "bench": cmd_bench, "stop": cmd_stop,
|
|
8446
8973
|
"free": cmd_free, "doctor": lambda a: cmd_doctor_crash(a), "check": lambda a: cmd_check(a), "sub": lambda a: cmd_sub(a),
|
|
8447
|
-
"view": lambda a: cmd_view(a), "board": lambda a: cmd_board(a),
|
|
8974
|
+
"view": lambda a: cmd_view(a), "board": lambda a: cmd_board(a), "changes": lambda a: cmd_changes(a),
|
|
8448
8975
|
}
|
|
8449
8976
|
# they lock per step instead of for the whole command (long-running, or they start the event manager after)
|
|
8450
8977
|
UNLOCKED = {"manual", "autopilot", "poll", "merge", "events", "dispatch", "answer", "defer", "fix", "team", "resume", "bench", "stop",
|
|
8451
|
-
"doctor", "check", "free", "view", "board"}
|
|
8978
|
+
"doctor", "check", "free", "view", "board", "changes"}
|
|
8452
8979
|
|
|
8453
8980
|
USAGE = """usage: orch <command> [args]
|
|
8454
8981
|
version print the installed herdr-orchestra version
|
|
@@ -8514,7 +9041,10 @@ USAGE = """usage: orch <command> [args]
|
|
|
8514
9041
|
"needs you" alert, time and cost, replay. --lan: also from your phone, with a secret link
|
|
8515
9042
|
view stop|status|herdr-config|plugin link|unlink|refresh
|
|
8516
9043
|
stop it / show its link / sidebar lines for herdr's config / the optional herdr plugin
|
|
8517
|
-
board [--once] the run as text, redrawn when it changes: for a herdr pane or popup (any terminal)
|
|
9044
|
+
board [--once] the run as text, redrawn when it changes: for a herdr pane or popup (any terminal);
|
|
9045
|
+
[f] or [enter] on a milestone shows its changed files, [enter] on a file its diff
|
|
9046
|
+
changes [Mn [file]] [--json] what each milestone changed: files with +/- counts, or one file's diff
|
|
9047
|
+
(live while a coder works, unsaved files included; landed = its commit). Read-only
|
|
8518
9048
|
report [--json] estimate vs actual time (why longer, who), rounds, first-pass rate, wasted work, tokens/cost
|
|
8519
9049
|
ready free coder slots, FIX jobs (do these first), then READY milestones
|
|
8520
9050
|
pick <Mn> first available worker for the task (respects Tier, then Prefer), or NONE (exit 3)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "herdr-orchestra",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.32.0",
|
|
4
4
|
"description": "Orchestrate AI coding agents (Claude Code, Codex, OpenCode, Amp, Pi) as one team: a lead plans, coders build, a reviewer checks, you get one PR. Runs in Herdr panes, or in one Pi window with subagents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -19,4 +19,6 @@ title = "orch board"
|
|
|
19
19
|
placement = "popup"
|
|
20
20
|
width = "90%"
|
|
21
21
|
height = "85%"
|
|
22
|
-
|
|
22
|
+
# Herdr starts a popup in the folder given with --cwd (the run's repo) and resolves only a first word with a "/" against
|
|
23
|
+
# the plugin folder, so "board.sh" alone would be looked for in the repo. HERDR_PLUGIN_ROOT is this plugin's folder.
|
|
24
|
+
command = ["sh", "-c", 'exec sh "$HERDR_PLUGIN_ROOT/board.sh"']
|
package/view/index.html
CHANGED
|
@@ -66,6 +66,18 @@ button:hover{border-color:var(--accent)}
|
|
|
66
66
|
.notes{margin:10px 16px 0;padding:8px 12px;border:1px solid var(--accent);border-radius:4px;color:var(--accent);font-size:13px;line-height:1.5}
|
|
67
67
|
.notes div+div{margin-top:4px}
|
|
68
68
|
.empty{padding:60px 20px;text-align:center;color:var(--muted);font-size:14px}
|
|
69
|
+
.chg .dir{font-family:var(--mono);font-size:11.5px;color:var(--faint);margin-top:6px}
|
|
70
|
+
.chg .f{display:grid;grid-template-columns:1fr auto 18px;gap:8px;align-items:center;font-family:var(--mono);font-size:12px;padding:2px 4px 2px 14px;border-radius:3px;cursor:pointer}
|
|
71
|
+
.chg .f:hover{background:var(--s2)}.chg .f .nm{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
72
|
+
.chg .f .st{text-align:center;font-weight:700}.st-A{color:var(--landed)}.st-D{color:var(--bad)}.st-M,.st-R,.st-T{color:var(--accent)}
|
|
73
|
+
.add{color:var(--landed)}.del{color:var(--bad)}
|
|
74
|
+
#diffbox{display:none;position:fixed;inset:4vh 4vw;background:var(--surface);border:1px solid var(--line2);border-radius:5px;z-index:10;flex-direction:column;box-shadow:0 10px 40px #000a}
|
|
75
|
+
#diffbox.on{display:flex}
|
|
76
|
+
#diffbox .dh{display:flex;gap:12px;align-items:center;padding:10px 14px;border-bottom:1px solid var(--line);font-family:var(--mono);font-size:12.5px}
|
|
77
|
+
#diffbox .dh b{font-weight:700}#diffbox .dh button{margin-left:auto}
|
|
78
|
+
#diffbox pre{flex:1;overflow:auto;margin:0;padding:10px 0;font-family:var(--mono);font-size:12px;line-height:1.5}
|
|
79
|
+
#diffbox pre div{padding:0 14px;white-space:pre}
|
|
80
|
+
.dl-a{background:#14261a;color:#b8e6a8}.dl-d{background:#2a1513;color:#f1a49c}.dl-h{color:var(--checking)}.dl-m{color:var(--faint)}
|
|
69
81
|
@media (max-width:820px){
|
|
70
82
|
.grid{grid-template-columns:1fr}.left{border-right:0}
|
|
71
83
|
#ring{display:none}#graphwrap{display:none}#list{display:block}
|
|
@@ -82,6 +94,7 @@ button:hover{border-color:var(--accent)}
|
|
|
82
94
|
</div>
|
|
83
95
|
<div id="notes"></div>
|
|
84
96
|
<div id="root"></div>
|
|
97
|
+
<div id="diffbox"><div class="dh" id="diffhead"></div><pre id="diffbody"></pre></div>
|
|
85
98
|
<script>
|
|
86
99
|
"use strict";
|
|
87
100
|
const Q = location.search; // carries ?t=<token> for `orch view --lan`
|
|
@@ -258,10 +271,73 @@ function detail(v) {
|
|
|
258
271
|
<div class="muted" style="margin-top:6px">${esc([m.worker ? "coder " + m.worker : "", m.tier ? "tier " + m.tier : "", m.deps.length ? "after " + m.deps.join(", ") : "", m.door === "one-way" ? "hard to undo" : ""].filter(Boolean).join(" · "))}</div>
|
|
259
272
|
${you && how ? `<div style="margin-top:8px">Answer in the lead's pane, or run:</div><code>${esc(how)}</code>` : ""}
|
|
260
273
|
${m.attempts.length ? `<div class="h" style="margin:10px 0 4px">Steps so far</div><table>${m.attempts.map((a) => `<tr><td class="muted">${esc(a.kind || "step")} · ${esc(a.agent || "")}${a.model ? " · " + esc(a.model) : ""}</td><td>${mins(a.secs)} ${esc(a.outcome || "")}</td></tr>`).join("")}</table>` : ""}
|
|
261
|
-
|
|
274
|
+
<div class="h" style="margin:12px 0 2px">Changed files</div><div class="chg" id="chg" data-id="${esc(m.id)}">${chgHTML(m.id)}</div>
|
|
275
|
+
${m.files && m.files.length ? `<div class="h" style="margin:10px 0 4px">Files the plan expects</div><div class="mono muted">${m.files.map(esc).join("<br>")}</div>` : ""}
|
|
262
276
|
</div>`;
|
|
277
|
+
wireChanges();
|
|
278
|
+
loadChanges(m.id, m.status);
|
|
263
279
|
}
|
|
264
280
|
|
|
281
|
+
// What the picked milestone changed (read-only git on the server): a folder tree with +/- and A/M/D, click for the diff.
|
|
282
|
+
// Live while a coder works (unsaved files included), so it is asked again every few seconds then.
|
|
283
|
+
let CH = {id: null, key: null, at: 0, data: null, busy: false}, DIFF = null;
|
|
284
|
+
const nums = (f) => f.add == null ? `<span class="faint">binary</span>` : `<span class="add">+${f.add}</span> <span class="del">−${f.del || 0}</span>`;
|
|
285
|
+
function chgHTML(id) {
|
|
286
|
+
if (CH.id !== id || !CH.data) return `<div class="faint">loading…</div>`;
|
|
287
|
+
const d = CH.data;
|
|
288
|
+
if (d.error && !d.files.length) return `<div class="bad">${esc(d.error)}</div>`;
|
|
289
|
+
let h = `<div class="faint" style="margin-bottom:4px">${esc(d.note)}</div>`;
|
|
290
|
+
if (!d.files.length) return h;
|
|
291
|
+
h += `<div class="mono" style="margin-bottom:4px"><b>${d.totals.files} file${d.totals.files === 1 ? "" : "s"}</b> <span class="add">+${d.totals.add}</span> <span class="del">−${d.totals.del}</span></div>`;
|
|
292
|
+
let last = null;
|
|
293
|
+
d.files.forEach((f, i) => {
|
|
294
|
+
const slash = f.path.lastIndexOf("/"), dir = slash < 0 ? "" : f.path.slice(0, slash), name = f.path.slice(slash + 1);
|
|
295
|
+
if (dir !== last) { h += `<div class="dir">${esc(dir ? dir + "/" : "./")}</div>`; last = dir; }
|
|
296
|
+
h += `<div class="f" data-i="${i}" title="${esc(f.path)}${f.untracked ? " (not added to git yet)" : ""}"><span class="nm">${esc(name)}${f.old ? ` <span class="faint">← ${esc(f.old)}</span>` : ""}</span><span>${nums(f)}</span><span class="st st-${f.untracked ? "A" : esc(f.status)}">${f.untracked ? "U" : esc(f.status)}</span></div>`;
|
|
297
|
+
});
|
|
298
|
+
h += `<div class="faint" style="margin-top:6px;font-size:11px">A added · M changed · D deleted · R renamed · U new, not added to git yet. Click a file for its diff.</div>`;
|
|
299
|
+
if (d.more) h += `<div class="faint">… and ${d.more} more files (<code style="display:inline;padding:0 4px">orch changes ${esc(d.id)}</code>)</div>`;
|
|
300
|
+
if (d.error) h += `<div class="bad">${esc(d.error)}</div>`;
|
|
301
|
+
return h;
|
|
302
|
+
}
|
|
303
|
+
function wireChanges() {
|
|
304
|
+
document.querySelectorAll("#chg .f").forEach((el) => el.onclick = () => openDiff(CH.data.id, CH.data.files[+el.dataset.i]));
|
|
305
|
+
}
|
|
306
|
+
async function loadChanges(id, status, force) {
|
|
307
|
+
const key = id + ":" + status;
|
|
308
|
+
const live = CH.data && CH.id === id && CH.data.kind === "live";
|
|
309
|
+
if (!force && CH.busy) return;
|
|
310
|
+
if (!force && CH.id === id && CH.key === key && !(live && Date.now() - CH.at > 3000)) return;
|
|
311
|
+
CH.busy = true;
|
|
312
|
+
try {
|
|
313
|
+
const r = await fetch(`/api/changes${Q ? Q + "&" : "?"}m=${encodeURIComponent(id)}`);
|
|
314
|
+
const d = await r.json();
|
|
315
|
+
CH = {id, key, at: Date.now(), data: r.ok ? d : {id, files: [], note: "", error: d.error || "could not load", totals: {}}, busy: false};
|
|
316
|
+
} catch (e) { CH.busy = false; return; }
|
|
317
|
+
const el = $("chg");
|
|
318
|
+
if (el && el.dataset.id === id) { el.innerHTML = chgHTML(id); wireChanges(); }
|
|
319
|
+
if (DIFF && DIFF.id === id && CH.data.kind === "live") openDiff(id, CH.data.files.find((f) => f.path === DIFF.f.path) || DIFF.f, true);
|
|
320
|
+
}
|
|
321
|
+
setInterval(() => { if (CH.id && CH.data && CH.data.kind === "live") loadChanges(CH.id, (CH.key || "").split(":")[1]); }, 3000);
|
|
322
|
+
async function openDiff(id, f, quiet) {
|
|
323
|
+
DIFF = {id, f};
|
|
324
|
+
$("diffhead").innerHTML = `<b>${esc(id)}</b><span>${esc(f.path)}</span><span>${nums(f)}</span><span class="st-${esc(f.status)}">${esc(f.status)}${f.untracked ? " · not added to git yet" : ""}</span><button id="diffclose">close (Esc)</button>`;
|
|
325
|
+
$("diffclose").onclick = closeDiff;
|
|
326
|
+
if (!quiet) { $("diffbody").innerHTML = `<div class="faint">loading…</div>`; }
|
|
327
|
+
$("diffbox").classList.add("on");
|
|
328
|
+
const r = await fetch(`/api/diff${Q ? Q + "&" : "?"}m=${encodeURIComponent(id)}&f=${encodeURIComponent(f.path)}`);
|
|
329
|
+
const d = await r.json();
|
|
330
|
+
if (!DIFF || DIFF.f.path !== f.path) return;
|
|
331
|
+
const cls = (l) => /^(\+\+\+|---|diff --git|index |new file|deleted file|similarity|rename )/.test(l) ? "dl-m" : l[0] === "+" ? "dl-a" : l[0] === "-" ? "dl-d" : l.startsWith("@@") ? "dl-h" : "";
|
|
332
|
+
const keep = $("diffbody").scrollTop;
|
|
333
|
+
$("diffbody").innerHTML = (d.error ? `<div class="bad">${esc(d.error)}</div>` : "") +
|
|
334
|
+
(d.lines || []).map((l) => `<div class="${cls(l)}">${esc(l) || " "}</div>`).join("") +
|
|
335
|
+
(d.cut ? `<div class="faint">… cut at ${d.lines.length} of ${d.total} lines: <code style="display:inline">orch changes ${esc(id)} ${esc(f.path)}</code> shows all</div>` : "");
|
|
336
|
+
if (quiet) $("diffbody").scrollTop = keep;
|
|
337
|
+
}
|
|
338
|
+
function closeDiff() { DIFF = null; $("diffbox").classList.remove("on"); }
|
|
339
|
+
document.addEventListener("keydown", (e) => { if (e.key === "Escape" && DIFF) closeDiff(); });
|
|
340
|
+
|
|
265
341
|
function cost(v) {
|
|
266
342
|
const done = v.milestones.filter((m) => m.spent_s && m.estimate_s);
|
|
267
343
|
const est = v.time.estimate_s, so = v.time.driven_s;
|