Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 139 additions & 51 deletions agents/conductors/batch/_status.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
"""agents/conductors/batch/_status.py β€” one reading of "is a batch in flight?".

The Mind's dashboard opens with this box: the slot that is in flight, every
member on one line, and β€” once there is something to review β€” the button to
its packet. The *reading* lives here and the dashboard only supplies its facts.
The Mind's dashboard shows this as the Shift part of its Autopilot block
(PyAutoBrain#650): the slot that is in flight, every member on one line, and β€”
once there is something to review β€” the button to its packet. The *reading* lives here and the dashboard only supplies its facts.

Two constraints shape this module, and they are why it is a module at all:

Expand Down Expand Up @@ -67,10 +67,6 @@
#: Tone per display word, as `_theme.pills` classes: go / caution / neutral.
_TONE = {IN_PROGRESS: "n", AWAITING: "y", RULED: "g", NOT_DELIVERED: "r"}

#: What the box says when nothing is in flight. A fixed sentence, so an
#: unchanged tree renders an unchanged page.
FIXTURE = "No batch in flight."


def read_record(text: str, member_re=None) -> dict:
"""One batch record as `{"keys": {k: [v, …]}, "members": [row, …]}`.
Expand Down Expand Up @@ -189,9 +185,28 @@ def _status(slot: str, kind: str, keys: dict, rows: list, reviewable: bool,
# A running shift's status, as its watcher last wrote it into the
# record (`- live:`, PyAutoBrain#622) β€” a record line, not a clock.
"live": _one(keys, "live"),
"issue": issue_url(keys),
}


def issue_url(keys: dict) -> str:
"""The shift issue a record names (`- issue:`, its trailing `# …` comment
dropped), `''` when it names none."""
m = re.match(r"https://\S+", _one(keys, "issue"))
return m.group(0) if m else ""


def last_shift(records: list) -> dict | None:
"""`{"slot", "issue"}` of the latest-dispatched record, for the quiet line
the dashboard shows once every shift has been reviewed. `records` are
`(slot, keys)` pairs; one with no `- dispatched:` is not a shift."""
shifts = [(_one(k, "dispatched"), slot, k) for slot, k in records if _one(k, "dispatched")]
if not shifts:
return None
_when, slot, keys = max(shifts)
return {"slot": slot, "issue": issue_url(keys)}


