From 4cc8dfa079c2a7850cea589fb2bbf5754a3a6e1b Mon Sep 17 00:00:00 2001 From: MendixMau Date: Mon, 16 Nov 2026 11:02:25 +0800 Subject: [PATCH 01/16] Cockpit: Decide now cards, one click per open question, saved by the local server Cold test WM1: the plan questions were two or three clicks deep in drawers, never asked as a question, and the page buttons could not save on the local cockpit. - Decide now at the top of the live page: one card per open item, one button per option, the recommended one marked, the sign-off last; the sidebar and the red bar link to it. - cockpitserve.py POST /decide: JSON only, through decisions.py import and apply (the same ledger as the chat path; a sign-off carries the current plan hash), rewrites the page, appends .cockpit-decided for the session that watches it. - A sign-off stop (exit 14/15) shows a short red bar and no stop rows; the plan choice no longer lists the recommended option twice. - Control cockpit-decide-cards-pass; steps/decide.md documents the page path and the 15 s watch. Co-Authored-By: Claude Opus 5.5 --- upgrade-toolkit/bin/cockpitmatrix.py | 53 +++++++++++++++++-- upgrade-toolkit/bin/cockpitpage.py | 16 +++++- upgrade-toolkit/bin/cockpitserve.py | 57 ++++++++++++++++++++- upgrade-toolkit/controls/cockpit_control.sh | 20 ++++++++ upgrade-toolkit/controls/run-controls.sh | 3 ++ upgrade-toolkit/steps/decide.md | 6 +++ 6 files changed, 149 insertions(+), 6 deletions(-) diff --git a/upgrade-toolkit/bin/cockpitmatrix.py b/upgrade-toolkit/bin/cockpitmatrix.py index 6f52801..b615da2 100644 --- a/upgrade-toolkit/bin/cockpitmatrix.py +++ b/upgrade-toolkit/bin/cockpitmatrix.py @@ -1286,6 +1286,18 @@ def band(model, rows, chips, g, tl, kpi=None): #feed,#feed *{overflow-wrap:anywhere} .nowrun{display:flex;align-items:center;gap:12px;margin:0 0 14px;padding:10px 14px;border-radius:12px;background:var(--panel);border:1px solid var(--wait);font-size:14px} .nowrun[hidden]{display:none} +.decide{margin:0 0 16px;padding:14px 16px;border-radius:14px;background:var(--youbg);border:2px solid var(--you)} +.decide .dtop{display:flex;flex-wrap:wrap;gap:10px;align-items:center;justify-content:space-between} +.decide h2{margin:0;font-size:19px}.decide label{font-size:14px}.decide input{font:inherit;padding:6px 8px;border:1px solid var(--line);border-radius:8px;background:var(--panel);color:var(--fg)} +.qhint{margin:6px 0 10px;font-size:13px;color:var(--muted)} +.qcard{margin:10px 0 0;padding:12px 14px;border-radius:12px;background:var(--panel);border:1px solid var(--line)} +.qcard.done{opacity:.6}.qk{font:12px var(--mono);color:var(--muted)}.qcard h3{margin:4px 0 6px;font-size:17px} +.qwhy,.qrec{margin:4px 0;font-size:14px}.qrec{color:var(--you)} +.qopts{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px} +.qopts button{font:inherit;font-size:14px;text-align:left;padding:8px 12px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);cursor:pointer;max-width:100%} +.qopts button.rec{border:2px solid var(--accent);background:var(--accentbg)}.qopts button small{display:block;font-size:12px;color:var(--muted)} +.qopts button:disabled{cursor:default;opacity:.7}.qmsg{margin-top:6px;font-size:13px;font-weight:600} +.qlink{display:block;margin:0 0 12px;padding:10px 12px;border-radius:12px;background:var(--youbg);border:2px solid var(--you);color:var(--fg);font-weight:600;text-decoration:none} .stopbar{margin:0 0 14px;padding:10px 14px;border-radius:12px;background:var(--badbg);border:1px solid var(--bad);font-size:14px} .stopbar b{color:var(--bad)}.stopbar ul{margin:6px 0;padding-left:20px}.stopbar small{display:block;color:var(--muted,#6c7a87);overflow-wrap:anywhere} .nowrun .pulse{flex:none;width:10px;height:10px;border-radius:50%;background:var(--wait);animation:nrp 1.4s ease-in-out infinite} @@ -1730,10 +1742,45 @@ def h_stopped(s): """A judgment stop (NEEDS-JUDGMENT.md): a red bar under the header, so a run that waits for a person says so first.""" if not s: return "" + if str(s["code"]) in ("14", "15"): # the plan waits for sign-off: the Decide now cards are the questions, no paths or commands + return ('') li = "".join(f"
  • {E(t)}
  • " for t in s["titles"]) cmd = f'Then rerun: {E(s["rerun"])}' if s["rerun"] else "" return (f'') + f'{"" if li else ""}Answer below in Decide now. Details: NEEDS-JUDGMENT.md in the work folder.{cmd}') + + +def open_questions(model): + """The items a person still has to answer, one question card each: plan choices and judgments first, the sign-off last.""" + qs = [i for i in model["items"] if i.get("options") and not i.get("decided") and i["kind"] != "confirmgroup"] + return sorted(qs, key=lambda i: i["kind"] == "signoff") + + +def question_of(i): + t = i["title"] + return {"plan-choice": f"What should the upgrade do with {t}?", "signoff": "Sign the plan? Nothing in the app changes before you do.", + "confirm": f"Accept this change: {t}?"}.get(i["kind"], t) + + +def h_decide(model): + """Decide now: every open question as a card with one button per option, at the top of the page. The buttons post to the + local server (cockpitserve.py /decide, live page only); on a static copy they stay off and the answer goes through chat.""" + qs = open_questions(model) + if not qs: + return "" + cards = [] + for n, i in enumerate(qs, 1): + btns = "".join(f'' for o in i["options"]) + why = f'

    {E(i["problem"])}

    ' if i.get("problem") else "" + rec = f'

    Recommended: {E(i["rec_text"])}

    ' if i.get("rec_text") and len(i["options"]) > 1 else "" + cards.append(f'
    Question {n} of {len(qs)} · {E(i.get("step") or "")}
    ' + f'

    {E(question_of(i))}

    {why}{rec}
    {btns}
    ') + return (f'

    Decide now: {len(qs)} ' + f'{"question" if len(qs) == 1 else "questions"} for you

    ' + '

    The buttons work in the live cockpit. On this copy, answer in chat.

    ' + "".join(cards) + "
    ") def render(model, matrix): @@ -1749,7 +1796,7 @@ def render(model, matrix): f"

    {e(model['title'])}

    \n
    {e(model['sub'])}
    \n" " \n" f" {h_ladder(matrix.get('ladder'))}\n \n" - f" {h_stopped(model.get('stopped'))}{h_running(model.get('running'))}\n" + f" {h_stopped(model.get('stopped'))}{h_running(model.get('running'))}\n {h_decide(model)}\n" '
    \n
    \n' '
    Counts by kind (tap one to mark its rows)\n' f'
    {head_}
    \n
    {tiles_}
    \n
    \n' @@ -1762,7 +1809,7 @@ def render(model, matrix): f" {h_health(matrix.get('health'))}\n" '
    \n

    Since you last looked

    \n' f'
      {h_feed(matrix)}
    \n
    \n
    \n' - f' \n
    \n\n\n' + f' \n \n\n\n' '\n' '\n\n' diff --git a/upgrade-toolkit/bin/cockpitpage.py b/upgrade-toolkit/bin/cockpitpage.py index e29bb34..f400ec3 100644 --- a/upgrade-toolkit/bin/cockpitpage.py +++ b/upgrade-toolkit/bin/cockpitpage.py @@ -505,7 +505,8 @@ def add(it): rerun = (re.search(r"then rerun:\n\n {4}(.+)", nj) or [None, ""])[1] secs = re.findall(r"^## (.+?) \(exit (\d+)\)\n\n(.*?)(?=^## |\Z)", nj, re.M | re.S) stopinfo = {"step": stopped[0], "code": stopped[1], "titles": [s[0] for s in secs], "rerun": rerun} - if stopped and not any(j.get("step") == stopped[0] for j in djo): + # exit 14 / 15 (the plan awaits sign-off, or is paused): the sign-off and the P-n items are the questions, no stop rows + if stopped and stopped[1] not in (14, 15) and not any(j.get("step") == stopped[0] for j in djo): for k, (title, code, body) in enumerate(secs, 1): add({"id": f"stop:{stopped[0]}:{k}", "kind": "judgment", "dot": "bad", "title": title, "step": stopped[0], "meta": f"The run stopped at {stopped[0]} (exit {code}) and waits for you", @@ -553,7 +554,8 @@ def add(it): rec_txt = it["sub"].get("recommendation", "") opts = [{"key": "rec", "label": short(rec_txt.split(";")[0] if rec_txt else "Take the recommendation", 110), "causes": ""}] for n, o in enumerate(opts_txt, 1): - opts.append({"key": f"o{n}", "label": short(o, 110), "causes": ""}) + if short(o, 110) != opts[0]["label"]: # the recommended option is already the first one (WM1: "keep old version" twice) + opts.append({"key": f"o{n}", "label": short(o, 110), "causes": ""}) for o in opts: o["writes"] = [{"decisions_md": {"id": pid, "name": it["name"], "kind": it["kind"], "option": o["label"]}}] is_assumed = bool(row and "ASSUMED" in (row[5] if len(row) > 5 else "")) or not row @@ -779,6 +781,16 @@ def phase_time(steps): setInterval(function(){fetch("status",{cache:"no-store"}).then(function(r){return r.json();}).then(run).catch(function(){});},3000); setInterval(function(){var dr=document.getElementById("drawer");if(due){if(!dr||dr.hidden)reload();return;} fetch("stamp",{cache:"no-store"}).then(function(r){return r.text();}).then(function(t){if(s===null)s=t;else if(t!==s){due=true;if(!dr||dr.hidden)reload();}}).catch(function(){});},3000);})(); +(function(){var n=document.getElementById("dname");if(!n)return;try{n.value=localStorage.getItem("cockpit-name")||"";}catch(e){} +document.querySelectorAll("#decide button[data-choice]").forEach(function(b){b.disabled=false;b.addEventListener("click",function(){ +var c=b.closest(".qcard"),m=c.querySelector("[data-qmsg]"),who=n.value.trim(); +if(!who){m.textContent="Type your name at the top first.";n.focus();return;}try{localStorage.setItem("cockpit-name",who);}catch(e){} +c.querySelectorAll("button").forEach(function(x){x.disabled=true;});m.textContent="Saving..."; +fetch("decide",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({item:c.dataset.item,choice:b.dataset.choice,by:who})}) +.then(function(r){return r.json();}).then(function(r){if(r.ok){c.classList.add("done");m.textContent=r.said+". The agent picks it up within 15 seconds.";} +else{c.querySelectorAll("button").forEach(function(x){x.disabled=false;});m.textContent="Not saved: "+r.said;}}) +.catch(function(e){c.querySelectorAll("button").forEach(function(x){x.disabled=false;});m.textContent="Not saved: "+e;});});}); +var h=document.querySelector("#decide .qhint");if(h)h.textContent="One click per question. Your answer goes into the run; the agent picks it up within 15 seconds.";})(); """ diff --git a/upgrade-toolkit/bin/cockpitserve.py b/upgrade-toolkit/bin/cockpitserve.py index 116a102..7a8e436 100644 --- a/upgrade-toolkit/bin/cockpitserve.py +++ b/upgrade-toolkit/bin/cockpitserve.py @@ -10,15 +10,52 @@ /stamp the page's change stamp (mtime in ns); the page polls it every few seconds and reloads when it moves. Every /stamp request also touches D/.cockpit-seen: the pipeline reads that heartbeat to know a tab is open, and opens the page again at the next step when no tab has asked for a while (cockpit_live in upgrade-pipeline.sh). + POST /decide one answer from a "Decide now" card: {"item", "choice", "by", "reason"?}, or {"item": "signoff", "by"}. + It goes through decisions.py import (source page; a sign-off carries the current plan hash) and apply, into the + same decisions.json the pipeline reads, then the page is written again and D/.cockpit-decided is touched, so + the session that drives the run sees the answer within seconds. JSON only (a cross-site form cannot send it). Writes D/.cockpit-port and D/.cockpit-pid at start. Exits on its own after --idle-exit seconds without a request (default 6 h). Exit: 0 idle exit, 2 usage. """ -import argparse, http.server, json, os, sys, threading, time +import argparse, http.server, json, os, subprocess, sys, tempfile, threading, time sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import cockpitpage # noqa: E402 VIEW = "COCKPIT-view.html" +BIN = os.path.dirname(os.path.abspath(__file__)) + + +def decide(d, work, body): + """One answer from the page into the run's decision ledger; returns (http status, message).""" + item, by = str(body.get("item") or ""), " ".join(str(body.get("by") or "").split())[:80] + if not item or not by: + return 400, "an answer needs the item and your name" + if item == "signoff": + data = {"signoffs": [{"by": by, "plan": cockpitpage.build_model(work)["planHash"], "source": "page"}]} + else: + row = {"item": item, "choice": str(body.get("choice") or ""), "by": by} + if body.get("reason"): + row["reason"] = str(body["reason"])[:200] + data = {"decisions": [row]} + with tempfile.NamedTemporaryFile("w", suffix=".json", delete=False) as f: + json.dump(data, f) + try: + imp = subprocess.run([sys.executable, os.path.join(BIN, "decisions.py"), "import", "--work", work, "--json", f.name], + capture_output=True, text=True) + finally: + os.unlink(f.name) + said = (imp.stdout + imp.stderr).strip() + if imp.returncode != 0 or "imported 0 row" in said: + return 422, said or "not saved" + subprocess.run([sys.executable, os.path.join(BIN, "decisions.py"), "apply", "--work", work], capture_output=True) + new = os.path.join(d, ".COCKPIT-view.new") + if subprocess.run([sys.executable, os.path.join(BIN, "cockpitpage.py"), "--work", work, "--out", new, "--standalone", "--live"], + capture_output=True).returncode == 0 and os.path.exists(new): + os.replace(new, os.path.join(d, VIEW)) + with open(os.path.join(d, ".cockpit-decided"), "a") as f: + f.write(json.dumps({"item": item, "choice": body.get("choice") or "sign", "by": by, "at": time.time()}) + "\n") + return 200, f"Saved: {item} by {by}" def main(): @@ -61,6 +98,24 @@ def do_GET(self): self.end_headers() self.wfile.write(body) + def do_POST(self): + last[0] = time.time() + if self.path.split("?")[0] != "/decide" or "application/json" not in (self.headers.get("Content-Type") or ""): + self.send_error(404) + return + try: + body = json.loads(self.rfile.read(min(int(self.headers.get("Content-Length") or 0), 65536)) or b"{}") + except ValueError: + body = None + work = (cockpitpage.rd(os.path.join(d, ".cockpit-work")) or "").strip() or d + code, msg = (400, "not JSON") if not isinstance(body, dict) else decide(d, work, body) + out = json.dumps({"ok": code == 200, "said": msg}).encode() + self.send_response(code) + self.send_header("Content-Type", "application/json") + self.send_header("Content-Length", str(len(out))) + self.end_headers() + self.wfile.write(out) + def log_message(self, *args): pass diff --git a/upgrade-toolkit/controls/cockpit_control.sh b/upgrade-toolkit/controls/cockpit_control.sh index 4e102d5..0237df6 100755 --- a/upgrade-toolkit/controls/cockpit_control.sh +++ b/upgrade-toolkit/controls/cockpit_control.sh @@ -121,6 +121,26 @@ PY echo "cell: $(grep -o '"l": "[0-9] decisions needed"' "$T/out.html" | head -1)" echo "state: $(grep -o '"state": {[^}]*}' "$T/out.html")" rm "$W/NEEDS-JUDGMENT.md"; ck > /dev/null; echo "no file: bars $(cnt -c 'class="stopbar"' "$T/out.html")" ;; + decide) # Decide now (cold test WM1): every open question is a card with one button per option, the sign-off last; the local + # server's POST /decide writes the same ledger as the page import, refuses bad answers and form posts, and a card + # disappears once answered + ck > /dev/null + echo "cards: $(grep -o '
    "$d/.cockpit-work" + python3 "$B/cockpitserve.py" --dir "$d" --idle-exit 60 > /dev/null 2>&1 & sp=$! + for _ in 1 2 3 4 5 6 7 8 9 10; do [ -s "$d/.cockpit-port" ] && break; sleep 0.3; done; u=http://127.0.0.1:$(cat "$d/.cockpit-port")/decide + post() { curl -s -X POST -H 'Content-Type: application/json' -d "$1" "$u"; echo; } + echo "no name: $(post '{"item":"P-1","choice":"rec"}')" + echo "bad option: $(post '{"item":"P-1","choice":"zzz","by":"Ana"}' | grep -o '"ok": false')" + echo "form post: $(curl -s -o /dev/null -w '%{http_code}' -X POST -d item=P-1 "$u")" + echo "answer: $(post '{"item":"P-2","choice":"o1","by":"Ana"}')" + echo "ledger: $(python3 -c 'import json,sys; print(*[r["item"]+"="+r["choice"]+" by "+r["by"]+" via "+r["source"] for r in json.load(open(sys.argv[1]))])' "$W/decisions.json")" + echo "sign: $(post '{"item":"signoff","by":"Ana"}')" + echo "signed: $(grep '^Signed-off: Ana ' "$W/PROPOSAL.md")" + echo "page cards: $(grep -o '
    /dev/null ;; live-open) # cockpit_live as the pipeline runs it, with a stub opener that counts the opens { sed -n '/^say() /p' "$B/cloud/upgrade-pipeline.sh"; sed -n '/^cockpit_live() {/,/^}/p' "$B/cloud/upgrade-pipeline.sh"; } > "$T/fn.sh" . "$T/fn.sh"; DRY=0; WORK=$W; mkdir -p "$W/state" "$W/logs"; rm -f "$W/state/triage.done" diff --git a/upgrade-toolkit/controls/run-controls.sh b/upgrade-toolkit/controls/run-controls.sh index 006a7ae..af0527c 100755 --- a/upgrade-toolkit/controls/run-controls.sh +++ b/upgrade-toolkit/controls/run-controls.sh @@ -6616,6 +6616,9 @@ ctl cockpit-serve-stamp-heartbeat-pass 0 'page served: True' 'heartbeat written: ctl cockpit-running-bar-pass 0 'bar: Running now: Clicking through every page of the old app \(basewalk\) \| 5 min · now in runapp\.py · starting the old app on db_x' '"dot": "bad"' 'status: \{"step": "basewalk".*"tool": "runapp\.py"' 'dead pid: hidden 1' 'no file: hidden 1' -- $CK running ctl cockpit-stopped-bar-pass 0 'bar: The run stopped at basewalk \(exit 11\) and waits for you\.' 'sections: The smoke walk SKIPPED microflow steps\|Role Anonymous has no walk$' \ 'rerun: upgrade-pipeline\.sh --work W --from basewalk' 'rows: "id": "stop:basewalk:1" "id": "stop:basewalk:2"' 'cell: "l": "2 decisions needed"' 'no file: bars 0' -- $CK stopped +ctl cockpit-decide-cards-pass 0 'cards: regression:overlay regression:Gridmod confirm:D2 P-1 P-2 signoff$' 'keep twice: data-choice="rec" data-choice="o2" data-choice="o3"$' \ + 'no name: {"ok": false, "said": "an answer needs the item and your name"}' 'bad option: "ok": false' 'form post: 404' 'answer: {"ok": true, "said": "Saved: P-2 by Ana"}' \ + 'ledger: P-2=o1 by Ana via page$' 'sign: {"ok": true' 'signed: Signed-off: Ana 20' 'page cards: regression:overlay regression:Gridmod confirm:D2 P-1$' 'decided log: 2' -- $CK decide ctl cockpit-live-opens-after-triage-catch 0 'before triage: opened 0' 'stopped in triage: opened 1' 'after triage: opened 1' 'tab polling: opened 1' 'tab gone: opened 2' 'off: opened 2' -- $CK live-open # doctor.sh: a dead docker socket is a FAIL with its fix, never a pass; a missing toolset names the version ctl doctor-docker-down-catch 1 'FAIL docker' 'fix: ' 'doctor: [1-9][0-9]* FAIL' -- env DOCKER_HOST=unix://$T/no.sock bash $B/doctor.sh diff --git a/upgrade-toolkit/steps/decide.md b/upgrade-toolkit/steps/decide.md index 4dbaf9d..2046345 100644 --- a/upgrade-toolkit/steps/decide.md +++ b/upgrade-toolkit/steps/decide.md @@ -29,6 +29,12 @@ on any other harness print the same as a numbered markdown list ending "5. somet wait. Recommending an option from the evidence is fine; choosing silently is not. UNATTENDED runs keep the existing default (keep at the old version) and record it ASSUMED. +The live cockpit asks the same questions: "Decide now" at the top of the page has one card per open item, one button per +option, the sign-off last (cold test WM1: the questions were two or three clicks deep in drawers and nobody found them). +A click posts to cockpitserve.py /decide, which runs decisions.py import and apply, so the page and the chat write one +ledger. The session that drives the run watches `/.cockpit-decided` every 15 s (Monitor on +`tail -F`), says what came in, and reruns from the stop once the plan is signed. A person can answer in either place. + ## Pattern catalogue (playbooks/rearchitecture.md) Before asking, look for an RA entry for the item: bin/proposal.py already cites it in section 3 (`[RA-n, status]`). Ask with that entry's options and recipe. When the owner answers **rebuild** or **replace** (options 2-3), the run, in the same commit as the From 442f43a507d499d9bb6661d1ad361cc1b4a99319 Mon Sep 17 00:00:00 2001 From: MendixMau Date: Mon, 16 Nov 2026 11:17:45 +0800 Subject: [PATCH 02/16] Cockpit: questions as Blocked on you in the sidebar, a dialog per question with context; approval without a typed name; legend for grey cells Maurits on the first version: the Decide now panel was too big and still gave too little context, and a typed name on the sign-off makes no sense when the dev work is tracked in Git anyway. - Sidebar: Blocked on you, one row per open question with a Resolve button; the dialog says what the item is, why it is asked, what each option does and why one is recommended, in words (no file or rule names). - The sign-off is Approve and continue; cockpitserve.py records the machine's Git name. - Legend: what Not yet, Not started and Not needed mean. Co-Authored-By: Claude Opus 5.5 --- upgrade-toolkit/bin/cockpitmatrix.py | 121 ++++++++++++++------ upgrade-toolkit/bin/cockpitpage.py | 23 ++-- upgrade-toolkit/bin/cockpitserve.py | 12 +- upgrade-toolkit/controls/cockpit_control.sh | 9 +- upgrade-toolkit/controls/run-controls.sh | 4 +- 5 files changed, 114 insertions(+), 55 deletions(-) diff --git a/upgrade-toolkit/bin/cockpitmatrix.py b/upgrade-toolkit/bin/cockpitmatrix.py index b615da2..a464ce9 100644 --- a/upgrade-toolkit/bin/cockpitmatrix.py +++ b/upgrade-toolkit/bin/cockpitmatrix.py @@ -1286,18 +1286,21 @@ def band(model, rows, chips, g, tl, kpi=None): #feed,#feed *{overflow-wrap:anywhere} .nowrun{display:flex;align-items:center;gap:12px;margin:0 0 14px;padding:10px 14px;border-radius:12px;background:var(--panel);border:1px solid var(--wait);font-size:14px} .nowrun[hidden]{display:none} -.decide{margin:0 0 16px;padding:14px 16px;border-radius:14px;background:var(--youbg);border:2px solid var(--you)} -.decide .dtop{display:flex;flex-wrap:wrap;gap:10px;align-items:center;justify-content:space-between} -.decide h2{margin:0;font-size:19px}.decide label{font-size:14px}.decide input{font:inherit;padding:6px 8px;border:1px solid var(--line);border-radius:8px;background:var(--panel);color:var(--fg)} -.qhint{margin:6px 0 10px;font-size:13px;color:var(--muted)} -.qcard{margin:10px 0 0;padding:12px 14px;border-radius:12px;background:var(--panel);border:1px solid var(--line)} -.qcard.done{opacity:.6}.qk{font:12px var(--mono);color:var(--muted)}.qcard h3{margin:4px 0 6px;font-size:17px} -.qwhy,.qrec{margin:4px 0;font-size:14px}.qrec{color:var(--you)} -.qopts{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px} -.qopts button{font:inherit;font-size:14px;text-align:left;padding:8px 12px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);cursor:pointer;max-width:100%} -.qopts button.rec{border:2px solid var(--accent);background:var(--accentbg)}.qopts button small{display:block;font-size:12px;color:var(--muted)} -.qopts button:disabled{cursor:default;opacity:.7}.qmsg{margin-top:6px;font-size:13px;font-weight:600} -.qlink{display:block;margin:0 0 12px;padding:10px 12px;border-radius:12px;background:var(--youbg);border:2px solid var(--you);color:var(--fg);font-weight:600;text-decoration:none} +.blocked{margin:0 0 14px;padding:12px 14px;border-radius:14px;background:var(--youbg);border:2px solid var(--you)} +.blocked h2{margin:0 0 4px;font-size:17px}.blocked p{margin:0 0 8px;font-size:13px;color:var(--muted)} +.blocked ol{margin:0;padding:0;list-style:none}.blocked li{display:flex;gap:8px;align-items:center;justify-content:space-between;padding:8px 0;border-top:1px solid var(--line);font-size:14px} +.resolve{font:inherit;font-size:13px;font-weight:600;white-space:nowrap;padding:6px 10px;border-radius:9px;border:0;background:var(--you);color:#fff;cursor:pointer} +.qdlg{max-width:640px;width:calc(100% - 32px);border:0;border-radius:16px;padding:0;background:var(--panel);color:var(--fg);box-shadow:0 20px 60px rgba(0,0,0,.35)} +.qdlg::backdrop{background:rgba(0,0,0,.4)}.qcard{padding:18px 20px}.qcard.done{opacity:.6} +.qk{font:12px var(--mono);color:var(--muted)}.qcard h3{margin:4px 0 10px;font-size:19px}.qcard p{margin:6px 0;font-size:14px;line-height:1.45} +.qrec{padding:8px 10px;border-radius:10px;background:var(--accentbg)} +.qopts{display:grid;gap:8px;margin-top:12px} +.qopts button{font:inherit;font-size:14px;text-align:left;padding:10px 12px;border-radius:10px;border:1px solid var(--line);background:var(--bg);color:var(--fg);cursor:pointer} +.qopts button.rec{border:2px solid var(--accent);background:var(--accentbg)}.qopts button em{margin-left:8px;font-size:12px;font-style:normal;color:var(--accent);font-weight:600} +.qopts button small{display:block;margin-top:3px;font-size:13px;color:var(--muted)}.qopts button:disabled{cursor:default;opacity:.7} +.qmsg{margin-top:8px;font-size:13px;font-weight:600}.qhint{font-size:12px!important;color:var(--muted)} +.qclose{font:inherit;font-size:13px;margin-top:6px;padding:6px 12px;border-radius:9px;border:1px solid var(--line);background:var(--bg);color:var(--fg);cursor:pointer} +.legend .gbreak{flex-basis:100%;height:0}.legend .gl b{color:var(--fg);font-weight:600} .stopbar{margin:0 0 14px;padding:10px 14px;border-radius:12px;background:var(--badbg);border:1px solid var(--bad);font-size:14px} .stopbar b{color:var(--bad)}.stopbar ul{margin:6px 0;padding-left:20px}.stopbar small{display:block;color:var(--muted,#6c7a87);overflow-wrap:anywhere} .nowrun .pulse{flex:none;width:10px;height:10px;border-radius:50%;background:var(--wait);animation:nrp 1.4s ease-in-out infinite} @@ -1722,9 +1725,16 @@ def fmt(t): return "".join(f'
  • {E(f["text"])}
  • ' for f in M["feed"]) or "
  • Nothing recorded yet.
  • " +GREY = [("Not yet", "the run has not reached this stage for the item"), ("Not started", "planned, waits for the plan approval"), + ("Not needed", "this stage has nothing to do for the item")] + + def h_legend(M): used = {c["s"] for r in M["rows"] for c in r["cells"].values()} | {c["s"] for c in M["ready"]} - return "".join(f'{t}' for k, t in LEGEND if k in used) + labels = {c["l"] for r in M["rows"] for c in r["cells"].values() if c["s"] == "none"} + grey = "".join(f'{l}: {t}' for l, t in GREY if l in labels) + return ("".join(f'{t}' for k, t in LEGEND if k in used) + + (f'Grey cells:{grey}' if grey else "")) def h_running(r): @@ -1744,11 +1754,11 @@ def h_stopped(s): return "" if str(s["code"]) in ("14", "15"): # the plan waits for sign-off: the Decide now cards are the questions, no paths or commands return ('') + 'your sign-off.Open Blocked on you on the right to answer. The run goes on after you approve.
    ') li = "".join(f"
  • {E(t)}
  • " for t in s["titles"]) cmd = f'Then rerun: {E(s["rerun"])}' if s["rerun"] else "" return (f'') + f'{"
      " + li + "
    " if li else ""}Answer under Blocked on you on the right. Details: NEEDS-JUDGMENT.md in the work folder.{cmd}
    ') def open_questions(model): @@ -1758,29 +1768,71 @@ def open_questions(model): def question_of(i): - t = i["title"] - return {"plan-choice": f"What should the upgrade do with {t}?", "signoff": "Sign the plan? Nothing in the app changes before you do.", + t = re.sub(r"\s*\((module|widget|jar|java)\)$", "", i["title"]) + return {"plan-choice": f"What should the upgrade do with {t}?", "signoff": "Approve the plan and start the upgrade?", "confirm": f"Accept this change: {t}?"}.get(i["kind"], t) -def h_decide(model): - """Decide now: every open question as a card with one button per option, at the top of the page. The buttons post to the - local server (cockpitserve.py /decide, live page only); on a static copy they stay off and the answer goes through chat.""" +def plain(t): + """An option or recommendation without the file names and rule names behind it (they stay in the technical details).""" + t = re.sub(r"\s*\((kept list|replacements\.tsv row|[a-z0-9_./ ]+\.(?:json|txt|tsv|md))\)", "", t or "") + t = re.sub(r"\beffort ([SML])\b", lambda m: {"S": "small", "M": "medium", "L": "large"}[m.group(1)] + " effort", t) + t = t.replace("a RED edit", "the app's own edit").replace("RED local edit", "the app's own edit") + return "; ".join(x.strip() for x in t.split(";") if x.strip() and "stop rule" not in x).strip() + + +# what an option of a module plan choice does, in words, by the phrase the proposal uses for it +OPTION_SAYS = [("keep old", "The module stays exactly as it is now. Nothing is lost. It misses the Marketplace fixes and is checked again on every Mendix version."), + ("replace", "Take the new Marketplace version. The app's own additions to the module are removed, and their data with them unless it is moved first."), + ("rebuild", "Move the app's own additions into a module of its own, then take the clean Marketplace version. Most work, cleanest result."), + ("hand to", "Park this one. The run waits until the named person answers.")] + + +def context_of(i): + """Two or three plain sentences: what the item is and why it is asked.""" + if i["kind"] == "signoff": + return ["The run has prepared the upgrade and changed nothing in the app yet.", + "Approving starts the upgrade with the choices above. Every change it makes is a Git commit, so you can review or revert each one."] + if i["kind"] == "plan-choice": + ent = [x.split(".")[-1] for x in re.findall(r"ADDED entity ([\w.]+)", i.get("problem") or "")] + more = re.search(r"\(\+(\d+)\)", i.get("problem") or "") + if ent: + n = len(ent) + (int(more.group(1)) if more else 0) + name = re.sub(r"\s*\(.*\)$", "", i["title"]) + return [f"{name} is a Marketplace module, but this app changed it: it added {n} entities of its own ({', '.join(ent)}{', ...' if more else ''}).", + "A Marketplace update overwrites the whole module, so those additions, and the data stored in them, would be lost."] + return [plain(i.get("problem") or "")] if i.get("problem") else [] + + +def h_questions(model): + """The open questions: a "Blocked on you" list in the sidebar, each with a Resolve button that opens one question in a dialog + with its context, one button per option and what each option does. The buttons post to the local server (cockpitserve.py + /decide, live page only); on a static copy they stay off and the answer goes through chat.""" qs = open_questions(model) if not qs: - return "" - cards = [] + return "", "" + rows, dlgs = [], [] for n, i in enumerate(qs, 1): - btns = "".join(f'' for o in i["options"]) - why = f'

    {E(i["problem"])}

    ' if i.get("problem") else "" - rec = f'

    Recommended: {E(i["rec_text"])}

    ' if i.get("rec_text") and len(i["options"]) > 1 else "" - cards.append(f'
    Question {n} of {len(qs)} · {E(i.get("step") or "")}
    ' - f'

    {E(question_of(i))}

    {why}{rec}
    {btns}
    ') - return (f'

    Decide now: {len(qs)} ' - f'{"question" if len(qs) == 1 else "questions"} for you

    ' - '

    The buttons work in the live cockpit. On this copy, answer in chat.

    ' + "".join(cards) + "
    ") + rows.append(f'
  • {E(question_of(i))}
  • ') + btns = [] + for o in i["options"]: + lab = plain(o["label"]) or o["label"] + say = o.get("causes") or next((t for k, t in OPTION_SAYS if k in lab.lower()), "") if i["kind"] == "plan-choice" else "" + if i["kind"] == "signoff": + lab = "Approve and continue" + rec = o["key"] == i.get("rec") and len(i["options"]) > 1 + btns.append(f'') + ctx = "".join(f"

    {E(t)}

    " for t in context_of(i) if t) + why = plain(i.get("rec_text") or "") + rec = f'

    Why we recommend it: {E(why)}

    ' if why and len(i["options"]) > 1 else "" + dlgs.append(f'
    Question {n} of {len(qs)} · ' + f'blocks step {E(i.get("step") or "")}

    {E(question_of(i))}

    {ctx}{rec}
    {btns and "".join(btns)}
    ' + '

    The buttons work in the live cockpit. On a copy, answer in chat.

    ' + '
    ') + side = (f'

    Blocked on you: {len(qs)}

    ' + '

    The run waits for these answers. Click Resolve for the full question.

      ' + "".join(rows) + "
    ") + return side, "".join(dlgs) def render(model, matrix): @@ -1788,6 +1840,7 @@ def render(model, matrix): data = data.replace("{e(model['title'])}\n" '\n' '\n' @@ -1796,7 +1849,7 @@ def render(model, matrix): f"

    {e(model['title'])}

    \n
    {e(model['sub'])}
    \n" " \n" f" {h_ladder(matrix.get('ladder'))}\n \n" - f" {h_stopped(model.get('stopped'))}{h_running(model.get('running'))}\n {h_decide(model)}\n" + f" {h_stopped(model.get('stopped'))}{h_running(model.get('running'))}\n" '
    \n
    \n' '
    Counts by kind (tap one to mark its rows)\n' f'
    {head_}
    \n
    {tiles_}
    \n
    \n' @@ -1809,7 +1862,7 @@ def render(model, matrix): f" {h_health(matrix.get('health'))}\n" '
    \n

    Since you last looked

    \n' f'
      {h_feed(matrix)}
    \n
    \n
    \n' - f' \n
    \n\n\n' + f' \n \n\n{qdlgs}\n' '\n' '\n\n' diff --git a/upgrade-toolkit/bin/cockpitpage.py b/upgrade-toolkit/bin/cockpitpage.py index f400ec3..4d7d002 100644 --- a/upgrade-toolkit/bin/cockpitpage.py +++ b/upgrade-toolkit/bin/cockpitpage.py @@ -572,7 +572,7 @@ def add(it): add({"id": "signoff", "kind": "signoff", "dot": "warn", "title": "Sign the plan", "meta": f"{pl(n, 'choice')} {'was' if n == 1 else 'were'} assumed by the agent" if n else "Nothing goes live without your name", "step": "propose", "problem": "Nothing goes live without your name on the plan. Review it under Plan. To change one choice first, say so in chat (decisions.py pending lists them).", - "rec": "sign", "rec_text": "Read the plan, then sign.", "options": [{"key": "sign", "label": "Sign the plan"}], "plan_hash": P["hash"]}) + "rec": "sign", "rec_text": "", "options": [{"key": "sign", "label": "Approve and continue"}], "plan_hash": P["hash"]}) visible = [i for i in items if not i.get("hidden")] open_visible = [i for i in visible if not (i.get("decided") and i["kind"] != "signoff") and i.get("open", 1)] order = {"bad": 0, "warn": 1} @@ -779,18 +779,17 @@ def phase_time(steps): var w=[r.mins?r.mins+" min":"just started"];if(r.tool)w.push("now in "+r.tool);if(r.said)w.push(r.said); b.querySelector("b").textContent="Running now: "+r.text+" ("+r.step+")";b.querySelector("small").textContent=w.join(" \u00b7 ");b.hidden=false;} setInterval(function(){fetch("status",{cache:"no-store"}).then(function(r){return r.json();}).then(run).catch(function(){});},3000); -setInterval(function(){var dr=document.getElementById("drawer");if(due){if(!dr||dr.hidden)reload();return;} -fetch("stamp",{cache:"no-store"}).then(function(r){return r.text();}).then(function(t){if(s===null)s=t;else if(t!==s){due=true;if(!dr||dr.hidden)reload();}}).catch(function(){});},3000);})(); -(function(){var n=document.getElementById("dname");if(!n)return;try{n.value=localStorage.getItem("cockpit-name")||"";}catch(e){} -document.querySelectorAll("#decide button[data-choice]").forEach(function(b){b.disabled=false;b.addEventListener("click",function(){ -var c=b.closest(".qcard"),m=c.querySelector("[data-qmsg]"),who=n.value.trim(); -if(!who){m.textContent="Type your name at the top first.";n.focus();return;}try{localStorage.setItem("cockpit-name",who);}catch(e){} -c.querySelectorAll("button").forEach(function(x){x.disabled=true;});m.textContent="Saving..."; -fetch("decide",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({item:c.dataset.item,choice:b.dataset.choice,by:who})}) +setInterval(function(){var dr=document.getElementById("drawer"),qo=document.querySelector("dialog.qdlg[open]");if(due){if((!dr||dr.hidden)&&!qo)reload();return;} +fetch("stamp",{cache:"no-store"}).then(function(r){return r.text();}).then(function(t){if(s===null)s=t;else if(t!==s){due=true;if((!dr||dr.hidden)&&!qo)reload();}}).catch(function(){});},3000);})(); +(function(){document.querySelectorAll(".resolve").forEach(function(r){r.addEventListener("click",function(){var d=document.getElementById(r.dataset.q);if(d&&d.showModal)d.showModal();});}); +document.querySelectorAll(".qclose").forEach(function(c){c.addEventListener("click",function(){c.closest("dialog").close();});}); +document.querySelectorAll(".qcard button[data-choice]").forEach(function(b){b.disabled=false;b.addEventListener("click",function(){ +var c=b.closest(".qcard"),m=c.querySelector("[data-qmsg]");c.querySelectorAll("button[data-choice]").forEach(function(x){x.disabled=true;});m.textContent="Saving..."; +fetch("decide",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({item:c.dataset.item,choice:b.dataset.choice})}) .then(function(r){return r.json();}).then(function(r){if(r.ok){c.classList.add("done");m.textContent=r.said+". The agent picks it up within 15 seconds.";} -else{c.querySelectorAll("button").forEach(function(x){x.disabled=false;});m.textContent="Not saved: "+r.said;}}) -.catch(function(e){c.querySelectorAll("button").forEach(function(x){x.disabled=false;});m.textContent="Not saved: "+e;});});}); -var h=document.querySelector("#decide .qhint");if(h)h.textContent="One click per question. Your answer goes into the run; the agent picks it up within 15 seconds.";})(); +else{c.querySelectorAll("button[data-choice]").forEach(function(x){x.disabled=false;});m.textContent="Not saved: "+r.said;}}) +.catch(function(e){c.querySelectorAll("button[data-choice]").forEach(function(x){x.disabled=false;});m.textContent="Not saved: "+e;});});}); +document.querySelectorAll(".qhint").forEach(function(h){h.textContent="Saved into the run with your Git name; the agent picks it up within 15 seconds.";});})(); """ diff --git a/upgrade-toolkit/bin/cockpitserve.py b/upgrade-toolkit/bin/cockpitserve.py index 7a8e436..b571627 100644 --- a/upgrade-toolkit/bin/cockpitserve.py +++ b/upgrade-toolkit/bin/cockpitserve.py @@ -10,7 +10,8 @@ /stamp the page's change stamp (mtime in ns); the page polls it every few seconds and reloads when it moves. Every /stamp request also touches D/.cockpit-seen: the pipeline reads that heartbeat to know a tab is open, and opens the page again at the next step when no tab has asked for a while (cockpit_live in upgrade-pipeline.sh). - POST /decide one answer from a "Decide now" card: {"item", "choice", "by", "reason"?}, or {"item": "signoff", "by"}. + POST /decide one answer from a question dialog: {"item", "choice", "by"?, "reason"?}, or {"item": "signoff"}. Without "by" + the answer carries the machine's Git name (git config user.name): the dev work is tracked in Git anyway. It goes through decisions.py import (source page; a sign-off carries the current plan hash) and apply, into the same decisions.json the pipeline reads, then the page is written again and D/.cockpit-decided is touched, so the session that drives the run sees the answer within seconds. JSON only (a cross-site form cannot send it). @@ -26,11 +27,16 @@ BIN = os.path.dirname(os.path.abspath(__file__)) +def git_name(): + r = subprocess.run(["git", "config", "user.name"], capture_output=True, text=True) + return r.stdout.strip() if r.returncode == 0 else "" + + def decide(d, work, body): """One answer from the page into the run's decision ledger; returns (http status, message).""" - item, by = str(body.get("item") or ""), " ".join(str(body.get("by") or "").split())[:80] + item, by = str(body.get("item") or ""), " ".join(str(body.get("by") or git_name()).split())[:80] if not item or not by: - return 400, "an answer needs the item and your name" + return 400, "an answer needs the item and a name (no git config user.name on this machine)" if item == "signoff": data = {"signoffs": [{"by": by, "plan": cockpitpage.build_model(work)["planHash"], "source": "page"}]} else: diff --git a/upgrade-toolkit/controls/cockpit_control.sh b/upgrade-toolkit/controls/cockpit_control.sh index 0237df6..cfb724f 100755 --- a/upgrade-toolkit/controls/cockpit_control.sh +++ b/upgrade-toolkit/controls/cockpit_control.sh @@ -121,7 +121,7 @@ PY echo "cell: $(grep -o '"l": "[0-9] decisions needed"' "$T/out.html" | head -1)" echo "state: $(grep -o '"state": {[^}]*}' "$T/out.html")" rm "$W/NEEDS-JUDGMENT.md"; ck > /dev/null; echo "no file: bars $(cnt -c 'class="stopbar"' "$T/out.html")" ;; - decide) # Decide now (cold test WM1): every open question is a card with one button per option, the sign-off last; the local + decide) # Blocked on you (cold test WM1): every open question is a sidebar row and a dialog with one button per option, the sign-off last; the local # server's POST /decide writes the same ledger as the page import, refuses bad answers and form posts, and a card # disappears once answered ck > /dev/null @@ -131,13 +131,14 @@ PY python3 "$B/cockpitserve.py" --dir "$d" --idle-exit 60 > /dev/null 2>&1 & sp=$! for _ in 1 2 3 4 5 6 7 8 9 10; do [ -s "$d/.cockpit-port" ] && break; sleep 0.3; done; u=http://127.0.0.1:$(cat "$d/.cockpit-port")/decide post() { curl -s -X POST -H 'Content-Type: application/json' -d "$1" "$u"; echo; } - echo "no name: $(post '{"item":"P-1","choice":"rec"}')" + echo "rows: $(grep -o '`}).join("")+``; + STAGES.map(s=>{const c=it.cells[s.key];return `
    `}).join("")+``; }); $("#matrix").innerHTML=h; const pb=$("#phases"); if(pb&&M.phases&&M.phases.length>1){const n=v=>ROWS.filter(r=>r.phase===v).length; @@ -1453,6 +1541,9 @@ def band(model, rows, chips, g, tl, kpi=None): return `
    ${esc(a.name)}${esc(a.sub)}${esc(t.say||"")}${t.gap?' not linked':""}${TLBL[a.status]||""}
    ${b}${pf}
    `;}).join(""); return `

    ${TSAY[k]}, per action (${it.trail.length})

    Open an action for the reasons and the result. The proof is the record from the run itself.

    ${acts}
    `; } +const STORY=[["found","What we found"],["means","What it means for this app"],["plan","What the plan does, and why"]]; +const storyBox=it=>{const s=it.story||{};const b=STORY.filter(([k])=>(s[k]||[]).length); + return b.length?`
    ${b.map(([k,h])=>`

    ${h}

    ${s[k].map(t=>`

    ${esc(t)}

    `).join("")}
    `).join("")}
    `:"";}; const planBtn=i=>(M.plan||[]).length?``:""; function topicPlan(it){ const acts=(it.trail||[]).map(a=>{const t=a.stages.plan||{}; @@ -1489,7 +1580,8 @@ def band(model, rows, chips, g, tl, kpi=None): function propBox(it){ const sign=(M.plan||[]).find(s=>/sign-off/i.test(s.h)), st=sign?sign.intro.filter(t=>/^(Status:|Signed-off:)/.test(t)&&!t.includes("<")).pop()||"":""; const signed=/^Signed-off:/.test(st); - const hits=it.id==="runtime"?(M.plan||[]).filter(s=>/summary/i.test(s.h)).flatMap(s=>s.items.map(x=>[s.h,x])):planFor(it); + const hits=it.id==="runtime"?(M.plan||[]).filter(s=>/summary/i.test(s.h)).flatMap(s=>s.items.map(x=>[s.h,x])) + :it.id==="modules"?(M.plan||[]).flatMap(s=>s.items.filter(x=>/^module update /.test(x.text||"")).map(x=>[s.h,x])):planFor(it); const rows=hits.map(([h,x])=>{const g=Object.fromEntries(x.subs.filter(y=>y[0]));const asm=/ASSUMED/.test(g.answer||""); return `
  • ${esc(h)}${x.id?" · "+esc(x.id):""}
    ${esc(x.name||x.text)}${g.recommendation?`Recommended: ${esc(g.recommendation)}`:""}${g.answer?`Answer: ${esc(g.answer.replace(/\s*\(ASSUMED[^)]*\)\)?$/,""))}${asm?' · assumed by the agent':""}`:""}
  • `;}).join(""); const who=signed?`Approved: ${esc(st.replace(/^Signed-off:\s*/,""))}`:`Not approved yet. The plan's sign-off line says "${esc(st||"no status")}".`; @@ -1503,13 +1595,14 @@ def band(model, rows, chips, g, tl, kpi=None): open(`${navBar(esc(it.name)+" › "+esc(s.name))}
    ${tabs}

    ${esc(c.l)}

    + ${storyBox(it)} ${k==="plan"&&!it.fromSteps?propBox(it)+planBtn(i):""} ${k==="plan"&&it.fromSteps&&it.ask?`
    Needs your OK. The agent chose this on its own while it worked. Nothing is final until a person approves it.
    `:""} ${k==="plan"&&it.fromSteps&&it.ans?`
    ${it.ans.state==="approved"?"Approved":"Rejected"} by ${esc(who(it.ans.by))}${it.ans.day?" on "+esc(it.ans.day):""}.${it.ans.reason?" Reason: "+esc(it.ans.reason):""}
    `:""} -

    What happens, step by step

    ${ol(c.steps.length?c.steps:["Nothing recorded for this cell."])}
    +

    This stage, step by step

    ${ol(c.steps.length?c.steps:["Nothing recorded for this cell."])}
    ${trailBox(it,k)} ${decBox(di)} - ${it.trail&&it.trail.length?"":fixBox(it.fix,NONGREEN.includes(c.s)&&!di)} + ${it.trail&&it.trail.length||(it.story&&(it.story.plan||[]).length&&!it.fix)?"":fixBox(it.fix,NONGREEN.includes(c.s)&&!di)} ${c.late?`
    For the toolkit: triage did not flag this item. The new triage checks it from the start.
    `:""}
    ${techBox((it.tech||[]).concat(c.tech||[]))}`); @@ -1754,7 +1847,7 @@ def h_stopped(s): return "" if str(s["code"]) in ("14", "15"): # the plan waits for sign-off: the Decide now cards are the questions, no paths or commands return ('') + 'your approval.Open Blocked on you on the right to answer. The run goes on after you approve.') li = "".join(f"
  • {E(t)}
  • " for t in s["titles"]) cmd = f'Then rerun: {E(s["rerun"])}' if s["rerun"] else "" return (f'