fwdloop 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <!-- borrowed-from: bareloop src/panel/index.html@a30bbef — ADAPTED for fwdloop.
3
3
  M4a piece 3+ (docs/wiki/the-module-ladder.md, "M4a — read-only panel —
4
- SIGNED"): the Tokyo Night box-drawing visual design (CSS tokens, tab
4
+ SIGNED"; M4b adds the answer doors): the Tokyo Night box-drawing visual design (CSS tokens, tab
5
5
  layout, glyph/badge styling, responsive 390px breakpoint) is kept from
6
6
  the borrowed page; every data-bearing script (fetches, run rendering,
7
7
  step map, audit, job, run grouping) is rewired for fwdloop's own book
@@ -171,6 +171,18 @@
171
171
  .btn:disabled{color:var(--text-faint);border-color:var(--border);cursor:not-allowed;}
172
172
  .btn:disabled::before,.btn:disabled::after{color:var(--text-faint);opacity:0.4;}
173
173
  .btn.small{padding:0 9px;height:32px;min-height:0;font-size:12px;}
174
+ /* M4b piece 4: the answer doors. Shape/placement from bareloop's mockup Run-tab
175
+ action bar (a row of `.btn`s with a hint line under it), redo is ours. */
176
+ .answer-doors{margin-top:12px;padding-top:8px;border-top:1px solid var(--border);}
177
+ .answer-doors label{display:block;font-size:11px;font-weight:700;color:var(--text-dim);text-transform:uppercase;letter-spacing:0.04em;margin-bottom:3px;}
178
+ .answer-doors textarea{display:block;width:100%;max-width:100%;box-sizing:border-box;min-height:64px;padding:6px 8px;font:inherit;color:var(--text);background:var(--bg);border:1px solid var(--border-strong);resize:vertical;}
179
+ .answer-doors .actions-row{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px;}
180
+ .answer-doors .btn{min-width:44px;}
181
+ .answer-msg{margin-top:8px;padding:6px 8px;border:1px solid var(--border-strong);font-size:13px;color:var(--text);white-space:pre-wrap;word-break:break-word;overflow-wrap:anywhere;}
182
+ .answer-msg.refused{border-color:var(--red);}
183
+ .answer-msg.refused::before{content:"refused: ";color:var(--red);font-weight:700;}
184
+ .answer-msg.stuck{border-color:var(--amber);}
185
+ .answer-msg.info::before{content:"[·] ";color:var(--amber);font-weight:700;}
174
186
 