def pick_slot(rows: list) -> dict | None:
"""The one slot the box shows: the OPEN record with the latest dispatch.

Expand All @@ -212,43 +227,109 @@ def review_url(pages: str, slot: str) -> str:


# ------------------------------------------------------------ the renders ---
def _headline(st: dict) -> str:
counts = [f"{st['in_progress']} in progress", f"{st['awaiting']} awaiting "
"review"]
return f"Batch {st['slot']} β€” " + " Β· ".join(counts)
#: The Shift sub-part's anchor on the dashboard.
ANCHOR = "shift"

#: What the Shift part says when the Mind has no shift record at all.
FIXTURE = "(no shift yet)"


def _counts(st: dict) -> str:
return f"{st['in_progress']} in progress Β· {st['awaiting']} awaiting review"


def _mode(st: dict) -> str:
"""`LIVE`/`SHADOW` when the watcher's `- live:` line says the shift is
running (it opens with the mode; a closed shift's line does not)."""
word = (st.get("live") or "").split(" ", 1)[0]
return word if word in ("LIVE", "SHADOW") else ""


def is_live(st: dict | None) -> bool:
return bool(st) and bool(_mode(st) or st["in_progress"])


_URL_RE = re.compile(r"https://[^\s<>\"']+")
def to_review(st: dict | None) -> int:
"""Members a human still has to review once the shift has ended."""
if not st:
return 0
return st["awaiting"] or (len(st["members"]) if st["reviewable"] else 0)


def _linked(text: str) -> str:
"""`text` escaped, with each https URL in it a link."""
out, last = [], 0
for m in _URL_RE.finditer(text):
out.append(_html.escape(text[last:m.start()]))
url = _html.escape(m.group(0))
out.append(f'<a href="{url}">{url}</a>')
last = m.end()
return "".join(out) + _html.escape(text[last:])
def active(st: dict | None) -> bool:
"""Running, or ended with something to review: the Shift part shows the
detail. Otherwise it is one quiet line."""
return bool(st) and (is_live(st) or bool(to_review(st)) or st["reviewable"])


def render_html(st: dict | None) -> str:
"""The box as one `verdict` banner β€” the theme's existing class."""
if st is None:
return f'<div class="verdict ok"><b>{FIXTURE}</b></div>'
def badge(st: dict | None) -> str:
"""The Autopilot badge's shift reading, `''` when the shift has nothing to
say: `LIVE Β· N in progress` while running, `N to review` after."""
if is_live(st):
return f"{_mode(st) or 'LIVE'} Β· {st['in_progress']} in progress"
n = to_review(st)
if n or (st and st["reviewable"]):
return f"{n} to review"
return ""


_STATUS_RE = re.compile(r"\s*β€”\s*status:\s*(https://\S+)\s*$")
_ISSUE_RE = re.compile(r"/issues/(\d+)")


def _issue_label(url: str) -> str:
issue = _ISSUE_RE.search(url)
return f"shift issue #{issue.group(1)}" if issue else "shift status"


def _live_parts(live: str) -> tuple[str, str]:
"""(text, url) of a `- live:` line: the watcher's words, and its trailing
`β€” status: <url>`, to be linked by issue number rather than printed raw."""
m = _STATUS_RE.search(live)
return (live[:m.start()], m.group(1)) if m else (live, "")


def _quiet(st: dict | None, last: dict | None) -> tuple[str, str]:
"""(text, url) of the one quiet line an idle Shift part shows."""
if st:
return (f"last shift {st['slot']} β€” closed, nothing to review",
st.get("issue") or _live_parts(st.get("live") or "")[1])
if last:
return f"last shift {last['slot']} β€” reviewed", last.get("issue", "")
return FIXTURE[1:-1], ""


def render_html(st: dict | None, last: dict | None = None) -> str:
"""The Shift sub-part of the dashboard's Autopilot block, in the page's
conventions: an `<h3>` with a quiet `facets` note, `facets` lines, the
members as a list with their state pills, and β€” when nothing is running
or awaiting review β€” one muted parenthesised line linking the issue."""
esc = _html.escape
tone = "warn" if st["reviewable"] else "ok"
H = [f'<div class="verdict {tone}"><b>{esc(_headline(st))}</b>']
if not active(st):
text, url = _quiet(st, last)
link = f' Β· <a href="{esc(url)}">{esc(_issue_label(url))}</a>' if url else ""
return (f'<h3 id="{ANCHOR}">Shift</h3>\n'
f'<p class="muted">({esc(text)}{link})</p>')
H = [f'<h3 id="{ANCHOR}">Shift <span class="facets">({esc(st["slot"])} β€” '
f"{esc(_counts(st))})</span></h3>"]
if st.get("freeze"):
H.append(f'<p class="facets">{esc(st["freeze"])}</p>')
if st.get("live"):
H.append(f'<p class="facets">Live: {_linked(st["live"])}</p>')
for r in st["members"]:
line = (f'<code>{esc(r["slug"])}</code>'
f'{pills((r["state"], _TONE.get(r["state"], "n")))}')
if r["detail"]:
line += f'<span class="facets"> β€” {esc(r["detail"])}</span>'
H.append(f"<p>{line}</p>")
text, url = _live_parts(st.get("live") or "")
url = url or st.get("issue", "")
if text or url:
line = f"Live: {esc(text)}" if text else ""
if url:
line += (" Β· " if line else "") + f'<a href="{esc(url)}">{esc(_issue_label(url))}</a>'
H.append(f'<p class="facets">{line}</p>')
if st["members"]:
items = []
for r in st["members"]:
line = (f'<code>{esc(r["slug"])}</code>'
f'{pills((r["state"], _TONE.get(r["state"], "n")))}')
if r["detail"]:
line += f'<span class="facets"> β€” {esc(r["detail"])}</span>'
items.append(f"<li>{line}</li>")
H.append("<ul>" + "".join(items) + "</ul>")
if st["url"]:
H.append(f'<p><a class="go" href="{esc(st["url"])}">Review this batch '
"β†’</a></p>")
Expand All @@ -258,30 +339,37 @@ def render_html(st: dict | None) -> str:
H.append(f'<p class="muted">Review packet: <code>'
f'{esc(st["packet"])}</code></p>')
else:
H.append('<p class="muted">Nothing to review yet.</p>')
return "".join(H) + "</div>"
H.append('<p class="muted">(nothing to review yet)</p>')
return "\n".join(H)


def render_md(st: dict | None) -> str:
"""The same box in markdown, as a blockquote β€” the same words, in the
same order, so the two versions of a board read as one page."""
if st is None:
return f"> **{FIXTURE}**"
L = [f"> **{_headline(st)}**", ">"]
def render_md(st: dict | None, last: dict | None = None) -> str:
"""The same sub-part in markdown β€” the same words, in the same order, so
the two versions of a board read as one page."""
if not active(st):
text, url = _quiet(st, last)
return "**Shift**\n\n_(" + text + (f" Β· [{_issue_label(url)}]({url})" if url else "") + ")_"
L = [f"**Shift** ({st['slot']} β€” {_counts(st)})", ""]
if st.get("freeze"):
L += [f"> {st['freeze']}", ">"]
if st.get("live"):
L += [f"> Live: {st['live']}", ">"]
L += [st["freeze"], ""]
text, url = _live_parts(st.get("live") or "")
url = url or st.get("issue", "")
if text or url:
line = f"Live: {text}" if text else ""
if url:
line += (" Β· " if line else "") + f"[{_issue_label(url)}]({url})"
L += [line, ""]
for r in st["members"]:
line = f"> - `{r['slug']}` β€” {r['state']}"
line = f"- `{r['slug']}` β€” {r['state']}"
if r["detail"]:
line += f" β€” {r['detail']}"
L.append(line)
L.append(">")
if st["members"]:
L.append("")
if st["url"]:
L.append(f"> [Review this batch β†’]({st['url']})")
L.append(f"[Review this batch β†’]({st['url']})")
elif st["reviewable"]:
L.append(f"> Review packet: `{st['packet']}`")
L.append(f"Review packet: `{st['packet']}`")
else:
L.append("> _Nothing to review yet._")
L.append("_(nothing to review yet)_")
return "\n".join(L)
2 changes: 1 addition & 1 deletion agents/conductors/intake/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ with or without it. Unknown keywords are counted in the page's Hygiene section.
| **classify** | `intake "<text>"` / `intake classify --file P [--lane L]` | classify one raw input; `--apply` writes the prompt β€” and **refuses** (exit 6) when no lane is decided: no `--lane`, no `Lane:` header in the text, no resource signal (M2.3, `AUTONOMY.md` "M2 rulings β€” 2026-11-12") |
| **ideas** | `intake ideas [--lane L]` | scan `ideas.md`, propose one prompt per bullet; `--apply` writes them, refusing (and not marking) any bullet with no decided lane |
| **census** | `intake census` | inventory every filed prompt (work-type/target/difficulty/status + hygiene flags); always read-only |
| **dashboard** | `intake dashboard` | render the census as the Mind **task** page β€” picks, in flight, pending release, planned, backlog (including human review), recent, epics; `--apply` writes `PyAutoMind/dashboard.md` + `dashboard.html` + `state.json` (the organ-cockpit feed, `board/_state.py` v1: red when a task awaits input/is blocked or prompts drift, yellow when work waits on a merge/release/review or picks exist; items carry the page's own copy payloads), `--check` exits 1 on drift (ignoring the page date and the feed's `updated`). The page is read-only (PyAutoBrain#640): a Goals and Queue box from `goals.md`/`queue.md`, and a β˜… `#n` on each queued prompt row, ranked by the planner's own `read_queue` (`batch/_steer.py`); every task row's πŸ“‹ copies its `Use the start-dev skill. <path>` line, which a `/queue` chat (`skills/queue`) takes as "add to the queue"; one inline script, pinned by a CSP hash, no network (`default-src 'none'`, no `connect-src`) |
| **dashboard** | `intake dashboard` | render the census as the Mind **task** page β€” picks, in flight, pending release, planned, backlog (including human review), recent, epics; `--apply` writes `PyAutoMind/dashboard.md` + `dashboard.html` + `state.json` (the organ-cockpit feed, `board/_state.py` v1: red when a task awaits input/is blocked or prompts drift, yellow when work waits on a merge/release/review or picks exist; items carry the page's own copy payloads), `--check` exits 1 on drift (ignoring the page date and the feed's `updated`). The page is read-only (PyAutoBrain#640): one Autopilot block β€” Goals, Queue, Questions, Shift (`goals.md`, `queue.md`, `questions.md`, `batches/`) β€” an ordinary `section_layout` section straight above Start here with its own nav card (PyAutoBrain#650), and a β˜… `#n` on each queued prompt row, ranked by the planner's own `read_queue` (`batch/_steer.py`); every task row's πŸ“‹ copies its `Use the start-dev skill. <path>` line, which a `/queue` chat (`skills/queue`) takes as "add to the queue"; one inline script, pinned by a CSP hash, no network (`default-src 'none'`, no `connect-src`) |
| **formalise** | `intake formalise [prefix]` | retroactively header the prompts census flags β€” derive the missing fields, insert in place, prose untouched; `--apply` writes |
| **reconcile** | `intake reconcile [prefix]` | rank backlog prompts that look already-shipped (vs the `complete/` records / `active/`), and pair live prompts that look like the same work filed twice; always read-only β€” retiring stays human |
| **looks-shipped** | `intake looks-shipped [prefix] [--root DIR] [--pr-cache F]` | the **close-out guard**: flag open drafts with *strong* evidence their work already shipped (see "Close-out guard" below); `--apply` writes `PyAutoMind/looks_shipped.json` only β€” never anything under `draft/` |
Expand Down
Loading
Loading