diff --git a/agents/conductors/batch/_status.py b/agents/conductors/batch/_status.py index 73e3df43..2ee2082c 100644 --- a/agents/conductors/batch/_status.py +++ b/agents/conductors/batch/_status.py @@ -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: @@ -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, …]}`. @@ -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. @@ -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'{url}') - 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'
{FIXTURE}
' +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: `, 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 `

` 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'
{esc(_headline(st))}'] + if not active(st): + text, url = _quiet(st, last) + link = f' · {esc(_issue_label(url))}' if url else "" + return (f'

Shift

\n' + f'

({esc(text)}{link})

') + H = [f'

Shift ({esc(st["slot"])} — ' + f"{esc(_counts(st))})

"] if st.get("freeze"): H.append(f'

{esc(st["freeze"])}

') - if st.get("live"): - H.append(f'

Live: {_linked(st["live"])}

') - for r in st["members"]: - line = (f'{esc(r["slug"])}' - f'{pills((r["state"], _TONE.get(r["state"], "n")))}') - if r["detail"]: - line += f' — {esc(r["detail"])}' - H.append(f"

{line}

") + 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'{esc(_issue_label(url))}' + H.append(f'

{line}

') + if st["members"]: + items = [] + for r in st["members"]: + line = (f'{esc(r["slug"])}' + f'{pills((r["state"], _TONE.get(r["state"], "n")))}') + if r["detail"]: + line += f' — {esc(r["detail"])}' + items.append(f"
  • {line}
  • ") + H.append("
      " + "".join(items) + "
    ") if st["url"]: H.append(f'

    Review this batch ' "→

    ") @@ -258,30 +339,37 @@ def render_html(st: dict | None) -> str: H.append(f'

    Review packet: ' f'{esc(st["packet"])}

    ') else: - H.append('

    Nothing to review yet.

    ') - return "".join(H) + "
    " + H.append('

    (nothing to review yet)

    ') + 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) diff --git a/agents/conductors/intake/AGENTS.md b/agents/conductors/intake/AGENTS.md index 2d72ef83..7d642300 100644 --- a/agents/conductors/intake/AGENTS.md +++ b/agents/conductors/intake/AGENTS.md @@ -124,7 +124,7 @@ with or without it. Unknown keywords are counted in the page's Hygiene section. | **classify** | `intake ""` / `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. ` 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. ` 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/` | diff --git a/agents/conductors/intake/_intake.py b/agents/conductors/intake/_intake.py index fdad11ee..066b8312 100755 --- a/agents/conductors/intake/_intake.py +++ b/agents/conductors/intake/_intake.py @@ -81,7 +81,9 @@ / "conductors" / "batch")) from _status import ( # noqa: E402 dev_status, pick_slot, read_record, - render_html as _status_box_html, render_md as _status_box_md, + render_html as _shift_html, render_md as _shift_md, + badge as _shift_badge, is_live as _shift_live, to_review as _shift_to_review, + last_shift, ) # The human's steering files (queue.md, goals.md): readers shared with the # batch planner and `batch brief --new` (PyAutoMind#565). `read_queue` IS the @@ -1755,17 +1757,20 @@ def _count(key): "hygiene": hygiene, "drift": drift, "batch": _batch_status(mind), + # The latest shift, for the Autopilot block's quiet line once every + # shift has been reviewed (PyAutoBrain#650). + "last_batch": _last_batch(mind), # Strong-evidence close-out flags (`intake looks-shipped`), minus what # a human dismissed or already closed — the "Looks shipped" section. "looks_shipped": _looks_shipped_rows(mind, records), # The human's steering (PyAutoMind#565), read-only (PyAutoBrain#640): # `queue_order` is the planner's own read, so each row's ★ `#n` is its - # rank; `queue` gives the labels; `goals` the box at the top. + # rank; `queue` gives the labels; `goals` the Goals block. "queue": read_queue_entries(mind), "queue_order": read_queue(mind), "goals": read_goals(mind), - # The questions inbox (M3.5, #645), read-only: the section below - # the steering box, with a 📋 per question. + # The questions inbox (M3.5, #645), read-only: the Questions part of + # the Autopilot block (PyAutoBrain#650), with a 📋 per question. "questions": _questions.read(mind), } c["recent"] = recent_events(c) @@ -1981,6 +1986,15 @@ def _batch_status(mind: Path) -> dict | None: return pick_slot(readings) +def _last_batch(mind: Path) -> dict | None: + """`{"slot", "issue"}` of the latest-dispatched batch record, or None.""" + batches = mind / "batches" + if not batches.is_dir(): + return None + return last_shift([(path.stem, read_record(path.read_text( + encoding="utf-8", errors="replace"))["keys"]) for path in sorted(batches.glob("*.md"))]) + + def _board_links(home: str) -> list: """The cross-board footer nav every one-tap board carries: (name, url) pairs for the sibling boards, from PyAutoBrain's declared config surface @@ -2291,12 +2305,17 @@ def cost(r): def _dashboard_navigation(c: dict) -> list: - """Seven stable destinations, counted from the content actually rendered.""" + """Eight stable destinations, counted from the content actually rendered. + + Autopilot leads (PyAutoBrain#650): its number is `_autopilot_reading`'s, + the same reading as the block's badge.""" standalone = sorted((r for r in c["records"] if not r.get("epic")), key=_pick_key) high = [r for r in standalone if r["priority"] == "high"][:PICK_LIST_MAX] quick = _fits_a_slot(standalone)[:PICK_LIST_MAX] epics = {e["slug"] for e in c.get("epics") or []} | set(_epic_members(c)) return [ + {"label": "Autopilot", "href": f"#{AUTOPILOT_ANCHOR}", + "count": _autopilot_reading(c)[0]}, {"label": "Start here", "href": "#start-here", "count": len({r["path"] for r in high + quick})}, {"label": "Epics", "href": "#epics", "count": len(epics)}, @@ -2359,10 +2378,7 @@ def render_dashboard(c: dict) -> str: L += _items([_task_row(_looks_shipped_head(f), _looks_shipped_payload(f)) for f in flags]) L += [""] - if c["batch"] is not None: - L += [_status_box_md(c["batch"]), ""] - L += _steer_md(c) - L += _inbox_md(c) + L += _autopilot_md(c) L += ["## Start here", ""] # Epic members never appear in the pick lists or the work-type sections — @@ -2649,29 +2665,24 @@ def _queued_rows(c: dict) -> list: for n, ref in enumerate(c.get("queue_order") or [], 1)] -def _steer_md(c: dict) -> list: - """The markdown page's read-only Goals and Queue (as on the HTML twin).""" - goals = c.get("goals") or [] - L = ["## Goals", ""] - L += [f"{g['n']}. {_md_inline_escape(g['text'])}" for g in goals] or [ - "_(no goals — write them in [`goals.md`](goals.md))_"] - L += ["", "## Queue", ""] - L += [f"{n}. [{_md_inline_escape(label)}]({ref})" for n, label, ref in _queued_rows(c)] or [ - "_(nothing queued — [`queue.md`](queue.md) is empty)_"] - return L + [""] +#: The Autopilot block (PyAutoBrain#650): Goals, Queue, Questions and Shift in +#: ONE ordinary section straight above Start here, folded by the shared +#: `section_layout` like every other section. Empty states take the page's own +#: form — a muted, parenthesised line, as "(none right now)" is. +AUTOPILOT_TITLE = "Autopilot" +AUTOPILOT_ANCHOR = "autopilot" +GOALS_EMPTY = "(no goals yet — edit in chat)" +QUEUE_EMPTY = "(queue is empty — add with `/queue`)" +QUESTIONS_EMPTY = "(no open questions)" def _md_inline_escape(text: str) -> str: return str(text).replace("<", "<").replace(">", ">").replace("[", "\\[").replace("]", "\\]") +# The ★ rank chip every queued prompt row carries, on whichever section the row +# is in (PyAutoBrain#640). _STEER_CSS = """\ -.steer{margin:0 0 1.2rem;padding:.75rem .9rem;border:1px solid var(--edge); - border-radius:11px;background:var(--tint)} -.steer h2{margin:.1rem 0 .4rem;font-size:1.05rem} -.steer h3{margin:.7rem 0 .2rem} -.steer ol{margin:.2rem 0;padding-left:1.4rem} -.steer ol.steer-queue{list-style:none;padding-left:0} span.star{flex:0 0 auto;display:inline-flex;align-items:center;gap:.15rem; min-height:2.75rem;padding:0 .4rem;font-size:1.05rem;color:#d4a017; border:1px solid var(--edge);border-radius:9px;background:var(--tint)} @@ -2679,48 +2690,6 @@ def _md_inline_escape(text: str) -> str: """ -def _steer_html(c: dict, link) -> list: - """The read-only steering box at the top of the page: Goals, then Queue. - - Server-rendered from the census, with no script of its own: each queued - prompt shows its ★ rank and the 📋 copy button every task row carries. - Edits happen in a `/queue` chat (PyAutoBrain `skills/queue`).""" - goals = c.get("goals") or [] - queue = _queued_rows(c) - H = ['"] - return H - - -_INBOX_CSS = """\ -.inbox{margin:0 0 1.2rem;padding:.75rem .9rem;border:1px solid var(--edge); - border-radius:11px;background:var(--tint)} -.inbox h2{margin:.1rem 0 .4rem;font-size:1.05rem;display:flex;align-items:center;gap:.5rem} -.inbox ol{list-style:none;margin:.2rem 0;padding-left:0} -.inbox .qid{font-weight:700;margin-right:.3rem} -.inbox details{margin:.2rem 0} -""" - - def _age(asked: str, today: str) -> str: """`asked` (an ISO time) as an age in whole days against the census date; "" when either cannot be read. Day-grained, so `--check` is stable.""" @@ -2744,85 +2713,123 @@ def _questions_payload(qid: str = "") -> str: return "Use the questions skill." + (f" {qid}" if qid else "") -def _inbox_md(c: dict) -> list: - """The markdown page's read-only Questions list (as on the HTML twin).""" +def _autopilot_reading(c: dict) -> tuple: + """(count, badge) — the one at-a-glance reading the Autopilot nav card and + the block's badge share: `LIVE · N in progress` during a shift (count N), + `N to review` after one (count N), else `N queued · M questions` (count + the queued prompts).""" + st = c.get("batch") + shift = _shift_badge(st) + if _shift_live(st): + return st["in_progress"], shift + if shift: + return _shift_to_review(st), shift + opened, _deferred = _open_questions(c) + queued = len(c.get("queue_order") or []) + return queued, (f"{queued} queued · " + f"{len(opened)} question{'' if len(opened) == 1 else 's'}") + + +def _autopilot_md(c: dict) -> list: + """The markdown page's read-only Autopilot block, straight above Start + here: the same four sub-parts as the HTML twin, in Start here's own + sub-heading form (`**Title** (note)`).""" + goals = c.get("goals") or [] opened, deferred = _open_questions(c) - L = [f"## Questions ({len(opened)} open, {len(deferred)} deferred)", ""] + L = [f"## {AUTOPILOT_TITLE}", "", f"_{_autopilot_reading(c)[1]}_", "", + "**Goals** ([`goals.md`](goals.md))", ""] + L += [f"{g['n']}. {_md_inline_escape(g['text'])}" for g in goals] or [f"_{GOALS_EMPTY}_"] + L += ["", "**Queue** ([`queue.md`](queue.md)) — read-only; change it in a `/queue` chat", ""] + L += [f"{n}. [{_md_inline_escape(label)}]({ref})" for n, label, ref in _queued_rows(c)] or [ + f"_{QUEUE_EMPTY}_"] + L += ["", f"**Questions** ({len(opened)} open, {len(deferred)} deferred — " + "[`questions.md`](questions.md))", ""] for e in opened: f = e["fields"] age = _age(f.get("asked", ""), c.get("generated", "")) L.append(f"- {e['id']} — {_md_inline_escape(f.get('ask', ''))} " f"({f.get('issue', '')}" + (f", {age}" if age else "") + ")") if not opened: - L.append("_(no open questions — [`questions.md`](questions.md))_") - return L + [""] - - -def _inbox_html(c: dict, link) -> list: - """The read-only questions inbox, straight after the steering box (M3.5, - PyAutoBrain#645). Server-rendered with no script of its own: each Open - question carries the 📋 every task row has, copying `Use the questions - skill. Q` to paste into a chat; the heading's 📋 copies `Use the - questions skill.`, which starts a sitting. Portable text, not a slash - command (`board/copy_contract.py`), as the task rows' start-dev line is. - Deferred entries fold to one line each. No form, input or fetch.""" - opened, deferred = _open_questions(c) - copy = ('') - H = ['"] - return H - + L.append(f"_{QUESTIONS_EMPTY}_") + L += ["", _shift_md(c.get("batch"), c.get("last_batch")), ""] + return L -def _steer_first(page: str) -> str: - """Lift the Goals and queue box above the section cards. - The shared layout moves the orchestration panel above the navigation - cards; the steering box belongs straight after it, at the top of the - first screen, not below seven count cards. The questions inbox that - follows it (M3.5) travels with it.""" - start = page.find('", start) + len("") - inbox = page.find('", inbox) + len("") - box = page[start:end] - page = page[:start] + page[end:] - return page[:nav] + box + "\n" + page[nav:] +def _issue_link(url: str) -> str: + """` — issue #N`, linked, as the In flight rows write an issue; "" if none.""" + if not str(url).startswith("https://"): + return "" + m = re.search(r"/(?:issues|pull)/(\d+)", url) + return f' — issue #{m.group(1) if m else "?"}' + + +def _question_row(c: dict, e: dict, link) -> str: + """One question as an ordinary task row: its 📋 copies `Use the questions + skill. Q`; the text is the id, the task, the ask, then the quiet facets.""" + f = e["fields"] + task = f.get("task", "") + age = _age(f.get("asked", ""), c.get("generated", "")) + text = (f"{_attr(e['id'])} " + + link(task, _summary_label(Path(task).stem or e["title"])) + + f" — {_summary_label(f.get('ask', ''))}") + if f.get("options"): + text += f' — {_summary_label(f["options"])}' + text += _issue_link(f.get("issue", "")) + meta = f"from shift {_summary_label(f.get('shift', '?'))}" + (f" · {age}" if age else "") + if e["state"] == "deferred": + meta += f" · deferred until {_summary_label(f.get('until') or 'the next sitting')}" + text += f' — {meta}' + return _html_task(text, _questions_payload(e["id"])) + + +def _autopilot_html(c: dict, link, h2) -> list: + """The read-only Autopilot block, straight above Start here. + + One plain `

    ` section, so the shared `section_layout` folds it into the + same closed `details.board-section` as every other section, with one badge + (`_autopilot_reading`, passed as its summary; the nav card shows the same + reading's count, and opens it as every card opens its section). Inside, + four sub-parts in Start here's conventions — an `

    ` with a `facets` note, ordinary `.task` rows + with their 📋, a muted parenthesised line when empty: + + - Goals, from `goals.md`, as a plain list (goals carry no action); + - Queue, from `queue.md` via the planner's `read_queue`, each row with its + ★ rank and the prompt's 📋 (PyAutoBrain#640); + - Questions (M3.5, PyAutoBrain#645), each row's 📋 copying `Use the + questions skill. Q`; deferred ones fold behind a `
    `; + - Shift (`batch/_status.py`): the running or to-be-reviewed shift's + detail, else one quiet line naming the last shift and its issue. + + Server-rendered, no script, no form or input: edits happen in chat.""" + goals = c.get("goals") or [] + queue = _queued_rows(c) + opened, deferred = _open_questions(c) + H = [h2(AUTOPILOT_TITLE, ""), '

    Goals

    '] + if goals: + H.append("
      " + "".join(f"
    1. {_summary_label(g['text'])}
    2. " + for g in goals) + "
    ") + else: + H.append(f'

    {GOALS_EMPTY}

    ') + H.append('

    Queue (read-only — paste a ' + "row's 📋 into a chat that ran /queue to change it)

    ") + H += [_html_task(link(ref, _summary_label(label)), _prompt_payload(ref), + _queue_star(ref, {Path(ref).name: n})) + for n, label, ref in queue] or [f'

    {_md_inline(QUEUE_EMPTY)}

    '] + H.append(f'

    Questions ({len(opened)} open, ' + f"{len(deferred)} deferred — read-only; answer by pasting a 📋 into a chat)" + "

    ") + if opened: + H.append(_html_task("Answer the open questions in one sitting", + _questions_payload())) + H += [_question_row(c, e, link) for e in opened] + else: + H.append(f'

    {QUESTIONS_EMPTY}

    ') + if deferred: + H += ["
    ", f"{len(deferred)} deferred"] + H += [_question_row(c, e, link) for e in deferred] + H += ["
    "] + H.append(_shift_html(c.get("batch"), c.get("last_batch"))) + return H def _with_csp(page: str) -> str: @@ -2888,11 +2895,11 @@ def record_row(r): "PyAutoMind Dashboard", f"", - f"", + f"", "", "", hero(THEME_ORGAN, "Dashboard", navigation=_dashboard_navigation(c), - navigation_columns=7), + navigation_columns=8), ] H.append(orchestration_panel( "mind", "Plan and coordinate development", @@ -2933,8 +2940,6 @@ def record_row(r): work_links=[{"label": "Open Mind repository", "href": home}] if home else [], organ="mind", refreshed_at=c.get("refreshed_at"), refresh_url=home + "/actions/workflows/dashboard_refresh.yml" if home else None)) - H += _steer_html(c, link) - H += _inbox_html(c, link) if c.get("drift"): H += ['

    ⚠️ Needs lifecycle reconciliation — draft prompts ' "whose body records a fix PR (done, never advanced):

    ", "
      "] @@ -2956,8 +2961,19 @@ def record_row(r): f'{_summary_label(_clip(f["signals"][0].get("evidence", "")))}' "") H.append(_html_task(text, _looks_shipped_payload(f))) - if c["batch"] is not None: - H.append(_status_box_html(c["batch"])) + + def h2(title, src): + # Every section links the markdown file it is rendered from — the + # registry file is the full record, the page is the view. + a = (f' markdown ' + "version") if blob and src else "" + anchor = {"In flight": "in-flight", + "Planned": "planned", "Backlog": "backlog", + "Epics": "epics", AUTOPILOT_TITLE: AUTOPILOT_ANCHOR}.get(title) + prefix = f'' if anchor else "" + return prefix + f"

      {title}{a}

      " + + H += _autopilot_html(c, link, h2) H += ['

      Start here

      '] members = _epic_members(c) @@ -2976,17 +2992,6 @@ def record_row(r): H += [f'

      {title} ({note}){more}

      '] H += [record_row(r) for r in shown] or ['

      (none right now)

      '] - def h2(title, src): - # Every section links the markdown file it is rendered from — the - # registry file is the full record, the page is the view. - a = (f' markdown ' - "version") if blob else "" - anchor = {"In flight": "in-flight", - "Planned": "planned", "Backlog": "backlog", - "Epics": "epics"}.get(title) - prefix = f'' if anchor else "" - return prefix + f"

      {title}{a}

      " - known = {e["slug"] for e in c.get("epics") or []} stray = [s for s in members if s not in known] H += [h2("Epics", "epics.md")] @@ -3133,7 +3138,11 @@ def h2(title, src): if footer: H.append(footer) H += [f"", "", ""] - return _with_csp(_steer_first(section_layout("\n".join(H) + "\n"))) + # The Autopilot badge is a reading, not the nav card's bare number, so it + # goes in through the shared layout's `summaries` — the one mechanism + # every owner uses for that. + badges = {AUTOPILOT_ANCHOR: {"count": _autopilot_reading(c)[1]}} + return _with_csp(section_layout("\n".join(H) + "\n", badges)) def _dashboard_body(page: str) -> str: diff --git a/tests/test_batch_freeze.py b/tests/test_batch_freeze.py index 231a2190..69663ff5 100644 --- a/tests/test_batch_freeze.py +++ b/tests/test_batch_freeze.py @@ -122,7 +122,7 @@ def test_the_box_carries_one_line_when_it_is_supplied(): st = _box(_status.freeze_line(ACTIVE_REC)) md, html = _status.render_md(st), _status.render_html(st) line = "FROZEN: release validation until 2026-09-03T19:30:00+00:00" - assert f"> {line}" in md + assert f"\n{line}\n" in md assert line in html # One line, and above the members — a human reading the box is deciding # what to merge. diff --git a/tests/test_batch_status.py b/tests/test_batch_status.py index d82c56d3..a3ceb4a9 100644 --- a/tests/test_batch_status.py +++ b/tests/test_batch_status.py @@ -45,7 +45,8 @@ def test_dev_in_flight_member_reads_as_in_progress_with_no_button(): assert st["reviewable"] is False assert st["url"] == "" assert st["members"][0]["state"] == _status.IN_PROGRESS - assert "Nothing to review yet" in _status.render_md(st) + assert "_(nothing to review yet)_" in _status.render_md(st) + assert _status.is_live(st) and _status.badge(st) == "LIVE · 1 in progress" assert 'class="go"' not in _status.render_html(st) @@ -60,6 +61,7 @@ def test_dev_collected_slot_gets_the_button(): assert st["url"] == f"{PAGES}packets/2026-09-03-pm.html" assert 'class="go"' in _status.render_html(st) assert "[Review this batch →]" in _status.render_md(st) + assert not _status.is_live(st) and _status.badge(st) == "1 to review" def test_dev_slot_closes_on_reviewed_at_key(): @@ -125,7 +127,50 @@ def test_md_and_html_agree_on_every_slug_and_the_review_url(): assert st["url"] in html -def test_fixture_when_nothing_is_open(): - assert _status.render_md(None) == "> **No batch in flight.**" +def test_fixture_when_there_is_no_shift_at_all(): + assert _status.render_md(None) == "**Shift**\n\n_(no shift yet)_" assert _status.render_html(None) == ( - '
      No batch in flight.
      ') + '

      Shift

      \n

      (no shift yet)

      ') + assert _status.badge(None) == "" + + +def test_a_live_shift_shows_its_detail_and_links_the_shift_issue_tidily(): + """PyAutoBrain#650: the Shift part of the Autopilot block. The watcher's + raw `— status: ` becomes a link named by the shift issue's number.""" + url = "https://github.com/o/PyAutoMind/issues/571#issuecomment-6883569285" + keys = {"dispatched": ["2026-11-14T18:00Z"], + "issue": ["https://github.com/o/PyAutoMind/issues/571 # the digest lands here"], + "live": [f"LIVE · 1 running · review-at 21:20 — status: {url}"]} + st = _status.dev_status("2026-11-14-pm3", keys, + [{"slug": "gears", "outcome": "RUNNING"}], + review_exists=False, pages=PAGES) + assert st["issue"] == "https://github.com/o/PyAutoMind/issues/571" + assert _status.badge(st) == "LIVE · 1 in progress" + html = _status.render_html(st) + assert html.startswith('

      Shift (2026-11-14-pm3 — ' + "1 in progress · 0 awaiting review)

      ") + assert (f'

      Live: LIVE · 1 running · review-at 21:20 · ' + f'shift issue #571

      ') in html + assert "
    • gears" in html + assert f">{url}<" not in html and "status: http" not in html + assert 'class="verdict' not in html and "Shift

    \n

    (last shift 2026-11-14-pm3 — closed, ' + f'nothing to review · shift issue #571)

    ') + # Every shift reviewed: the last one, from `last_shift`, says so. + last = _status.last_shift([("2026-11-14-pm2", {"dispatched": ["2026-11-14T13:00Z"]}), + ("2026-11-14-pm3", keys), ("AGENTS", {})]) + assert last == {"slot": "2026-11-14-pm3", "issue": issue} + assert _status.render_md(None, last) == ( + f"**Shift**\n\n_(last shift 2026-11-14-pm3 — reviewed · [shift issue #571]({issue}))_") + assert "(last shift 2026-11-14-pm3 — reviewed ·

    Autopilot

    ' + 'LIVE · 1 in progress') in html + assert ('board-nav-count">1Autopilot<') in html + assert '

    Shift (2026-09-03-pm' in html + assert "

    Batch" not in html and "## Batch" not in page + assert 'class="verdict' not in html assert 'Review this batch →' in html + # After the shift, the Autopilot badge and nav card read what is to review. + n = re.search(r'(\d+) to review', html) + assert n and int(n.group(1)) >= 1 + assert (f'board-nav-count">{n.group(1)}' + "Autopilot<") in html def test_a_reviewed_batch_disappears_from_the_box(tmp_path): @@ -1399,11 +1412,11 @@ def test_seven_navigation_counts_and_nested_review(tmp_path): nav = re.search(r'