175
187
  .wf-row,.hist-row{
176
188
  display:flex;flex-direction:column;row-gap:4px;min-width:0;
@@ -421,21 +433,22 @@
421
433
  <section id="panel-chat" class="tabpanel active" role="tabpanel" aria-labelledby="tab-chat">
422
434
  <div class="chat-thread">
423
435
  Authoring a flow from this page isn't built yet — the drafter is a POC. This
424
- panel is read-only: it shows flows and runs already started from the
425
- <code>fwdloop</code> CLI. Use the Runs tab to open one, or the Inbox tab for
426
- anything waiting on you.
436
+ panel shows flows and runs already started from the
437
+ <code>fwdloop</code> CLI, and lets you answer an ask that is waiting on you
438
+ (accept, redo or rerun, with a reason). It cannot start a run. Use the Runs
439
+ tab to open one, or the Inbox tab for anything waiting on you.
427
440
  </div>
428
441
  </section>
429
442
 
430
443
  <section id="panel-inbox" class="tabpanel" role="tabpanel" aria-labelledby="tab-inbox" hidden>
431
444
  <!-- M4a-1: a list of STOPS, like History — open ones first with
432
445
  [.] and time left, then past ones newest first with a short
433
- status word ([accepted]/[rejected: reason]/[reran: reason]/
446
+ status word ([accepted]/[redo: reason]/[reran: reason]/
434
447
  [expired]/[unanswered]). No evidence is rendered here any
435
448
  more (M4a-1 review): clicking a stop selects its run, switches
436
449
  the right pane to the Ask tab, and expands that ONE ask there
437
- — the wide right pane is where the evidence lives now. No
438
- answer controls — those are M4b. -->
450
+ — the wide right pane is where the evidence lives now. The
451
+ answer doors are in the Ask tab, not here (M4b). -->
439
452
  <div id="inbox-list" data-testid="inbox-list"></div>
440
453
  </section>
441
454
 
@@ -560,13 +573,12 @@
560
573
  (past), the draft under review (scrollable), then each
561
574
  unjudged input labelled by step (goal as subtitle). A
562
575
  pre-M4a-1 ask shows "draft not kept (before M4a-1)" in place
563
- of the draft. Read-only: no answer controls here (M4b) — a
564
- clearly marked EMPTY slot stands in their place. Nothing in
565
- this panel is a real <button>/<input> — even the
566
- collapse/expand toggle is a div with role="button"
567
- tabindex="0" (the SAME pattern the step-map's own SVG nodes
568
- already use elsewhere on this page), so "no controls yet"
569
- holds by construction. -->
576
+ of the draft. M4b: an OPEN ask also carries the answer doors
577
+ (a labelled reason textarea + Accept / Redo / Rerun
578
+ buttons), or a stated reason there are none; a saved answer
579
+ whose resume did not start carries ONE "Try the resume
580
+ again" button. The collapse/expand toggle stays a div with
581
+ role="button" tabindex="0". -->
570
582
  <div id="ask-empty" class="hint" style="font-size:13px;padding:24px 0;">select a run first</div>
571
583
  <div id="ask-list" data-testid="ask-list" hidden></div>
572
584
  </section>
@@ -583,6 +595,9 @@
583
595
  "use strict";
584
596
 
585
597
  var PORT = "__FWDLOOP_PANEL_PORT__";
598
+ // M4b piece 1: per-process answer token, replaced at serve time; sent only as
599
+ // the x-fwdloop-token header of the two POSTs (postJSON below).
600
+ var TOKEN = "__FWDLOOP_PANEL_TOKEN__";
586
601
  document.getElementById("host-line").textContent = "127.0.0.1:" + PORT;
587
602
 
588
603
  function wireTabs(tabButtons){
@@ -603,15 +618,32 @@
603
618
  wireTabs([document.getElementById("tab-chat"), document.getElementById("tab-runs"), document.getElementById("tab-inbox")]);
604
619
  wireTabs([document.getElementById("tab-run"), document.getElementById("tab-audit"), document.getElementById("tab-details"), document.getElementById("tab-ask")]);
605
620
 
606
- // ---- fetch helpers — GET only, this panel is read-only by construction
607
- // (src/panel/server.js is GET/HEAD-only too; nothing on this page ever
608
- // sends a non-GET request or a request body). ----
621
+ // ---- fetch helpers. Reads are GET. The ONLY non-GET requests on this page are
622
+ // the two POSTs below (M4b): /api/answer (a human clicking a door) and
623
+ // /api/resume ("try the resume again"). The token goes in the request header
624
+ // and nowhere else — never the DOM, a URL, storage or a log. Same-origin. ----
609
625
  function getJSON(path){
610
626
  return fetch(path, { method: "GET", headers: { accept: "application/json" } }).then(function(r){
611
627
  if(!r.ok) throw new Error(path + ": HTTP " + r.status);
612
628
  return r.json();
613
629
  });
614
630
  }
631
+ // Resolves { status, body } for ANY HTTP status (a refusal is data to show by
632
+ // name, never an exception); rejects only on a network failure.
633
+ function postJSON(path, payload){
634
+ return fetch(path, {
635
+ method: "POST",
636
+ headers: { "content-type": "application/json", accept: "application/json", "x-fwdloop-token": TOKEN },
637
+ body: JSON.stringify(payload),
638
+ credentials: "same-origin"
639
+ }).then(function(r){
640
+ return r.text().then(function(t){
641
+ var body = null;
642
+ try{ body = JSON.parse(t); }catch(e){}
643
+ return { status: r.status, body: body, text: t };
644
+ });
645
+ });
646
+ }
615
647
 
616
648
  function escapeXml(s){
617
649
  return String(s).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");
@@ -737,17 +769,17 @@
737
769
  // rendering the raw words green/red/softgreen anywhere (coordinator's
738
770
  // browser-walk fix #2). `verdictWord`/`verdictGlyph` are the ONE place
739
771
  // that turns a verdict (plus the step's own close class, for telling a
740
- // human's reject apart from a mechanical red) into plain words and a
772
+ // human's redo apart from a mechanical red) into plain words and a
741
773
  // pass/fail glyph — used by the step cards, the map's inline attempt
742
774
  // text, and the flat Audit table alike, so they can never say something
743
775
  // different for the same row.
744
776
  // - `paused`/`refused`/an ask timeout/expiry are NOT failures (fix #3) —
745
777
  // no ✗, a plain word instead.
746
- // - a `red` verdict on a `hitl`-classed step is the human's own reject
747
- // (src/runner.js's redo path), not a mechanical stop — "rejected by
778
+ // - a `red` verdict on a `hitl`-classed step is the human's own redo
779
+ // (src/runner.js's redo path), not a mechanical stop — "redo by
748
780
  // you: <reason>", never "verdict red" / a fail glyph (fix #3).
749
781
  function verdictWord(verdict, closeClass, gap){
750
- if(closeClass === "hitl" && verdict === "red") return "rejected by you" + (gap ? ": " + gap : "");
782
+ if(closeClass === "hitl" && verdict === "red") return "redo by you" + (gap ? ": " + gap : "");
751
783
  if(verdict === "paused") return "paused for you";
752
784
  if(verdict === "refused") return "refused — no reason given";
753
785
  if(verdict === "ask-timeout" || verdict === "ask-expired") return "expired waiting for you";
@@ -759,7 +791,7 @@
759
791
  }
760
792
  function verdictPassed(verdict){ return verdict === "green" || verdict === "hitl"; }
761
793
  // `null` — no glyph at all — for a verdict that is neither a pass nor a
762
- // fail (paused/refused/expired/a human reject); a bare attempt glyph
794
+ // fail (paused/refused/expired/a human redo); a bare attempt glyph
763
795
  // would misread a pause as a failure (fix #3).
764
796
  function verdictGlyph(verdict, closeClass){
765
797
  if(closeClass === "hitl" && verdict === "red") return null;
@@ -803,7 +835,7 @@
803
835
  var ROW_GAP = 70;
804
836
  // hamr review #2: "map cards missing try 2 if multiple attempts/iteration"
805
837
  // — a plain "try N" count whenever a step has been attempted more than
806
- // once, plus a mark when the LATEST attempt followed a human reject (the
838
+ // once, plus a mark when the LATEST attempt followed a human redo (the
807
839
  // same `afterReject` boundary src/panel/data.js already worked out —
808
840
  // never re-derived here). One attempt (the common case) shows no "try"
809
841
  // text at all, matching bareloop's own "only say it when it's true" shape.
@@ -816,7 +848,7 @@
816
848
  if(!tryCount || tryCount <= 1) return "";
817
849
  var last = attempts && attempts.length ? attempts[attempts.length - 1] : null;
818
850
  var txt = "try " + tryCount;
819
- if(last && last.afterReject) txt += " (re-attempt after reject)";
851
+ if(last && last.afterReject) txt += " (re-attempt after redo)";
820
852
  return txt;
821
853
  }
822
854
  // hamr review (browser re-walk #1): the per-attempt list ("attempt 1
@@ -1298,7 +1330,7 @@
1298
1330
  'id="' + scope + '-filter-search" data-testid="' + scope + '-filter-search" autocomplete="off">' +
1299
1331
  '<div class="chips" role="group" aria-label="Filter">' +
1300
1332
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[✓]" title="passed" data-testid="chip-' + scope + '-res-pass">✓</button>' +
1301
- '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[✗]" title="failed" data-testid="chip-' + scope + '-res-fail">✗</button>' +
1333
+ '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[✗]" title="stopped" data-testid="chip-' + scope + '-res-fail">✗</button>' +
1302
1334
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[·]" title="waiting on a human" data-testid="chip-' + scope + '-res-waiting">&middot;</button>' +
1303
1335
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[?]" title="running or died: unknown" data-testid="chip-' + scope + '-res-unknown">?</button>' +
1304
1336
  '<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="time" data-filter-value="7d" title="last 7 days" data-testid="chip-' + scope + '-time-7d">7d</button>' +
@@ -2072,6 +2104,60 @@
2072
2104
  });
2073
2105
  }
2074
2106
 
2107
+ // ---- M4b piece 4: re-read the run from the BOOKS. There was no refresh loop
2108
+ // before (the page loaded once), so: `reloadRun` re-reads one run's detail,
2109
+ // asks, audit, job + the inbox and runs lists, applied only if that run is
2110
+ // still the selected one; `startLive` calls it every LIVE_POLL_MS for up to
2111
+ // LIVE_MAX_MS after an answer (or a resume retry) and stops at the first
2112
+ // outcome the books show. Success is only ever said from what this reads. ----
2113
+ var LIVE_POLL_MS = 2000;
2114
+ var LIVE_MAX_MS = 5 * 60 * 1000;
2115
+ var live = null; // { flow, runId, askId, until, timer }
2116
+ function reloadRun(flow, runId){
2117
+ var base = "/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId);
2118
+ var still = function(){ return currentFlow === flow && currentRunId === runId; };
2119
+ var detailP = getJSON(base).then(function(d){ if(still()) renderRun(d); return d; }).catch(function(){ return null; });
2120
+ var asksP = getJSON(base + "/asks").then(function(a){ if(still()) renderAsk(a, null); return a; }).catch(function(e){ if(still()) renderAsk(null, null, e.message); return null; });
2121
+ getJSON(base + "/audit").then(function(a){ if(still()) renderAudit(a); }).catch(function(){});
2122
+ getJSON("/api/inbox").then(function(r){ renderInbox(r.rows || []); }).catch(function(){});
2123
+ getJSON("/api/runs").then(function(r){ runsFilterBar.setItems(r.rows || []); runsFilterBar.refresh(); }).catch(function(){});
2124
+ return Promise.all([detailP, asksP]);
2125
+ }
2126
+ function stopLive(){ if(live){ clearTimeout(live.timer); live = null; } }
2127
+ // What the books say now, in words (pure; `null` = keep waiting).
2128
+ function liveOutcome(askId, detail, asks){
2129
+ if(asks && asks.resume && asks.resume.state === "not-started") return { done: true, cls: null, text: null };
2130
+ var list = (asks && asks.asks) || [];
2131
+ var fresh = list.find(function(a){ return a.waiting && a.askId !== askId; });
2132
+ if(fresh) return { done: true, cls: "info", text: "the run is parked at a new ask — the doors above are for it" };
2133
+ if(detail && detail.glyph === "[✓]") return { done: true, cls: "info", text: "run finished [✓] — the sent artifact is in the Run tab" };
2134
+ if(detail && detail.outcome === "rerun") return { done: true, cls: "info", text: "rerun: this run ended and a fresh run was started — find it in Runs" };
2135
+ if(detail && detail.glyph === "[✗]") return { done: true, cls: "info", text: "run ended [✗] " + (detail.label || "") };
2136
+ var st = asks && asks.resume ? asks.resume.label : null;
2137
+ return { done: false, cls: "info", text: (st || "answer applied") + " — run: " + ((detail && detail.label) || "state unknown") };
2138
+ }
2139
+ function startLive(flow, runId, askId){
2140
+ stopLive();
2141
+ live = { flow: flow, runId: runId, askId: askId, until: Date.now() + LIVE_MAX_MS, timer: null };
2142
+ var mine = live;
2143
+ function tick(){
2144
+ if(live !== mine) return;
2145
+ reloadRun(flow, runId).then(function(res){
2146
+ if(live !== mine) return;
2147
+ var o = liveOutcome(askId, res[0], res[1]);
2148
+ if(o.text) say(flow, runId, o.cls, o.text); else if(o.done){ answerMsg = null; paintAnswerMsg(); }
2149
+ if(o.done){ stopLive(); return; }
2150
+ if(Date.now() > mine.until){
2151
+ say(flow, runId, "info", "no outcome after " + Math.round(LIVE_MAX_MS / 60000) + " minutes of watching — reload the page to check the run's books");
2152
+ stopLive();
2153
+ return;
2154
+ }
2155
+ mine.timer = setTimeout(tick, LIVE_POLL_MS);
2156
+ });
2157
+ }
2158
+ mine.timer = setTimeout(tick, 600);
2159
+ }
2160
+
2075
2161
  getJSON("/api/runs").then(function(result){
2076
2162
  var runs = result.rows || [];
2077
2163
  runsFilterBar.setItems(runs);
@@ -2106,13 +2192,14 @@
2106
2192
  // first with a short status word, off GET /api/inbox
2107
2193
  // (src/panel/data.js's listStops). Status vocabulary is exactly the
2108
2194
  // words the books' own decision field maps to (never a second, made-up
2109
- // vocabulary): "accepted" / "rejected" / "reran" / "expired" /
2195
+ // vocabulary): "accepted" / "redo" / "reran" / "expired" /
2110
2196
  // "unanswered" (this IS the open case) / the rare "open" fallback (an
2111
2197
  // archived ask.json itself failed to parse). No evidence renders here any
2112
2198
  // more — clicking a stop selects its run and opens the wide right pane's
2113
- // Ask tab, focused on that one ask. No answer controls — those are M4b. --
2199
+ // Ask tab, focused on that one ask. The answer doors live in the Ask tab. --
2114
2200
  function stopStatusLine(row){
2115
- if(row.open) return "time left: " + duration(row.timeLeftMs);
2201
+ if(row.waiting) return "time left: " + duration(row.timeLeftMs);
2202
+ if(row.open && row.resume) return row.resume.label;
2116
2203
  var bits = [row.status];
2117
2204
  if(row.reason) bits.push("reason: " + row.reason);
2118
2205
  if(row.answeredAt) bits.push("answered " + (readableDateTime(row.answeredAt) || row.answeredAt));
@@ -2129,7 +2216,7 @@
2129
2216
  var head = document.createElement("div");
2130
2217
  head.className = "wf-line1";
2131
2218
  var badge = document.createElement("span");
2132
- badge.className = "badge " + (row.open ? "amber" : (row.status === "accepted" ? "green" : (row.status === "rejected" ? "red" : "grey")));
2219
+ badge.className = "badge " + (row.open ? "amber" : (row.status === "accepted" ? "green" : (row.status === "redo" ? "red" : "grey")));
2133
2220
  badge.textContent = row.open ? "·" : row.status;
2134
2221
  head.appendChild(badge);
2135
2222
  var flowName = textDiv(null, row.flow + " (" + row.runId + ")");
@@ -2156,7 +2243,7 @@
2156
2243
  var el = document.getElementById("inbox-list");
2157
2244
  el.innerHTML = "";
2158
2245
  var openCount = 0;
2159
- (rows || []).forEach(function(r){ if(r.open) openCount += 1; });
2246
+ (rows || []).forEach(function(r){ if(r.waiting) openCount += 1; });
2160
2247
  document.getElementById("inbox-count-label").textContent = openCount > 0 ? (" (" + openCount + ")") : "";
2161
2248
  if(!rows || !rows.length){
2162
2249
  el.innerHTML = '<div class="hint">nothing waiting on you — no stops recorded under this root</div>';
@@ -2173,19 +2260,158 @@
2173
2260
  // getRunAsks). Clicking a stop in the left Inbox calls `selectRun` with
2174
2261
  // that ask's id, which reaches here as `focusAskId` and expands exactly
2175
2262
  // that one. With no `focusAskId` (a run selected any other way), this
2176
- // run's own open ask (if it has one) expands by default. No answer
2177
- // controls anywhere in this panel (M4b) — a clearly marked EMPTY slot
2178
- // stands in their place; the collapse/expand toggle is a div with
2263
+ // run's own open ask (if it has one) expands by default. M4b: an open ask
2264
+ // carries the answer doors (renderAnswerBlock); the collapse/expand toggle is a div with
2179
2265
  // role="button" (never a real <button>), same posture as the step-map's
2180
2266
  // own SVG nodes elsewhere on this page. ----
2181
2267
  function askStatusBlock(ask){
2182
- if(ask.open) return textDiv("wf-meta", "time left: " + duration(ask.timeLeftMs));
2268
+ if(ask.waiting) return textDiv("wf-meta", "time left: " + duration(ask.timeLeftMs));
2269
+ if(ask.open && ask.resume) return textDiv("wf-meta", ask.resume.label);
2183
2270
  var bits = [ask.status];
2184
2271
  if(ask.reason) bits.push("reason: " + ask.reason);
2185
2272
  if(ask.answeredAt) bits.push("answered " + (readableDateTime(ask.answeredAt) || ask.answeredAt));
2186
2273
  return textDiv("wf-meta", bits.join(" · "));
2187
2274
  }
2188
- function renderAskEvidenceBlock(ask){
2275
+ // ---- M4b piece 4: answer doors. The panel is a CLIENT of the arbiter: it sends
2276
+ // what the human typed and shows the server's/library's refusal by name; it
2277
+ // never decides that a reason is "good enough". ----
2278
+ // Pure: which controls does this ask get? `resume` is the run's own
2279
+ // `resume` field (src/panel/data.js deriveResumeState), never guessed here.
2280
+ function answerControls(ask, resume){
2281
+ if(!ask || !ask.open){
2282
+ return { kind: "none", why: "no answer doors: this ask is " + ((ask && ask.status) || "closed") + " — there is nothing left to answer" };
2283
+ }
2284
+ if(resume && resume.askId === ask.askId){
2285
+ if(resume.state === "starting"){
2286
+ return { kind: "starting", label: resume.label, why: "no answer doors: this ask already has a saved answer" };
2287
+ }
2288
+ if(resume.state === "not-started"){
2289
+ return { kind: "stuck", label: resume.label, reason: resume.reason || "no reason recorded", why: "no answer doors: this ask already has a saved answer" };
2290
+ }
2291
+ return { kind: "none", why: "no answer doors: " + resume.label };
2292
+ }
2293
+ return { kind: "doors" };
2294
+ }
2295
+ // One message per run, shown in the answer block of that run until the next
2296
+ // action. Set by `say`, never by a guess that the answer worked.
2297
+ var answerMsg = null; // { flow, runId, cls: "refused"|"info", text }
2298
+ var reasonDrafts = {}; // askId -> what the human has typed so far
2299
+ function say(flow, runId, cls, text){ answerMsg = { flow: flow, runId: runId, cls: cls, text: text }; paintAnswerMsg(); }
2300
+ function paintAnswerMsg(){
2301
+ document.querySelectorAll("[data-answer-msg]").forEach(function(el){
2302
+ var m = answerMsg;
2303
+ var mine = m && el.getAttribute("data-flow") === m.flow && el.getAttribute("data-run") === m.runId;
2304
+ el.hidden = !mine;
2305
+ el.className = "answer-msg" + (mine ? " " + m.cls : "");
2306
+ el.textContent = mine ? m.text : "";
2307
+ });
2308
+ }
2309
+ function refusalText(r){
2310
+ var b = r.body;
2311
+ var name = b && typeof b.red === "string" ? b.red : (r.text || "no detail");
2312
+ return "HTTP " + r.status + " — " + name;
2313
+ }
2314
+ // While a POST is out the buttons are disabled (stops a double click) — nothing else is ever disabled.
2315
+ function setBusy(root, busy){
2316
+ root.querySelectorAll("button").forEach(function(b){ b.disabled = busy; });
2317
+ }
2318
+ // Every POST names the ask THIS block was rendered for (closure, never
2319
+ // re-read at click time), plus flow/runId captured the same way.
2320
+ function sendAnswer(root, ask, ctx, decision){
2321
+ var ta = root.querySelector("textarea");
2322
+ var payload = { flow: ctx.flow, runId: ctx.runId, askId: ask.askId, decision: decision, reason: ta ? ta.value : "" };
2323
+ say(ctx.flow, ctx.runId, "info", "sending " + decision + "…");
2324
+ setBusy(root, true);
2325
+ postJSON("/api/answer", payload).then(function(r){
2326
+ if(r.status === 202 && r.body && r.body.ok){
2327
+ delete reasonDrafts[ask.askId];
2328
+ say(ctx.flow, ctx.runId, "info", "answer sent (" + decision + ") — waiting for the run's books to show what happened");
2329
+ startLive(ctx.flow, ctx.runId, ask.askId);
2330
+ } else {
2331
+ say(ctx.flow, ctx.runId, "refused", refusalText(r));
2332
+ }
2333
+ return reloadRun(ctx.flow, ctx.runId);
2334
+ }).catch(function(e){
2335
+ say(ctx.flow, ctx.runId, "refused", "network failure: " + e.message + " — nothing is confirmed; what the books say is shown in the ask header above");
2336
+ return reloadRun(ctx.flow, ctx.runId);
2337
+ }).then(function(){ if(root.isConnected) setBusy(root, false); });
2338
+ }
2339
+ function sendResumeAgain(root, ctx, askId){
2340
+ say(ctx.flow, ctx.runId, "info", "asking for the resume again…");
2341
+ setBusy(root, true);
2342
+ postJSON("/api/resume", { flow: ctx.flow, runId: ctx.runId }).then(function(r){
2343
+ if(r.status === 202 && r.body && r.body.ok){
2344
+ say(ctx.flow, ctx.runId, "info", "resume requested — waiting for the run's books to show whether it took over");
2345
+ startLive(ctx.flow, ctx.runId, askId);
2346
+ } else {
2347
+ say(ctx.flow, ctx.runId, "refused", refusalText(r));
2348
+ }
2349
+ return reloadRun(ctx.flow, ctx.runId);
2350
+ }).catch(function(e){
2351
+ say(ctx.flow, ctx.runId, "refused", "network failure: " + e.message + " — nothing is confirmed; what the books say is shown in the ask header above");
2352
+ return reloadRun(ctx.flow, ctx.runId);
2353
+ }).then(function(){ if(root.isConnected) setBusy(root, false); });
2354
+ }
2355
+ function makeButton(label, testid, onClick){
2356
+ var b = document.createElement("button");
2357
+ b.type = "button";
2358
+ b.className = "btn";
2359
+ b.textContent = label;
2360
+ b.setAttribute("data-testid", testid);
2361
+ b.addEventListener("click", onClick);
2362
+ return b;
2363
+ }
2364
+ function renderAnswerBlock(ask, ctx){
2365
+ var model = answerControls(ask, ctx.resume);
2366
+ var root = document.createElement("div");
2367
+ root.className = "answer-doors";
2368
+ root.setAttribute("data-testid", "answer-doors");
2369
+ if(model.kind === "doors"){
2370
+ var idSafe = "reason-" + String(ask.askId).replace(/[^A-Za-z0-9_-]/g, "_");
2371
+ var lab = document.createElement("label");
2372
+ lab.setAttribute("for", idSafe);
2373
+ lab.textContent = "reason (needed for redo and rerun)";
2374
+ var ta = document.createElement("textarea");
2375
+ ta.id = idSafe;
2376
+ ta.rows = 3;
2377
+ ta.setAttribute("data-testid", "answer-reason");
2378
+ ta.value = reasonDrafts[ask.askId] || "";
2379
+ ta.addEventListener("input", function(){ reasonDrafts[ask.askId] = ta.value; });
2380
+ root.appendChild(lab);
2381
+ root.appendChild(ta);
2382
+ var bar = document.createElement("div");
2383
+ bar.className = "actions-row";
2384
+ bar.setAttribute("data-testid", "action-bar");
2385
+ bar.appendChild(makeButton("Accept", "btn-accept", function(){ sendAnswer(root, ask, ctx, "accept"); }));
2386
+ bar.appendChild(makeButton("Redo", "btn-redo", function(){ sendAnswer(root, ask, ctx, "redo"); }));
2387
+ bar.appendChild(makeButton("Rerun", "btn-rerun", function(){ sendAnswer(root, ask, ctx, "rerun"); }));
2388
+ root.appendChild(bar);
2389
+ root.appendChild(textDiv("hint", "accept ships this draft; redo: redo the last step with your reason; rerun: end this run and start a fresh one from the top"));
2390
+ } else if(model.kind === "starting"){
2391
+ root.appendChild(textDiv("hint", model.label + " — " + model.why));
2392
+ } else if(model.kind === "stuck"){
2393
+ root.appendChild(textDiv("answer-msg stuck", model.label + ": " + model.reason));
2394
+ root.appendChild(textDiv("hint", model.why + ". Trying again starts a resume only; it cannot answer."));
2395
+ var bar2 = document.createElement("div");
2396
+ bar2.className = "actions-row";
2397
+ bar2.appendChild(makeButton("Try the resume again", "btn-resume-again", function(){ sendResumeAgain(root, ctx, ask.askId); }));
2398
+ root.appendChild(bar2);
2399
+ } else {
2400
+ root.appendChild(textDiv("hint", model.why));
2401
+ }
2402
+ var msg = document.createElement("div");
2403
+ msg.setAttribute("data-answer-msg", "1");
2404
+ msg.setAttribute("data-flow", ctx.flow);
2405
+ msg.setAttribute("data-run", ctx.runId);
2406
+ msg.setAttribute("role", "status");
2407
+ msg.setAttribute("aria-live", "polite");
2408
+ msg.setAttribute("data-testid", "answer-msg");
2409
+ msg.hidden = true;
2410
+ root.appendChild(msg);
2411
+ setTimeout(paintAnswerMsg, 0);
2412
+ return root;
2413
+ }
2414
+ function renderAskEvidenceBlock(ask, ctx){
2189
2415
  var ev = document.createElement("div");
2190
2416
  ev.className = "attempts-list";
2191
2417
  var evidence = ask.evidence || {};
@@ -2221,14 +2447,8 @@
2221
2447
  art.textContent = typeof u.text === "string" ? u.text : "no artifact text on file";
2222
2448
  ev.appendChild(art);
2223
2449
  });
2224
- // M4b's answer doors (accept/reject/rerun) land here — this panel is
2225
- // read-only by construction (M4a-1 scope), so the slot is empty and
2226
- // clearly marked rather than silently absent.
2227
- var answerSlot = document.createElement("div");
2228
- answerSlot.className = "hint";
2229
- answerSlot.setAttribute("data-testid", "ask-answer-slot");
2230
- answerSlot.textContent = "answer controls are not built yet (M4b)";
2231
- ev.appendChild(answerSlot);
2450
+ // M4b piece 4: the answer doors (or the reason there are none) live here.
2451
+ ev.appendChild(renderAnswerBlock(ask, ctx));
2232
2452
  return ev;
2233
2453
  }
2234
2454
  // hamr's 2026-09-27 exit-check review #3: "when opened from an Inbox
@@ -2246,10 +2466,10 @@
2246
2466
  : (ask.stepWhy || "step not determinable");
2247
2467
  bits.push(stepBit);
2248
2468
  bits.push(typeof ask.askedAt === "string" ? "asked " + (readableDateTime(ask.askedAt) || ask.askedAt) : "asked: unknown");
2249
- bits.push(ask.open ? "waiting on you" : ask.status);
2469
+ bits.push(ask.waiting ? "waiting on you" : (ask.open && ask.resume ? ask.resume.label : ask.status));
2250
2470
  return bits.join(" · ");
2251
2471
  }
2252
- function renderAskRow(ask, expanded){
2472
+ function renderAskRow(ask, expanded, ctx){
2253
2473
  var wrap = document.createElement("div");
2254
2474
  wrap.className = "audit-group";
2255
2475
  wrap.setAttribute("data-testid", "ask-row-" + (ask.askId || "no-id"));
@@ -2261,7 +2481,7 @@
2261
2481
  var metaLine = document.createElement("div");
2262
2482
  metaLine.className = "wf-line1";
2263
2483
  var badge = document.createElement("span");
2264
- badge.className = "badge " + (ask.open ? "amber" : (ask.status === "accepted" ? "green" : (ask.status === "rejected" ? "red" : "grey")));
2484
+ badge.className = "badge " + (ask.open ? "amber" : (ask.status === "accepted" ? "green" : (ask.status === "redo" ? "red" : "grey")));
2265
2485
  badge.textContent = ask.open ? "·" : ask.status;
2266
2486
  metaLine.appendChild(badge);
2267
2487
  metaLine.appendChild(textDiv("wf-meta", askHeaderMetaText(ask)));
@@ -2277,7 +2497,7 @@
2277
2497
  var body = document.createElement("div");
2278
2498
  body.hidden = !expanded;
2279
2499
  body.appendChild(askStatusBlock(ask));
2280
- body.appendChild(renderAskEvidenceBlock(ask));
2500
+ body.appendChild(renderAskEvidenceBlock(ask, ctx));
2281
2501
  wrap.appendChild(body);
2282
2502
  function toggle(){
2283
2503
  var next = body.hidden;
@@ -2316,7 +2536,7 @@
2316
2536
  }
2317
2537
  asks.forEach(function(ask){
2318
2538
  var expanded = defaultOpenId != null && ask.askId === defaultOpenId;
2319
- var row = renderAskRow(ask, expanded);
2539
+ var row = renderAskRow(ask, expanded, { flow: result.flow, runId: result.runId, resume: result.resume || null });
2320
2540
  // hamr's 2026-09-27 exit-check review #3: "the ask opened from the
2321
2541
  // Inbox gets a visible highlight" — a REAL Inbox click (`focusAskId`
2322
2542
  // set) on THIS ask, never a run's own default open-ask expansion