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
71 changes: 2 additions & 69 deletions agents/conductors/batch/_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,7 @@ def planner_pool(records: list[dict]) -> list[dict]:
def plan(records: list[dict], *, budget: int = DEFAULT_REVIEW_BUDGET,
session_lane: str = "web-github", awaiting_review: int = 0,
cap: int = DEFAULT_BACKPRESSURE_CAP, queue: list[str] | None = None,
awaiting_source: str = "given", carried: list[str] | None = None,
carried_from: str = "", brief: dict | None = None,
awaiting_source: str = "given", brief: dict | None = None,
attended: bool = False, released: set[str] | None = None,
epic_ledgers: dict[str, str] | None = None,
withheld: list[tuple[dict, str]] | None = None) -> dict:
Expand Down Expand Up @@ -703,8 +702,6 @@ def plan(records: list[dict], *, budget: int = DEFAULT_REVIEW_BUDGET,
"backpressure": {"awaiting_review": awaiting_review, "cap": cap,
"state": pressure, "source": awaiting_source},
"queue": queue,
"carried": carried or [],
"carried_from": carried_from,
"review_minutes_planned": spent,
"members": members,
"rejected": rejected,
Expand Down Expand Up @@ -782,13 +779,6 @@ def emit(d: dict) -> None:
n = len(d["lane_absent"])
print(f"Lane absent: {n} draft(s) excluded — no valid `Lane:`, and an "
"unattended pick fails closed (declare one; bin/lane_backfill.py)")
if d.get("carried"):
# Read first, because a carried member is work the human is already
# holding: it costs review-minutes in THIS slot that no new member
# accounted for.
print(f"Carried in: {', '.join(d['carried'])} "
f"(from {d.get('carried_from') or 'the previous slot'}) — still "
f"in flight, and yours to review before anything new")
lines = queued_epic_lines(d)
if lines:
# One line per queued epic ledger: what it gives this batch, or why
Expand Down Expand Up @@ -862,20 +852,6 @@ class BatchUsageError(Exception):
"""Bad input from the human — reported on stderr, exit 2, nothing written."""


def batch_records(mind: Path) -> list[Path]:
return sorted(p for p in (mind / "batches").glob("*.md")
if p.name != "AGENTS.md")


def newest_slot(mind: Path) -> str:
"""The last record by NAME, which is lexical: `-night` sorts before `-pm`
on the same date, so a night slot collected after a pm one is not the
newest by this reckoning. `--slot` is the escape, and the reason it exists.
"""
records = batch_records(mind)
return records[-1].stem if records else ""


def find_prompt(mind: Path, path: str) -> Path | None:
"""A member's prompt, wherever the lifecycle has moved it to.

Expand Down Expand Up @@ -976,47 +952,6 @@ def derive_awaiting_review(mind: Path) -> int:
return n


def read_outcomes(text: str) -> dict:
"""The record's `- outcomes:` block as `{slug: outcome}`.

`read_record` deliberately does not see the body of a non-`members:` block
(it keeps only key VALUES), so this reads the lines itself — the same way
`- notes:` is left alone."""
out: dict[str, str] = {}
inside = False
for raw in text.split("\n"):
if raw.startswith("- outcomes:"):
inside = True
continue
if not inside:
continue
if raw.startswith(" - "):
slug, _, value = raw[4:].partition(":")
if value.strip():
out[slug.strip()] = value.strip().split()[0]
continue
if raw.strip():
inside = False
return out


def previous_carried(mind: Path) -> tuple:
"""`(slot, [slug…])` — what the last collected slot handed forward.

The next plan reads these FIRST: a carried member is already costing the
human review-minutes in the slot being planned, and a batch composed as
though it were not is over-sold by exactly that much."""
slot = newest_slot(mind)
if not slot:
return "", []
try:
text = (mind / "batches" / f"{slot}.md").read_text(
encoding="utf-8", errors="replace")
except OSError:
return "", []
return slot, [s for s, o in read_outcomes(text).items() if o == "carried"]


# -------------------------------------------------------------------- cli ---
#: Flags other verbs own. Passing one to `plan` or `slice` is a usage error
#: rather than a silent no-op.
Expand Down Expand Up @@ -1903,7 +1838,6 @@ def _main_plan(mind: Path, a, lane: str) -> int:
awaiting, source = derive_awaiting_review(mind), "derived from active.md"
else:
awaiting, source = a.awaiting_review, "--awaiting-review"
carried_from, carried = previous_carried(mind)
brief = None
if a.brief:
res = _brief.check(Path(a.brief), mind)
Expand All @@ -1914,8 +1848,7 @@ def _main_plan(mind: Path, a, lane: str) -> int:
brief = _brief.parse(Path(a.brief).read_text(encoding="utf-8"))["brief"]
d = plan(survey(mind), budget=a.budget, session_lane=lane,
awaiting_review=awaiting, cap=a.cap, queue=read_queue(mind),
awaiting_source=source, carried=carried, carried_from=carried_from,
brief=brief, attended=a.attended, epic_ledgers=read_epic_ledgers(mind))
awaiting_source=source, brief=brief, attended=a.attended, epic_ledgers=read_epic_ledgers(mind))
if a.as_json:
print(json.dumps(d, indent=2))
return RC_OK
Expand Down
13 changes: 10 additions & 3 deletions agents/conductors/batch/_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3949,13 +3949,20 @@ def _close_status(brief_path: Path, slot: Path, issue: str, now: _dt.datetime,
now, github)


#: The opt-in digest page is one `<pre>`: this is all the style it uses.
PACKET_STYLE = (":root{color-scheme:light dark;--ground:#eef1f4;--ink:#17202b}"
"@media (prefers-color-scheme:dark){:root{--ground:#121820;--ink:#e6ebf0}}"
"body{background:var(--ground);color:var(--ink);margin:0}"
"main{max-width:72rem;margin:0 auto;padding:1.5rem 1rem}"
"pre{white-space:pre-wrap;overflow-wrap:anywhere;"
"font:14px/1.5 \"SFMono-Regular\",Menlo,Consolas,monospace}")


def _write_packet(slot: Path, digest: str) -> Path:
"""The opt-in HTML packet (`packet: yes`): the digest on one page."""
import html
css = Path(__file__).with_name("packet.css")
style = css.read_text(encoding="utf-8") if css.is_file() else ""
page = ("<!doctype html><meta charset=\"utf-8\"><title>Shift digest "
f"{html.escape(slot.name)}</title><style>{style}</style>"
f"{html.escape(slot.name)}</title><style>{PACKET_STYLE}</style>"
f"<main><pre>{html.escape(digest)}</pre></main>\n")
out = slot / "digest.html"
out.write_text(page, encoding="utf-8")
Expand Down
54 changes: 15 additions & 39 deletions agents/conductors/batch/_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"""agents/conductors/batch/_status.py — one reading of "is a batch in flight?".

The Mind's dashboard shows this as the Shift part of its Autopilot block: 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.
slot that is in flight, its watcher's `- live:` line and shift issue, and any
member rows the record lists. 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 @@ -102,13 +102,13 @@ def _head(text: str, limit: int = 72) -> str:
return head if len(head) <= limit else head[:limit - 1].rstrip() + "…"


def dev_status(slot: str, keys: dict, members: list, review_exists: bool,
pages: str) -> dict | None:
def dev_status(slot: str, keys: dict, members: list,
review_exists: bool) -> dict | None:
"""The Mind's (development) reading.

A dev batch is dispatched at once and reviewed at once: it is open until
it has been reviewed, and the review button appears when `collect` has
stamped `collected:` — that is when a packet exists to press it on.
A shift is open until it has been reviewed: `reviewed-at:` stamped in the
record, or a review file on disk. A record that still carries the retired
`collected:` key reads like any other.
"""
if _one(keys, "reviewed-at") or review_exists:
return None
Expand All @@ -125,22 +125,17 @@ def dev_status(slot: str, keys: dict, members: list, review_exists: bool,
state, detail = AWAITING, _head(outcome)
rows.append({"slug": m.get("slug", ""), "state": state,
"detail": detail})
return _status(slot, "dev", keys, rows,
reviewable=bool(_one(keys, "collected")), pages=pages)
return _status(slot, "dev", keys, rows)


def _status(slot: str, kind: str, keys: dict, rows: list, reviewable: bool,
pages: str) -> dict:
def _status(slot: str, kind: str, keys: dict, rows: list) -> dict:
return {
"slot": slot,
"kind": kind,
"dispatched": _one(keys, "dispatched"),
"members": rows,
"in_progress": sum(1 for r in rows if r["state"] == IN_PROGRESS),
"awaiting": sum(1 for r in rows if r["state"] == AWAITING),
"reviewable": reviewable,
"url": review_url(pages, slot) if reviewable else "",
"packet": f"batches/packets/{slot}.html",
# A running shift's status, as its watcher last wrote it into the
# record (`- live:`) — a record line, not a clock.
"live": _one(keys, "live"),
Expand Down Expand Up @@ -180,11 +175,6 @@ def pick_slot(rows: list) -> dict | None:
return max(live, key=lambda r: (r["dispatched"], r["slot"]))


def review_url(pages: str, slot: str) -> str:
"""The packet's Pages URL, `''` when the site URL is underivable."""
return f"{pages}packets/{slot}.html" if pages else ""


# ------------------------------------------------------------ the renders ---
#: The Shift sub-part's anchor on the dashboard.
ANCHOR = "shift"
Expand Down Expand Up @@ -212,13 +202,13 @@ 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)
return st["awaiting"]


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"])
return bool(st) and (is_live(st) or bool(to_review(st)))


def badge(st: dict | None) -> str:
Expand All @@ -227,7 +217,7 @@ def badge(st: dict | None) -> str:
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"]):
if n:
return f"{n} to review"
return ""

Expand Down Expand Up @@ -287,16 +277,7 @@ def render_html(st: dict | None, last: dict | None = None) -> str:
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>")
elif st["reviewable"]:
# Reviewable, but no Pages site to link into: name the packet by path
# rather than render a button that goes nowhere.
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>')
H.append('<p class="muted">(nothing to review yet)</p>')
return "\n".join(H)


Expand All @@ -321,10 +302,5 @@ def render_md(st: dict | None, last: dict | None = None) -> str:
L.append(line)
if st["members"]:
L.append("")
if st["url"]:
L.append(f"[Review this batch →]({st['url']})")
elif st["reviewable"]:
L.append(f"Review packet: `{st['packet']}`")
else:
L.append("_(nothing to review yet)_")
L.append("_(nothing to review yet)_")
return "\n".join(L)
Loading
Loading