fwdloop 0.8.0 → 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.
- package/bin/fwdloop +10 -8
- package/package.json +1 -1
- package/src/ask.js +112 -14
- package/src/drafter.js +2 -2
- package/src/panel/data.js +145 -39
- package/src/panel/index.html +269 -58
- package/src/panel/resume.js +197 -0
- package/src/panel/server.js +166 -14
- package/src/provider.js +1 -1
- package/src/runner.js +46 -24
- package/src/send.js +19 -2
- package/src/types.js +2 -2
- package/types/ask.d.ts +63 -5
- package/types/panel/data.d.ts +63 -12
- package/types/panel/resume.d.ts +51 -0
- package/types/panel/server.d.ts +15 -3
- package/types/runner.d.ts +5 -4
- package/types/send.d.ts +4 -1
- package/types/types.d.ts +2 -2
package/src/panel/index.html
CHANGED
|
@@ -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
|
|
425
|
-
<code>fwdloop</code> CLI
|
|
426
|
-
|
|
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]/[
|
|
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.
|
|
438
|
-
answer
|
|
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.
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
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
|
|
607
|
-
// (
|
|
608
|
-
//
|
|
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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");
|
|
@@ -644,14 +676,6 @@
|
|
|
644
676
|
bits.push(duration(r.wallMs));
|
|
645
677
|
return bits.join(" · ");
|
|
646
678
|
}
|
|
647
|
-
// hamr's 2026-09-27 review item (d): the new Time column — this row's own
|
|
648
|
-
// `at`, read locally (`readableDateTime`, same formatter every other
|
|
649
|
-
// timestamp on this page already uses); a pre-M4a-2 row (server-derived
|
|
650
|
-
// `r.atWhy`) shows its own why instead of guessing a date.
|
|
651
|
-
function auditTimeCellText(r){
|
|
652
|
-
if(typeof r.atWhy === "string" && r.atWhy.length > 0) return r.atWhy;
|
|
653
|
-
return readableDateTime(r.at) || "unknown";
|
|
654
|
-
}
|
|
655
679
|
// fix (2026-09-28, borrowed-from: bareloop src/panel/index.html@2711b1b):
|
|
656
680
|
// hamr's UI review found the Time cell's full date+time string overflowed
|
|
657
681
|
// the Audit tab's mobile stacked-card cell sideways at 390px. bareloop's
|
|
@@ -663,8 +687,7 @@
|
|
|
663
687
|
// in `title` is the same local `readableDateTime` string used everywhere
|
|
664
688
|
// else, not the raw ISO. A pre-M4a-2 row's `atWhy` (or a genuinely
|
|
665
689
|
// unparseable/missing `at`) is unaffected: that text renders plain, never
|
|
666
|
-
// wrapped in a <span title
|
|
667
|
-
// stays exactly what it was.
|
|
690
|
+
// wrapped in a <span title>.
|
|
668
691
|
function auditTimeCellHtml(r){
|
|
669
692
|
if(typeof r.atWhy === "string" && r.atWhy.length > 0) return escapeXml(r.atWhy);
|
|
670
693
|
var full = readableDateTime(r.at);
|
|
@@ -746,17 +769,17 @@
|
|
|
746
769
|
// rendering the raw words green/red/softgreen anywhere (coordinator's
|
|
747
770
|
// browser-walk fix #2). `verdictWord`/`verdictGlyph` are the ONE place
|
|
748
771
|
// that turns a verdict (plus the step's own close class, for telling a
|
|
749
|
-
// human's
|
|
772
|
+
// human's redo apart from a mechanical red) into plain words and a
|
|
750
773
|
// pass/fail glyph — used by the step cards, the map's inline attempt
|
|
751
774
|
// text, and the flat Audit table alike, so they can never say something
|
|
752
775
|
// different for the same row.
|
|
753
776
|
// - `paused`/`refused`/an ask timeout/expiry are NOT failures (fix #3) —
|
|
754
777
|
// no ✗, a plain word instead.
|
|
755
|
-
// - a `red` verdict on a `hitl`-classed step is the human's own
|
|
756
|
-
// (src/runner.js's redo path), not a mechanical stop — "
|
|
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
|
|
757
780
|
// you: <reason>", never "verdict red" / a fail glyph (fix #3).
|
|
758
781
|
function verdictWord(verdict, closeClass, gap){
|
|
759
|
-
if(closeClass === "hitl" && verdict === "red") return "
|
|
782
|
+
if(closeClass === "hitl" && verdict === "red") return "redo by you" + (gap ? ": " + gap : "");
|
|
760
783
|
if(verdict === "paused") return "paused for you";
|
|
761
784
|
if(verdict === "refused") return "refused — no reason given";
|
|
762
785
|
if(verdict === "ask-timeout" || verdict === "ask-expired") return "expired waiting for you";
|
|
@@ -768,7 +791,7 @@
|
|
|
768
791
|
}
|
|
769
792
|
function verdictPassed(verdict){ return verdict === "green" || verdict === "hitl"; }
|
|
770
793
|
// `null` — no glyph at all — for a verdict that is neither a pass nor a
|
|
771
|
-
// fail (paused/refused/expired/a human
|
|
794
|
+
// fail (paused/refused/expired/a human redo); a bare attempt glyph
|
|
772
795
|
// would misread a pause as a failure (fix #3).
|
|
773
796
|
function verdictGlyph(verdict, closeClass){
|
|
774
797
|
if(closeClass === "hitl" && verdict === "red") return null;
|
|
@@ -812,7 +835,7 @@
|
|
|
812
835
|
var ROW_GAP = 70;
|
|
813
836
|
// hamr review #2: "map cards missing try 2 if multiple attempts/iteration"
|
|
814
837
|
// — a plain "try N" count whenever a step has been attempted more than
|
|
815
|
-
// once, plus a mark when the LATEST attempt followed a human
|
|
838
|
+
// once, plus a mark when the LATEST attempt followed a human redo (the
|
|
816
839
|
// same `afterReject` boundary src/panel/data.js already worked out —
|
|
817
840
|
// never re-derived here). One attempt (the common case) shows no "try"
|
|
818
841
|
// text at all, matching bareloop's own "only say it when it's true" shape.
|
|
@@ -825,7 +848,7 @@
|
|
|
825
848
|
if(!tryCount || tryCount <= 1) return "";
|
|
826
849
|
var last = attempts && attempts.length ? attempts[attempts.length - 1] : null;
|
|
827
850
|
var txt = "try " + tryCount;
|
|
828
|
-
if(last && last.afterReject) txt += " (re-attempt after
|
|
851
|
+
if(last && last.afterReject) txt += " (re-attempt after redo)";
|
|
829
852
|
return txt;
|
|
830
853
|
}
|
|
831
854
|
// hamr review (browser re-walk #1): the per-attempt list ("attempt 1
|
|
@@ -1307,7 +1330,7 @@
|
|
|
1307
1330
|
'id="' + scope + '-filter-search" data-testid="' + scope + '-filter-search" autocomplete="off">' +
|
|
1308
1331
|
'<div class="chips" role="group" aria-label="Filter">' +
|
|
1309
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>' +
|
|
1310
|
-
'<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[✗]" title="
|
|
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>' +
|
|
1311
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">·</button>' +
|
|
1312
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>' +
|
|
1313
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>' +
|
|
@@ -2081,6 +2104,60 @@
|
|
|
2081
2104
|
});
|
|
2082
2105
|
}
|
|
2083
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
|
+
|
|
2084
2161
|
getJSON("/api/runs").then(function(result){
|
|
2085
2162
|
var runs = result.rows || [];
|
|
2086
2163
|
runsFilterBar.setItems(runs);
|
|
@@ -2115,13 +2192,14 @@
|
|
|
2115
2192
|
// first with a short status word, off GET /api/inbox
|
|
2116
2193
|
// (src/panel/data.js's listStops). Status vocabulary is exactly the
|
|
2117
2194
|
// words the books' own decision field maps to (never a second, made-up
|
|
2118
|
-
// vocabulary): "accepted" / "
|
|
2195
|
+
// vocabulary): "accepted" / "redo" / "reran" / "expired" /
|
|
2119
2196
|
// "unanswered" (this IS the open case) / the rare "open" fallback (an
|
|
2120
2197
|
// archived ask.json itself failed to parse). No evidence renders here any
|
|
2121
2198
|
// more — clicking a stop selects its run and opens the wide right pane's
|
|
2122
|
-
// Ask tab, focused on that one ask.
|
|
2199
|
+
// Ask tab, focused on that one ask. The answer doors live in the Ask tab. --
|
|
2123
2200
|
function stopStatusLine(row){
|
|
2124
|
-
if(row.
|
|
2201
|
+
if(row.waiting) return "time left: " + duration(row.timeLeftMs);
|
|
2202
|
+
if(row.open && row.resume) return row.resume.label;
|
|
2125
2203
|
var bits = [row.status];
|
|
2126
2204
|
if(row.reason) bits.push("reason: " + row.reason);
|
|
2127
2205
|
if(row.answeredAt) bits.push("answered " + (readableDateTime(row.answeredAt) || row.answeredAt));
|
|
@@ -2138,7 +2216,7 @@
|
|
|
2138
2216
|
var head = document.createElement("div");
|
|
2139
2217
|
head.className = "wf-line1";
|
|
2140
2218
|
var badge = document.createElement("span");
|
|
2141
|
-
badge.className = "badge " + (row.open ? "amber" : (row.status === "accepted" ? "green" : (row.status === "
|
|
2219
|
+
badge.className = "badge " + (row.open ? "amber" : (row.status === "accepted" ? "green" : (row.status === "redo" ? "red" : "grey")));
|
|
2142
2220
|
badge.textContent = row.open ? "·" : row.status;
|
|
2143
2221
|
head.appendChild(badge);
|
|
2144
2222
|
var flowName = textDiv(null, row.flow + " (" + row.runId + ")");
|
|
@@ -2165,7 +2243,7 @@
|
|
|
2165
2243
|
var el = document.getElementById("inbox-list");
|
|
2166
2244
|
el.innerHTML = "";
|
|
2167
2245
|
var openCount = 0;
|
|
2168
|
-
(rows || []).forEach(function(r){ if(r.
|
|
2246
|
+
(rows || []).forEach(function(r){ if(r.waiting) openCount += 1; });
|
|
2169
2247
|
document.getElementById("inbox-count-label").textContent = openCount > 0 ? (" (" + openCount + ")") : "";
|
|
2170
2248
|
if(!rows || !rows.length){
|
|
2171
2249
|
el.innerHTML = '<div class="hint">nothing waiting on you — no stops recorded under this root</div>';
|
|
@@ -2182,19 +2260,158 @@
|
|
|
2182
2260
|
// getRunAsks). Clicking a stop in the left Inbox calls `selectRun` with
|
|
2183
2261
|
// that ask's id, which reaches here as `focusAskId` and expands exactly
|
|
2184
2262
|
// that one. With no `focusAskId` (a run selected any other way), this
|
|
2185
|
-
// run's own open ask (if it has one) expands by default.
|
|
2186
|
-
//
|
|
2187
|
-
// 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
|
|
2188
2265
|
// role="button" (never a real <button>), same posture as the step-map's
|
|
2189
2266
|
// own SVG nodes elsewhere on this page. ----
|
|
2190
2267
|
function askStatusBlock(ask){
|
|
2191
|
-
if(ask.
|
|
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);
|
|
2192
2270
|
var bits = [ask.status];
|
|
2193
2271
|
if(ask.reason) bits.push("reason: " + ask.reason);
|
|
2194
2272
|
if(ask.answeredAt) bits.push("answered " + (readableDateTime(ask.answeredAt) || ask.answeredAt));
|
|
2195
2273
|
return textDiv("wf-meta", bits.join(" · "));
|
|
2196
2274
|
}
|
|
2197
|
-
|
|
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){
|
|
2198
2415
|
var ev = document.createElement("div");
|
|
2199
2416
|
ev.className = "attempts-list";
|
|
2200
2417
|
var evidence = ask.evidence || {};
|
|
@@ -2230,14 +2447,8 @@
|
|
|
2230
2447
|
art.textContent = typeof u.text === "string" ? u.text : "no artifact text on file";
|
|
2231
2448
|
ev.appendChild(art);
|
|
2232
2449
|
});
|
|
2233
|
-
// M4b
|
|
2234
|
-
|
|
2235
|
-
// clearly marked rather than silently absent.
|
|
2236
|
-
var answerSlot = document.createElement("div");
|
|
2237
|
-
answerSlot.className = "hint";
|
|
2238
|
-
answerSlot.setAttribute("data-testid", "ask-answer-slot");
|
|
2239
|
-
answerSlot.textContent = "answer controls are not built yet (M4b)";
|
|
2240
|
-
ev.appendChild(answerSlot);
|
|
2450
|
+
// M4b piece 4: the answer doors (or the reason there are none) live here.
|
|
2451
|
+
ev.appendChild(renderAnswerBlock(ask, ctx));
|
|
2241
2452
|
return ev;
|
|
2242
2453
|
}
|
|
2243
2454
|
// hamr's 2026-09-27 exit-check review #3: "when opened from an Inbox
|
|
@@ -2255,10 +2466,10 @@
|
|
|
2255
2466
|
: (ask.stepWhy || "step not determinable");
|
|
2256
2467
|
bits.push(stepBit);
|
|
2257
2468
|
bits.push(typeof ask.askedAt === "string" ? "asked " + (readableDateTime(ask.askedAt) || ask.askedAt) : "asked: unknown");
|
|
2258
|
-
bits.push(ask.
|
|
2469
|
+
bits.push(ask.waiting ? "waiting on you" : (ask.open && ask.resume ? ask.resume.label : ask.status));
|
|
2259
2470
|
return bits.join(" · ");
|
|
2260
2471
|
}
|
|
2261
|
-
function renderAskRow(ask, expanded){
|
|
2472
|
+
function renderAskRow(ask, expanded, ctx){
|
|
2262
2473
|
var wrap = document.createElement("div");
|
|
2263
2474
|
wrap.className = "audit-group";
|
|
2264
2475
|
wrap.setAttribute("data-testid", "ask-row-" + (ask.askId || "no-id"));
|
|
@@ -2270,7 +2481,7 @@
|
|
|
2270
2481
|
var metaLine = document.createElement("div");
|
|
2271
2482
|
metaLine.className = "wf-line1";
|
|
2272
2483
|
var badge = document.createElement("span");
|
|
2273
|
-
badge.className = "badge " + (ask.open ? "amber" : (ask.status === "accepted" ? "green" : (ask.status === "
|
|
2484
|
+
badge.className = "badge " + (ask.open ? "amber" : (ask.status === "accepted" ? "green" : (ask.status === "redo" ? "red" : "grey")));
|
|
2274
2485
|
badge.textContent = ask.open ? "·" : ask.status;
|
|
2275
2486
|
metaLine.appendChild(badge);
|
|
2276
2487
|
metaLine.appendChild(textDiv("wf-meta", askHeaderMetaText(ask)));
|
|
@@ -2286,7 +2497,7 @@
|
|
|
2286
2497
|
var body = document.createElement("div");
|
|
2287
2498
|
body.hidden = !expanded;
|
|
2288
2499
|
body.appendChild(askStatusBlock(ask));
|
|
2289
|
-
body.appendChild(renderAskEvidenceBlock(ask));
|
|
2500
|
+
body.appendChild(renderAskEvidenceBlock(ask, ctx));
|
|
2290
2501
|
wrap.appendChild(body);
|
|
2291
2502
|
function toggle(){
|
|
2292
2503
|
var next = body.hidden;
|
|
@@ -2325,7 +2536,7 @@
|
|
|
2325
2536
|
}
|
|
2326
2537
|
asks.forEach(function(ask){
|
|
2327
2538
|
var expanded = defaultOpenId != null && ask.askId === defaultOpenId;
|
|
2328
|
-
var row = renderAskRow(ask, expanded);
|
|
2539
|
+
var row = renderAskRow(ask, expanded, { flow: result.flow, runId: result.runId, resume: result.resume || null });
|
|
2329
2540
|
// hamr's 2026-09-27 exit-check review #3: "the ask opened from the
|
|
2330
2541
|
// Inbox gets a visible highlight" — a REAL Inbox click (`focusAskId`
|
|
2331
2542
|
// set) on THIS ask, never a run's own default open-ask expansion
|