fwdloop 0.9.0 → 0.10.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/package.json +1 -1
- package/src/ask.js +19 -0
- package/src/books.js +20 -0
- package/src/liveness.js +160 -0
- package/src/panel/data.js +315 -50
- package/src/panel/index.html +380 -110
- package/src/panel/server.js +3 -2
- package/src/runner.js +72 -18
- package/types/ask.d.ts +12 -0
- package/types/books.d.ts +19 -0
- package/types/liveness.d.ts +69 -0
- package/types/panel/data.d.ts +126 -15
- package/types/runner.d.ts +4 -3
package/src/panel/index.html
CHANGED
|
@@ -153,6 +153,26 @@
|
|
|
153
153
|
arrow [▶], which this reserves for "running" alone. Its own class so
|
|
154
154
|
the two states never share a ::before rule. */
|
|
155
155
|
.dot.expired::before{content:"[!]";color:var(--amber);}
|
|
156
|
+
/* M4c amendment 2: stuck — answer saved, nobody carrying the run on. Its own glyph,
|
|
157
|
+
amber like the other "needs you" signs; it pulses (server-decided, glyphPulses). */
|
|
158
|
+
.dot.stuck::before{content:"[II]";color:var(--amber);}
|
|
159
|
+
/* M4c: only the two "alive" signs pulse — [▶] running and [·] waiting on
|
|
160
|
+
you — keyed to `.pulse`, which the server decides (glyphPulses), never to
|
|
161
|
+
a colour class (.grey is also the placeholder dot). A gentle opacity wave on the existing colors;
|
|
162
|
+
reduced-motion keeps the sign and drops only the animation. */
|
|
163
|
+
@keyframes signPulse{0%,100%{opacity:1;}50%{opacity:.35;}}
|
|
164
|
+
.dot.pulse::before{animation:signPulse 1.6s ease-in-out infinite;}
|
|
165
|
+
@media (prefers-reduced-motion: reduce){
|
|
166
|
+
.dot.pulse::before{animation:none;}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* M4c inbox: section 1 (waiting on you) carries the page's amber accent
|
|
170
|
+
treatment; section 3 (answered/expired) is dimmed. Tokens only. */
|
|
171
|
+
.inbox-h{font-size:12px;color:var(--text-dim);font-weight:700;margin:12px 0 6px;}
|
|
172
|
+
.inbox-h:first-child{margin-top:0;}
|
|
173
|
+
.inbox-row.s1{border-left:4px solid var(--amber);background:var(--amber-bg);}
|
|
174
|
+
.inbox-row.s3{opacity:.6;}
|
|
175
|
+
.inbox-row .wf-line1{min-width:0;}
|
|
156
176
|
|
|
157
177
|
.badge{display:inline-block;font-size:11px;padding:1px 4px;color:var(--text-dim);background:none;font-weight:700;}
|
|
158
178
|
.badge::before{content:"[";color:var(--text-faint);}
|
|
@@ -178,6 +198,8 @@
|
|
|
178
198
|
.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
199
|
.answer-doors .actions-row{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px;}
|
|
180
200
|
.answer-doors .btn{min-width:44px;}
|
|
201
|
+
.working-line{margin-top:4px;font-size:13px;color:var(--text);overflow-wrap:anywhere;}
|
|
202
|
+
.answer-line{font-size:13px;color:var(--text-dim);margin:2px 0;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word;}
|
|
181
203
|
.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
204
|
.answer-msg.refused{border-color:var(--red);}
|
|
183
205
|
.answer-msg.refused::before{content:"refused: ";color:var(--red);font-weight:700;}
|
|
@@ -342,8 +364,8 @@
|
|
|
342
364
|
("resume-text"/"jd-text" etc.), never the faint `.hint` style. */
|
|
343
365
|
.evidence-heading{font-size:11px;font-weight:700;color:var(--text-dim);margin:8px 0 3px;text-transform:uppercase;letter-spacing:0.04em;}
|
|
344
366
|
.evidence-heading:first-child{margin-top:0;}
|
|
345
|
-
/* review #3: the ask's own question, a real heading under the "
|
|
346
|
-
|
|
367
|
+
/* review #3: the ask's own question, a real heading under the "step ·
|
|
368
|
+
draft N · asked · status" meta line — reuses the box-drawing h4 look
|
|
347
369
|
the Audit/Job group headers already use, but inline (no absolute
|
|
348
370
|
┤ ├ pips — those are reserved for a whole-box title, not an in-flow
|
|
349
371
|
line) so it reads as a clear, bold heading without a second border. */
|
|
@@ -425,10 +447,10 @@
|
|
|
425
447
|
<div class="tabrow" role="tablist" aria-label="Left panel views">
|
|
426
448
|
<button role="tab" id="tab-chat" aria-controls="panel-chat" aria-selected="true" data-testid="left-tab-chat">Chat</button>
|
|
427
449
|
<button role="tab" id="tab-runs" aria-controls="panel-runs" aria-selected="false" data-testid="left-tab-runs">Runs</button>
|
|
428
|
-
<button role="tab" id="tab-inbox" aria-controls="panel-inbox" aria-selected="false" data-testid="left-tab-inbox">Inbox<span id="inbox-count-label"
|
|
450
|
+
<button role="tab" id="tab-inbox" aria-controls="panel-inbox" aria-selected="false" data-testid="left-tab-inbox">Inbox<span id="inbox-count-label"> (0)</span></button>
|
|
429
451
|
</div>
|
|
430
452
|
|
|
431
|
-
<div class="pane-body">
|
|
453
|
+
<div class="pane-body" id="left-pane-body">
|
|
432
454
|
|
|
433
455
|
<section id="panel-chat" class="tabpanel active" role="tabpanel" aria-labelledby="tab-chat">
|
|
434
456
|
<div class="chat-thread">
|
|
@@ -483,7 +505,7 @@
|
|
|
483
505
|
<button role="tab" id="tab-ask" aria-controls="panel-ask" aria-selected="false" data-testid="right-tab-ask">Ask</button>
|
|
484
506
|
</div>
|
|
485
507
|
|
|
486
|
-
<div class="pane-body">
|
|
508
|
+
<div class="pane-body" id="right-pane-body">
|
|
487
509
|
|
|
488
510
|
<section id="panel-run" class="tabpanel active" role="tabpanel" aria-labelledby="tab-run">
|
|
489
511
|
<div id="run-empty" class="hint" style="font-size:13px;padding:24px 0;">select a run from Workflows or History</div>
|
|
@@ -799,8 +821,11 @@
|
|
|
799
821
|
return verdictPassed(verdict) ? "✓" : "✗";
|
|
800
822
|
}
|
|
801
823
|
// The run-row glyph strings src/panel/data.js's computeGlyph emits are
|
|
802
|
-
// already bracketed ("[✓]", "[✗]", "[·]", "[?]") — this only ever picks a
|
|
824
|
+
// already bracketed ("[✓]", "[✗]", "[·]", "[▶]", "[?]") — this only ever picks a
|
|
803
825
|
// CSS color class off them, never re-derives the glyph itself.
|
|
826
|
+
// the dot's class list: colour from the glyph, `pulse` only when the server
|
|
827
|
+
// says this sign is [▶] running or [·] waiting on you (data.js glyphPulses).
|
|
828
|
+
function dotClass(g, pulse){ return "dot " + glyphClass(g) + (pulse ? " pulse" : ""); }
|
|
804
829
|
function glyphClass(g){
|
|
805
830
|
if(g === "[✓]") return "green";
|
|
806
831
|
if(g === "[✗]") return "red";
|
|
@@ -813,6 +838,7 @@
|
|
|
813
838
|
// "running", but a different glyph, so it gets its own dot class
|
|
814
839
|
// (never "amber", which draws the reserved running arrow [▶]).
|
|
815
840
|
if(g === "[!]") return "expired";
|
|
841
|
+
if(g === "[II]") return "stuck";
|
|
816
842
|
return "grey"; // "[·]" — waiting on a human, or answered-not-resumed
|
|
817
843
|
}
|
|
818
844
|
|
|
@@ -1137,18 +1163,35 @@
|
|
|
1137
1163
|
return row;
|
|
1138
1164
|
}
|
|
1139
1165
|
row.innerHTML =
|
|
1140
|
-
'<span class="wf-line1"><span class="
|
|
1166
|
+
'<span class="wf-line1"><span class="' + dotClass(r.glyph, r.pulse) + '"></span>' +
|
|
1141
1167
|
'<span class="wf-name" title="' + escapeXml(fullName) + '">' + escapeXml(fullName) + '</span></span>' +
|
|
1142
1168
|
'<span class="wf-meta-line">' +
|
|
1143
1169
|
'<span class="wf-meta">' + escapeXml(r.label || "unknown") + '</span>' +
|
|
1144
|
-
'<span class="wf-meta">' + escapeXml(r
|
|
1145
|
-
'<span class="wf-meta">' + escapeXml(
|
|
1170
|
+
'<span class="wf-meta">' + escapeXml(runSpendText(r)) + '</span>' +
|
|
1171
|
+
'<span class="wf-meta">' + escapeXml(runAtText(r)) + '</span>' +
|
|
1146
1172
|
'</span>';
|
|
1147
|
-
row.addEventListener("click", function(){
|
|
1173
|
+
row.addEventListener("click", function(){ openRunFromRuns(r, row); });
|
|
1148
1174
|
row.addEventListener("keydown", function(e){ if(e.key === "Enter" || e.key === " "){ e.preventDefault(); row.click(); } });
|
|
1149
1175
|
return row;
|
|
1150
1176
|
}
|
|
1151
1177
|
|
|
1178
|
+
// M4c amendment 1 (a): the ONE place a click on a run in Runs decides where it lands.
|
|
1179
|
+
// Right side: that run, on the Run tab. A run with an ask waiting on the human also
|
|
1180
|
+
// moves the left side to the Inbox with that ask's row selected; any other run leaves
|
|
1181
|
+
// the left side on Runs.
|
|
1182
|
+
function openRunFromRuns(r, rowEl){
|
|
1183
|
+
if(r.waiting){
|
|
1184
|
+
var inboxId = "inbox-row-" + r.flow + "-" + r.runId + "-" + r.waitingAskId;
|
|
1185
|
+
var inboxRow = Array.prototype.find.call(document.querySelectorAll(".inbox-row"), function(el){ return el.getAttribute("data-testid") === inboxId; }) || null;
|
|
1186
|
+
selectRun(r.flow, r.runId, inboxRow, ".inbox-row", r.waitingAskId);
|
|
1187
|
+
document.getElementById("tab-inbox").click();
|
|
1188
|
+
} else {
|
|
1189
|
+
selectRun(r.flow, r.runId, rowEl, ".hist-row");
|
|
1190
|
+
}
|
|
1191
|
+
document.getElementById("tab-run").click();
|
|
1192
|
+
scrollRunIntoViewMobile();
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1152
1195
|
// ---- History view: every row exactly as /api/runs returned it. ----
|
|
1153
1196
|
function renderHistory(runs){
|
|
1154
1197
|
var el = document.getElementById("history-list");
|
|
@@ -1163,6 +1206,14 @@
|
|
|
1163
1206
|
// ---- Workflows view: groups the ONE /api/runs payload by flow name
|
|
1164
1207
|
// client-side. Runs arrive newest-first within a flow (server contract,
|
|
1165
1208
|
// listRuns), so the first run seen for a flow is its latest.
|
|
1209
|
+
// The words for a run row's spend and time cells — the Workflows card (a flow's latest run) and
|
|
1210
|
+
// every History/expanded row say the same thing, from the same server fields.
|
|
1211
|
+
function runSpendText(r){
|
|
1212
|
+
return r.spend || r.spendWhy || "unknown";
|
|
1213
|
+
}
|
|
1214
|
+
function runAtText(r){
|
|
1215
|
+
return r.at ? r.at.slice(0,10) : (r.askedAt ? "asked " + readableDateTime(r.askedAt) : (r.startedAt ? "started " + readableDateTime(r.startedAt) : (r.atWhy || "unknown")));
|
|
1216
|
+
}
|
|
1166
1217
|
function groupRunsByFlow(runs){
|
|
1167
1218
|
var byFlow = {};
|
|
1168
1219
|
var order = [];
|
|
@@ -1178,10 +1229,8 @@
|
|
|
1178
1229
|
runs: flowRuns,
|
|
1179
1230
|
runCount: last.runId === null ? 0 : flowRuns.length,
|
|
1180
1231
|
lastRunId: last.runId,
|
|
1181
|
-
lastAt: last.at,
|
|
1182
1232
|
lastGlyph: last.glyph,
|
|
1183
1233
|
lastLabel: last.label,
|
|
1184
|
-
lastSpend: last.spend,
|
|
1185
1234
|
lastRow: last,
|
|
1186
1235
|
};
|
|
1187
1236
|
});
|
|
@@ -1285,21 +1334,19 @@
|
|
|
1285
1334
|
row.setAttribute("aria-pressed", isSelected ? "true" : "false");
|
|
1286
1335
|
var wfFullName = g.flow + ' (' + g.lastRunId + ')';
|
|
1287
1336
|
row.innerHTML =
|
|
1288
|
-
'<span class="wf-line1"><span class="wf-caret">' + (hasOtherRuns ? (expanded ? "▼" : "▶") : "") + '</span><span class="
|
|
1337
|
+
'<span class="wf-line1"><span class="wf-caret">' + (hasOtherRuns ? (expanded ? "▼" : "▶") : "") + '</span><span class="' + dotClass(g.lastGlyph, g.lastRow.pulse) + '"></span>' +
|
|
1289
1338
|
'<span class="wf-name" title="' + escapeXml(wfFullName) + '">' + escapeXml(wfFullName) + '</span></span>' +
|
|
1290
1339
|
'<span class="wf-meta-line">' +
|
|
1291
1340
|
'<span class="wf-meta">' + escapeXml(g.lastLabel || "unknown") + '</span>' +
|
|
1292
|
-
'<span class="wf-meta">' + escapeXml(g.
|
|
1293
|
-
'<span class="wf-meta">' + escapeXml(g.
|
|
1341
|
+
'<span class="wf-meta">' + escapeXml(runSpendText(g.lastRow)) + '</span>' +
|
|
1342
|
+
'<span class="wf-meta">' + escapeXml(runAtText(g.lastRow)) + '</span>' +
|
|
1294
1343
|
'<span class="wf-meta">' + g.runCount + ' run' + (g.runCount === 1 ? '' : 's') + '</span>' +
|
|
1295
1344
|
'</span>';
|
|
1296
1345
|
row.addEventListener("click", function(){
|
|
1297
1346
|
// a single-run flow has nothing to expand — the click still opens
|
|
1298
1347
|
// the run, it just never toggles `wfExpanded` for it.
|
|
1299
1348
|
if(hasOtherRuns) wfExpanded[g.flow] = !expanded;
|
|
1300
|
-
|
|
1301
|
-
document.getElementById("tab-run").click();
|
|
1302
|
-
scrollRunIntoViewMobile();
|
|
1349
|
+
openRunFromRuns(g.runs.filter(function(x){ return x.runId === targetRunId; })[0] || g.lastRow, null);
|
|
1303
1350
|
renderWorkflows(flows);
|
|
1304
1351
|
});
|
|
1305
1352
|
row.addEventListener("keydown", function(e){ if(e.key === "Enter" || e.key === " "){ e.preventDefault(); row.click(); } });
|
|
@@ -1320,9 +1367,8 @@
|
|
|
1320
1367
|
// the Workflows tab (filters by each flow's OWN latest-run fields).
|
|
1321
1368
|
// bareloop's checkType (deterministic/rubric) chips are dropped — fwdloop
|
|
1322
1369
|
// has no such concept; the result chips use fwdloop's own glyph
|
|
1323
|
-
// vocabulary ([✓]/[✗]/[·]/[?] — `[▶]`
|
|
1324
|
-
//
|
|
1325
|
-
// for a state the books can't produce).
|
|
1370
|
+
// vocabulary ([✓]/[✗]/[·]/[▶]/[?] — `[▶]` running is known from M4c's pid
|
|
1371
|
+
// rows, src/liveness.js).
|
|
1326
1372
|
function filterBarHTML(scope){
|
|
1327
1373
|
return (
|
|
1328
1374
|
'<div class="filterbar" data-scope="' + scope + '" data-testid="' + scope + '-filters">' +
|
|
@@ -1332,7 +1378,8 @@
|
|
|
1332
1378
|
'<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>' +
|
|
1333
1379
|
'<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>' +
|
|
1334
1380
|
'<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>' +
|
|
1335
|
-
'<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[
|
|
1381
|
+
'<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[▶]" title="running" data-testid="chip-' + scope + '-res-running">▶</button>' +
|
|
1382
|
+
'<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="result" data-filter-value="[?]" title="died or unknown" data-testid="chip-' + scope + '-res-unknown">?</button>' +
|
|
1336
1383
|
'<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>' +
|
|
1337
1384
|
'<button class="chip fchip" type="button" aria-pressed="false" data-filter-group="time" data-filter-value="30d" title="last 30 days" data-testid="chip-' + scope + '-time-30d">30d</button>' +
|
|
1338
1385
|
'<button class="chip fchip" type="button" aria-pressed="true" data-filter-group="time" data-filter-value="all" title="all time" data-testid="chip-' + scope + '-time-all">all</button>' +
|
|
@@ -1555,14 +1602,14 @@
|
|
|
1555
1602
|
var date = document.getElementById("active-wf-date");
|
|
1556
1603
|
|
|
1557
1604
|
name.textContent = detail.flow + " (" + detail.runId + ")";
|
|
1558
|
-
dot.className =
|
|
1605
|
+
dot.className = dotClass(detail.glyph, detail.pulse);
|
|
1559
1606
|
verdict.textContent = detail.label || "unknown";
|
|
1560
1607
|
// browser re-walk bug #4: this is the DATE field — it must use its own
|
|
1561
1608
|
// why (`detail.atWhy`), never `detail.outcomeWhy` (a different book
|
|
1562
1609
|
// fact borrowed by mistake). A parked run's ask.json `askedAt` is a
|
|
1563
1610
|
// real timestamp the books hold, shown ahead of any generic why text.
|
|
1564
1611
|
date.textContent = detail.at ? readableDateTime(detail.at)
|
|
1565
|
-
: (detail.askedAt ? "asked " + readableDateTime(detail.askedAt) : (detail.atWhy || "unknown"));
|
|
1612
|
+
: (detail.askedAt ? "asked " + readableDateTime(detail.askedAt) : (detail.startedAt ? "started " + readableDateTime(detail.startedAt) : (detail.atWhy || "unknown")));
|
|
1566
1613
|
|
|
1567
1614
|
document.getElementById("run-empty").hidden = true;
|
|
1568
1615
|
document.getElementById("run-content").hidden = false;
|
|
@@ -1571,13 +1618,13 @@
|
|
|
1571
1618
|
// wallMs (never derived/guessed) — a died/parked run or one whose
|
|
1572
1619
|
// history row predates the field both say why instead (fix #5).
|
|
1573
1620
|
var capText = typeof detail.capUsd === "number" ? ("$" + detail.capUsd.toFixed(2)) : "unknown";
|
|
1574
|
-
var spendText = detail.spend || "unknown — no spend recorded yet";
|
|
1621
|
+
var spendText = detail.spend || (detail.glyph === "[▶]" ? "no priced spend yet" : "unknown — no spend recorded yet");
|
|
1575
1622
|
var wallText = typeof detail.wallMs === "number" ? ("took " + duration(detail.wallMs)) : (detail.wallMsWhy || "wall time unknown");
|
|
1576
1623
|
document.getElementById("run-counters").innerHTML =
|
|
1577
1624
|
escapeXml(spendText) + " of " + escapeXml(capText) + " cap · " + escapeXml(wallText);
|
|
1578
1625
|
|
|
1579
1626
|
var box = document.getElementById("run-summary");
|
|
1580
|
-
box.className = "summary-box " + (detail.glyph === "[✗]" ? "red" : (detail.glyph === "[·]" ? "amber" : (detail.glyph === "[?]" ? "magenta" : "")));
|
|
1627
|
+
box.className = "summary-box " + (detail.glyph === "[✗]" ? "red" : ((detail.glyph === "[·]" || detail.glyph === "[▶]" || detail.glyph === "[II]") ? "amber" : (detail.glyph === "[?]" ? "magenta" : "")));
|
|
1581
1628
|
var stepBoxes = buildStepBoxes(detail.steps);
|
|
1582
1629
|
var stepsDone = stepBoxes.filter(function(s){ return s.state === "done"; }).length;
|
|
1583
1630
|
var stepsText = stepBoxes.length === 0
|
|
@@ -1593,7 +1640,7 @@
|
|
|
1593
1640
|
var modelText = detail.model || (detail.modelWhy || "no model call recorded yet");
|
|
1594
1641
|
var closeText = closeClassSummaryText(detail.steps) || (detail.stepsWhy || "no steps recorded");
|
|
1595
1642
|
box.innerHTML =
|
|
1596
|
-
'<div class="summary-headline"><span class="
|
|
1643
|
+
'<div class="summary-headline"><span class="' + dotClass(detail.glyph, detail.pulse) + '"></span><b>' + escapeXml(detail.label || "unknown") + '</b> · <span class="num">' + escapeXml(spendText) + '</span></div>' +
|
|
1597
1644
|
'<div class="summary-row" data-testid="summary-model"><span class="sum-label">model:</span><span class="sum-val">' + escapeXml(modelText) + '</span></div>' +
|
|
1598
1645
|
'<div class="summary-row"><span class="sum-label">steps:</span><span class="sum-val">' + stepsText + '</span></div>' +
|
|
1599
1646
|
'<div class="summary-row" data-testid="summary-why"><span class="sum-label">why:</span><span class="sum-val">' + escapeXml(detail.stopReason || detail.stopReasonWhy || "not recorded") + '</span></div>' +
|
|
@@ -2075,6 +2122,39 @@
|
|
|
2075
2122
|
// ---- selection + loading ----
|
|
2076
2123
|
var currentFlow = null;
|
|
2077
2124
|
var currentRunId = null;
|
|
2125
|
+
// The ask the last click named (null = none): an Inbox row is "selected" only when its own
|
|
2126
|
+
// flow, run AND ask match, so two stops of one run never both light up.
|
|
2127
|
+
var currentAskId = null;
|
|
2128
|
+
// borrowed-from: bareloop src/panel/index.html@0a45f40 (sig / withScrollPreserved), adjusted to fwdloop's shape
|
|
2129
|
+
// One last-payload signature per render. Equal payload = the DOM is not touched. `selectRun` resets
|
|
2130
|
+
// the ones a different selection invalidates.
|
|
2131
|
+
var lastSig = { inbox: null, runs: null, detail: null, asks: null, audit: null };
|
|
2132
|
+
function sig(obj){
|
|
2133
|
+
try { return JSON.stringify(obj); } catch(e){ return null; }
|
|
2134
|
+
}
|
|
2135
|
+
// Saves/restores scrollTop of the given element ids around a re-render.
|
|
2136
|
+
function withScrollPreserved(ids, fn){
|
|
2137
|
+
var saved = ids.map(function(id){
|
|
2138
|
+
var el = document.getElementById(id);
|
|
2139
|
+
return el ? el.scrollTop : null;
|
|
2140
|
+
});
|
|
2141
|
+
fn();
|
|
2142
|
+
ids.forEach(function(id, i){
|
|
2143
|
+
if(saved[i] === null) return;
|
|
2144
|
+
var el = document.getElementById(id);
|
|
2145
|
+
if(el) el.scrollTop = saved[i];
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
// If keyboard focus sits on a row inside `listEl`, put it back on the rebuilt row with the same
|
|
2149
|
+
// data-testid. Lookup is by attribute equality (never a selector built from ids).
|
|
2150
|
+
function withFocusPreserved(listEl, fn){
|
|
2151
|
+
var a = document.activeElement;
|
|
2152
|
+
var id = (a && a !== listEl && listEl.contains && listEl.contains(a) && a.getAttribute) ? a.getAttribute("data-testid") : null;
|
|
2153
|
+
fn();
|
|
2154
|
+
if(!id) return;
|
|
2155
|
+
var again = Array.prototype.find.call(listEl.querySelectorAll("[data-testid]"), function(el){ return el.getAttribute("data-testid") === id; });
|
|
2156
|
+
if(again && again.focus) again.focus();
|
|
2157
|
+
}
|
|
2078
2158
|
// `focusAskId` (M4a-1): when a click on an Inbox stop calls `selectRun`,
|
|
2079
2159
|
// it names the ONE ask that stop is about — `renderAsk` expands exactly
|
|
2080
2160
|
// that ask and scrolls it into view, rather than whatever this run's
|
|
@@ -2085,6 +2165,10 @@
|
|
|
2085
2165
|
if(rowEl){ rowEl.classList.add("selected"); rowEl.setAttribute("aria-pressed","true"); }
|
|
2086
2166
|
currentFlow = flow;
|
|
2087
2167
|
currentRunId = runId;
|
|
2168
|
+
currentAskId = focusAskId || null;
|
|
2169
|
+
openRunLive = true; // unknown until this run's own detail says it is finished
|
|
2170
|
+
// a different selection: every payload-equality skip for the selection's own panes is void
|
|
2171
|
+
lastSig.runs = lastSig.detail = lastSig.asks = lastSig.audit = null;
|
|
2088
2172
|
var base = "/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId);
|
|
2089
2173
|
// detail, audit, job, and asks each load independently — the Run tab's
|
|
2090
2174
|
// step cards get everything they need (including a step's own attempt-
|
|
@@ -2092,7 +2176,7 @@
|
|
|
2092
2176
|
// src/panel/data.js works out the boundary server-side, off the run's
|
|
2093
2177
|
// full audit-row order, so the client no longer needs a second,
|
|
2094
2178
|
// separately-fetched copy of the audit rows to cross-reference (fix #6).
|
|
2095
|
-
getJSON(base).then(
|
|
2179
|
+
getJSON(base).then(paintRun).catch(function(e){
|
|
2096
2180
|
document.getElementById("run-empty").hidden = false;
|
|
2097
2181
|
document.getElementById("run-empty").textContent = "failed to load run: " + e.message;
|
|
2098
2182
|
document.getElementById("run-content").hidden = true;
|
|
@@ -2104,26 +2188,97 @@
|
|
|
2104
2188
|
});
|
|
2105
2189
|
}
|
|
2106
2190
|
|
|
2107
|
-
// ---- M4b piece 4
|
|
2108
|
-
//
|
|
2109
|
-
//
|
|
2110
|
-
//
|
|
2111
|
-
//
|
|
2112
|
-
//
|
|
2191
|
+
// ---- The ONE refresh loop (M4b piece 4, widened by the M4c exit walk). The page used to load
|
|
2192
|
+
// once, so a run that parked after load kept `[▶]`, Inbox stayed (0) and the run header kept its
|
|
2193
|
+
// first words. Now `pageTick` runs every LIVE_POLL_MS for the whole life of the page: it re-reads
|
|
2194
|
+
// the Runs list, History/Workflows, the Inbox list + (N), and the selected run's detail, asks and
|
|
2195
|
+
// audit — all through the SAME render functions, so the same guards hold (`holdAskRender` never
|
|
2196
|
+
// redraws over a typed reason; a refusal lives in `answerMsg` and is repainted). `startLive` no
|
|
2197
|
+
// longer owns a timer: it only names the answer being watched, and the tick judges it from the
|
|
2198
|
+
// books it just read (`liveOutcome`), up to LIVE_MAX_MS. `reloadRun` is also called straight
|
|
2199
|
+
// after an answer POST. Success is only ever said from what this reads. ----
|
|
2113
2200
|
var LIVE_POLL_MS = 2000;
|
|
2201
|
+
// borrowed-from: bareloop src/panel/index.html@0a45f40 (RUNS_LIST_POLL_MS throttle inside the one tick), adjusted:
|
|
2202
|
+
// the open run's own panes keep the 2 s tick (only while that run is live); the Inbox and Runs lists
|
|
2203
|
+
// refresh at most every LISTS_POLL_MS. ONE timer: the throttle lives in `pageTick`, never a second timer.
|
|
2204
|
+
var LISTS_POLL_MS = 10000;
|
|
2114
2205
|
var LIVE_MAX_MS = 5 * 60 * 1000;
|
|
2115
|
-
var live = null; // { flow, runId, askId, until,
|
|
2116
|
-
|
|
2206
|
+
var live = null; // { flow, runId, askId, until } — the answer being watched, if any
|
|
2207
|
+
var pollTimer = null;
|
|
2208
|
+
var lastListsAt = 0; // when the lists were last asked for (any caller)
|
|
2209
|
+
var openRunLive = true; // is the open run still changing? (true until its detail says otherwise)
|
|
2210
|
+
var wasHidden = false;
|
|
2211
|
+
// One writer of `openRunLive`: every paint of the open run's detail goes through here.
|
|
2212
|
+
function paintRun(d){
|
|
2213
|
+
openRunLive = !(d && (d.glyph === "[\u2713]" || d.glyph === "[\u2717]"));
|
|
2214
|
+
var next = sig(d);
|
|
2215
|
+
if(next !== null && next === lastSig.detail) return;
|
|
2216
|
+
lastSig.detail = next;
|
|
2217
|
+
withScrollPreserved(["right-pane-body"], function(){ renderRun(d); });
|
|
2218
|
+
}
|
|
2219
|
+
// Immediate (every user action that re-reads calls this); the tick uses `listsDue` to throttle.
|
|
2220
|
+
function reloadLists(){
|
|
2221
|
+
lastListsAt = Date.now();
|
|
2222
|
+
getJSON("/api/inbox").then(function(r){ renderInbox(r.rows || [], r.openCount); }).catch(function(){});
|
|
2223
|
+
getJSON("/api/runs").then(function(r){
|
|
2224
|
+
var rows = r.rows || [];
|
|
2225
|
+
var next = sig(rows);
|
|
2226
|
+
if(next !== null && next === lastSig.runs) return;
|
|
2227
|
+
lastSig.runs = next;
|
|
2228
|
+
withScrollPreserved(["left-pane-body"], function(){ runsFilterBar.setItems(rows); runsFilterBar.refresh(); });
|
|
2229
|
+
}).catch(function(){});
|
|
2230
|
+
}
|
|
2231
|
+
function reloadRun(flow, runId, skipLists){
|
|
2117
2232
|
var base = "/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId);
|
|
2118
2233
|
var still = function(){ return currentFlow === flow && currentRunId === runId; };
|
|
2119
|
-
var detailP = getJSON(base).then(function(d){ if(still())
|
|
2120
|
-
var asksP = getJSON(base + "/asks").then(function(a){
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2234
|
+
var detailP = getJSON(base).then(function(d){ if(still()) paintRun(d); return d; }).catch(function(){ return null; });
|
|
2235
|
+
var asksP = getJSON(base + "/asks").then(function(a){
|
|
2236
|
+
if(still()){
|
|
2237
|
+
// the Ask tab is drawn from the books AND the page's own pending answer ("working…" block)
|
|
2238
|
+
var next = sig({ asks: a, pending: pendingAnswer });
|
|
2239
|
+
// the signature is stamped only when renderAsk REALLY drew (it returns false when held over a typed
|
|
2240
|
+
// reason): a held redraw leaves the stamp unset, so the next tick retries it against the same payload
|
|
2241
|
+
if(next === null || next !== lastSig.asks){ lastSig.asks = renderAsk(a, null) ? next : null; }
|
|
2242
|
+
}
|
|
2243
|
+
return a;
|
|
2244
|
+
}).catch(function(e){ if(still()){ lastSig.asks = null; renderAsk(null, null, e.message); } return null; });
|
|
2245
|
+
getJSON(base + "/audit").then(function(a){
|
|
2246
|
+
if(!still()) return;
|
|
2247
|
+
var next = sig(a);
|
|
2248
|
+
if(next !== null && next === lastSig.audit) return;
|
|
2249
|
+
lastSig.audit = next;
|
|
2250
|
+
renderAudit(a);
|
|
2251
|
+
}).catch(function(){});
|
|
2252
|
+
if(!skipLists) reloadLists();
|
|
2124
2253
|
return Promise.all([detailP, asksP]);
|
|
2125
2254
|
}
|
|
2126
|
-
function
|
|
2255
|
+
function schedulePoll(ms){ clearTimeout(pollTimer); pollTimer = setTimeout(pageTick, ms); }
|
|
2256
|
+
function pageTick(){
|
|
2257
|
+
pollTimer = null;
|
|
2258
|
+
if(document.hidden){ wasHidden = true; schedulePoll(LIVE_POLL_MS); return; }
|
|
2259
|
+
var catchUp = wasHidden; // first tick after the tab came back: force both
|
|
2260
|
+
wasHidden = false;
|
|
2261
|
+
var watch = live;
|
|
2262
|
+
var sel = currentFlow !== null && currentRunId !== null;
|
|
2263
|
+
var watchIsSelected = watch && sel && watch.flow === currentFlow && watch.runId === currentRunId;
|
|
2264
|
+
var listsDue = catchUp || (Date.now() - lastListsAt) >= LISTS_POLL_MS;
|
|
2265
|
+
var wasLive = openRunLive;
|
|
2266
|
+
var selP;
|
|
2267
|
+
// the open run's own panes: every tick, but only while it is live (or being watched), or on catch-up
|
|
2268
|
+
if(sel && (openRunLive || watchIsSelected || catchUp)) selP = reloadRun(currentFlow, currentRunId, true);
|
|
2269
|
+
else selP = Promise.resolve([null, null]);
|
|
2270
|
+
if(listsDue) reloadLists();
|
|
2271
|
+
// the watched run, when it is not the one on screen: read it for its outcome only (no paint — `still()` is false)
|
|
2272
|
+
var watchP = (watch && !watchIsSelected) ? reloadRun(watch.flow, watch.runId, true) : selP;
|
|
2273
|
+
watchP.then(function(res){
|
|
2274
|
+
if(watch && live === watch) watchStep(watch, res);
|
|
2275
|
+
}).catch(function(){}).then(function(){
|
|
2276
|
+
// the open run just stopped being live: its list glyph must not wait up to LISTS_POLL_MS
|
|
2277
|
+
if(sel && wasLive && !openRunLive && !listsDue) reloadLists();
|
|
2278
|
+
if(!pollTimer) schedulePoll(LIVE_POLL_MS);
|
|
2279
|
+
});
|
|
2280
|
+
}
|
|
2281
|
+
function stopLive(){ live = null; }
|
|
2127
2282
|
// What the books say now, in words (pure; `null` = keep waiting).
|
|
2128
2283
|
function liveOutcome(askId, detail, asks){
|
|
2129
2284
|
if(asks && asks.resume && asks.resume.state === "not-started") return { done: true, cls: null, text: null };
|
|
@@ -2136,27 +2291,38 @@
|
|
|
2136
2291
|
var st = asks && asks.resume ? asks.resume.label : null;
|
|
2137
2292
|
return { done: false, cls: "info", text: (st || "answer applied") + " — run: " + ((detail && detail.label) || "state unknown") };
|
|
2138
2293
|
}
|
|
2294
|
+
// A watch outcome never overwrites a refusal the human has not yet clicked past (M4c item 7).
|
|
2295
|
+
function sayLive(flow, runId, o){
|
|
2296
|
+
if(answerMsg && answerMsg.cls === "refused") return;
|
|
2297
|
+
if(o.text) say(flow, runId, o.cls, o.text);
|
|
2298
|
+
else if(o.done){ answerMsg = null; paintAnswerMsg(); }
|
|
2299
|
+
}
|
|
2300
|
+
// The books showed the next state (or the watch gave up): the "working…" block ends and the Ask tab
|
|
2301
|
+
// is drawn from what the books say now. Uses the SAME renderAsk guard as every refresh.
|
|
2302
|
+
function endPending(flow, runId, asks){
|
|
2303
|
+
if(!pendingAnswer) return;
|
|
2304
|
+
pendingAnswer = null;
|
|
2305
|
+
if(currentFlow === flow && currentRunId === runId && asks) renderAsk(asks, null);
|
|
2306
|
+
}
|
|
2139
2307
|
function startLive(flow, runId, askId){
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
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
|
-
});
|
|
2308
|
+
live = { flow: flow, runId: runId, askId: askId, until: Date.now() + LIVE_MAX_MS };
|
|
2309
|
+
schedulePoll(600);
|
|
2310
|
+
}
|
|
2311
|
+
function watchStep(mine, res){
|
|
2312
|
+
var o = liveOutcome(mine.askId, res[0], res[1]);
|
|
2313
|
+
sayLive(mine.flow, mine.runId, o);
|
|
2314
|
+
if(o.done){ endPending(mine.flow, mine.runId, res[1]); stopLive(); return; }
|
|
2315
|
+
if(Date.now() > mine.until){
|
|
2316
|
+
say(mine.flow, mine.runId, "info", "no outcome after " + Math.round(LIVE_MAX_MS / 60000) + " minutes of watching — reload the page to check the run's books");
|
|
2317
|
+
endPending(mine.flow, mine.runId, res[1]);
|
|
2318
|
+
stopLive();
|
|
2157
2319
|
}
|
|
2158
|
-
mine.timer = setTimeout(tick, 600);
|
|
2159
2320
|
}
|
|
2321
|
+
schedulePoll(LIVE_POLL_MS);
|
|
2322
|
+
// Back on the tab: one catch-up tick now (forcing both rates) instead of waiting out the 2 s beat.
|
|
2323
|
+
document.addEventListener("visibilitychange", function(){
|
|
2324
|
+
if(!document.hidden){ wasHidden = true; schedulePoll(0); }
|
|
2325
|
+
});
|
|
2160
2326
|
|
|
2161
2327
|
getJSON("/api/runs").then(function(result){
|
|
2162
2328
|
var runs = result.rows || [];
|
|
@@ -2199,6 +2365,8 @@
|
|
|
2199
2365
|
// Ask tab, focused on that one ask. The answer doors live in the Ask tab. --
|
|
2200
2366
|
function stopStatusLine(row){
|
|
2201
2367
|
if(row.waiting) return "time left: " + duration(row.timeLeftMs);
|
|
2368
|
+
if(row.stuck) return row.stuckLabel;
|
|
2369
|
+
if(row.working) return "working on your " + row.working + "…";
|
|
2202
2370
|
if(row.open && row.resume) return row.resume.label;
|
|
2203
2371
|
var bits = [row.status];
|
|
2204
2372
|
if(row.reason) bits.push("reason: " + row.reason);
|
|
@@ -2208,17 +2376,29 @@
|
|
|
2208
2376
|
}
|
|
2209
2377
|
function renderStopRow(row){
|
|
2210
2378
|
var wrap = document.createElement("div");
|
|
2211
|
-
wrap.className = "hist-row inbox-row";
|
|
2379
|
+
wrap.className = "hist-row inbox-row s" + row.section;
|
|
2212
2380
|
wrap.setAttribute("role", "button");
|
|
2213
2381
|
wrap.setAttribute("tabindex", "0");
|
|
2214
|
-
|
|
2382
|
+
// Selected is derived here, off the page's own selection (flow + run + ask), so a rebuild keeps it.
|
|
2383
|
+
var selected = row.flow === currentFlow && row.runId === currentRunId && (row.askId || null) === currentAskId;
|
|
2384
|
+
if(selected) wrap.className += " selected";
|
|
2385
|
+
wrap.setAttribute("aria-pressed", selected ? "true" : "false");
|
|
2215
2386
|
wrap.setAttribute("data-testid", "inbox-row-" + row.flow + "-" + row.runId + (row.askId ? "-" + row.askId : ""));
|
|
2216
2387
|
var head = document.createElement("div");
|
|
2217
2388
|
head.className = "wf-line1";
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2389
|
+
// section 1: [·] waiting on you (pulses); section 2 working: [▶] (pulses);
|
|
2390
|
+
// a stuck run (answer saved, nobody carrying it on): [II] pulses, in section 1;
|
|
2391
|
+
// resume starting: [·] still; section 3: the status word.
|
|
2392
|
+
if(row.section === 1 || row.working || row.resume){
|
|
2393
|
+
var sign = document.createElement("span");
|
|
2394
|
+
sign.className = "dot " + (row.working ? "amber pulse" : (row.stuck ? "stuck pulse" : (row.waiting ? "grey pulse" : "grey")));
|
|
2395
|
+
head.appendChild(sign);
|
|
2396
|
+
} else {
|
|
2397
|
+
var badge = document.createElement("span");
|
|
2398
|
+
badge.className = "badge " + (row.status === "accepted" ? "green" : (row.status === "redo" ? "red" : "grey"));
|
|
2399
|
+
badge.textContent = row.status;
|
|
2400
|
+
head.appendChild(badge);
|
|
2401
|
+
}
|
|
2222
2402
|
var flowName = textDiv(null, row.flow + " (" + row.runId + ")");
|
|
2223
2403
|
flowName.className = "wf-name";
|
|
2224
2404
|
head.appendChild(flowName);
|
|
@@ -2239,19 +2419,33 @@
|
|
|
2239
2419
|
});
|
|
2240
2420
|
return wrap;
|
|
2241
2421
|
}
|
|
2242
|
-
|
|
2422
|
+
var INBOX_HEADS = { 1: "waiting on you", 2: "working on your answer", 3: "answered and expired" };
|
|
2423
|
+
// N comes from the server (data.js inboxOpenCount); the page only shows it.
|
|
2424
|
+
function renderInbox(rows, openCount){
|
|
2243
2425
|
var el = document.getElementById("inbox-list");
|
|
2426
|
+
var next = sig({ rows: rows, openCount: openCount });
|
|
2427
|
+
if(next !== null && next === lastSig.inbox) return; // unchanged payload — never rebuild the DOM for nothing
|
|
2428
|
+
lastSig.inbox = next;
|
|
2429
|
+
withScrollPreserved(["left-pane-body"], function(){ withFocusPreserved(el, function(){ buildInbox(el, rows, openCount); }); });
|
|
2430
|
+
}
|
|
2431
|
+
function buildInbox(el, rows, openCount){
|
|
2244
2432
|
el.innerHTML = "";
|
|
2245
|
-
|
|
2246
|
-
(rows || []).forEach(function(r){ if(r.waiting) openCount += 1; });
|
|
2247
|
-
document.getElementById("inbox-count-label").textContent = openCount > 0 ? (" (" + openCount + ")") : "";
|
|
2433
|
+
document.getElementById("inbox-count-label").textContent = " (" + (typeof openCount === "number" ? openCount : 0) + ")";
|
|
2248
2434
|
if(!rows || !rows.length){
|
|
2249
2435
|
el.innerHTML = '<div class="hint">nothing waiting on you — no stops recorded under this root</div>';
|
|
2250
2436
|
return;
|
|
2251
2437
|
}
|
|
2252
|
-
|
|
2438
|
+
var lastSection = 0;
|
|
2439
|
+
rows.forEach(function(row){
|
|
2440
|
+
if(row.section !== lastSection){
|
|
2441
|
+
lastSection = row.section;
|
|
2442
|
+
el.appendChild(textDiv("inbox-h", INBOX_HEADS[row.section] || ""));
|
|
2443
|
+
}
|
|
2444
|
+
el.appendChild(renderStopRow(row));
|
|
2445
|
+
});
|
|
2253
2446
|
}
|
|
2254
|
-
getJSON("/api/inbox").then(function(result){ renderInbox(result.rows || []); }).catch(function(e){
|
|
2447
|
+
getJSON("/api/inbox").then(function(result){ renderInbox(result.rows || [], result.openCount); }).catch(function(e){
|
|
2448
|
+
lastSig.inbox = null;
|
|
2255
2449
|
document.getElementById("inbox-list").innerHTML = '<div class="hint">failed to load: ' + escapeXml(e.message) + '</div>';
|
|
2256
2450
|
});
|
|
2257
2451
|
|
|
@@ -2266,7 +2460,8 @@
|
|
|
2266
2460
|
// own SVG nodes elsewhere on this page. ----
|
|
2267
2461
|
function askStatusBlock(ask){
|
|
2268
2462
|
if(ask.waiting) return textDiv("wf-meta", "time left: " + duration(ask.timeLeftMs));
|
|
2269
|
-
|
|
2463
|
+
// an open ask with a saved answer: the header meta line already says the resume label (stuck or starting) — once.
|
|
2464
|
+
if(ask.open && ask.resume) return null;
|
|
2270
2465
|
var bits = [ask.status];
|
|
2271
2466
|
if(ask.reason) bits.push("reason: " + ask.reason);
|
|
2272
2467
|
if(ask.answeredAt) bits.push("answered " + (readableDateTime(ask.answeredAt) || ask.answeredAt));
|
|
@@ -2277,7 +2472,18 @@
|
|
|
2277
2472
|
// never decides that a reason is "good enough". ----
|
|
2278
2473
|
// Pure: which controls does this ask get? `resume` is the run's own
|
|
2279
2474
|
// `resume` field (src/panel/data.js deriveResumeState), never guessed here.
|
|
2280
|
-
|
|
2475
|
+
// `pending` (M4c item 6) = the answer this page just sent and got a 202 for,
|
|
2476
|
+
// for THIS ask: until the books show the next state there are no doors, only
|
|
2477
|
+
// what is happening. Null when nothing was sent (or the send was refused).
|
|
2478
|
+
function pendingText(p){
|
|
2479
|
+
if(p.decision === "redo") return "working on your redo… draft " + (p.draftNo + 1) + " is coming";
|
|
2480
|
+
if(p.decision === "accept") return "shipping draft " + p.draftNo + "…";
|
|
2481
|
+
return "ending this run, starting a fresh one…";
|
|
2482
|
+
}
|
|
2483
|
+
function answerControls(ask, resume, pending){
|
|
2484
|
+
if(pending && ask && pending.askId === ask.askId){
|
|
2485
|
+
return { kind: "working", text: pendingText(pending), why: "no answer doors: the answer was sent" };
|
|
2486
|
+
}
|
|
2281
2487
|
if(!ask || !ask.open){
|
|
2282
2488
|
return { kind: "none", why: "no answer doors: this ask is " + ((ask && ask.status) || "closed") + " — there is nothing left to answer" };
|
|
2283
2489
|
}
|
|
@@ -2286,7 +2492,7 @@
|
|
|
2286
2492
|
return { kind: "starting", label: resume.label, why: "no answer doors: this ask already has a saved answer" };
|
|
2287
2493
|
}
|
|
2288
2494
|
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" };
|
|
2495
|
+
return { kind: "stuck", label: resume.label, lockPath: resume.lockPath || null, reason: resume.reason || "no reason recorded", why: "no answer doors: this ask already has a saved answer" };
|
|
2290
2496
|
}
|
|
2291
2497
|
return { kind: "none", why: "no answer doors: " + resume.label };
|
|
2292
2498
|
}
|
|
@@ -2296,6 +2502,19 @@
|
|
|
2296
2502
|
// action. Set by `say`, never by a guess that the answer worked.
|
|
2297
2503
|
var answerMsg = null; // { flow, runId, cls: "refused"|"info", text }
|
|
2298
2504
|
var reasonDrafts = {}; // askId -> what the human has typed so far
|
|
2505
|
+
var pendingAnswer = null; // { flow, runId, askId, decision, draftNo } — set on a 202, cleared by the live watch
|
|
2506
|
+
// M4c item 7: should a periodic refresh skip re-drawing the Ask tab? Only while the
|
|
2507
|
+
// human is mid-answer (text typed, or the box focused) on an ask that is STILL
|
|
2508
|
+
// waiting in the new books — a dead ask's box never pins the page. A refusal needs no
|
|
2509
|
+
// hold: it lives in `answerMsg` and is repainted after every render, until the next click.
|
|
2510
|
+
function holdAskRender(box, result){
|
|
2511
|
+
if(!box || !(box.value !== "" || box.focused)) return false;
|
|
2512
|
+
return ((result && result.asks) || []).some(function(a){ return a.waiting && a.askId === box.askId; });
|
|
2513
|
+
}
|
|
2514
|
+
function readReasonBox(){
|
|
2515
|
+
var ta = document.querySelector("#ask-list textarea[data-testid='answer-reason']");
|
|
2516
|
+
return ta ? { askId: ta.getAttribute("data-askid"), value: ta.value, focused: document.activeElement === ta } : null;
|
|
2517
|
+
}
|
|
2299
2518
|
function say(flow, runId, cls, text){ answerMsg = { flow: flow, runId: runId, cls: cls, text: text }; paintAnswerMsg(); }
|
|
2300
2519
|
function paintAnswerMsg(){
|
|
2301
2520
|
document.querySelectorAll("[data-answer-msg]").forEach(function(el){
|
|
@@ -2325,7 +2544,8 @@
|
|
|
2325
2544
|
postJSON("/api/answer", payload).then(function(r){
|
|
2326
2545
|
if(r.status === 202 && r.body && r.body.ok){
|
|
2327
2546
|
delete reasonDrafts[ask.askId];
|
|
2328
|
-
|
|
2547
|
+
pendingAnswer = { flow: ctx.flow, runId: ctx.runId, askId: ask.askId, decision: decision, draftNo: ctx.draftNo };
|
|
2548
|
+
answerMsg = null; paintAnswerMsg();
|
|
2329
2549
|
startLive(ctx.flow, ctx.runId, ask.askId);
|
|
2330
2550
|
} else {
|
|
2331
2551
|
say(ctx.flow, ctx.runId, "refused", refusalText(r));
|
|
@@ -2362,7 +2582,7 @@
|
|
|
2362
2582
|
return b;
|
|
2363
2583
|
}
|
|
2364
2584
|
function renderAnswerBlock(ask, ctx){
|
|
2365
|
-
var model = answerControls(ask, ctx.resume);
|
|
2585
|
+
var model = answerControls(ask, ctx.resume, pendingAnswer);
|
|
2366
2586
|
var root = document.createElement("div");
|
|
2367
2587
|
root.className = "answer-doors";
|
|
2368
2588
|
root.setAttribute("data-testid", "answer-doors");
|
|
@@ -2375,6 +2595,7 @@
|
|
|
2375
2595
|
ta.id = idSafe;
|
|
2376
2596
|
ta.rows = 3;
|
|
2377
2597
|
ta.setAttribute("data-testid", "answer-reason");
|
|
2598
|
+
ta.setAttribute("data-askid", ask.askId);
|
|
2378
2599
|
ta.value = reasonDrafts[ask.askId] || "";
|
|
2379
2600
|
ta.addEventListener("input", function(){ reasonDrafts[ask.askId] = ta.value; });
|
|
2380
2601
|
root.appendChild(lab);
|
|
@@ -2387,10 +2608,20 @@
|
|
|
2387
2608
|
bar.appendChild(makeButton("Rerun", "btn-rerun", function(){ sendAnswer(root, ask, ctx, "rerun"); }));
|
|
2388
2609
|
root.appendChild(bar);
|
|
2389
2610
|
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"));
|
|
2611
|
+
} else if(model.kind === "working"){
|
|
2612
|
+
var wk = document.createElement("div");
|
|
2613
|
+
wk.className = "working-line";
|
|
2614
|
+
wk.setAttribute("data-testid", "answer-working");
|
|
2615
|
+
var wsign = document.createElement("span");
|
|
2616
|
+
wsign.className = "dot amber pulse";
|
|
2617
|
+
wk.appendChild(wsign);
|
|
2618
|
+
wk.appendChild(document.createTextNode(model.text));
|
|
2619
|
+
root.appendChild(wk);
|
|
2390
2620
|
} else if(model.kind === "starting"){
|
|
2391
2621
|
root.appendChild(textDiv("hint", model.label + " — " + model.why));
|
|
2392
2622
|
} else if(model.kind === "stuck"){
|
|
2393
2623
|
root.appendChild(textDiv("answer-msg stuck", model.label + ": " + model.reason));
|
|
2624
|
+
if(model.lockPath) root.appendChild(textDiv("hint", "lock file: " + model.lockPath));
|
|
2394
2625
|
root.appendChild(textDiv("hint", model.why + ". Trying again starts a resume only; it cannot answer."));
|
|
2395
2626
|
var bar2 = document.createElement("div");
|
|
2396
2627
|
bar2.className = "actions-row";
|
|
@@ -2423,7 +2654,7 @@
|
|
|
2423
2654
|
// bolder" — a real heading class (same weight/size/uppercase posture
|
|
2424
2655
|
// as the Job tab's own field `<label>`s), never the plain `.hint`
|
|
2425
2656
|
// style a footnote/why-text uses.
|
|
2426
|
-
ev.appendChild(textDiv("evidence-heading", "draft
|
|
2657
|
+
ev.appendChild(textDiv("evidence-heading", "draft " + ctx.draftNo));
|
|
2427
2658
|
ev.appendChild(draftEl);
|
|
2428
2659
|
} else {
|
|
2429
2660
|
ev.appendChild(textDiv("hint", evidence.why || "no draft on file"));
|
|
@@ -2447,32 +2678,50 @@
|
|
|
2447
2678
|
art.textContent = typeof u.text === "string" ? u.text : "no artifact text on file";
|
|
2448
2679
|
ev.appendChild(art);
|
|
2449
2680
|
});
|
|
2450
|
-
// M4b piece 4: the answer doors (or the reason there are none) live here.
|
|
2451
|
-
ev.appendChild(renderAnswerBlock(ask, ctx));
|
|
2452
2681
|
return ev;
|
|
2453
2682
|
}
|
|
2683
|
+
// M4c item 5: "your answers so far" — one line per answered draft, every field from
|
|
2684
|
+
// the server's block (data.js groupAskBlocks); the page only lays it out.
|
|
2685
|
+
function answerLineText(a){
|
|
2686
|
+
return "draft " + a.draft + " → " + a.decision + (a.reason ? ' "' + a.reason + '"' : "")
|
|
2687
|
+
+ (a.answeredAt ? " " + (readableDateTime(a.answeredAt) || a.answeredAt) : "");
|
|
2688
|
+
}
|
|
2689
|
+
function renderAnswersSoFar(block){
|
|
2690
|
+
var box = document.createElement("div");
|
|
2691
|
+
box.setAttribute("data-testid", "answers-so-far");
|
|
2692
|
+
if(!block.answers.length) return box;
|
|
2693
|
+
box.appendChild(textDiv("evidence-heading", "your answers so far"));
|
|
2694
|
+
block.answers.forEach(function(a){ box.appendChild(textDiv("answer-line", answerLineText(a))); });
|
|
2695
|
+
return box;
|
|
2696
|
+
}
|
|
2454
2697
|
// hamr's 2026-09-27 exit-check review #3: "when opened from an Inbox
|
|
2455
2698
|
// click it's not clear which ask is shown" — one line naming exactly
|
|
2456
|
-
// which ask this is (
|
|
2457
|
-
//
|
|
2699
|
+
// which ask line this block is (M4c: one block per signed ask line, its
|
|
2700
|
+
// draft number from src/panel/data.js's groupAskBlocks), which declared step it belongs to (`stepName`, at its
|
|
2458
2701
|
// signed prose `stepLine` — src/panel/data.js's `deriveAskStepInfo`,
|
|
2459
2702
|
// never re-derived here), when it was asked, and its status. `stepWhy` is
|
|
2460
2703
|
// shown verbatim (never a guessed step name) when the books can't name
|
|
2461
2704
|
// one — the honest word "before" a real value never invents.
|
|
2462
|
-
function
|
|
2463
|
-
var
|
|
2464
|
-
var
|
|
2465
|
-
|
|
2705
|
+
function blockMetaText(block){
|
|
2706
|
+
var ask = block.current;
|
|
2707
|
+
var bits = [];
|
|
2708
|
+
var stepBit = typeof block.stepName === "string" && block.stepName.length > 0
|
|
2709
|
+
? block.stepName + (typeof block.stepLine === "number" ? " (line " + block.stepLine + ")" : "")
|
|
2466
2710
|
: (ask.stepWhy || "step not determinable");
|
|
2467
2711
|
bits.push(stepBit);
|
|
2712
|
+
bits.push("draft " + block.draftNo);
|
|
2468
2713
|
bits.push(typeof ask.askedAt === "string" ? "asked " + (readableDateTime(ask.askedAt) || ask.askedAt) : "asked: unknown");
|
|
2469
2714
|
bits.push(ask.waiting ? "waiting on you" : (ask.open && ask.resume ? ask.resume.label : ask.status));
|
|
2470
2715
|
return bits.join(" · ");
|
|
2471
2716
|
}
|
|
2472
|
-
|
|
2717
|
+
// One block per signed ask line (M4c item 5), drawn from the server's `blocks`.
|
|
2718
|
+
function renderAskRow(block, expanded, ctx){
|
|
2719
|
+
var ask = block.current;
|
|
2720
|
+
ctx = { flow: ctx.flow, runId: ctx.runId, resume: ctx.resume, draftNo: block.draftNo };
|
|
2473
2721
|
var wrap = document.createElement("div");
|
|
2474
2722
|
wrap.className = "audit-group";
|
|
2475
|
-
wrap.setAttribute("data-testid", "ask-
|
|
2723
|
+
wrap.setAttribute("data-testid", "ask-block-" + (block.stepName || "no-step"));
|
|
2724
|
+
wrap.setAttribute("data-open", String(!!ask.open));
|
|
2476
2725
|
var head = document.createElement("div");
|
|
2477
2726
|
head.setAttribute("role", "button");
|
|
2478
2727
|
head.setAttribute("tabindex", "0");
|
|
@@ -2481,14 +2730,19 @@
|
|
|
2481
2730
|
var metaLine = document.createElement("div");
|
|
2482
2731
|
metaLine.className = "wf-line1";
|
|
2483
2732
|
var badge = document.createElement("span");
|
|
2484
|
-
|
|
2485
|
-
|
|
2733
|
+
if(ask.stuck){
|
|
2734
|
+
// the same sign as the Inbox card and run header: [II], pulsing (server-decided `stuck`, data.js getRunAsks)
|
|
2735
|
+
badge.className = "dot stuck pulse";
|
|
2736
|
+
} else {
|
|
2737
|
+
badge.className = "badge " + (ask.open ? "amber" : (ask.status === "accepted" ? "green" : (ask.status === "redo" ? "red" : "grey")));
|
|
2738
|
+
badge.textContent = ask.open ? "·" : ask.status;
|
|
2739
|
+
}
|
|
2486
2740
|
metaLine.appendChild(badge);
|
|
2487
|
-
metaLine.appendChild(textDiv("wf-meta",
|
|
2741
|
+
metaLine.appendChild(textDiv("wf-meta", blockMetaText(block)));
|
|
2488
2742
|
head.appendChild(metaLine);
|
|
2489
2743
|
// The question itself — a real, bold heading (review #3: "the question
|
|
2490
2744
|
// as a clear heading"), never folded into the same small meta line.
|
|
2491
|
-
var qText = typeof
|
|
2745
|
+
var qText = typeof block.question === "string" ? block.question : (block.questionWhy || "question not recorded");
|
|
2492
2746
|
var qHeading = document.createElement("h4");
|
|
2493
2747
|
qHeading.className = "ask-question-heading";
|
|
2494
2748
|
qHeading.textContent = qText;
|
|
@@ -2496,8 +2750,12 @@
|
|
|
2496
2750
|
wrap.appendChild(head);
|
|
2497
2751
|
var body = document.createElement("div");
|
|
2498
2752
|
body.hidden = !expanded;
|
|
2499
|
-
|
|
2753
|
+
var statusBlock = askStatusBlock(ask);
|
|
2754
|
+
if(statusBlock) body.appendChild(statusBlock);
|
|
2500
2755
|
body.appendChild(renderAskEvidenceBlock(ask, ctx));
|
|
2756
|
+
body.appendChild(renderAnswersSoFar(block));
|
|
2757
|
+
// M4b piece 4: the answer doors (or the reason there are none) — for the CURRENT draft.
|
|
2758
|
+
body.appendChild(renderAnswerBlock(ask, ctx));
|
|
2501
2759
|
wrap.appendChild(body);
|
|
2502
2760
|
function toggle(){
|
|
2503
2761
|
var next = body.hidden;
|
|
@@ -2510,33 +2768,44 @@
|
|
|
2510
2768
|
});
|
|
2511
2769
|
return wrap;
|
|
2512
2770
|
}
|
|
2771
|
+
var askDrawnFor = null; // "flow/runId" whose blocks the Ask tab last drew
|
|
2513
2772
|
function renderAsk(result, focusAskId, loadError){
|
|
2514
2773
|
var empty = document.getElementById("ask-empty");
|
|
2515
2774
|
var list = document.getElementById("ask-list");
|
|
2516
|
-
if(loadError){ empty.hidden = false; empty.textContent = "failed to load asks: " + loadError; list.hidden = true; list.innerHTML = ""; return; }
|
|
2517
|
-
if(!result){ empty.hidden = false; empty.textContent = "select a run first"; list.hidden = true; list.innerHTML = ""; return; }
|
|
2518
|
-
var
|
|
2519
|
-
if(!
|
|
2775
|
+
if(loadError){ empty.hidden = false; empty.textContent = "failed to load asks: " + loadError; list.hidden = true; list.innerHTML = ""; return true; }
|
|
2776
|
+
if(!result){ empty.hidden = false; empty.textContent = "select a run first"; list.hidden = true; list.innerHTML = ""; return true; }
|
|
2777
|
+
var blocks = result.blocks || [];
|
|
2778
|
+
if(!blocks.length){
|
|
2520
2779
|
empty.hidden = false;
|
|
2521
2780
|
empty.textContent = "this run has never parked on a human — no asks recorded";
|
|
2522
2781
|
list.hidden = true;
|
|
2523
2782
|
list.innerHTML = "";
|
|
2524
|
-
return;
|
|
2783
|
+
return true;
|
|
2525
2784
|
}
|
|
2785
|
+
// M4c item 7: never redraw over a reason being typed (every periodic refresh comes through here).
|
|
2786
|
+
// Returns false when held (nothing drawn), true after every real draw — the one signal `reloadRun` stamps on.
|
|
2787
|
+
if(!focusAskId && holdAskRender(readReasonBox(), result)) return false;
|
|
2526
2788
|
empty.hidden = true;
|
|
2527
2789
|
list.hidden = false;
|
|
2528
|
-
|
|
2529
|
-
//
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
if(openAsk) defaultOpenId = openAsk.askId;
|
|
2790
|
+
// The refresh redraws this tab every tick: a block the human opened or closed by hand keeps that
|
|
2791
|
+
// state while its own openness is unchanged (a Inbox click, `focusAskId`, resets to its default).
|
|
2792
|
+
var kept = {};
|
|
2793
|
+
if(!focusAskId && askDrawnFor === result.flow + "/" + result.runId){
|
|
2794
|
+
list.querySelectorAll("[data-testid^='ask-block-']").forEach(function(w){
|
|
2795
|
+
kept[w.getAttribute("data-testid")] = { open: w.getAttribute("data-open"), expanded: w.firstChild.getAttribute("aria-expanded") === "true" };
|
|
2796
|
+
});
|
|
2536
2797
|
}
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2798
|
+
askDrawnFor = result.flow + "/" + result.runId;
|
|
2799
|
+
list.innerHTML = "";
|
|
2800
|
+
// Default expansion: the block holding the ask a click from the Inbox
|
|
2801
|
+
// (`focusAskId`) named wins; otherwise a block with an open ask expands;
|
|
2802
|
+
// a run with a single ask line expands it; otherwise blocks stay collapsed.
|
|
2803
|
+
blocks.forEach(function(block){
|
|
2804
|
+
var ask = block.current;
|
|
2805
|
+
var expanded = focusAskId ? block.askIds.indexOf(focusAskId) !== -1 : (ask.open || blocks.length === 1);
|
|
2806
|
+
var prev = kept["ask-block-" + (block.stepName || "no-step")];
|
|
2807
|
+
if(prev && prev.open === String(!!ask.open)) expanded = prev.expanded;
|
|
2808
|
+
var row = renderAskRow(block, expanded, { flow: result.flow, runId: result.runId, resume: result.resume || null });
|
|
2540
2809
|
// hamr's 2026-09-27 exit-check review #3: "the ask opened from the
|
|
2541
2810
|
// Inbox gets a visible highlight" — a REAL Inbox click (`focusAskId`
|
|
2542
2811
|
// set) on THIS ask, never a run's own default open-ask expansion
|
|
@@ -2545,7 +2814,7 @@
|
|
|
2545
2814
|
// highlight`, this row already carries the `audit-group` class) —
|
|
2546
2815
|
// persistent here, not momentary, since the human navigated here
|
|
2547
2816
|
// specifically to see this one.
|
|
2548
|
-
if(focusAskId &&
|
|
2817
|
+
if(focusAskId && block.askIds.indexOf(focusAskId) !== -1){
|
|
2549
2818
|
row.classList.add("audit-group-highlight");
|
|
2550
2819
|
}
|
|
2551
2820
|
list.appendChild(row);
|
|
@@ -2558,6 +2827,7 @@
|
|
|
2558
2827
|
}
|
|
2559
2828
|
}
|
|
2560
2829
|
});
|
|
2830
|
+
return true;
|
|
2561
2831
|
}
|
|
2562
2832
|
|
|
2563
2833
|
// theme toggle
|